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

    $companyID = $id;

    $projectID = $_POST['interface_projectname'];

    $title =  $_POST['interface-title'];

    $stage =  $_POST['interface-stage'];

    $creationDate = date('Y-m-d');


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

        $RID = $_REQUEST['del'];



        if(mysql_query("UPDATE interfaceinitiate SET interface_status ='2' WHERE interface_plan_id = '$RID'"))

        {

            header("location: 03-InterfacePlan01-initiate01.php?msg=DELETED");

        }



        else



        {

            header("location: 03-InterfacePlan01-initiate01.php?msg=NOT DELETED");



        }



    }


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



        $briefID = $_REQUEST['Edit'];

 $q1 = "UPDATE

  `interfaceinitiate`

SET

  `interface_plan_pid` = '$projectID',

  `interface_title` = '$title',

  `interface_stage` = '$stage'


WHERE

  `interface_plan_id` = '$briefID'";

        if (mysql_query($q1)) {

            header("location: 03-InterfacePlan01-initiate01.php?msg=UPDATED");

            }

        else

        {

            header("location: 03-InterfacePlan01-initiate01.php?msg=NOT UPDATED");

        }

    }

    else if(isset($_REQUEST['InActive'])){


        $bid = $_REQUEST['InActive'];

        if(mysql_query("UPDATE interfaceinitiate SET interface_status ='0' WHERE interface_plan_id = '$bid'"))

        {

            header("location: 03-InterfacePlan01-initiate01.php?msg=HIDDEN");}



        else

        {

            header("location: 03-InterfacePlan01-initiate01.php?msg=NOT HIDDEN");

        }



    }


    else if(isset($_REQUEST['Active'])){

        $bid = $_REQUEST['Active'];

        if(mysql_query("UPDATE interfaceinitiate SET interface_status ='1' WHERE interface_plan_id = '$bid'"))

        {

            header("location: 03-InterfacePlan01-initiate01.php?msg=MADE ACTIVE");}



        else

        {

            header("location: 03-InterfacePlan01-initiate01.php?msg=NOT HIDDEN");

        }



    }

    else if(isset($_REQUEST['send'])){

        $bid = $_REQUEST['send'];

        $sub="";

        if(mysql_query("UPDATE interfaceinitiate SET review_status ='3' WHERE interface_plan_id = '$bid'"))

        {

            $result = mysql_query("SELECT  * FROM interfaceinitiate where interfaceinitiate.companyID='$id' AND interfaceinitiate.interface_plan_id='$bid'");

            $row = mysql_fetch_array($result, MYSQL_ASSOC);

            $subject = $row['interface_title'];

            $projectID = $row['interface_plan_pid'];

            $creationDate = $row['interface_creationdate'];

            //$description = $row[''];

           // $client_id = $row[''];

            //$PreparedBy = $row[''];



            // send for assign

            $sub.=	"PR - ". $bid." |  ".$subject;

            $an = $projectID;

            $description ="";

            $client_id = '';

            $PreparedBy = $_SESSION['user_id'];


            mysql_query("INSERT INTO receipt SET 

receipt_doc_date='$creationDate',

receipt_doc_subject='$sub',

receipt_archive_id='$an',

receipt_des='$description',

receipt_submitted_by='$client_id',

receipt_submitted_by_cv='',

receipt_discipline_id='',

receipt_type='Report',

receipt_initiated_by='$PreparedBy',

`receipt_fc`='0',  `receipt_fc1`='0',  `receipt_fc2`='0',  `receipt_fc3`='0',  `receipt_fc4`='0',

`receipt_fc5`='0',`receipt_fc6`='0',`receipt_fd`='0',`receipt_fsprt`='0',`receipt_fspr`='0',receipt_intimation='',

receipt_intimation_date='',

receipt_company_id='$id'");



                header("location: 03-InterfacePlan01-initiate01.php?msg=SENT: It will show in the list of documents to be assigned as an initiated document.");}



        else

        {

            header("location: 03-InterfacePlan01-initiate01.php?msg=Error on sending document");

        }



    }

    else if(mysql_query("insert into interfaceinitiate values('NULL','$projectID','$companyID', '$title', '$stage', '$ipusername', '$creationDate', 1, 1 )"))
    {
       header("location: 03-InterfacePlan01-initiate01.php?msg=INFORMATION IS SAVED");
    }

    else
    {
        header("location: 03-InterfacePlan01-initiate01.php?msg= INFORMATION IS NOT SAVED: ERROR");

    }
?>