<?php
include('../../includes/checkSession.php');
include('../../includes/con2pma3.php');
$companyID = $_SESSION['id'];
?>

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

<body>
<?php
$BID =isset($_GET['sid'])?$_GET['sid']:0;
$cid  = $_SESSION['id'];
$scope ='specs-brief';


$result = mysql_query("SELECT specs_scope.*,projects.*,client.* FROM projects,client,specs_scope where specs_scope.companyID='$id' AND specs_scope.SPECID='$BID' AND specs_scope.spec_status='1' AND projects.projectSerial=specs_scope.spec_project AND client.clientSerial=specs_scope.spec_client ");
$row = mysql_fetch_array($result , MYSQL_ASSOC);
$PreparedBy = "";
if($row["spec_preparedby"]==$row["companyID"]){
	$resultPre = mysql_query("SELECT firstName, lastName FROM login where loginId='".$row["spec_preparedby"]."'");
	//$PreparedBy .= mysql_result($resultPre,0,0);
	//$PreparedBy .=" ". mysql_result($resultPre,0,1);
}
else{
	$resultPre = mysql_query("SELECT internal_personnel_firstName, internal_personnel_lastName FROM internal_personnel where internal_personnel_id='".$row["spec_preparedby"]."'");
	$PreparedBy .= mysql_result($resultPre,0,0);
	$PreparedBy .=" ". mysql_result($resultPre,0,1);
}

$resultS = mysql_query("SELECT pack_id,pack_type from specs_scope_brief WHERE scope_type='$scope' AND brief_id = '$BID' AND pack_id > 0 GROUP BY pack_id");
$arr = array();
while($rowS = mysql_fetch_array($resultS)){
	$arr[$rowS['pack_id']] = $rowS;
}

$resultS = mysql_query("SELECT pack_id,pack_type from specs_scope_brief_description WHERE scope_type='$scope' AND brief_id = '$BID' AND pack_id > 0 GROUP BY pack_id");
while($rowS = mysql_fetch_array($resultS)){
	$arr[$rowS['pack_id']] = $rowS;
}
foreach($arr as $key => $wids){
	$WID = $wids['pack_id'];
?>
<div>
    <br><br>
    <fieldset>
        <legend align="center"><?php echo $row["title"]; ?></legend>
        <table name="entryform" align="center" class="table1" width="80%" border="0" cellpadding="0">
            <tr>
                <td colspan="6" align="center" valign="top"><span class="projectTitle">
				<?php  
				if($wids['pack_type'] != ""){
					if($wids['pack_type'] == "wbs"){
						$result1 = mysql_query("SELECT * FROM globalwbs where WBSID ='$WID' && companyID = '$cid'  ORDER BY WBSIDA ASC,WBSIDB ASC,WBSIDC ASC,WBSIDD ASC,WBSIDE ASC");
						$row1wbs = mysql_fetch_array($result1 , MYSQL_ASSOC);
						echo $row1wbs["description"];  
						$WBSIDA = $row1wbs["WBSIDA"];
						$WBSIDB = $row1wbs["WBSIDB"];
						$WBSIDC = $row1wbs["WBSIDC"];
						$WBSIDD = $row1wbs["WBSIDD"];
						$WBSIDE = $row1wbs["WBSIDE"];
						$WBSID1 = $row1wbs["WBSID"];
						$parent = $row1wbs["parent"];
						$wbs_code = $WBSIDA.".".$WBSIDB.".".$WBSIDC.".".$WBSIDD.".".$WBSIDE;               
					}else{
						$iid = $wids['pack_id'];
						$result123 = mysql_query("SELECT * FROM globalitems where itemID='$iid' ORDER BY itemID ASC");			
						$row1item = mysql_fetch_array($result123 , MYSQL_ASSOC);
						echo $row1item["description"];
						
						$result1 = mysql_query("SELECT * FROM globalwbs where WBSID ='".$row1item['WBSID']."' && companyID = '$cid' ");
						$row1wbs = mysql_fetch_array($result1 , MYSQL_ASSOC);
						$WBSIDA = $row1wbs["WBSIDA"];
						$WBSIDB = $row1wbs["WBSIDB"];
						$WBSIDC = $row1wbs["WBSIDC"];
						$WBSIDD = $row1wbs["WBSIDD"];
						$WBSIDE = $row1wbs["WBSIDE"];
						$WBSID1 = $row1wbs["WBSID"];
						$parent = $row1wbs["parent"];
						$wbs_code = $WBSIDA.".".$WBSIDB.".".$WBSIDC.".".$WBSIDD.".".$WBSIDE.".".$row1item["itemID"]; 
						                     
					}
				}
                ?>
                
                </span>
                </td>
            </tr>
            <tr>
                <td width="9%" align="left" valign="top"><strong>Project</strong>:</td>
                <td width="28%" align="left" valign="top"><?php echo $row["projectCode"]; ?> - <?php echo $row["projectName"]; ?></td>
                <td align="left" valign="top"><strong>Client</strong>:</td>
                <td align="left" valign="top"><?php echo $row["clientCode"]; ?> - <?php echo $row["clientName"]; ?></td>
                <td width="7%" align="left" valign="top"><strong>Consultant</strong></td>
                <td width="23%" align="left" valign="top">
					<?php $resultC = mysql_query("SELECT * FROM consultants WHERE conSerial = '".$row['spec_consultant']."'");
					  $consaltant = mysql_fetch_array($resultC, MYSQL_ASSOC);
					  echo $consaltant["conCode"]." - ".$consaltant['conName']."";
					?>
                </td>
            </tr>
        </table>
    </fieldset>
    <br />
</div>
<table width="95%" border="0" align="center" cellpadding="0" class="table3">
  <tbody>
    <tr>
      <td ><span class="subTitle"><?php echo $wbs_code;?></span></td>
    </tr>
  </tbody>
</table>
<br>
<br />
<table align="center" width="95%" class="table1" border="0">
  <tbody>
    <tr>
      <td  width="95%"><span class="subTitle">1.0 GENERAL</span></td>
    </tr>
  </tbody>
</table>
<br />
<?php
    $queryGen ="SELECT * from specs_scope_brief WHERE scope_type='$scope' AND (company_id= 0 OR company_id = '$cid') AND (brief_id= 0 OR brief_id = '$BID') AND brief_type ='General' AND (pack_id = 0 OR pack_id = '".$WID."')";
    $resultGen = mysql_query($queryGen);
    $k=1;

    while ($rowGen = mysql_fetch_array($resultGen, MYSQL_ASSOC)) {

        $query2Gen ="SELECT * from specs_scope_brief_description WHERE `heading_id` = '".$rowGen['id']."' AND `brief_id` ='".$BID."' AND company_id= '$cid' AND pack_id = '".$WID."'";
        $resultsGen = mysql_query($query2Gen);
        $row2Gen = mysql_fetch_object($resultsGen);	
        ?>        
        <table align="center" width="95%" class="table1" border="0">
          <tbody>
            <tr>
              <td width="95%"><strong><em><?php  echo '1.'.$k.'. '.$rowGen['heading']; ?></em></strong></td>
            </tr>
          </tbody>
        </table>
        <table class="table1" align="center" width="95%" border="0">
          <tbody>
            <tr>
              <td width="3%">&nbsp;</td>
              <td width="97%"><?php  echo ((@$row2Gen->description) ? @$row2Gen->description : ''); ?></td>
            </tr>
          </tbody>
        </table>
<br />
<br />
        
<?php $k=$k+1; 
} ?>  
<table align="center" width="95%" class="table1" border="0">
  <tbody>
    <tr>
      <td width="95%"><span class="subTitle" >2.0 PRODUCTS </span></td>
    </tr>
  </tbody>
</table>
<br />
<?php
 $queryPro ="SELECT * from specs_scope_brief WHERE scope_type='$scope' AND (company_id= 0 OR company_id = '$cid') AND (brief_id= 0 OR brief_id = '$BID') AND brief_type='Products' AND (pack_id = 0 OR pack_id = '".$WID."')";
 $resultPro = mysql_query($queryPro);
 $k = 1;

while ($rowPro = mysql_fetch_array($resultPro, MYSQL_ASSOC)) {

    $query2Pro ="SELECT * from specs_scope_brief_description WHERE `heading_id` = '".$rowPro['id']."' AND `brief_id` ='".$BID."' AND company_id= '$cid' AND pack_id = '".$WID."'";
    $resultsPro = mysql_query($query2Pro);
    $row2Pro = mysql_fetch_object($resultsPro);
?>	
    <table align="center" width="95%" class="table1" border="0">
      <tbody>
        <tr>
          <td width="95%"><strong><em><?php  echo '2.'.$k.'. '.$rowPro['heading']; ?></em></strong></td>
        </tr>
      </tbody>
    </table>
    <table class="table1" align="center" width="95%" border="0">
      <tbody>
        <tr>
          <td width="3%">&nbsp;</td>
          <td width="97%"><?php  echo ((@$row2Pro->description) ? @$row2Pro->description : ''); ?></td>
        </tr>
      </tbody>
    </table>
    <br />
    <br />
<?php
    $k=$k+1;
    }
?>
<table align="center" width="95%" class="table1" border="0">
  <tbody>
    <tr>
	  <td width="95%"><span class="subTitle" >3.0 EXECUTION</span> </td>
    </tr>
  </tbody>
</table>
<br />
<?php
    $queryExe ="SELECT * from specs_scope_brief WHERE scope_type='$scope' AND (company_id= 0 OR company_id = '$cid') AND (brief_id= 0 OR brief_id = '$BID') AND brief_type='Execution' AND (pack_id = 0 OR pack_id = '".$WID."')";
    $resultExe = mysql_query($queryExe);
    $k=1;

    while ($rowExe = mysql_fetch_array($resultExe, MYSQL_ASSOC)) {

        $query2Exe ="SELECT * from specs_scope_brief_description WHERE `heading_id` = '".$rowExe['id']."' AND `brief_id` ='".$BID."' AND company_id= '$cid' AND pack_id = '".$WID."'";
        $resultsExe = mysql_query($query2Exe);
        $row2Exe = mysql_fetch_object($resultsExe);

?>
		<table align="center" width="95%" class="table1" border="0">
          <tbody>
            <tr>
              <td width="95%"><strong><em><?php  echo '3.'.$k.'. '.$rowExe['heading']; ?></em></strong></td>
            </tr>
          </tbody>
        </table>
        <table class="table1" align="center" width="95%" border="0">
          <tbody>
            <tr>
              <td width="3%">&nbsp;</td>
              <td width="97%"><?php  echo ((@$row2Exe->description) ? @$row2Exe->description : ''); ?></td>
            </tr>
          </tbody>
        </table>
        <br />
        <br />

<?php
	$k=$k+1;
}
?>
<table align="center" width="95%" class="table2" border="0">
  <tbody>
    <tr>
      <td width="25%"><strong></strong></td>
      <td width="25%">&nbsp;</td>
      <td width="25%">&nbsp;</td>
      <td width="25%">&nbsp;</td>
    </tr>
    <tr>
      <td><em>Signatures</em></td>
      <td><em>Signatures</em></td>
      <td><em>Signatures</em></td>
      <td><em>Signatures</em></td>
    </tr>
    <tr>
      <td><em>Prepared By</em></td>
      <td><em>Reviewed By</em></td>
      <td><em>Approved By</em></td>
      <td><em>Received By</em></td>
    </tr>
    <tr>
      <td><em>Name: </em><?php echo $_SESSION['UserName']; ?></td>
      <td><em>Name</em></td>
      <td><em>Name</em></td>
      <td><em>Name</em></td>
    </tr>
    <tr>
      <td><em>Date: </em><?php echo $row['obs_creation_date'];?></td>
      <td><em>Date</em></td>
      <td><em>Date</em></td>
      <td><em>Date</em></td>
    </tr>
  </tbody>
</table>  
<hr>
<?php
}
?>
</body>
</html>

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