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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SOW</title>

<style>
    .editfield{display:none}
    .pheadin-txt .panel-numbering,.pheadin-txt .htitle {font-size:14px; font-weight:bold}
    .whead{    padding: 4px 0 4px 0;}
    .panel-edit a{margin-right:7px}
    .panel-edit span{margin-left:7px}
    .panel-edit{text-align:right}
    .panel-detail{padding:0 !important}
    .content .widget > [class*="whead"] h6 {
        padding: 7px 14px 5px 3px !important;
    }
     .panel-edit .glyph{float:right}
    .delhead{float:right}
    .delhead .fa{color:#900; font-size:16px;padding-right:0px !important}
    .update_alert{width:30% !important; margin:0 auto 2px auto !important; padding:3px !important; text-align:center }
    .delhead{margin: 0 0 0 10px !important}
</style>

<?php
$BID =isset($_GET['BID'])?$_GET['BID']:0;
 $cid  = $_SESSION['id'];
 $scope ='sow-brief';
 
 
  $result = mysql_query("SELECT scope_sow.*,projects.projectName,projects.projectCode,client.clientName FROM projects,client,scope_sow where scope_sow.sowCompany='$id' AND scope_sow.sowID='$BID' AND (scope_sow.sowStatus='1' || scope_sow.sowStatus='3') AND projects.projectSerial=scope_sow.sowProject AND client.clientSerial=scope_sow.sowClient");
   		$row = mysql_fetch_array($result , MYSQL_ASSOC);  		
			$PreparedBy = "";
  		 if($row["sowPreparedBy"]==0){
			$resultPre = mysql_query("SELECT firstName, lastName FROM login where loginId='" . $id . "'"); 
			$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["sowPreparedBy"]."'"); 
			 $PreparedBy .= mysql_result($resultPre,0,0);
			 $PreparedBy .=" ". mysql_result($resultPre,0,1);
		 }	
          
                 $bstatus = $row['sowStatus'];
?>

<style>
.table1 td {
    border-bottom: 1px solid #000;
}

.table2 td {
    border-bottom: 1px solid #BBBBBB;
}
</style>

<strong>
<h1>SCOPE OF WORK</h1></strong>
<table width="100%" class="table1" border="0">
  <tbody>
    <tr>
      <td width="15%"><em>Project Name</em></td>
		<td width="35%"><strong><?php echo $row["projectName"] ; ?></strong></td>
      <td width="15%"><em>Project Code</em></td>
      <td width="35%"><span class="col-sm-2-2 docdetail-field" style="padding-left:0px;"><?php echo $row["projectCode"]; ?></span></td>
    </tr>
    <tr>
      <td><em>Prepared By</em></td>
      <td><span class="prj-table-vendour"><?php echo $PreparedBy; ?></span></td>
      <td><em>Submitted To</em></td>
      <td><strong><?php echo $row["clientName"]; ?>&nbsp;</strong></td>
    </tr>
    <tr>
      <td><em>Title</em></td>
      <td><span class="prj-table-name"><?php echo $row['sowName'] ; ?></span></td>
      <td><em>SOW ID Code</em></td>
	  <td><span class="prj-table-code"><?php echo "SOW-" . $row['sowID']; ?></span></td>
    </tr>
    <tr>
      <td><em>Dated</em></td>
      <td><span class="prj-table-datecreated"><?php echo $row['sowDateCreated']; ?></span></td>
      <td><em>Revision</em></td>
      <td><span class="prj-table-code"><?php echo  $row['sowrev']; ?></span></td>
    </tr>
  </tbody>
</table>
<br>
<br>
<!-- no need to show fixed headings  -->	
	<?php //$query ="SELECT heading, id from scope_brief WHERE scope_type='$scope' AND (company_id= 0 OR company_id = '$cid') AND (brief_id= 0 OR brief_id = '$BID') ";  
// $result = mysql_query($query);
//$k =1;
 ?>


    <?php
    $query = "SELECT heading, id from scope_brief WHERE scope_type='$scope' AND company_id = '$cid' AND brief_id = '$BID' AND parent = 0 ";
    $result = mysql_query($query);
    $k = 1;
    ?>
    <?php while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { ?>

        <table width="100%" class="table2" border="0">
            <tbody>
            <tr>
                <td><strong><?php echo $k  ?>. <?php echo $row['heading'] ?></strong></td>
            </tr>
            </tbody>
        </table>
        <?php
        $query2 = "SELECT description from scope_brief_description WHERE `heading_id` = '" . $row['id'] . "' AND `brief_id` ='" . $BID . "' AND company_id= '$cid'";
        $results = mysql_query($query2);
        $row2 = mysql_fetch_object($results);
        ?>
        <?php echo @$row2->description ?>
        <br />

        <!--     sub heading -->
        <?php
// code for custom headings
        $resultH = mysql_query("SELECT * FROM scope_brief WHERE parent = ".$row['id']." AND scope_type='$scope' AND  company_id = '$cid' AND brief_id = '$BID' ");

        $i = 1;

        while( $rowH = mysql_fetch_object($resultH) ) {
            $queryHD = "SELECT * from scope_brief_description WHERE `heading_id` = '" . $rowH->id . "' AND `brief_id` ='" . $BID . "' AND company_id= '$cid'";
            $resultHD = mysql_query($queryHD);
            $rowHD = mysql_fetch_object($resultHD);

            ?>
            <table width="100%" class="table2" border="0">
                <tbody>
                <tr>
                    <td><strong style="margin-left:15px"><?php echo $k . '.' . $i . '. ' . $rowH->heading; ?></strong></td>
                </tr>
                </tbody>
            </table>
            <?php echo @$rowHD->description; $i++; ?><br/>

            <?php
        }



        $k = $k + 1;

    } ?>
