<?php
include('../../includes/checkSession.php');
    $dwgcomplePercent = $_POST['complevel2'];
    $dwgType = $_POST['dwg_type'];
   // $dwgNotes = $_POST['dwglistingnotes'];
    $dwgConsultant = $_POST['consultant_id'];
    $dwgProject = $_POST['projname'];
    $phase = $_POST['phase'];
	$zone = $_POST['zone'];	
	$contract = $_POST['contract'];
	$client = $_POST['client_id'];
    $noofdwg = $_POST['noofdwg'];
    $relatedSOW = $_POST['relatedSOW'];
    $title = $_POST['title'];
    $rangefrom = $_POST['rangefrom'];
    $rangeto = $_POST['rangeto'];
    $design_type = $_POST['designtype'];
    $dwgsuffix = $_POST['dwgsuffix'];
    $Startdate = $_POST['Startdate'];
	$Startdate2 = $_POST['Startdate2'];
	$Startdate3 = $_POST['Startdate3'];
    $date = date('Y-m-d');
    $id = $_SESSION['id'];


    if (isset($_REQUEST['del'])) {
        $dwgID = $_REQUEST['del'];
        if (mysql_query("UPDATE scope_dwg SET `dwgStatus`=2 WHERE `dwgID` = '$dwgID'")) {
            header("location: 03-06Scope-01Drawings01.php?msg=DELETED");
        } else {
            header("location: 03-06Scope-01Drawings01.php?msg=NOT DELETED");
        }
    }





    else if (isset($_REQUEST['Range'])) {
        $dwgID = $_REQUEST['Range'];
        $noofdwg = $_POST['noofdwg'.$dwgID];
        $rangefrom = $_POST['rangefrom'.$dwgID];
        $rangeto = $_POST['rangeto'.$dwgID];
        $suffix = $_POST['dwgsuffix'.$dwgID];
        if (mysql_query("INSERT INTO scope_dwg_range (dwgID, no_of_dwgs, range_from, range_to, status, created_date, created_by, companyID, dwg_suffix) 
                                                      VALUES( '$dwgID', '$noofdwg', '$rangefrom', '$rangeto', '1', '$date', '$ipusername', '$id', '$suffix') ")) {
            header("location: 03-06Scope-01Drawings01.php?msg=RANGE ADDED");
        } else {
            header("location: 03-06Scope-01Drawings01.php?msg=RANGE NOT ADDED");
        }
    }
    else if (isset($_REQUEST['RemoveRange'])) {
        $rangeID = $_REQUEST['RemoveRange'];

        if (mysql_query("UPDATE scope_dwg_range SET status = '2' WHERE rangeID = '$rangeID'")) {
            header("location: 03-06Scope-01Drawings01.php?msg=RANGE REMOVED");
        } else {
            header("location: 03-06Scope-01Drawings01.php?msg=RANGE NOT REMOVED");
        }
    }






    else if (isset($_REQUEST['Active'])) {
        $dwgID = $_REQUEST['Active'];
        if (mysql_query("UPDATE scope_dwg SET `dwgStatus`=1 WHERE `dwgID` = '$dwgID'")) {
            header("location: 03-06Scope-01Drawings01.php?msg=MADE ACTIVE");
        } else {
            header("location: 03-06Scope-01Drawings01.php?msg=NOT MADE ACTIVE");
        }
    } else if (isset($_REQUEST['InActive'])) {
        $dwgID = $_REQUEST['InActive'];
        if (mysql_query("UPDATE scope_dwg SET `dwgStatus`=0 WHERE `dwgID` = '$dwgID'")) {
            header("location: 03-06Scope-01Drawings01.php?msg=HIDDEN");
        } else {
            header("location: 03-06Scope-01Drawings01.php?msg=NOT HIDDEN");
        }
    } else if (isset($_REQUEST['Edit'])) {
        $SID = $_REQUEST['Edit'];

        if (mysql_query("UPDATE scope_dwg SET "
            . "`dwgProject`='$dwgProject',"
            . "`phaseID`='$phase',"
            . "`zoneID`='$zone',"
            . "`contractID`='$contract',"
            . "`dwg_clientID`='$client',"
			. "`dwgcomplePercent`='$dwgcomplePercent',"
            . "`dwgType`='$dwgType',"
            . "`no_of_dwgs`='$noofdwg',"
            . "`range_from`='$rangefrom',"
            . "`range_to`='$rangeto',"
            . "`dwg_type`='$design_type',"
            . "`dwg_suffix`='$dwgsuffix',"
            . "`dwg_sowID`='$relatedSOW',"
            . "`dwgList_Title`='$title',"
            . "`dwg_consultantID`='$dwgConsultant',"
			. "`rDate_Start`='$Startdate2',"
			. "`rDate_End`='$Startdate3',"
            . "`Date_Started`='$Startdate'
             WHERE `dwgID` = '$SID'")) {
            header("location: 03-06Scope-01Drawings01.php?msg=UPDATED");
        } else {
            header("location: 03-06Scope-01Drawings01.php?msg=NOT UPDATED");
        }
    } else {


        if (mysql_query("INSERT INTO scope_dwg "
            . "SET `dwgProject`='$dwgProject',"
            . "`phaseID`='$phase',"
            . "`zoneID`='$zone',"
            . "`contractID`='$contract',"
            . "`dwg_clientID`='$client',"
            . "`dwgcomplePercent`='$dwgcomplePercent',"
            . "`dwgType`='$dwgType',"
            . "`no_of_dwgs`='$noofdwg',"
            . "`range_from`='$rangefrom',"
            . "`range_to`='$rangeto',"
            . "`dwg_type`='$design_type',"
            . "`dwg_suffix`='$dwgsuffix',"
            . "`Date_Started`='$Startdate',"
            . "`rDate_Start`='$Startdate2',"
            . "`rDate_End`='$Startdate3',"
            . "`dwgCompany`='$id',"
            . "`dwgDateCreated`='$date',"
            . "`dwg_sowID`='$relatedSOW',"
            . "`dwgList_Title`='$title',"
            . "`dwg_consultantID`='$dwgConsultant',"
            . "`dwgStatus` = '1'")) {


            header("location: 03-06Scope-01Drawings01.php?msg=SAVED");
        } else {
			 
            header("location: 03-06Scope-01Drawings01.php?msg=NOT SAVED");
        }
    }
?>