<?php
include('../../includes/checkSession.php');
include('../../includes/con2pma3.php');
include("getname.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>Variation SOW Brief</title>
    <?php
    $BID =isset($_GET['BID'])?$_GET['BID']:0;
    $cid  = $_SESSION['id'];
    $scope ='variation-brief';
    $queryr = "SELECT var.*,projects.projectName /*,client.clientName ,client.clientContactName*/ FROM projects, /*client,*/ var where var.companyID='$id' AND var.var_id='$BID' AND
 (var.var_status='1' || var.var_status='3' || var.var_status='4') AND projects.projectSerial=var.var_project_id /* AND client.clientSerial=scope_sow.sowClient*/";

    $result = mysql_query($queryr);
    $row = mysql_fetch_array($result , MYSQL_ASSOC);
    $PreparedBy = $row[var_inputby];


    $bstatus = $row['var_status'];
    ?>

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

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

    <strong>
        <h1>SOW VARIATION BRIEF</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>2nd Party</em></td>
            <td width="35%"><strong><?php echo $row['var_presented_to'];?> - <?php echo getName($row['var_presented_to'],$row['var_presented_toto']); ?></strong></td>
        </tr>

        <tr>
            <td><em>Variation Title</em></td>
            <td><strong><?php echo $row["var_title"]; ?></strong></td>
            <td><em>Prepared By</em></td>
            <td><strong><?php echo $PreparedBy; ?></strong></td>
        </tr>

        <tr>
            <td><em>VAR No</em></td>
            <td><strong><?php echo $BID; ?></strong></td>
            <td><em>Date Initiated</em></td>
            <td><strong><?php echo $row["var_dataentry_date"]; ?></strong></td>
        </tr>


        </tbody>
    </table>
    <br>
    <br>

    <!-- shows fixed headings which is not ncecessary  -->
    <?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);
    //                  $i = 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;

    } ?>

