<?php
include('../../includes/checkSession.php');
include('../../includes/con2pma3.php');
/*include('../includes/header_in.php');*/
/*include('../includes/topmenuin.php');*/
header("Cache-Control: no cache");
session_cache_limiter("private_no_expire");
$companyID = $_SESSION['id'];
//include('1-Quality-Procedures1DB.php');
?>

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

</head>

<!-- Hope this text editor works well --->
<!--<style type="text/css" media="all">
	@import "css/info.css";
	@import "css/main.css";
	@import "css/widgEditor.css";
</style>-->

<script>
    function sendforinitiate(bid)
    {
        var c = confirm("Are you sure you want to send this document for review? It will show in the list of documents to be assigned as an initiated document.");
        if (c)
        {
            window.location.href = "03-03Scope-01ProjectBrief01DB.php?send=" + bid;
        }
        else
        {
            return false;
        }
    }
</script>

<?php $PID = isset($_GET['pid']) ? $_GET['pid'] : 0; ?>
<?php
$cid = $_SESSION['id'];


$result = mysql_query("SELECT pdri.*,projects.projectCode,client.clientName FROM projects,client,pdri where pdri.CompanyID='$id' AND pdri.pdri_id='$PID' AND (pdri.pdri_status='1' || pdri.pdri_status='3') AND projects.projectSerial=pdri.project_id AND client.clientSerial=pdri.client_id ");
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$PreparedBy = "";
$bstatus = $row["pdri_status"];
if ($row["pdri_PreparedBy"] == 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["pdri_PreparedBy"] . "'");
    $PreparedBy .= mysql_result($resultPre, 0, 0);
    $PreparedBy .=" " . mysql_result($resultPre, 0, 1);
}
?>

<body>
<div>
    <div><br></div>

    <?php if ($uacc == "Full Control" || $uacc == "Consolidate") { ?>
    <fieldset>
        <legend align="center">PROJECT DEFINITION RATING INDEX</legend>
        <table name="entryform" align="center" class="table1" width="80%" border="0" cellpadding="0">
            <tr>
                <td width="7%" align="left" valign="top"><strong>Project Code</strong>:</td>
                <td width="30%" align="left" valign="top"><span class="col-sm-2-2 docdetail-field" style="padding-left:0px;"><?php echo $row["projectCode"]; ?></span></td>
                <td width="7%" align="left" valign="top"><strong>Title</strong></td>
                <td width="30%" align="left" valign="top"><span class="col-sm-2-2 docdetail-field" style="padding-left:0px;"><?php echo $row["pdri_name"]; ?></span></td>
                <td align="left" valign="top"><strong>ID/ Revision</strong>:</td>
                <td align="left" valign="top"><span class="col-sm-2-2 docdetail-field" style="padding-left:0px;"><?php echo "PDRI - " . $PID; ?></span></td>
            </tr>
            <tr>
              <td align="left" valign="top"><strong>Prepared By</strong>:</td>
              <td align="left" valign="top"><span class="col-sm-2-2 docdetail-field" style="padding-left:0px;"><?php echo $PreparedBy; ?></span></td>
              <td align="left" valign="top"><strong>Revision</strong>:</td>
              <td align="left" valign="top"><span class="col-sm-2-2 docdetail-field" style="padding-left:0px;"><?php echo $row["pdri_rev"]; ?></span></td>
                <td align="left" valign="top"><strong>Date Initiated</strong>:</td>
                <td align="left" valign="top"><span class="col-sm-2-2 docdetail-field" style="padding-left:0px;"><?php echo $row["creationDate"]; ?></span></td>
            </tr>

        </table>
    </fieldset>
    </div>
	
	
	<!----- TABLE FOR TOP ICONS STARTS----------------------------->
	
	<table width="100%" class="table4" align="center" border="0" cellpadding="0">
		    <?php
    $query = "SELECT * from scope_brief WHERE scope_type='$scope' AND company_id = '$cid' AND brief_id = '$BID' AND parent=0 AND status = 1  ";
    $result = mysql_query($query);
    $k = 1;
    ?>

    <tbody>

    <tr align="right">
        <td valign="top">
			<div></div><div style='float: left; text-align: left'>
			<strong>Legend</strong>: 0* = Not Applicable, 1* = Complete Definition, 2* = Minor Deficiencies, 3* = Some Deficiencies, 4* = Major Deficiencies, 5* = Incomplete or Poor Definition</div>
			
			<div style='float: right; text-align: right'>
        
            <?php if ($bstatus == 1)
            { ?>
                <input type="image" onClick="return submitallforms()" class="imgbtn" name="save1" src="img/save.png" title="Save All" />
                &nbsp;
                <input type="image" onClick="return saveandclose()" class="imgbtn" name="saveclose" src="img/close.png" title="Save and Close" />
                &nbsp;
                <a href="#">
                    <img src="img/send.png" onclick="sendforinitiate(<?php echo $BID; ?>)" width="13" height="13" alt="" title="Send for Review"/></a>
&nbsp;
                <a href="03-03Scope-01ProjectBrief01DB.php?lock=<?php echo $BID; ?>">
                    <img src="img/lockgohome.png" width="13" height="13" alt="" title="Lock and Exit"/></a>
            <?php } else if( $bstatus == 4 ){ ?>
                <a href="03-03Scope-01ProjectBrief01DB.php?unlock=<?php echo $BID; ?>">
                    <img src="img/lockgohome.png" width="13" height="13" alt="" title="Unlock"/></a>
            <?php }?>
            &nbsp;
            <a href="03-03Scope-01ProjectBrief02PV.php?BID=<?php echo $BID;?>"><img src="img/print.png" width="13" height="13" alt="" title="PrintView"/></a>
            &nbsp;
		  </div></div>
        </td>
      </tr>
	</table>
	
	
	
	
<div class="loading" style="display:none;">Loading&#8230;</div>
	
	
	
	
	
<!-----PDRI CALCULATIONS START--------------------------->
	
<form name="pdriform" method="post" action="../../DB/03-scope/PDRIonlineDB.php?pdri_id=<?php echo  $PID;?>">
                <?php
				$saveC1 = "A";
				$saveC2 = "1";
				
                  $c1 = "A";
				 
				$query = "SELECT * from pdri_rating_section WHERE status='1' ";
                $result = mysql_query($query);
                $rom ="I";
                while ($row = mysql_fetch_array($result)) {
                    ?>	
<br>
	
<table width="90%">
  <tbody>
    <tr>
      <td align="left">SECTION-<?php echo $rom; ?> : <?php echo $row['section_title'] ?></td>
      <td align="right">
  <label>0*</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label>1*</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label>2*</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label>3*</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label>4*</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label>5*</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label>Score</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label>Sub Total</label>
        </td>
    </tr>
    <tr>
	   <?php
                        $catq = "SELECT * FROM pdri_rating_categories WHERE pdri_section_id = " . $row['id'];
                        $cres = mysql_query($catq);
                       
                        while ($row1 = mysql_fetch_array($cres)) {
							 $c2 = 1;
                            ?>	
		
		
		
		
      <td>CATEGORY&nbsp;(<?php echo $c1." ) ". $row1['category_title'] ?></td>
      <td>&nbsp;</td>
	  </tr>	  
    <tr>
		
			     <?php
                            $dq = "SELECT * from pdri_rating_detail WHERE category_id = " . $row1['id'] . " AND section_id = " . $row['id'];
                            $cc = mysql_query($dq);
                           
                            while ($row2 = mysql_fetch_array($cc)) {
                                ?> 
		
      <td><?php echo $row2['rating_title'] ?></td>
      <td>       
                                    <?php
									//$rating_id = $row2['id'];
									$ra = "SELECT pdri_sec_value from pdri_values WHERE pdri_id = " . $PID . " AND pdri_rating_id = " . $row2['id'];
                           			$rra = mysql_query($ra);
									$row3 = mysql_fetch_array($rra);
									$save = "";
									
                                    $points = explode(",", $row2['rating_points']);
                                    for ($i = 0; $i < 6; $i++) {
                                        ?>
                                        <input <?php if (isset($row3[0]) && ($row3[0] == $points[$i])) { $save =  $points[$i]; ?> checked="checked"  <?php }?>id="<?php echo $c1 . $c2 ?>" name="<?php echo $c1 . $c2 ?>" onclick="fnclicked('<?php echo $c1 . $c2 ?>')" type='radio' value='<?php echo $points[$i] ?>'> <?php echo $points[$i] ?>
                                        <?php
                                    }
                                    ?></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </tbody>
</table>			
	

                       
                           
                       

                                    <div class="col-md-1" id="<?php echo $c1 . $c2; ?>score" >0</div>
                                    <div class="col-md-1" id="<?php echo $c1 . $c2; ?>sub" >0</div>
                                
                                <?php
								
								 if (isset($row3[0]) && ($row3[0] == $save)) { 
								 
								 $saveC1 = $c1;
								 $saveC2 = $c2;
								 ?> 
										<script> 
										$( window ).load(fnclicked('<?php echo $c1 . $c2 ?>'));
										 </script>
                                         <?php }
                                 $c2++;
                            }
?>


<div class="formRow fRow">
			<div class="col-md-8 docdetail-label" id=""> <strong>CATEGORY "<?php echo $c1;?>" TOTAL</strong></div>
		  <div class="col-md-1" id=""></div>
          <div class="col-md-1" id=""></div>
          <div class="col-md-1" id=""></div>
          <div class="col-md-1" id=""></div>
            <div class="col-md-1" id=""></div>
            <div class="col-md-1" id=""></div>
          <div class="col-md-1" id=""></div>
          <div class="col-md-1" id=""></div>
          <div class="col-md-1" style="margin-left:7px" id="<?php echo $c1;?>totscore">0</div>
            <div class="col-md-1" id="<?php echo $c1;?>totsub">0</div>
</div>

<script> 
										$( window ).load(fnclicked('<?php echo $saveC1 . $saveC2 ?>'));
										 </script>
<?php
                            $c1++;
                        }
                        ?> 
                        <div class="formRow fRow">
                        <div class="col-md-8 docdetail-label" id=""> <strong>SECTION "<?php echo $rom; ?>" TOTAL </strong></div>
                        <div class="col-md-1" id=""></div>
          <div class="col-md-1" id=""></div>
          <div class="col-md-1" id=""></div>
          <div class="col-md-1" id=""></div>
            <div class="col-md-1" id=""></div>
            <div class="col-md-1" id=""></div>
          <div class="col-md-1" id=""></div>
        <div class="col-md-1" id=""></div>
                       <div class="col-md-1" style="margin-left:7px" id="<?php echo $rom; ?>cattotscore">0</div>
                             <div class="col-md-1" id="<?php echo $rom; ?>cattotsub"  >0</div>
                        </div> 
<?php $rom = $rom."I"; ?>
                    <?php } ?>
                    
                   <!-- total........................................-->
                    <div class="formRow fRow">
                        <div class="col-md-8 docdetail-label" id=""> <strong>RDRI SCORE</strong></div>
                        <div class="col-md-1" id=""></div>
          <div class="col-md-1" id=""></div>
          <div class="col-md-1" id=""></div>
          <div class="col-md-1" id=""></div>
            <div class="col-md-1" id=""></div>
            <div class="col-md-1" id=""></div>
          <div class="col-md-1" id=""></div>
        <div class="col-md-1" id=""></div>
                       <div class="col-md-1" style="margin-left:7px" id=""></div>
                             <div class="col-md-1" id="lblTotal">0</div>
                             
                             
                            <div style="text-align:right; margin-right:50px"> <input align="right"  class="a1 a1 buttonM formSubmit bGreen" type="submit" name="Save5" id="Save5" value="Save"/></div>
  </div> 
                        
                         
                </div>
                
               
</form>
<p>&nbsp;</p>

            <div style="margin-left:15px" align="left"><br />
              Index created and distributed by <a href="http://construction-institute.org/">Construction Industry Institute, Austin, Texas</a>.</div>
            </div>
            
        </div>
</section>


<script> 
										$( window ).load(fnclicked('<?php echo $saveC1 . $saveC2 ?>'));
										 </script>








	
<br><br>



<?php } ?>
</body>
</html>

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