<?php

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

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

include('../../includes/topmenunewest.php');


$id = $company_id = $_SESSION['id'];
$order_type = "DESC";
$order_start = "Date_Started";
if (isset($_REQUEST['otype'])) {
    $order_type = $_REQUEST['otype'];
}

if (isset($_REQUEST['opar'])) {
    $order_start = $_REQUEST['opar'];
}

?>


<html>
<head>
    <meta charset="utf-8">
    <title>pmAnywhere - Scope Module</title>
    <link href="03-00Scope-Styles0.css" rel="stylesheet" type="text/css"/>
    <script src="../includes/js/jquery.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

    <script src="02-06Scope-01Drawings01-JS.js"></script>
</head>
<style>
    .actionTD a {
        text-decoration: none;
    }
</style>
<body style="backgrond-color:#E8E8E8">
<!----------------------- Div For errors and warnings--------------------------------->

<!----------------------- Div For errors and warnings--------------------------------->

<!----------------------- Div For errors and warnings--------------------------------->
<div><h5 class="msg">
        <?php if (isset($_REQUEST["msg"])) { ?>
            <?php echo $_REQUEST["msg"]; ?>
        <?php } ?>
    </h5></div>


<script>

    function showConfirm(did) {

        if (confirm("Are you sure to delete? Press OK to Delete.")) {

            window.location.href = "03-06Scope-01Drawings01DB.php?del=" + did;

        }

    }


    function loadProjectSOW(projectID) {

        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari

            xmlhttp = new XMLHttpRequest();

        }

        else {// code for IE6, IE5

            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

        }

        xmlhttp.onreadystatechange = function () {

            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("relatedSOW").innerHTML = xmlhttp.responseText;
            }

        }

        xmlhttp.open("GET", "getProjectSOW.php?projectID=" + projectID, true);

        xmlhttp.send();


    }

    function loadProjectPhases(projectID) {

        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari

            xmlhttp = new XMLHttpRequest();

        }

        else {// code for IE6, IE5

            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

        }

        xmlhttp.onreadystatechange = function () {

            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("phase").innerHTML = xmlhttp.responseText;
                loadProjectZones(projectID);
            }

        }

        xmlhttp.open("GET", "getProjectPhases1.php?projectID=" + projectID, true);

        xmlhttp.send();


    }

    function loadProjectZones(projectID) {
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari

            xmlhttp = new XMLHttpRequest();

        }

        else {// code for IE6, IE5

            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

        }

        xmlhttp.onreadystatechange = function () {

            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("zone").innerHTML = xmlhttp.responseText;
                loadProjectContracts(projectID);

            }

        }

        xmlhttp.open("GET", "getProjectZones.php?projectID=" + projectID, true);

        xmlhttp.send();
    }

    function loadProjectContracts(projectID) {
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari

            xmlhttp = new XMLHttpRequest();

        }

        else {// code for IE6, IE5

            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

        }

        xmlhttp.onreadystatechange = function () {

            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("contract").innerHTML = xmlhttp.responseText;
                loadProjectSOW(projectID);
            }

        }

        xmlhttp.open("GET", "getProjectContractsdwgs.php?projectID=" + projectID, true);

        xmlhttp.send();
    }
	
</script>

<div style="overflow-x:auto;">

    <div id="formdiv">


        <?php


        if (isset($_GET['Edit']) && !empty($_GET['Edit'])) {


            $dwgID = $_REQUEST['Edit'];
            $result = mysql_query("SELECT * FROM scope_dwg  where dwgID ='$dwgID' ");

            $row = mysql_fetch_array($result, MYSQL_ASSOC);

            $dwgID = $row['dwgID'];
            $dwgTitle = $row['dwgList_Title'];
            $dwgcomplePercent = $row['dwgcomplePercent'];
            $dwgType = $row['dwgType'];
            $designType = $row['dwg_type'];
            $dwgProject = $row['dwgProject'];
            $dwgDiscipline = $row['discipline_id'];
            $phaseID = $row['phaseID'];
			$zoneID = $row['zoneID'];
				  $contractID = $row['contractID'];
			$SDate = $row['Date_Started'];
			$SDate2 = $row['rDate_Start'];
			$SDate3 = $row['rDate_End'];
			$dwg_sowID = $row[dwg_sowID];

            $dwgConsultant = $row['dwg_consultantID'];
			$dwgClient = $row['dwg_clientID'];


            $editUrl = "?Edit=" . $_GET['Edit'];


        }


        ?>
        <?php if ($uacc == "Full Control" || $uacc == "Consolidate") { ?>
            <form align="center" action="03-06Scope-01Drawings01DB.php<?php if (isset($editUrl)) echo $editUrl; ?>"
                  method="post" style="margin-top:20px">

                <fieldset>

                    <legend align="center">

                        <button id="hideformdiv" class="button1" title="Click to Hide">&nbsp;&nbsp;&nbsp;DRAWING SETS&nbsp;&nbsp;&nbsp;</button>
                    </legend>

                    <table name="entryform" align="center" class="table1" width="85%" border="0" cellpadding="0">
                        <tr>
                            <td width="8%" align="left"><strong>Project/ Phase*:</strong></td>
                            <td width="23%" align="left">
                                <select name="projname" style="width:43%" class="" id="projname" required onchange="loadProjectPhases(this.value)">
                                    <option value="">Select</option>
                                    <?php
                                    $result = mysql_query("SELECT projectSerial,projectCode, projectName FROM projects where companySerial = '$id' AND projStatus=1 ORDER BY projectCode");


                                    while ($rows = mysql_fetch_array($result, MYSQL_ASSOC)) {
                                        $projectSerial = $rows['projectSerial'];
                                        if ($rows["projectSerial"] == $dwgProject)
                                            echo "<option selected='selected' value='$projectSerial'>" . $rows["projectCode"] . " - " . $rows["projectName"] . "</option>";
                                        else
                                            echo "<option value='$projectSerial'>" . $rows["projectCode"] . " - " . $rows["projectName"] . "</option>";
                                    }
                                    ?>
                                </select>
                                <select style="width:42%" name="phase" class="" id="phase" >
                                    <option value="0">Select</option>

                                    <?php
                                    if (isset($_GET['Edit']) && !empty($_GET['Edit'])) {
                                    $result21 = mysql_query("SELECT  Phase_id,Phase_name FROM projects, projectphases where
                                                                    projects.companySerial = '$id' AND projects.projStatus=1 AND projectphases.Phase_status=1 AND
                                                                     projects.projectSerial=projectphases.project_id AND projectphases.project_id='$dwgProject'
                                                                       ORDER BY Phase_name ASC");

                                    while ($row21 = mysql_fetch_array($result21, MYSQL_ASSOC)) {
                                        $i = $row21['Phase_id'];
                                        $n = $row21['Phase_name'];

                                            if( $i == $phaseID)
                                                echo " <option selected='selected' value='$i'> $n </option>";
                                            else
                                        echo " <option value='$i'> $n </option>";
                                    }
}
                                    ?>

                                </select>
                            <a href="http://pm4.pmanywhere.co/Interface/02-options/02-03Options-01Projects01.php"><img src="img/Adding.png" width="8" height="8" alt=""/></a>                            </td>

<!--
                            <td width="8%" align="left"><strong>Phase*:</strong></td>
                            <td width="25%" align="left">

                            </td>-->


                            <td width="8%" align="left"><strong>Zone/ Contract:</strong></td>
                            <td width="25%" align="left"><select style="width:43%" name="zone" class="" id="zone" >
                              <option value="0">Select</option>
                                    <?php
                                    if (isset($_GET['Edit']) && !empty($_GET['Edit'])) {
                                        $proID = $dwgProject;
                                        $result22 = mysql_query("SELECT  Zone_id,Zone_name FROM projects, projectzones where
                                                                    projects.companySerial = '$id' AND projects.projStatus=1 AND projectzones.Zone_status=1 AND
                                                                     projects.projectSerial=projectzones.project_id AND projectzones.project_id='$proID'
                                                                      ORDER BY Zone_name ASC");

                                        while ($row22 = mysql_fetch_array($result22, MYSQL_ASSOC)) {
                                            $i = $row22['Zone_id'];
                                            $n = $row22['Zone_name'];

                                            if( $i == $zoneID)
                                                echo " <option selected='selected' value='$i'> $n </option>";
                                            else
                                                echo " <option value='$i'> $n </option>";
                                        }
                                    }
                                    ?>
                            </select>
                              <select style="width:42%" name="contract" class="" id="contract" >
                                <option value="0">Select</option>
                                <?php
                                    if (isset($_GET['Edit']) && !empty($_GET['Edit'])) {
                                        $proID = $dwgProject;
                                        $result30 = mysql_query("SELECT  Contract_id,Contract_no, Contract_title FROM projects, projectcontracts where
                                                                    projects.companySerial = '$id' AND projects.projStatus=1 AND projectcontracts.Contract_status=1 AND
                                                                     projects.projectSerial=projectcontracts.project_id AND projectcontracts.project_id='$proID'
                                                                      ORDER BY Contract_title ASC");

                                        while ($row30 = mysql_fetch_array($result30, MYSQL_ASSOC)) {
                                            $i = $row30['Contract_id'];
                                            $n = $row30['Contract_no'];

                                            $t = $row30['Contract_title'];

                                            $n .= ' - '.$t;
                                            if( $i == $contractID)
                                                echo " <option selected='selected' value='$i'> $n </option>";
                                            else
                                                echo " <option value='$i'> $n </option>";
                                        }
                                    }
                                    ?>
                            </select></td>
                            <td align="left"><strong>Set Title:</strong></td>
                            <td align="left"><input type="text"
                                                                value="<?php if (isset($editUrl)) echo $dwgTitle; ?>"
                                                                name="title" id="title"></td>
                        </tr>
                        <tr>
                          <td align="left"><strong>DWG Start:</strong></td>
                          <td align="left">
							  <input value="<?php echo(($SDate) ? date("Y-m-d", strtotime($SDate)) : date("Y-m-d")); ?>"
                                        name="Startdate" type="date" id="Startdate"></td>
                          <td align="left"><strong>Review Start</strong></td>
                          <td align="left"><input
                                        value="<?php echo(($SDate2) ? date("Y-m-d", strtotime($SDate2)) : date("Y-m-d")); ?>"
                                        name="Startdate2" type="date" id="Startdate2"></td>
                          <td align="left"><strong>Review End</strong></td>
                          <td align="left"><input
                                        value="<?php echo(($SDate3) ? date("Y-m-d", strtotime($SDate3)) : date("Y-m-d")); ?>"
                                        name="Startdate3" type="date" id="Startdate3"></td>
                        </tr>
                        <tr>
                            <td align="left"><strong>Consultant:</strong></td>
                            <td align="left"><select  name="consultant_id" id="consultant_id">
                                    <option value="">Select</option>
                                    <?php
                                    $resultC = mysql_query("SELECT * FROM consultants WHERE companySerial = '$id' AND conStatus=1 ORDER BY conDepartment");

                                    while ($rowC = mysql_fetch_array($resultC, MYSQL_ASSOC)) {

                                        $consultant = $rowC['conSerial'];
                                        ?>
                                        <option value='<?php echo $consultant ?>' <?php
                                        if ($consultant == @$dwgConsultant) {
                                            echo "selected";
                                        }
                                        ?> ><?php

    echo $rowC["conName"] . " - " . $rowC["conContactName"] . " - " . $rowC['conDesignation'] . " - " . $rowC['conDepartment'] ; ?></option>

                                    <?php }
                                    ?>

                                </select>

							
							</td>
                            <td align="left"><strong>Client:</strong></td>
                            <td align="left">
                                <select  name="client_id" id="client_id">
                                    <option value="">Select</option>
                                    <?php
                                    $resultD = mysql_query("SELECT * FROM client WHERE companySerial = '$id' AND clientStatus=1 ORDER BY clientName");

                                    while ($rowD = mysql_fetch_array($resultD, MYSQL_ASSOC)) {

                                        $client = $rowD['clientSerial'];
                                        ?>
                                        <option value='<?php echo $client ?>' <?php
                                        if ($client == @$dwgClient) {
                                            echo "selected";
                                        }
                                        ?> ><?php

                                            echo $rowD["clientCode"] . " - " . $rowD["clientName"] . " - " . $rowD['clientContactName'] . " - " . $rowD['clientDesignation'] ; ?></option>

                                    <?php }
                                    ?>

                                </select>

                                <!--<input name="dwgsuffix" type="text" class="" id="dwgsuffix"
                                                    value="<?php /*if (isset($editUrl)) echo @$row['dwg_suffix'] */?>"/>-->

                            </td>

                            <td align="left"><strong>Related SOW:</strong></td>
                            <td align="left"><select name="relatedSOW" id="relatedSOW">
                              <option value="">Select</option>
                              <?php
                                    if($dwgProject){
                                        $result21 = mysql_query("SELECT sowID,sowName FROM scope_sow where sowCompany = '$id' AND sowProject='$dwgProject' AND sowStatus=1 order by sowName");

                                        while($rowSW = mysql_fetch_array($result21 , MYSQL_ASSOC))
                                        {
                                            $i = $rowSW['sowID'];
                                            $n = $rowSW['sowName'];
                                            if( $i == $dwg_sowID)
                                                echo " <option selected value='$i'> $n </option>";
                                            else
                                                echo " <option value='$i'> $n </option>";
                                        }
                                    }

                                    ?>
                            </select>
                              <a href="03-04Scope-01SOW01.php"><img src="img/Adding.png" width="8" height="8" alt=""/></a></td>


                        </tr>
                        <tr>
                            <td align="left"><strong>DWG Type:</strong></td>
                            <td align="left"><select name="dwg_type" class="" id="dwg_type">
                                    <option value="">Select</option>
                                    <option <?php
                                    if (isset($editUrl)) if ($dwgType == "3D Visualisation") {
                                        echo "selected";
                                    }
                                    ?> value="3D Visualisation">3D Visualisation
                                    </option>
                                    <option <?php
                                    if (isset($editUrl)) if ($dwgType == "Bid Package") {
                                        echo "selected";
                                    }
                                    ?> value="Bid Package">Bid Package
                                    </option>
                                    <option <?php
                                    if (isset($editUrl)) if ($dwgType == "Isometric") {
                                        echo "selected";
                                    }
                                    ?> value="Isometric">Isometric
                                    </option>
                                    <option <?php
                                    if (isset($editUrl)) if ($dwgType == "Issue for Construction") {
                                        echo "selected";
                                    }
                                    ?> value="Issue for Construction">Issue for Construction
                                    </option>
                                    <option <?php
                                            if (isset($editUrl)) if ($dwgType == "Issue for Construction - Key Drawing") {
                                                echo "selected";
                                            }
                                            ?>value="Issue for Construction - Key Drawing">Issue for Construction - Key
                                        Drawing
                                    </option>
                                    <option <?php
                                    if (isset($editUrl)) if ($dwgType == "Issue for Construction - Shop Drawing") {
                                        echo "selected";
                                    }
                                    ?> value="Issue for Construction - Shop Drawing">Issue for Construction - Shop
                                        Drawing
                                    </option>
                                    <option <?php
                                    if (isset($editUrl)) if ($dwgType == "Sketch") {
                                        echo "selected";
                                    }
                                    ?> value="Sketch">Sketch
                                    </option>
                                </select></td>
                            <td align="left"><strong>Design Stage*:</strong></td>
                            <td align="left"><select name="complevel2" class="" required id="complevel2">
                                    <option value="">Select</option>
                                    <option value="30" <?php if (isset($editUrl)) if ($dwgcomplePercent == 30) { ?> selected <?php } ?>>
                                        30 percent
                                    </option>
                                    <option value="50" <?php if (isset($editUrl)) if ($dwgcomplePercent == 50) { ?> selected <?php } ?>>
                                        50 percent
                                    </option>
                                    <option value="90" <?php if (isset($editUrl)) if ($dwgcomplePercent == 90) { ?> selected <?php } ?>>
                                        90 percent
                                    </option>
                                    <option value="100" <?php if (isset($editUrl)) if ($dwgcomplePercent == 100) { ?> selected <?php } ?>>
                                        100 percent
                                    </option>
                                </select></td>
                            <td align="left"><strong> of*: </strong></td>
                            <td align="left"><select name="designtype" required class="" id="designtype">
                                    <option value="">Select</option>
                                    <option value="Conceptual Design" <?php if (isset($editUrl)) if ($designType == "Conceptual Design") { ?> selected <?php } ?>>
                                        Conceptual Design
                                    </option>
                                    <option value="Developed Design" <?php if (isset($editUrl)) if ($designType == "Developed Design") { ?> selected <?php } ?>>
                                        Developed Design
                                    </option>
                                    <option value="Detailed Design" <?php if (isset($editUrl)) if ($designType == "Detailed Design") { ?> selected <?php } ?>>
                                        Detailed Design
                                    </option>
                                    <option value="Shop Drawings" <?php if (isset($editUrl)) if ($designType == "Shop Drawings") { ?> selected <?php } ?>>
                                        Shop Drawings
                                    </option>
                                    <option value="As-Built" <?php if (isset($editUrl)) if ($designType == "As-Built") { ?> selected <?php } ?>>
                                        As-Built
                                    </option>
                                </select>
                                <button style="vertical-align: bottom" class="button1" title="Save">&#x25ba;</button>
                            </td>
                        </tr>
                      <!--  <tr>

                            <td width="13%" align="left"><strong>No of Main Dwgs*:</strong></td>

                            <td width="23%" align="left">
                                <input type="hidden" id="prenoofdwgs" value="<?php /*if (isset($editUrl)) echo $row['no_of_dwgs'] */?>"/>
								
                                <input name="noofdwg" type="text" required id="noofdwg" 
									   <?php /*if (isset($editUrl)) { */?> onchange="ConfirmNoOfDwgs(this, this.value)" <?php /*} else { */?> onchange="check_is_number(this, this.value)" <?php /*} */?>
                                       value="<?php /*if (isset($editUrl)) echo $row['no_of_dwgs'] */?>"/>
                            </td>

                            <td width="13%" align="left"><strong>Range From*:</strong></td>

                            <td width="23%" align="left"><input name="rangefrom"
                                                                onChange="getLastValue(this, this.value)" required
                                                                type="number" class="" id="rangefrom"
                                                                value="<?php /*if (isset($editUrl)) echo $row['range_from'] */?>"/>
                            </td>

                            <td align="left"><strong> Range to: </strong></td>
                            <td align="left"><input name="rangeto" required type="number" readonly class="" id="rangeto"
                                                    value="<?php /*if (isset($editUrl)) echo $row['range_to'] */?>"/>

                                <button style="vertical-align: bottom" class="button1" title="Save">&#x25ba;</button>

                            </td>

                        </tr>-->

                    </table>

                </fieldset>
            </form>
        <?php } ?>
        <br></div>
</div>


<a name="activeanchor"></a>
<div style="overflow-x:auto;">

    <div>

        <table align="center" name="tabletitle" class="table1 tableActiveFilter" width="85%" border="0" cellpadding="0">

            <tr>

                <th>

                    <div style='float: left; text-align: left'>
                    <a href="#archiveanchor" style="text-decoration: none">
            <button class="button1" title="View Archived">&#x25bc;</button></a><button id="showformdiv" class="button1" title="Show/ Hide the Form">&#x25b2;&#x25bc;</button><a href="#" class="button1" title="">&nbsp;ACTIVE DRAWINGS SETS&nbsp;</a></div>

                    <div style='float: right; text-align: right'>
                        <select id="findproject" style="width:30%">
                            <option value="">Select a Project</option>

                            <?php

                            $result = mysql_query("SELECT projects.projectName,projects.projectCode
FROM projects,scope_dwg
WHERE scope_dwg.dwgProject = projects.projectSerial
AND scope_dwg.dwgCompany = '$id' AND scope_dwg.dwgStatus=1 GROUP BY projects.projectName ORDER BY projectCode");

                            while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                                //$projectSerial = $row['projectSerial'];
                                //echo "<option value='$projectSerial' ".(($estimate['projectid'] == $projectSerial) ? "selected" : "").">" . $row["projectCode"] . " - " . $row["projectName"] . "</option>";
                                ?>
                                <option value='<?php echo $row["projectCode"]; ?>'><?php echo $row["projectCode"]; ?></option>

                                <?php

                            }
                            ?>

                        </select>

                        <select style="width:30%" id="PagingRows">

                            <option value="10">Show 10 Rows</option>

                            <option value="20"> Show 20 Rows</option>

                            <option value="50"> Show 50 Rows</option>

                            <option value="100" selected> Show 100 Rows</option>

                            <option value="all"> Show All Rows</option>

                        </select>

                        <input style="width:30%" type="search" id="SearchMeasure" placeholder="Type to Search">

                    </div>

                </th>

            </tr>

        </table>

    </div>

</div>



<div style="overflow-x:auto;">

    <table align="center" class="table2 tableActive" name="datatable" border="0" width="85%" cellpadding="1">

        <tr>

            <th align="left" class="sorting" sorting="projectCode" bgcolor="#AAAAAA">Dated/ Started<br/>
                (yyyy.mm.dd)&nbsp;&#x21c5;
            </th>

            <th align="left" class="sorting" sorting="hazardID" bgcolor="#AAAAAA">Project Code/<br/>
                Phase/ Zone/ Contract&#x21c5;
            </th>
            <th align="left" class="sorting" sorting="DateLoction1" bgcolor="#AAAAAA">Related <br>
                SOW
            </th>
            <th align="left" class="sorting" sorting="DateLoction2" bgcolor="#AAAAAA">Title/<br>
                Consultant/ Client
            </th>

            <th align="left" class="sorting" sorting="DateLoction3" bgcolor="#AAAAAA"> DWG<br/>
                Type&nbsp;&#x21c5;
            </th>

            <th align="left" class="sorting" sorting="DateLoction4" bgcolor="#AAAAAA">Design<br/>
                Stage&nbsp;&#x21c5;
            </th>
<!--
            <th align="left" class="sorting" sorting="DateLoction5" bgcolor="#AAAAAA">No of Dwgs / Suffix<br/>
                Range (from-to)&nbsp;&#x21c5;
            </th>-->
            <th align="left" class="sorting" sorting="DateLoction6"  bgcolor="#AAAAAA">Review<br>
              Dates</th>


            <th align="right" bgcolor="#AAAAAA">Actions<br>Status</th>

        </tr>


        <?php
        $result = mysql_query("SELECT projects.projectSerial,projects.projectName,projects.projectCode,scope_dwg.*
FROM projects,scope_dwg
WHERE scope_dwg.dwgProject = projects.projectSerial
AND scope_dwg.dwgCompany = '$id' AND scope_dwg.dwgStatus=1 ORDER BY $order_start $order_par $order_type");
        while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
            ?>

            <tr class="tableData" trid="<?php echo $row['dwgID']; ?>">

                <td align="left" class="tdData projectCode"><?php echo $row['dwgDateCreated']; ?>
                    <br> <?php echo $row['Date_Started']; ?></td>

                <td align="left" class="tdData hazardID"><?php echo $row['projectCode'].'<br>';

                $pID = null;
                $pID = $row['phaseID'];
                    $result21 = mysql_query("SELECT  Phase_id,Phase_name FROM projectphases where
                   projectphases.Phase_status=1 AND projectphases.Phase_id='$pID'
                     ");

                    while ($row21 = mysql_fetch_array($result21, MYSQL_ASSOC)) {
                    $i = $row21['Phase_id'];
                    $n = $row21['Phase_name'];
                    echo $n;
                    }

                    ?><br>
              <?php 
                $pID = null;
                $pID = $row['zoneID'];
                    $result21 = mysql_query("SELECT  Zone_id,Zone_name FROM projectzones where
                   projectzones.Zone_status=1 AND projectzones.Zone_id='$pID'
                     ");

                    while ($row21 = mysql_fetch_array($result21, MYSQL_ASSOC)) {
                    $i = $row21['Zone_id'];
                    $n = $row21['Zone_name'];
                    echo $n;
                    }

                    ?> <br>
                    <?php
                    $pID = null;
                    $pID = $row['contractID'];
                    $result29 = mysql_query("SELECT  Contract_id,Contract_no,Contract_title FROM projectcontracts where
                   projectcontracts.Contract_status=1 AND projectcontracts.Contract_id='$pID'
                     ");

                    while ($row29 = mysql_fetch_array($result29, MYSQL_ASSOC)) {
                        //$i = $row29['Contract_no'];
                        $n = $row29['Contract_no'];
                        echo $n;
                    }

                    ?>
                </td>
                <td align="left" class="tdData DateLoction1"><span class="tdData DateLoction4"><?php
                        $resultSOW = mysql_query("SELECT sowName FROM scope_sow WHERE sowID =" . $row['dwg_sowID']);
                        if (@$rowSOW = mysql_fetch_assoc($resultSOW))
                            echo $rowSOW['sowName']; ?></span>
                    <br>
                </td>
                <td align="left" class="tdData DateLoction2"><span
                            class="tdData DateLoction4"><?php echo $row['dwgList_Title']; ?></span>

                    <br>
                    <span class="tdData DateLoction2"><?php
                        $resultC = mysql_query("SELECT * FROM consultants WHERE companySerial = '$id' AND conStatus=1 AND conSerial=" . $row['dwg_consultantID']);
                        if (@mysql_num_rows($resultC)) {
                            $rowC = mysql_fetch_array($resultC, MYSQL_ASSOC);
                          //  echo $rowC["conContactName"] . "            ";
                            echo $rowC["conDepartment"] . " - " . $rowC['conContactName'] . " - " .$rowC['conDesignation'];
                            /* Optional  addition

                            - ".$rowC['conDesignation']."(".$rowC['conDepartment'].")";

                            */

                        }
                        ?><br>
                        <?php
                        $resultD = mysql_query("SELECT * FROM client WHERE companySerial = '$id' AND clientStatus=1 AND clientSerial='$row[dwg_clientID]'");

                        if ($rowD = mysql_fetch_array($resultD, MYSQL_ASSOC)) {
                                echo $rowD["clientCode"] . " - " . $rowD["clientName"] . " - " . $rowD['clientContactName'] . " - " . $rowD['clientDesignation'] ;
                         }
                        ?>
                    </span>
                </td>
                <td align="left" class="tdData DateLoction3"><?php echo $row['dwgType']; ?><br/>
                </td>
                <td align="left" class="tdData DateLoction4"> <?php echo $row['dwgcomplePercent'] . " percent"; ?>
                </td>
               <!-- <td align="left" class="tdData DateLoction5"><?php /*echo $row['no_of_dwgs']; */?>
                    <br/><?php /*echo $row['dwg_suffix']; */?> (<?php /*echo $row['range_from'] . "-" . $row['range_to'] */?>)
                </td>-->
                <td align="left" class="tdData DateLoction6"><span class="tdData DateLoction6"><?php echo $row['rDate_Start']; ?></span><br>
                <span class="tdData DateLoction6"><?php echo $row['rDate_End']; ?></span></td>

                <td align="right" class="table2 sortable actionTD">


                    <!--	<button id="addformdiv" class="button3"> <img src="img/add.png" width="13" height="13" alt="" title="Add"/></button>  -->

                    <?php if ($uacc == "Full Control" || $uacc == "Consolidate") { ?>
                        <a href="03-06Scope-01Drawings01.php?Edit=<?php echo $row['dwgID']; ?>"><img src="img/edit.png"
                                                                                                     width="13"
                                                                                                     height="13" alt=""
                                                                                                     title="Edit"/></a>&nbsp;&nbsp;&nbsp;<?php } else { ?>&nbsp;&nbsp;&nbsp;
                        <img src="img/edit.png" width="13" height="13" alt="" title="Edit"/>&nbsp;&nbsp;&nbsp;<?php } ?>


                    <a href="03-06Scope-02Drawings01.php?expand_id=<?php echo $row['dwgID']; ?>"><img
                                src="img/expand.png" width="13" height="13" alt="" title="Expand"/></a>&nbsp;&nbsp;&nbsp;
					
					<a href="03-06Scope-02Drawings02.php?expand_id=<?php echo $row['dwgID']; ?>"><img
                                src="img/review.png" width="13" height="13" alt="" title="Review"/></a>&nbsp;&nbsp;&nbsp;
					
					<a href="03-06Scope-02Drawings03.php?expand_id=<?php echo $row['dwgID']; ?>"><img
                                src="img/commenting.png" width="13" height="13" alt="" title="Respond"/></a>&nbsp;&nbsp;&nbsp;
					

                    <!--        <a href="#"> <img src="img/print.png" width="13" height="13" alt="" title="Print"/></a>&nbsp;&nbsp;&nbsp;-->

                    <?php if ($uacc == "Full Control" || $uacc == "Consolidate") { ?>
                        <a href="03-06Scope-01Drawings01DB.php?InActive=<?php echo $row['dwgID']; ?>">

                            <img src="img/hide.png" width="13" height="13" alt="" title="Archive"/></a>
                    <?php } else { ?>
                        <img src="img/hide.png" width="13" height="13" alt="" title="Archive"/></a>
                    <?php } ?>
                </td>

                    <!--	<br>

                                        <button id="showremsdiv" class="button3"> <img src="img/mymentos.png" width="13" height="13" alt="" title="Add a Reminder"/></button>

                                        &nbsp;&nbsp;&nbsp;

                                        <button id="shownotesdiv" class="button3"> <img src="img/notes.png" width="13" height="13" alt="" title="Add Notes"/></button>

                                        &nbsp;&nbsp;&nbsp;

                                        <button id="showfilesdiv" class="button3"> <img src="img/attach.png" width="13" height="13" alt="" title="Attach" /></button></td>
                    -->

            </tr>

            <tr class="trid<?php echo $row['dwgID']; ?> notetr">

                <td colspan="9" align="left">

                    <img src="img/information.png" width="12" height="12" alt=""/>&nbsp;&nbsp;

                    <button id="rangeBtn<?php echo $row['dwgID']; ?>" class="button3"
                            onclick=" $('#div<?php echo $row[dwgID]; ?>').toggle();">
                        <img src="img/tweak.png" width="12" height="12" alt="" title="Specify Ranges"/>
                    </button>

                    <div id="div<?php echo $row['dwgID']; ?>" style="display: none">

                        <form id="rangeForm<?php echo $row['dwgID']; ?>" method="post" action="03-06Scope-01Drawings01DB.php?Range=<?php echo $row['dwgID']; ?>" >

                            <div id="rangeDiv<?php echo $row['dwgID']; ?>">

                                <input  style="width:15%" name="dwgsuffix<?php echo $row['dwgID']; ?>" type="text" class="" placeholder="Dwgs Suffix" id="dwgsuffix<?php echo $row['dwgID']; ?>"
                                       value=""/>

                                <input style="width:15%" name="noofdwg<?php echo $row['dwgID']; ?>" type="text" required id="noofdwg<?php echo $row['dwgID']; ?>"  onchange="check_is_number(this, this.value, '<?php echo $row[dwgID]; ?>')"  placeholder="No of Main Dwgs*" value=""/>

                                <input name="rangefrom<?php echo $row['dwgID']; ?>" style="width:15%" onChange="getLastValue(this, this.value, '<?php echo $row[dwgID]; ?>')" placeholder="Range From*" required type="number" class="" id="rangefrom<?php echo $row['dwgID']; ?>"  value=""/>

                                <input name="rangeto<?php echo $row['dwgID']; ?>" style="width:15%" required type="number" placeholder="Range to" readonly class="" id="rangeto<?php echo $row['dwgID']; ?>"  value=""/>

                                <button id="hiderangediv" class="button3" onclick="">
                                    <img src="img/add.png" width="15" height="15" alt="" title="Save">
                                </button>

                            </div>
                        </form>
                    </div>

                    <div id="dataDiv<?php echo $row['dwgID']; ?>">
                        <?php
                        $rangeQ = "SELECT * FROM scope_dwg_range WHERE dwgID = '$row[dwgID]' AND companyID = '$company_id' AND status = '1'";
                        $rangeRes = mysql_query( $rangeQ );
                        while( $rangeRow = mysql_fetch_assoc($rangeRes)){
                        ?><div>
                                <?php echo $rangeRow[dwg_suffix].' : '.$rangeRow[no_of_dwgs].'  ('.$rangeRow[range_from].'-'.$rangeRow[range_to].')' ?>

<!--                       Check if there are any entries in the range if yes then show warning     -->
                            <?php
                            $existRangeQ = "SELECT * FROM scope_dwg_revisions WHERE range_no BETWEEN $rangeRow[range_from] AND $rangeRow[range_to] AND dwg_id = '$row[dwgID]'";
                            $existRangeRes = mysql_query( $existRangeQ );
                            if(mysql_num_rows($existRangeRes) > 0)
                                $alert = "Records exist in this range. Are you sure to delete this drawing range ?";
                            else
                                $alert = "Are you sure to delete this drawing range ?";

                            ?>
                            <a onclick="return confirm('<?php echo $alert; ?>');" style="text-decoration: none;" href="03-06Scope-01Drawings01DB.php?RemoveRange=<?php echo $rangeRow['rangeID']; ?>">
                                <img src="img/delete.png" width="9" height="9" border="0">
                            </a>
                            </div><?php
                        }
                        ?>
                    </div>

                </td>

            </tr>

        <?php } ?>


    </table>

</div>

<table width="85%" class="table1 ActiveTablePaging" align="center" border="0" cellpadding="1">

    <tbody>

    <tr>

        <td align="right">

            <span class="pagingInfo"></span>


            &nbsp;

            <button class="button2 BtnPrev" title="Previous Page">&#9668;</button>

            &nbsp;

            <button class="button2 BtnNext" title="Next Page">&#x25ba;</button>

            <div id="pagination"></div>

        </td>

    </tr>

    </tbody>

</table>


<!-- HIDDEN TABLE-->

<a name="archiveanchor"></a><br>

<hr class="hrstyle1">

<br>


<div style="overflow-x:auto;">

    <div id="hiddendiv"> <!--- style="display:none" ------>

        <table align="center" name="tabletitle" class="table1 tableInActiveFilter" width="85%" border="0"
               cellpadding="1">

            <tr>

                <th>

                    <div style='float: left; text-align: left'>
                     <button id="hidehiddendiv" class="button1" title="Hide">&nbsp;&nbsp;&nbsp;</button><a href="#activeanchor" style="text-decoration: none"><button class="button1" title="Show Active">&#x25b2;</button></a>&nbsp;Archived Drawing Sets</div>

                    <div style='float: right; text-align: right'>
                        <select id="findprojectHide" style="width:30%">
                            <option value="">Select a Project</option>
                            <?php
                            $result = mysql_query("SELECT projects.projectName,projects.projectCode
FROM projects,scope_dwg
WHERE scope_dwg.dwgProject = projects.projectSerial
AND scope_dwg.dwgCompany = '$id' AND scope_dwg.dwgStatus=0 GROUP BY projects.projectName ORDER BY projectCode");
                            while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                                // $projectSerial = $row['projectSerial'];
                                //echo "<option value='$projectSerial' ".(($estimate['projectid'] == $projectSerial) ? "selected" : "").">" . $row["projectCode"] . " - " . $row["projectName"] . "</option>";
                                ?>
                                <option value='<?php echo $row["projectCode"]; ?>'><?php echo $row["projectCode"]; ?></option>

                                <?php

                            }
                            ?>

                        </select>

                        <select style="width:30%" id="PagingRows">

                            <option value="10">Show 10 Rows</option>

                            <option value="20"> Show 20 Rows</option>

                            <option value="30"> Show 50 Rows</option>

                            <option value="100"> Show 100 Rows</option>

                            <option value="all"> Show All Rows</option>

                        </select>

                        <input style="width:30%" type="search" id="SearchMeasureHide" placeholder="Type to Search">

                    </div>

                </th>

            </tr>

        </table>


        <table align="center" class="table2 tableInActive" name="datatable" border="0" width="85%" cellpadding="1">


            <tr>

                <th align="left" class="sorting" sorting="projectCode" bgcolor="#AAAAAA">Dated/ Started<br/>
                    (yyyy.mm.dd)&nbsp;&#x21c5;
                </th>
                <th align="left" class="sorting" sorting="hazardID" bgcolor="#AAAAAA">Project Code/<br/>
                    Phase/ Zone/ Contract&#x21c5; </th>
                <th align="left" class="sorting" sorting="DateLoction1" bgcolor="#AAAAAA">Related <br>
                    SOW
                </th>
                <th align="left" class="sorting" sorting="DateLoction2" bgcolor="#AAAAAA">Title/<br>
                    Consultant/ Client
                </th>

                <th align="left" class="sorting" sorting="DateLoction3" bgcolor="#AAAAAA"> DWG<br/>
                    Type&nbsp;&#x21c5;
                </th>

                <th align="left" class="sorting" sorting="DateLoction4" bgcolor="#AAAAAA">Design<br/>
                    Stage&nbsp;&#x21c5;
                </th>

               <!-- <th align="left" class="sorting" sorting="DateLoction5" bgcolor="#AAAAAA">No of Dwgs / Suffix<br/>
                    Range (from-to)&nbsp;&#x21c5;
                </th>-->
                <th align="left" class="sorting" sorting="DateLoction6" bgcolor="#AAAAAA">Review<br>
                  Dates</th>
                <th align="right" bgcolor="#AAAAAA">Actions<br>Status</th>

            </tr>


            <?php
            $result = mysql_query("SELECT projects.projectName,projects.projectCode,scope_dwg.*
FROM projects,scope_dwg
WHERE scope_dwg.dwgProject = projects.projectSerial
AND scope_dwg.dwgCompany = '$id' AND scope_dwg.dwgStatus=0 ORDER BY $order_start $order_par $order_type");
            while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                ?>


                <tr class="tableDataHide" trid="<?php echo $row['dwgID']; ?>">

                    <td align="left" class="tdDataHide projectCode"><?php echo $row['dwgDateCreated']; ?>
                        <br> <?php echo $row['Date_Started']; ?>
                    </td>

                    <td align="left" class="tdData hazardID"><?php echo $row['projectCode'].'<br>';

                $pID = null;
                $pID = $row['phaseID'];
                    $result21 = mysql_query("SELECT  Phase_id,Phase_name FROM projectphases where
                   projectphases.Phase_status=1 AND projectphases.Phase_id='$pID'
                     ");

                    while ($row21 = mysql_fetch_array($result21, MYSQL_ASSOC)) {
                    $i = $row21['Phase_id'];
                    $n = $row21['Phase_name'];
                    echo $n;
                    }

                    ?><br>
                      <?php 
                $pID = null;
                $pID = $row['zoneID'];
                    $result21 = mysql_query("SELECT  Zone_id,Zone_name FROM projectzones where
                   projectzones.Zone_status=1 AND projectzones.Zone_id='$pID'
                     ");

                    while ($row21 = mysql_fetch_array($result21, MYSQL_ASSOC)) {
                    $i = $row21['Zone_id'];
                    $n = $row21['Zone_name'];
                    echo $n;
                    }

                    ?>
                      <br>
                        <?php
                        $pID = null;
                        $pID = $row['contractID'];
                        $result29 = mysql_query("SELECT  Contract_id,Contract_no,Contract_title FROM projectcontracts where
                   projectcontracts.Contract_status=1 AND projectcontracts.Contract_id='$pID'
                     ");

                        while ($row29 = mysql_fetch_array($result29, MYSQL_ASSOC)) {
                            $i = $row29['Contract_id'];
                            $n = $row29['Contract_no'];
                            echo $n;
                        }

                        ?>
                    </td>

                    <td align="left" class="tdDataHide DateLoction1"><span class="tdDataHide DateLoction1"><?php
                            $resultSOW = mysql_query("SELECT sowName FROM scope_sow WHERE sowID =" . $row['dwg_sowID']);
                            if (@$rowSOW = mysql_fetch_assoc($resultSOW))
                                echo $rowSOW['sowName']; ?></span> <br>
                    </td>

                    <td align="left" class="tdDataHide DateLoction2">
                        <span
                                class="tdDataHide DateLoction2"><?php echo $row['dwgList_Title']; ?></span> <br>
                        <span class="tdDataHide DateLoction2"><?php
                            $resultC = mysql_query("SELECT * FROM consultants WHERE companySerial = '$id' AND conStatus=1 AND conSerial=" . $row['dwg_consultantID']);
                            if (@mysql_num_rows($resultC)) {
                                $rowC = mysql_fetch_array($resultC, MYSQL_ASSOC);
                         //       echo $rowC["conContactName"] . " - " . $rowC['conDesignation'] . "(" . $rowC['conDepartment'] . ")";
                                echo $rowC["conDepartment"] . " - " . $rowC['conContactName'] . " - " . $rowC['conDesignation'];
                            } ?>
                            <br>
                            <?php
                            $resultD = mysql_query("SELECT * FROM client WHERE companySerial = '$id' AND clientStatus=1 AND clientSerial='$row[dwg_clientID]'");

                            if ($rowD = mysql_fetch_array($resultD, MYSQL_ASSOC)) {
                                echo $rowD["clientCode"] . " - " . $rowD["clientName"] . " - " . $rowD['clientContactName'] . " - " . $rowD['clientDesignation'] ;
                            }
                            ?>
                        </span>
                    </td>

                    <td align="left" class="tdDataHide DateLoction3"><?php echo $row['dwgType']; ?><br/>
                    </td>

                    <td align="left" class="tdDataHide DateLoction4"> <?php echo $row['dwgcomplePercent'] . " percent"; ?>
                    </td>
                <!--    <td align="left"
                        class="tdDataHide DateLoction5"><?php /*echo $row['no_of_dwgs'] . "/" . $row['dwg_suffix'] */?>
                        <br/> <?php /*echo $row['range_from'] . "-" . $row['range_to'] */?>
                    </td>-->
                    <td align="left" class="tdDataHide DateLoction6"><span class="tdData DateLoction6"><?php echo $row['rDate_Start']; ?></span><br>
                      <span class="tdData DateLoction6"><?php echo $row['rDate_End']; ?></span>
                      <span class="tdData DateLoction6"><?php echo $row['rDate_End']; ?></span>
                    </td>

                    <td width="9%" align="right" class="actionTD">
                        <?php if ($uacc == "Full Control" || $uacc == "Consolidate") { ?>
                        <a href="03-06Scope-01Drawings01DB.php?Active=<?php echo $row['dwgID']; ?>"><img
                                        src="img/show.png" width="13" height="13" alt="" title="Unhide"/>
                            </a><?php } else { ?><img src="img/show.png" width="13" height="13" alt=""
                                                      title="Unhide"/><?php } ?>&nbsp;&nbsp;&nbsp;


                        <?php if ($uacc == "Full Control" || $uacc == "Consolidate") { ?>
                            <a href="javascript:void(0)" onClick="showConfirm('<?php echo $row['dwgID']; ?>')">

                                <img src="img/delete.png" width="13" height="13" alt="" title="Delete"/>

                            </a>

                        <?php } else { ?>
                            <img src="img/delete.png" width="13" height="13" alt="" title="Delete"/>
                        <?php } ?>
                    </td>

                </tr>

                <tr class="trid<?php echo $row['dwgID']; ?> notetr">

                    <td colspan="9" align="left">

                        <em>

                            <!--   <div id="div2"></div>        <br> --><img src="img/information.png" width="12"
                                                                             height="12" alt=""/></em></td>

                </tr>

            <?php } ?>

        </table>

        <table width="85%" class="table1 InActiveTablePaging" align="center" border="0" cellpadding="1">

            <tbody>

            <tr>

                <td align="right"><span class="pagingInfo"></span>


                    &nbsp;

                    <button class="button2 BtnPrev" title="Previous Page">&#9668;</button>

                    &nbsp;

                    <button class="button2 BtnNext" title="Next Page">&#x25ba;</button>
                </td>

            </tr>

            </tbody>

        </table>

    </div>

</div>

<br>

<br>


<script>
    function check_is_number(th, value, dwgID) {
        if (isNaN(value) || parseInt(value) < 1) {
            alert("Please insert numbers only and must be greater than 0");
            $(th).val("");
        }
        else {
            var rangefrom = $("#rangefrom"+dwgID).val();
            var noofdwgs = $("#noofdwg"+dwgID).val();
            if (rangefrom && noofdwgs) {
                var rto = parseInt(rangefrom) + (parseInt(noofdwgs) - 1);
                $("#rangeto"+dwgID).val(rto);

            }
        }

    }

    function getLastValue(th, value, dwgID) {
        if (isNaN(value) || parseInt(value) < 1) {
            alert("Please insert numbers only and must be greater than 0");
            $(th).val("");
        } else {
            var rangefrom = $("#rangefrom"+dwgID).val();
            var noofdwgs = $("#noofdwg"+dwgID).val();

            if (noofdwgs == '') {
                alert("Please enter No of drawings first");
                $(th).val("");
            } else {

                var rto = parseInt(rangefrom) + (parseInt(noofdwgs) - 1);
                $("#rangeto"+dwgID).val(rto);
            }
        }

    }

    function ConfirmNoOfDwgs(th, value) {

        var pval = $("#prenoofdwgs").val();

        if (isNaN(value) || parseInt(value) < 1) {
            alert("Please insert numbers only and must be greater than 0");
            $(th).val(pval);
        } else {
            if (parseInt(value) < parseInt(pval)) {
                // alertify.confirm("You are entering number less than previous which will result in  losing some records records temporary! You wish to continue", function (e) {

                if (confirm("You are entering number less than previous which will result in losing some records temporary! You wish to continue")) {
                    var rangefrom = $("#rangefrom").val();
                    var noofdwgs = $("#noofdwg").val();
                    if (rangefrom && noofdwgs) {
                        var rto = parseInt(rangefrom) + (parseInt(noofdwgs) - 1);
                        $("#rangeto").val(rto);

                    }

                }
                else {
                    $(th).val(pval);
                }
                //   });
            } else {
                var rangefrom = $("#rangefrom").val();
                var noofdwgs = $("#noofdwg").val();
                if (rangefrom && noofdwgs) {
                    var rto = parseInt(rangefrom) + (parseInt(noofdwgs) - 1);
                    $("#rangeto").val(rto);

                }
            }
        }
    }
</script>


</body>

</html>


<SCRIPT> // to show hide the forms and hidden tables

    $(document).ready(function () {


        $("#hideformdiv").click(function () {

            $("#formdiv").toggle();

        });

        $("#showformdiv").click(function () {

            $("#formdiv").toggle();

        });

        $("#addformdiv").click(function () {

            $("#formdiv").toggle();

        });

        $("#showhiddendiv").click(function () {

            $("#hiddendiv").toggle();

        });

        $("#hidehiddendiv").click(function () {

            $("#hiddendiv").toggle();

        })

        $("#shownotesdiv").click(function () {

            $("#notesdiv").toggle();

        })

        $("#showremsdiv").click(function () {

            $("#remsdiv").toggle();

        })

        $("#showfilesdiv").click(function () {

            $("#filesdiv").toggle();

        })

    });

</SCRIPT>


<?php include('../includes/footer.php'); ?>

