<?php
include('../includes/con2pma3.php');
if (isset($_SESSION['UserName'])) {
    $project_id = $_POST['projname'];
    $client_id = $_POST['clientname'];
    $brief_name = $_POST['briefname'];
    $brief_type = $_POST['brieftype'];
    $brief_create_from = $_POST['brieffrom'];
    $brief_copy_from = $_POST['brieflist'];
	$PreparedBy = ($_SESSION['user_id']==0) ? $_SESSION['id'] : $_SESSION['user_id'];    
    $date = date('Y-m-d');
    $id = $_SESSION['id'];

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

   	$bid = $_REQUEST['del'];
	if(mysql_query("UPDATE brief SET brief_status ='2' WHERE brief_id = '$bid'"))
        {
        header("location: Brief.php?msg=DELETED");}
        
        else
{
	header("location: Brief.php?msg=NOT DELETED");
}
    }
    
    if(isset($_REQUEST['Active'])){
	$bid = $_REQUEST['Active'];
	if(mysql_query("UPDATE brief SET brief_status ='1' WHERE brief_id = '$bid'"))
        {
        header("location: Brief.php?msg=ACTIVE");}
        
        else
{
	header("location: Brief.php?msg=NOT ACTIVE");
}


}
    else if(isset($_REQUEST['InActive'])){
    
	$bid = $_REQUEST['InActive'];
	if(mysql_query("UPDATE brief SET brief_status ='0' WHERE brief_id = '$bid'"))
        {
        header("location: Brief.php?msg=HIDDEN");}
        
        else
{
	header("location: Brief.php?msg=NOT HIDDEN");
}

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

        $briefID = $_REQUEST['Edit'];

        if (mysql_query("UPDATE brief SET `project_id`='$project_id',`client_id`='$client_id',`brief_name`='$brief_name',`brief_type`='$brief_type',`brief_create_from`='$brief_create_from',`brief_copy_from`='$brief_copy_from' WHERE `brief_id` = '$briefID'")) {

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

        if (mysql_query("insert into brief SET `project_id`='$project_id',`client_id`='$client_id',`brief_name`='$brief_name',`brief_type`='$brief_type',`brief_create_from`='$brief_create_from',`brief_copy_from`='$brief_copy_from',`creationDate`='$date',`CompanyID`='$id', `PreparedBy` = '$PreparedBy', `brief_status` = '1'")) {
            header("location: Brief.php?msg=SAVED");
        } else {

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