<?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" />
<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>

</head>

<div><br></div>
	<style>
        .imgbtn{width:14px; height:14px; border:none; padding: 0}
        .es{display:none}
    </style>
<div style="overflow-x:auto;">
<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'];
      $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="80%" 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 type="text" name="handover" value="<?php
          $resultSW = mysql_query("SELECT sowName FROM scope_sow WHERE sowID='".$row['dwg_sowID']."'");
          if($rowSW = mysql_fetch_array($resultSW, MYSQL_ASSOC)){
                $SOW = $rowSW['sowName'];
                  echo $SOW;
          }
          ?>" readonly style="background-color:gainsboro"></td>
      <td width="3%" align="left" valign="top">&nbsp;</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>
      <td align="left" valign="top">&nbsp;</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>
      <td align="left" valign="top">&nbsp;</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>
      <td align="left" valign="top">&nbsp;</td>
    </tr>
</table>


<input id="edit_id" name="edit_id" type="hidden" value="<?php echo $_REQUEST['expand_id']; ?>">
  </fieldset>
  </div>
</div>
<table width="100%" border="0" cellpadding="0" align="center">
  <tbody>
    <tr>
      <td align="right">
      <img src="img/doubletick.png" width="15" height="15" alt=""/>&nbsp;<img src="img/lockgohome.png" width="15" height="15" alt="" title="Lock and Exit"/>&nbsp;<a href="03-06Scope-02Drawings01-PV.php?expand_id=<?php echo $row['dwgID']; ?>"><img src="img/print.png" alt="" width="15" height="15" title="Print View" border="0"/></a>&nbsp;<a href="03-06Scope-02Drawings02.php?expand_id=<?php echo $row['dwgID']; ?>"><img src="img/review.png" width="15" height="15" alt=""/></a>&nbsp;<a href="03-06Scope-01Drawings01.php"><img src="img/cancel.png" width="15" height="15" alt=""/></a></td>
    </tr>
  </tbody>
</table>
<table width="90%" border="0" align="center" class="table2" cellpadding="0">
  <tbody>
    <tr>
      <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();
    $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();
    $drawingSuffix = 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;
//    for ($i = $row['range_from']; $i <= $row['range_to']; $i++) {
    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;
    ?>
    <form enctype="multipart/form-data" style="overflow:hidden" method="post" action="03-06Scope-02Drawings01DB.php">
        <input type="hidden" name="dwg_id"  value="<?php echo $DID ?>"/>
        <input type="hidden" name="recordID"  value="<?php echo $rew->id ?>"/>
        <input type="hidden" name="range_no" id="range_no<?php echo $i ?>" value="<?php echo $i ?>"/>
        <input type="hidden" name="task" id="task<?php echo $rew->id ;?>"  value="update"/>
        <!-------------------------------------------------- Edit DWG Row --------------------------------------------------->
    <tr class="es edit_section<?php echo $rew->id ?>">
      <td valign="middle">&nbsp;</td>
      <td valign="middle"><input value="<?php echo $rew->dwg_idate;?>" name="dwg_idate" type="date" id="dwg_idate"/></td>

      <td valign="middle">
          <?php 
          //$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))
//              echo $rowD['discipline_name'];
          ?>
          <select  class="field-with-icon" name="discipline" id="discipline">
                                                <?php
                                                $resultD = mysql_query("SELECT * FROM discipline where discipline_company_id='$id' AND discipline_status='1' order by discipline_name ASC");
                                                while ($rowD = mysql_fetch_array($resultD, MYSQL_ASSOC)) {
                                                    ?>
                                                    <option <?php echo ($rew->discipline == $rowD['discipline_id']) ? "selected='selected'" : ""; ?> value="<?php echo $rowD['discipline_id']; ?>"><?php echo $rowD['discipline_name']; ?></option>
                                                <?php } ?>
                                            </select>
      </td>
      <td valign="middle"><?php echo $suffix  .  " - ". $i; ?></td>


      <td valign="middle">


          <input type="text" STYLE="WIDTH:20% !IMPORTANT" name="dwgsheet"  id="dwgsheet<?php echo $i ?>" value="<?php echo str_pad($rew->sheet_no, 3, '0', STR_PAD_LEFT); ?>"/>-<input type="text" STYLE="WIDTH:20% !IMPORTANT" name="dwgrevision"  id="dwgrevision<?php echo $i ?>" value="<?php echo str_pad($rew->rev_no, 3, '0', STR_PAD_LEFT) ?>"/>
            <!--  <option value="">--</option>-->
              <?php /* for ($j = 0; $j <= 10; $j++) { ?>

                  <?php if (false === array_search($j, $reserved_rev) || $rew->rev_no == $j) { ?>
                      <option value="<?php echo str_pad($j, 3, '0', STR_PAD_LEFT) ?>" <?php
                      if ($rew->rev_no == str_pad($j, 3, '0', STR_PAD_LEFT)) {
                          echo "selected";
                      }
                      ?>><?php echo str_pad($j, 3, '0', STR_PAD_LEFT) ?></option>
                  <?php }
              }*/
              ?>

      </td>

      <td valign="middle"><input type="text" name="dwg_title" id="dwg_title<?php echo $i ?>" value="<?php echo $rew->dwg_title ?>" /></td>
      <td valign="middle"><input type="text" name="dwg_title2" id="dwg_title2" value="<?php echo $rew->dwg_title2 ?>"/></td>
      <td valign="middle">&nbsp;<input type='file' id="attachmentedit" name='attachment' <?php echo $allowed; ?>/> </td>
      <td valign="middle">
        <input type="image" class="imgbtn" name="save2" title="Save" src="img/savedisk.png" alt=""/>&nbsp;
        <img width="14" height="14" onClick="showreadsection(<?php echo $rew->id ?>)" name="cancel" title="Cancel" src="img/cancel.png" style="cursor: pointer"  alt=""/>&nbsp;
        <!-- <img src="img/editdisk.png" width="14" height="14" alt=""/>&nbsp;
      <img src="img/delete.png" width="14" height="14" alt=""/>&nbsp;
      <img src="img/attach4.png" width="14" height="14" alt=""/>-->
      </td>
      </tr>

       

        <!-------------------------------------------------- Show DWG Row --------------------------------------------------->
    <tr class="rs read_section<?php echo $rew->id ?>">
      <td valign="middle"><?php echo ++$serial; ?></td>
      <td valign="middle"><?php echo $rew->dwg_idate ?></td>
      <td valign="middle">          <?php
          $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)) {
              echo $rowD['discipline_name'];
          }
          ?>
          
                                            </td>
      <td valign="middle"><?php echo $suffix .  " - ". $i; ?></td>
      <td 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 valign="middle"><?php echo $rew->dwg_title ?></td>
      <td valign="middle"><?php echo $rew->dwg_title2 ?></td>
      <td 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>
    
    </form>
     <!----------------------------------------------------------- Revision Row ---------------------------------- -->
     
     <form enctype="multipart/form-data" style="overflow:hidden" method="post" action="03-06Scope-02Drawings01DB.php">
        <input type="hidden" name="dwg_id"  value="<?php echo $DID ?>"/>
        <input type="hidden" name="recordID"  value="<?php echo $rew->id ?>"/>
        <input type="hidden" name="range_no" id="range_no<?php echo $i ?>" value="<?php echo $i ?>"/>
        <input type="hidden" name="task" id="task<?php echo $rew->id ;?>"  value="add"/>
      
	<tr class="es rev_section<?php echo $rew->id;?>" valign="middle">
      <td valign="middle">&nbsp;</td>
      <td valign="middle"><input value="<?php echo ($rew->dwg_idate ? date("Y-m-d",strtotime($rew->dwg_idate)) : date("Y-m-d"));?>" name="dwg_idate" type="date" id="dwg_idate"></td>

      <td valign="middle">
          <?php
     //     $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))
     //         echo $rowD['discipline_name'];
     //     ?>
     <select  class="field-with-icon" name="discipline" id="discipline">
                                                
                                                <?php
                                                $resultD = mysql_query("SELECT * FROM discipline where discipline_company_id='$id' AND discipline_status='1' order by discipline_name ASC");
                                                while ($rowD = mysql_fetch_array($resultD, MYSQL_ASSOC)) {
                                                    ?>
                                                    <option <?php echo (($rowD['discipline_id'] == $dwgDiscipline) ? "selected='selected'" : "");?> value="<?php echo $rowD['discipline_id']; ?>"><?php echo $rowD['discipline_name']; ?></option>
                                                <?php } ?>
                                            </select>
      </td>
      <td valign="middle"><?php echo $suffix .   " - ".  $i; ?></td>


      <td valign="middle"><input type="hidden" STYLE="WIDTH:20% !IMPORTANT" name="dwgsheet"  id="dwgsheet<?php echo $i ?>" value="<?php echo str_pad($rew->sheet_no, 3, '0', STR_PAD_LEFT); ?>"/><?php echo str_pad($rew->sheet_no, 3, '0', STR_PAD_LEFT)?>


          -<input type="text" STYLE="WIDTH:18% !IMPORTANT" name="dwgrevision"  id="dwgrevision<?php echo $i ?>" value="<?php echo str_pad($rew->rev_no, 3, '0', STR_PAD_LEFT) ?>"/>
            <!--  <option value="">--</option>-->
              <?php /* for ($j = 0; $j <= 10; $j++) { ?>

                  <?php if (false === array_search($j, $reserved_rev) || $rew->rev_no == $j) { ?>
                      <option value="<?php echo str_pad($j, 3, '0', STR_PAD_LEFT) ?>" <?php
                      if ($rew->rev_no == str_pad($j, 3, '0', STR_PAD_LEFT)) {
                          echo "selected";
                      }
                      ?>><?php echo str_pad($j, 3, '0', STR_PAD_LEFT) ?></option>
                  <?php }
              }*/
              ?>

      </td>

      <td valign="middle"><input type="text" name="dwg_title" required id="dwg_title<?php echo $i ?>" value="<?php echo $rew->dwg_title ?>" /></td>
      <td valign="middle"><input type="text" name="dwg_title2" id="dwg_title2"  value="<?php echo $rew->dwg_title2 ?>"/></td>
      <td valign="middle">&nbsp;<input type='file' name='attachment' <?php echo $allowed; ?> /> </td>
      <td valign="middle">
        <input type="image" class="imgbtn" name="save2" title="Save" src="img/savedisk.png" alt=""/>&nbsp;
        <img width="14" height="14" onClick="showreadsection(<?php echo $rew->id ?>)" name="cancel" title="Cancel" src="img/cancel.png" style="cursor: pointer"  alt=""/>&nbsp;
        <!-- <img src="img/editdisk.png" width="14" height="14" alt=""/>&nbsp;
      <img src="img/delete.png" width="14" height="14" alt=""/>&nbsp;
      <img src="img/attach4.png" width="14" height="14" alt=""/>-->
      </td>
      </tr>
    
    </form>
    
     <!----------------------------------------------------------- Sheet Row ---------------------------------- -->
     <form enctype="multipart/form-data" style="overflow:hidden" method="post" action="03-06Scope-02Drawings01DB.php">
        <input type="hidden" name="dwg_id"  value="<?php echo $DID ?>"/>
        <input type="hidden" name="recordID"  value="<?php echo $rew->id ?>"/>
        <input type="hidden" name="range_no" id="range_no<?php echo $i ?>" value="<?php echo $i ?>"/>
        <input type="hidden" name="task" id="task<?php echo $rew->id ;?>"  value="add"/>
      
	<tr class="es sheet_section<?php echo $rew->id;?>" valign="middle">
      <td valign="middle">&nbsp;</td>
      <td valign="middle"><input value="<?php echo ($rew->dwg_idate ? date("Y-m-d",strtotime($rew->dwg_idate)) : date("Y-m-d"));?>" name="dwg_idate" type="date" id="dwg_idate"></td>

      <td valign="middle">
          <?php
     //     $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))
     //         echo $rowD['discipline_name'];
     //     ?>
     <select  class="field-with-icon" name="discipline" id="discipline">
                                                <?php
                                                $resultD = mysql_query("SELECT * FROM discipline where discipline_company_id='$id' AND discipline_status='1' order by discipline_name ASC");
                                                while ($rowD = mysql_fetch_array($resultD, MYSQL_ASSOC)) {
                                                    ?>
                                                    <option <?php echo (($rowD['discipline_id'] == $dwgDiscipline) ? "selected='selected'" : "");?> value="<?php echo $rowD['discipline_id']; ?>"><?php echo $rowD['discipline_name']; ?></option>
                                                <?php } ?>
                                            </select>
      </td>
      <td valign="middle"><?php echo $suffix . " - ".  $i; ?></td>


      <td valign="middle"><input type="text" STYLE="WIDTH:20% !IMPORTANT" name="dwgsheet"  id="dwgsheet<?php echo $i ?>" required />
               -000<input type="hidden" STYLE="WIDTH:20% !IMPORTANT" name="dwgrevision"  id="dwgrevision<?php echo $i ?>" value="000" />
            <!--  <option value="">--</option>-->
              <?php /* for ($j = 0; $j <= 10; $j++) { ?>

                  <?php if (false === array_search($j, $reserved_rev) || $rew->rev_no == $j) { ?>
                      <option value="<?php echo str_pad($j, 3, '0', STR_PAD_LEFT) ?>" <?php
                      if ($rew->rev_no == str_pad($j, 3, '0', STR_PAD_LEFT)) {
                          echo "selected";
                      }
                      ?>><?php echo str_pad($j, 3, '0', STR_PAD_LEFT) ?></option>
                  <?php }
              }*/
              ?>

      </td>

      <td valign="middle"><input type="text" name="dwg_title" required id="dwg_title<?php echo $i ?>" value="<?php echo $rew->dwg_title ?>" /></td>
      <td valign="middle"><input type="text" name="dwg_title2" id="dwg_title2"  value="<?php echo $rew->dwg_title2 ?>"/></td>
      <td valign="middle">&nbsp;<input type='file' name='attachment' <?php echo $allowed; ?>> </td>
      <td valign="middle">
        <input type="image" class="imgbtn" name="save2" title="Save" src="img/savedisk.png" alt=""/>&nbsp;
        <img width="14" height="14" onClick="showreadsection(<?php echo $rew->id ?>)" name="cancel" title="Cancel" src="img/cancel.png" style="cursor: pointer"  alt=""/>&nbsp;
        <!-- <img src="img/editdisk.png" width="14" height="14" alt=""/>&nbsp;
      <img src="img/delete.png" width="14" height="14" alt=""/>&nbsp;
      <img src="img/attach4.png" width="14" height="14" alt=""/>-->
      </td>
      </tr>
    </form>
    
    
    
        <?php
		}
        } else {
        ?>
        
    <form enctype="multipart/form-data" style="overflow:hidden" method="post" action="03-06Scope-02Drawings01DB.php" >
        <input type="hidden" name="dwg_id"  value="<?php echo $DID ?>" />
        <input type="hidden" name="task"  value="add" />
        <input type="hidden" name="range_no" id="range_no<?php echo $i ?>" value="<?php echo $i ?>" />

<!-------------------------------------------------- Add DWG Row --------------------------------------------------->
<tr>

        <td valign="middle"><?php echo ++$serial; ?></td>
        <td valign="middle"><input value="<?php echo date("Y-m-d");?>" name="dwg_idate" type="date" id="dwg_idate"></td>

        <td valign="middle">
            <?php
       //     $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))
       //         echo $rowD['discipline_name'];
       //     ?>
       
       <select  class="field-with-icon" name="discipline" id="discipline">
                                                
                                                <?php
                                                $resultD = mysql_query("SELECT * FROM discipline where discipline_company_id='$id' AND discipline_status='1' order by discipline_name ASC");
                                                while ($rowD = mysql_fetch_array($resultD, MYSQL_ASSOC)) {
                                                    ?>
                                                    <option <?php echo (17 == $rowD['discipline_id']) ? "selected='selected'" : ""; ?> value="<?php echo $rowD['discipline_id']; ?>"><?php echo $rowD['discipline_name']; ?></option>
                                                <?php } ?>
                                            </select>
        </td>
        <td valign="middle"><?php echo $suffix .  " - ". $i; ?></td>
<td valign="middle">
           <input name="dwgsheet"  id="dwgsheet<?php echo $i ?>" value="001" STYLE="WIDTH:20% !IMPORTANT"/>
               -<input type="text" STYLE="WIDTH:20% !IMPORTANT" name="dwgrevision"  id="dwgrevision<?php echo $i ?>" value="000" />
               <?php /* for ($j = 0; $j <= 10; $j++) { ?>
                   <?php if (false === array_search($j, $reserved_rev)) { ?>
                       <option value="<?php echo str_pad($j, 3, '0', STR_PAD_LEFT) ?>"><?php echo str_pad($j, 3, '0', STR_PAD_LEFT) ?></option>
                       <?php
                   }
               } */
               ?>
           
</td>
           <td valign="middle"><input type="text" value="" required name="dwg_title" id="dwg_title<?php echo $i ?>" /></td>
           <td valign="middle"><input type="text" name="dwg_title2" id="dwg_title2"></td>
           <td valign="middle">&nbsp;<input type='file' name='attachment' <?php echo $allowed; ?> /> </td>
           <td valign="middle">

               <input type="image" src="img/savedisk.png" class="imgbtn" name="save1" title="Save"  alt=""/>&nbsp;
               <!-- <input type="image" src="img/editdisk.png" class="imgbtn" name="edit1" title="Edit" alt=""/>&nbsp;
                <input type="image" src="img/delete.png" class="imgbtn" name="delete1" title="Delete" alt=""/>&nbsp;
              <img src="img/attach4.png" width="14" height="14" alt=""/>-->
           </td>
           </tr>
    </form>
      
       
       

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

	
<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'); ?>
