<?php
include('../../includes/checkSession.php');

    $project_id = $_POST['projname'];
    //$client_id = $_POST['clientname'];
    $pdriname = $_POST['pdriname'];
    $pdrirev = $_POST['pdrirev'];
    $preparedby = $uid;

    $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: 03-03Scope-01PDRI01.php?msg=DELETED");
    } else {
        header("location: 03-03Scope-01PDRI01.php?msg=NOT DELETED");
    }
}

elseif (isset($_REQUEST['Active'])) {
    $pdriid = $_REQUEST['Active'];
    if (mysql_query("UPDATE pdri SET pdri_status ='1' WHERE pdri_id = '$pdriid'")) {
        header("location: 03-03Scope-01PDRI01.php?msg=ACTIVE");
    } else {
        header("location: 03-03Scope-01PDRI01.php?msg=NOT ACTIVE");
    }


} elseif (isset($_REQUEST['InActive'])) {

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

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

        $pdriID = $_REQUEST['Edit'];

        if (mysql_query("UPDATE pdri SET `project_id`='$project_id',`pdri_name`='$pdriname',`pdri_PreparedBy`='$preparedby',pdri_rev='$pdrirev' WHERE `pdri_id` = '$pdriID'")) {

             header("location: 03-03Scope-01PDRI01.php?msg=UPDATED");
        } else {
             header("location: 03-03Scope-01PDRI01.php?msg=NOT UPDATED");
        }
    } else {
        

        if (mysql_query("INSERT INTO pdri SET `project_id`='$project_id',`pdri_name`='$pdriname',`pdri_PreparedBy`='$preparedby',`creationDate`='$date',`CompanyID`='$id', pdri_rev = '$pdrirev', `pdri_status` = '1'")) {
            header("location: 03-03Scope-01PDRI01.php?msg=SAVED");
        } else {

            header("location: 03-03Scope-01PDRI01.php?msg=NOT SAVED");
        }
    }

?> 