<?php
include('../../includes/checkSession.php');
include('../../includes/con2pma3.php');
/*include('../includes/header_in.php');*/
/*include('../includes/topmenuin.php');*/
$id= $company_id = $_SESSION['id'];
$expand_id=$_REQUEST['expand_id'];

if (strpos($_REQUEST['error'], 'Duplicate') !== false) {
    ?>
	<script>
    alert("Record not saved due to duplicate sheet OR revision numbers");
    </script>
	<?php
}
$allowed = "accept='.dwg,.dxf,.dgn,.dwf,.pdf,.jpg,.jpeg,.png,.bmp,.stl,.xps,.xls,.doc,.xlsx,.docx,.xml,.csv,.xps'";
?>

<html><head><meta charset="utf-8"><title>pmAnywhere - Scope</title>
<link href="03-00Scope-Styles0.css" rel="stylesheet" type="text/css" />
	<link href="00-noprint.css" rel="stylesheet" type="text/css" />

<script src="../includes/js/jquery.min.js"></script>
<script>
$(document).on('change', '#attachmentedit', function() {
    var file = $(this)[0]; // note the [0] to return the DOMElement from the jQuery object
	//alert(file.files[0].name);
	var exts=['.dwg', '.dxf','.dgn','.dwf','.pdf','.jpg','.jpeg','.png','.bmp','.stl','.xps','.xls','.doc','.xlsx','.docx','.xml','.csv','.xps'];
    if((new RegExp('(' + exts.join('|').replace(/\./g, '\\.') + ')$', "i")).test(file.files[0].name))
	{
		//alert("ok");
	}
	else 
	{
		document.getElementById("attachmentedit").value = "";
		alert("Only file extensions like dwg, dxf, dgn, dwf, pdf, jpg, jpeg, png, bmp, stl, xps, xls, doc, xlsx, docx, xml, csv, xps are allowed");
		//return false;
	}
});

</script>
	
<style>

.table-hideable td,
.table-hideable th {
  width: auto;
  transition: width .5s, margin .5s;
}

.btn-condensed.btn-condensed {
  padding: 0px;
  box-shadow: none;
	border:none;
}


/* use class to have a little animation */
.hide-col {
  width: 0px !important;
  height: 0px !important;
  display: block !important;
  overflow: hidden !important;
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
}
	</style>
	
	
<script>
	
	$(function() {
  // on init
  $(".table-hideable .hide-col").each(HideColumnIndex);

  // on click
  $('.hide-column').click(HideColumnIndex)

  function HideColumnIndex() {
    var $el = $(this);
    var $cell = $el.closest('th,td')
    var $table = $cell.closest('table')

    // get cell location - https://stackoverflow.com/a/4999018/1366033
    var colIndex = $cell[0].cellIndex + 1;

    // find and hide col index
    $table.find("tbody tr, thead tr")
      .children(":nth-child(" + colIndex + ")")
      .addClass('hide-col');
      
    // show restore footer
    $table.find(".footer-restore-columns").show()
  }

  // restore columns footer
  $(".restore-columns").click(function(e) {
    var $table = $(this).closest('table')
    $table.find(".footer-restore-columns").hide()
    $table.find("th, td")
      .removeClass('hide-col');

  })

 /* $('[data-toggle="tooltip"]').tooltip({
    trigger: 'hover'
  })*/

})
	
	</script>

</head>

	<style>
        .imgbtn{width:14px; height:14px; border:none; padding: 0}
        .es{display:none}
    </style>
<div style="overflow-x:auto;">
	<table width="100%" border="0">
  <thead>
      <?php
             $companyQ = "SELECT companyName,company_logo,street, city, email, gname, phone, website, fax, country FROM company WHERE serial='$id'";
             $resCompany = mysql_query($companyQ);
             $rowCompany = mysql_fetch_assoc($resCompany);

             $address = array();
        if (!empty($rowCompany[street])) {
            array_push($address, $rowCompany[street]);
        }
        if (!empty($rowCompany[city])) {
            array_push($address, $rowCompany[city]);
        }
        if (!empty($rowCompany[country])) {
            array_push($address, $rowCompany[country]);
        }

             ?>
	  
    <tr>
      <td align="right"><img src="../01-home/companylogos/<?php echo $rowCompany['company_logo']; ?>" height="48" alt=""/></td>
    </tr>
  </thead>
</table>


	
	
	
<div id="formdiv" > <!--div for the form (style="display:none;")-->
<!--<table name="entryformheading" align="center" width="80%" class="table1" border="0" cellpadding="0">
     <tr>
      <th>
      <div style='float: left; text-align: left'><button id="hideformdiv" class="button1">&#x25bc;</button>
      Add</div>
      <div style='float: right; text-align: right'>&nbsp;</div>
      </th>
    </tr>
  </table>-->

  <fieldset>
<legend align="center">DRAWINGS CONTROL LIST</legend>
      <?php
      $result = mysql_query("SELECT * FROM scope_dwg  where dwgID ='$expand_id'");
      $row = mysql_fetch_array($result, MYSQL_ASSOC);
      $dwgTitle = $row['dwgList_Title'];
      $dwgProject = $row['dwgProject'];
            $phaseID = $row['phaseID'];
			$zoneID = $row['zoneID'];
	  $contractID = $row['contractID'];
      $dwgType = $row['dwgType'];
      $dwgcomplePercent = $row['dwgcomplePercent'];
      $designType = $row['dwg_type'];
      $dwgConsultant = $row['dwg_consultantID'];
      $date = $row['dwgDateCreated'];
      
      ?>
<table name="entryform" align="center" class="table3" width="90%" border="0" cellpadding="0">
    <tr>
      <td width="10%" align="left" valign="top"><strong>Project Code</strong></td>
      <td width="22%" align="left" valign="top"><input type="text" name="Project" value="<?php
          $result = mysql_query("SELECT projectSerial,projectCode, projectName FROM projects where companySerial = '$id' AND projStatus=1 AND projectSerial='$dwgProject' ");
          if($rows = mysql_fetch_array($result, MYSQL_ASSOC)) {
                  echo $rows["projectCode"] . " - " . $rows["projectName"];

          } ?>" readonly style="background-color:gainsboro"></td>
      <td width="10%" align="left" valign="top"><strong>DWG Set Title</strong></td>
      <td width="22%" align="left" valign="top"><input type="text" name="Project" value="<?php echo $dwgTitle ?>" readonly style="background-color:gainsboro"></td>
      <td width="10%" align="left" valign="top"><strong>Related SOW</strong></td>
      <td width="23%" align="left" valign="top">
        <input readonly style="background-color:gainsboro" type="text" name="handover" 
			value="<?php
            if($resultSW = mysql_query("SELECT sowName FROM scope_sow WHERE sowID='".$row['dwg_sowID']."'")){
          $rowSW = mysql_fetch_array($resultSW, MYSQL_ASSOC);
                $SOW = $rowSW['sowName'];
                  echo $SOW;
          }
          ?>" >
      </td>
      </tr>
    <tr>
      <td align="left" valign="top"><strong>Phase</strong></td>
      <td align="left" valign="top">
		  

		  
		  <input type="text" name="Project" value="<?php 								 
                $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;
                    }

                    ?>" readonly style="background-color:gainsboro">
		  
		  </td>
      <td align="left" valign="top" class="table1"><strong>Zone</strong></td>
      <td align="left" valign="top" class="table1">
		<input type="text" name="Project" value="<?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;
                    }

                    ?>" readonly style="background-color:gainsboro">								 

		
		</td>
      <td align="left" valign="top"><strong>Contract</strong></td>
      <td align="left" valign="top">
		<input type="text" name="Project" value="<?php
        $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'
                     ");

        if ($row29 = mysql_fetch_array($result29, MYSQL_ASSOC)) {
            //$i = $row29['Contract_no'];
            $n = $row29['Contract_no'];
            echo $n;
        } ?>" readonly style="background-color:gainsboro">
		
		</td>
      </tr>
    <tr>
      <td align="left" valign="top"><strong>Type</strong></td>
      <td align="left" valign="top"><input type="text" name="Project" value="<?php echo $dwgType; ?>" readonly style="background-color:gainsboro"></td>
      <td align="left" valign="top" class="table1"><strong>Stage</strong></td>
      <td align="left" valign="top" class="table1"><input type="text" name="plantitle" value="<?php echo $dwgcomplePercent; ?> Percent" readonly style="background-color:gainsboro"></td>
      <td align="left" valign="top"><strong>of</strong></td>
      <td align="left" valign="top"><input type="text" name="planid" value="<?php echo $designType = $row['dwg_type']; ?>" readonly style="background-color:gainsboro"></td>
      </tr>
    <tr>
      <td align="left" valign="top"><strong>Consultant</strong></td>
      <td align="left" valign="top"><input type="text" name="Project" value="<?php
          $resultC = mysql_query("SELECT conSerial,conName,conContactName,conDepartment,conDesignation FROM consultants WHERE companySerial = '$id' AND
                                          conStatus=1 AND conSerial = '$dwgConsultant'");

          if ($rowC = mysql_fetch_array($resultC, MYSQL_ASSOC)) {
              echo $rowC["conName"]." ";
          }
          ?>" readonly style="background-color:gainsboro"></td>
      <td align="left" valign="top" class="table1"><strong>Date</strong></td>
      <td align="left" valign="top" class="table1"><input type="text" name="datetime" value="<?php echo $date; ?>" readonly style="background-color:gainsboro"></td>
      <td align="left" valign="top"><strong>Proponent</strong></td>
      <td align="left" valign="top"><input type="text" name="Proponent" value="Nothing to display" readonly style="background-color:gainsboro"></td>
      </tr>
</table>


<input id="edit_id" name="edit_id" type="hidden" value="<?php echo $_REQUEST['expand_id']; ?>">
  </fieldset>
  </div>
</div>

	<table width="95%" border="0" cellpadding="0" align="center">
  <tbody>
    <tr>
      <td align="right">&nbsp;</td>
    </tr>
  </tbody>
</table>
	
	
<table width="95%" align="center" class="no-print">
    <tbody>
    <tr align="right">

        <td align="right">

            <select name="discipline" id="discipline" style="width:10% !important" >
                <option value="">Select a Discipline</option>
            </select>

            <select name="title" id="title" style="width:10% !important">
                <option value="">Select a Title</option>
            </select>
            <span></span>
<form method="get" action="" style="display: inline">
            <input name="search-text" id="search-text" type="text"  style="width:10% !important" placeholder="Search Text">

    <input type="hidden" name="expand_id" value="<?php echo $expand_id; ?>">
            <button class="button3"> <img src="img/filter.png" width="14" height="14" alt=""/></a></button>
</form>
        </td>
    </tr>
    </tbody>
</table>


<table width="95%" border="0" align="center" class="table2 table-condensed table-hover table-bordered table-striped table-hideable" cellpadding="0">
  <tbody>
    <tr bgcolor="#E3E3E3" class="no-print">
      <td bgcolor="#D3D3D3"><a href="03-06Scope-02Drawings01-PV.php?expand_id=<?php echo $row['dwgID']; ?>"><img src="img/eye.png" width="10" height="10" alt="" title="Show All Columns"/></a></td>
      <td bgcolor="#D3D3D3"><button class="pull-right btn btn-default btn-condensed hide-column" data-toggle="tooltip" data-placement="bottom" title="Hide Column"><img src="img/eyecross.png" width="10" height="10" alt=""/>  </button></td>
      <td bgcolor="#D3D3D3"><button class="pull-right btn btn-default btn-condensed hide-column" data-toggle="tooltip" data-placement="bottom" title="Hide Column"><img src="img/eyecross.png" width="10" height="10" alt=""/>  </button></td>
      <td bgcolor="#D3D3D3"><button class="pull-right btn btn-default btn-condensed hide-column" data-toggle="tooltip" data-placement="bottom" title="Hide Column"><img src="img/eyecross.png" width="10" height="10" alt=""/>  </button></td>
      <td bgcolor="#D3D3D3"><button class="pull-right btn btn-default btn-condensed hide-column" data-toggle="tooltip" data-placement="bottom" title="Hide Column"><img src="img/eyecross.png" width="10" height="10" alt=""/>  </button></td>
      <td bgcolor="#D3D3D3"><button class="pull-right btn btn-default btn-condensed hide-column" data-toggle="tooltip" data-placement="bottom" title="Hide Column"><img src="img/eyecross.png" width="10" height="10" alt=""/>  </button></td>
      <td bgcolor="#D3D3D3"><button class="pull-right btn btn-default btn-condensed hide-column" data-toggle="tooltip" data-placement="bottom" title="Hide Column"><img src="img/eyecross.png" width="10" height="10" alt=""/>  </button></td>
      <td bgcolor="#D3D3D3"><button class="pull-right btn btn-default btn-condensed hide-column" data-toggle="tooltip" data-placement="bottom" title="Hide Column"><img src="img/eyecross.png" width="10" height="10" alt=""/>  </button></td>
    </tr>
    <tr bgcolor="#E3E3E3">
      <td width="4%" bgcolor="#D3D3D3"><span class="subTitle">#</span></td>
      <td width="6%" bgcolor="#D3D3D3"><span class="subTitle">ISSUED</span></td>
      <td width="10%" bgcolor="#D3D3D3"><span class="subTitle">Discipline</span></td>
      <td width="10%" bgcolor="#D3D3D3"><span class="subTitle">SUFFIX/DWG</span></td>
      <td width="11%" bgcolor="#D3D3D3"><span class="subTitle">SHEET/REV</span></td>
      <td width="17%" bgcolor="#D3D3D3"><span class="subTitle">DWG TITLE</span></td>
      <td width="17%" bgcolor="#D3D3D3"><span class="subTitle">DWG SUB-TITLE</span></td>
      <td width="15%" bgcolor="#D3D3D3"><span class="subTitle">FILENAME</span></td>
     <!-- <td width="10%" bgcolor="#D3D3D3"><span class="subTitle">ACTIONS</span></td>  -->
    </tr>
    <?php
    $DID = $expand_id;
    $reserved_sheets = array();
    $titleDD = array();
    $disciplineDD = array();
    $discipline = array();
    $reserved_rev = array();
    $query = "SELECT * FROM scope_dwg_revisions WHERE dwg_id =$DID";
    $result = mysql_query($query);
	$range = mysql_num_rows($result);
    while ($rr = mysql_fetch_array($result)) {
        array_push($reserved_sheets, $rr['sheet_no']);
        array_push($reserved_rev, $rr['rev_no']);
    }

    //getting dynamic ranges of dwg doc
    $drawingRange = array();
    $rangeQ = "SELECT * FROM scope_dwg_range WHERE dwgID = '$DID' AND companyID = '$company_id' AND status = '1'";
    $rangeRes = mysql_query( $rangeQ );
    while( $rangeRow = mysql_fetch_assoc($rangeRes)){
        $dRange = range($rangeRow[range_from],$rangeRow[range_to]);
        $dRange = preg_filter('/^/', $rangeRow[dwg_suffix].'_', $dRange);  //appending prefix with dwg suffix
        $drawingRange = array_merge(  $drawingRange, $dRange );
    }

$serial =0;




    foreach ($drawingRange as $range) {

        $rangeSuffix = explode( '_', $range);       //splitting range no and suffix
        $suffix = $rangeSuffix[0];
        $i = $rangeSuffix[1];



    $query = "SELECT * FROM scope_dwg_revisions WHERE dwg_id =$DID AND range_no=$i  order by sheet_no, rev_no ";
    $result = mysql_query($query);
	$have_rows = mysql_num_rows($result);
    //$rew = mysql_fetch_object($result);

    if ($have_rows) {
		while($rew = mysql_fetch_object($result)){
			$dwgDiscipline = $rew->discipline;
            $disciplineName = '';
            $resultD = mysql_query("SELECT discipline_name,discipline_code FROM discipline where discipline_company_id = '$id' 
                                          AND discipline_status=1 AND discipline_id='$dwgDiscipline' ");
            if ($rowD = mysql_fetch_array($resultD, MYSQL_ASSOC)) {
                $disciplineName =  $rowD['discipline_name'];

            }

            if(!in_array($disciplineName, $disciplineDD))
                array_push( $disciplineDD, $disciplineName);

            if(!in_array($rew->dwg_title, $titleDD))
                array_push( $titleDD,$rew->dwg_title);

    ?>

       
        <!-------------------------------------------------- Show DWG Row --------------------------------------------------->
    <tr class="rs tableData read_section<?php echo $rew->id ?>" >
      <td class="tdData" valign="middle"><?php echo ++$serial; ?></td>
      <td class="tdData"  valign="middle"><?php echo $rew->dwg_idate ?></td>
      <td  class="tdData disciplineName" valign="middle"><?php echo $disciplineName; ?>
          
                                            </td>
      <td class="tdData"  valign="middle"><?php echo $suffix .  " - ". $i; ?></td>
      <td class="tdData"  valign="middle"><?php echo str_pad($rew->sheet_no, 3, '0', STR_PAD_LEFT) . "-" . str_pad($rew->rev_no, 3, '0', STR_PAD_LEFT); ?>
      </td>
      <td class="tdData title"  valign="middle"><?php echo $rew->dwg_title;
          
      ?></td>
      <td class="tdData"  valign="middle"><?php echo $rew->dwg_title2 ?></td>
      <td class="tdData"  valign="middle">
          <input type="hidden" name="old_filename"  value="<?php echo $rew->attachment ?>"/>
          <?php if ($rew->attachment != "") { ?>
              <a href="uploads/<?php echo $rew->attachment ?>" target="_blank" ><?php echo $rew->attachment ?></a> <?php } ?>
      </td>
      
      <!--
      <td valign="middle"><img width="14" height="14" onClick="ShowEditSection(<?php echo $rew->id ?>)" name="edit2" title="Edit" src="img/edit.png" style="cursor: pointer"  alt=""/>&nbsp; <img width="14" height="14" onClick="ShowSheetSection(<?php echo $rew->id; ?>)" title="Add Sheet" src="img/addSheets.png" style="cursor: pointer"  alt=""/>&nbsp; <img width="14" height="14" onClick="ShowRevSection(<?php echo $rew->id; ?>)" title="Add Revision" src="img/addRev.png" style="cursor: pointer"  alt=""/>&nbsp;
         <?php if(!($rew->rev_no=="000" && $rew->sheet_no =="001")) {?><a style="text-decoration:none" href="03-06Scope-02Drawings01DB.php?dwgID=<?php echo $DID ?>&del=<?php echo $rew->id ?>"><img onClick="return confirm('Are you sure you want to delete the record?');"
               height="14" style="cursor:pointer" width="14" name="delete2" title="Delete" src="img/delete.png"  alt=""/>&nbsp;</a><?php } ?>

      </td>
      
      -->
      </tr>

    
    
        <?php
		}
        }

    }
    ?>
</table>
<br><br>

<script>



    $(document).ready(function()
    {
        var subs = <?php echo json_encode($titleDD); ?>;
        $.each(subs, function(val, text) {
            $('#title').append( $('<option></option>').val(text).html(text) )
        }); // there was also a ) missing here        
        
        
         var disp = <?php echo json_encode($disciplineDD); ?>;
        
        $.each(disp, function(val, text) {
            $('#discipline').append( $('<option></option>').val(text).html(text) )
        }); // there was also a ) missing here


        $('#search-text').keyup(function(e) {
            //console.log('keyup');
            $resultsFound = 0;
            $searchData = $(this).val().toLowerCase();
            $('.tableData').each(function(index, element) {
                $t = $(this);
                $status = false;
                $(this).find('td.tdData').each(function(index, element) {
                    $value = $(this).html();
                    if ($value.toLowerCase().indexOf($searchData) >= 0){
                        $status = true;
                    }
                });
                if($status){
                    $resultsFound++;
                    $t.show();
                }else{
                    $t.hide();
                }

            });
        });

        $('#discipline').change(function(e) {

            $searchData = $(this).val().toLowerCase();
            $('.tableData').each(function(index, element) {
                $t = $(this);
                $status = false;
                $(this).find('td.disciplineName').each(function(index, element) {
                    $value = $(this).html();
                    if ($value.toLowerCase().indexOf($searchData) >= 0){
                        $status = true;
                        //console.log('find');
                    }
                });
                if($status){
                    $t.show();
                }else{
                    $t.hide();
                }
            });
        });
        $('#title').change(function(e) {

            $searchData = $(this).val().toLowerCase();
            $('.tableData').each(function(index, element) {
                $t = $(this);
                $status = false;
                $(this).find('td.title').each(function(index, element) {
                    $value = $(this).html();
                    if ($value.toLowerCase().indexOf($searchData) >= 0){
                        $status = true;
                        //console.log('find');
                    }
                });
                if($status){
                    $t.show();
                }else{
                    $t.hide();
                }
            });
        });



    });
</script>
<script language="javascript">
    function ShowEditSection(id) {
		 $(".rev_section" + id).hide();
		  $(".sheet_section" + id).hide();
        $(".read_section" + id).hide();
        $(".edit_section" + id).show();
    }
	
	function ShowRevSection(id) {
		$(".edit_section" + id).hide();
        $(".rev_section" + id).show();
		$(".sheet_section" + id).hide();
		document.getElementById("task" +id).value = "add";
		
    }
	
	function ShowSheetSection(id) {
		$(".edit_section" + id).hide();
		 $(".rev_section" + id).hide();
        $(".sheet_section" + id).show();
		document.getElementById("task" +id).value = "add";
		
    }
	
    function showreadsection(id) {
		
		$(".sheet_section" + id).hide();
		$(".rev_section" + id).hide();
        $(".edit_section" + id).hide();
        $(".read_section" + id).show();

    }
	
</script>

</body>
</html>

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