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

if (isset($_SESSION['UserName'])) {
 
$title =  $_POST['briefname'];
$spec_master   =  $_POST['Specmf'];        
$spec_client  = $_POST['clientname'];
$spec_project =  $_POST['projname'];
$spec_preparedby = ($_SESSION['user_id']==0) ? $_SESSION['id'] : $_SESSION['user_id'];  
$date = date('Y-m-d');
$id = $_SESSION['id'];


    if (isset($_REQUEST['del'])) {
        $SID = $_REQUEST['del'];
        if (mysql_query("UPDATE specs SET `spec_status`=2 WHERE `SPECID` = '$SID'")) {
            header("location: Specs1.php?msg=DELETED");
        } else {
            header("location: Specs1.php?msg=NOT DELETED");
        }
    } else if (isset($_REQUEST['Active'])) {
        $SID = $_REQUEST['Active'];
        if (mysql_query("UPDATE specs SET `spec_status`=1 WHERE `SPECID` = '$SID'")) {
            header("location: Specs1.php?msg=ACTIVED");
        } else {
            header("location: Specs1.php?msg=NOT ACTIVED");
        }
    } else if (isset($_REQUEST['InActive'])) {
       $SID = $_REQUEST['InActive'];
        if (mysql_query("UPDATE specs SET `spec_status`=0 WHERE `SPECID` = '$SID'")) {
            header("location: Specs1.php?msg=HIDDEN");
        } else {
            header("location: Specs1.php?msg=NOT HIDDEN");
        }
    } else if (isset($_REQUEST['Edit'])) {
        $SID = $_REQUEST['Edit'];
        if (mysql_query("UPDATE specs SET `title`='$title',`spec_project`='$spec_project',`spec_client`='$spec_client',`spec_master`='$spec_master' WHERE `SPECID` = '$SID'")) {
            header("location: Specs1.php?msg=UPDATED");
        } else {
            header("location: Specs1.php?msg=NOT UPDATED");
        }
    } else {
        

        if (mysql_query("INSERT INTO specs SET `title`='$title',`spec_project`='$spec_project',`spec_client`='$spec_client',`spec_master`='$spec_master',`companyID`='$id',`dateCreated`='$date',`spec_preparedby` = '$spec_preparedby', `spec_status` = '1'")) {
            
     
            header("location: Specs1.php?msg=SAVED");
        } else {
            header("location: Specs1.php?msg=NOT SAVED");
        }
    }
} else {
    header("location: ../index.php?msg=YOU ARE NOT LOGINED");
}
?> 