<?php
include('../includes/con2pma3.php');
if (isset($_SESSION['UserName'])) {
    $project_id = $_POST['projname'];
    $client_id = $_POST['clientname'];
    $pdriname = $_POST['pdriname'];
    $preparedby = $_POST['preparedby'];
    $checkedby = $_POST['checkedby'];
    $approvedby = $_POST['approvedby'];	   
    $date = date('Y-m-d');
    $id = $_SESSION['id'];

    if (isset($_REQUEST['del'])) {

   	$pdriid = $_REQUEST['del'];
	if(mysql_query("UPDATE pdri SET pdri_status ='2' WHERE pdri_id = '$pdriid'"))
        {
        header("location: PDRI.php?msg=DELETED");}
        
        else
{
	header("location: PDRI.php?msg=NOT DELETED");
}
    }
    
    if(isset($_REQUEST['Active'])){
	$pdriid = $_REQUEST['Active'];
	if(mysql_query("UPDATE pdri SET pdri_status ='1' WHERE pdri_id = '$pdriid'"))
        {
        header("location: PDRI.php?msg=ACTIVE");}
        
        else
{
	header("location: PDRI.php?msg=NOT ACTIVE");
}


}
    else if(isset($_REQUEST['InActive'])){
    
	$pdriid = $_REQUEST['InActive'];
	if(mysql_query("UPDATE pdri SET pdri_status ='0' WHERE pdri_id = '$pdriid'"))
        {
        header("location: PDRI.php?msg=HIDDEN");}
        
        else
{
	header("location: PDRI.php?msg=NOT HIDDEN");
}

}
    else if (isset($_REQUEST['Edit'])) {

        $pdriID = $_REQUEST['Edit'];

        if (mysql_query("UPDATE pdri SET `project_id`='$project_id',`client_id`='$client_id',`pdri_name`='$pdriname',`pdri_PreparedBy`='$preparedby',`pdri_CheckedBy`='$checkedby',`pdri_ApprovedBy`='$approvedby' WHERE `pdri_id` = '$pdriID'")) {

             header("location: PDRI.php?msg=UPDATED");
        } else {
             header("location: PDRI.php?msg=NOT UPDATED");
        }
    } else {
        

        if (mysql_query("insert into pdri SET `project_id`='$project_id',`client_id`='$client_id',`pdri_name`='$pdriname',`pdri_PreparedBy`='$preparedby',`pdri_CheckedBy`='$checkedby',`pdri_ApprovedBy`='$approvedby',`creationDate`='$date',`CompanyID`='$id', `pdri_status` = '1'")) {
            header("location: PDRI.php?msg=SAVED");
        } else {

            header("location: PDRI.php?msg=NOT SAVED");
        }
    }
} else {
    header("location: ../login.php?msg=YOU ARE NOT LOGINED");
}
?> 