<head>
<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script>
<script type="text/javascript" src="../window/dhtmlwindow.js"></script>
<script type="text/javascript" src="../window/modal.js"></script>
</head>

<?php 
include('../include/wait.php'); 


?>

<body onLoad="MM_showHideLayers('wait','','hide'); <?php if ($_SESSION['error2']==1) {?> alertMessage(2, 'iets', 'Trusses listed below are already in the list and were not added.<br><?php echo $_SESSION['alert_message']?><br><br>Maybe it was not checked. If you want to add another truss, click the previous button.'); <?php } ?>  " onFocus="MM_showHideLayers('wait','','hide');"  onBlur="MM_showHideLayers('wait','','hide'); ">
<?php
$_SESSION['error2']= 0;
$_SESSION['alert_message']= '';
?>
<div class="page_middle_frame">   
<form id="form1" method="POST" action="trussesJobWizbase.php?p=4&s=3">
  <table id="tableMain" width="595">
    <!--begin of tableMain-->
    <tr>
      <td><!--center of tableMain-->
        <table width=650 border="0" align="center" cellpadding="10" cellspacing="0" bordercolor="#0066FF" border-collapse="collapse">
          <tr>
            <td width="650" valign="top" >
               <div class="wizard_frame">
               <label class="label_std">S5 Timber</label>
                  <?php 
				  $i=0;
				 					  				
					  $table_name = $_SESSION['db_prefix']."_store_items";
					  $size_query = "SELECT store_item_id, width, depth, class FROM $table_name WHERE subCategory='timber' AND class='S5' AND width > '50' AND depth < '50' GROUP BY `depth`, `width` , `class`  ";
					  $size_result = mySQL_query($size_query);
					  $size_num = mysql_num_rows($size_result);
					 
					  $n=0;	
					  
					  while ($n<$size_num) {
						$width = mysql_result($size_result, $n, "width");
						$_SESSION['S5_width'.$n]=$width;  
						$depth = mysql_result($size_result, $n, "depth");
						$class = mysql_result($size_result, $n, "class");
						$cap_timber = $depth.'x'.$width.' ('.$class.')';
						
						$table_name = $_SESSION['db_prefix']."_store_items";
						$name_query = "SELECT store_item_id, width, depth, length, class, quantity FROM $table_name WHERE subCategory='timber' AND width = '".$width."' AND depth = '".$depth."'  AND class='S5' AND quantity>0 ORDER BY length ASC";
						
						$name_result = mySQL_query($name_query);
						$name_num = mysql_num_rows($name_result);
						
						$table_name = $_SESSION['db_prefix']."_captured_timber";
						$required_query = "SELECT SUM(cap_timber_length) AS required_length  FROM $table_name WHERE cap_timber = '".$cap_timber."' AND cap_timber_group = 'Trusses' AND cap_job ='". $_SESSION['job_no']."'  ";
						$required_result = mySQL_query($required_query);
						$_SESSION['required_length'.$n] = mysql_result($required_result, 0, "required_length");
					  ?>
                      
                       <table width="650" border="0">
                      <tr style="background-color:#CCC;">
                      <td width="465">
                      <label class="label_std" style="font-size:14px;"><?php echo $depth." x ".$width."&nbsp;(".$class.")" ?></label>
                      - current stock in meters</td>
                      <td width="175" align="right">Quoted length: <?php echo $_SESSION['required_length'.$n] ?> m</td>
                      </tr>
                      </table>
                      
                      <table width="600" id="table_resume_wizard3">
                      <?php	
					  $d=0;    
					  $k=0;
					  
					  while ($k<$name_num) {
					  
					  ?>
					  <tr>
                      <?php
					  $c=0;
					  
					  while ($c<3) {
						  //echo ">>> c=".$c."  d=".$d;
						if ($d<$name_num) {  
						$a1 = mysql_result($name_result, $d, "store_item_id"); 
						
						//$a2 = mysql_result($name_result, 0, "item_name");
					  	//$a3 = mysql_result($name_result, $d, "checked"); 
						
					  	$a4 = mysql_result($name_result, $d, "width"); 
					  	$a5 = mysql_result($name_result, $d, "depth"); 
					  	$a6 = mysql_result($name_result, $d, "length");
						$a7 = mysql_result($name_result, $d, "class");
						$a8  = mysql_result($name_result, $d, "quantity");
						$a9 = ($a8*$a6)/1000;
						$a3='no';
						$table_name = $_SESSION['db_prefix']."_cutting_temp";
						$check_query = "SELECT job_id FROM $table_name WHERE job_id='".$_SESSION['job_no']."' AND store_item_id='".$a1."' AND user =  '".$_SESSION['username']."' ";
						$check_result = mySQL_query($check_query);
						$check_num = mysql_num_rows($check_result);
						if ($check_num!=0) {
							$a3='yes';
						}
						//echo "<br>".$a7.$a1;
						$i++;
						}
						else {
							$a1 = "";
							//$a2 = "";
					  		$a3 = "";
					  		$a4 = "";
					  		$a5 = "";
					  		$a6 = "";
							$a8 = "";
							//$c++;
							$k++;
							$d++;
						}
					 
                    if ($d<$name_num) {  ?>            
                    <td width="100" align="left"><input type="checkbox" name="<?php echo "check".$i ?>" id="<?php echo "check".$i ?>" value="<?php echo $a1 ?>" <?php if ($a3=='yes') { ?>  checked="checked" <?php } ?>  >
                    <?php  echo $a6; ?></td>
                    <td width="50" align="right"><?php echo number_format($a9, 0, '.', ',')?>&nbsp;&nbsp;m</td> 
                    <td width="50"><input type="hidden" name="<?php echo "item_no".$i ?>" id="<?php echo "item_no".$i ?>" value="<?php echo $a1 ?>"></td>
                    <?php
					}
					else { ?>
						<td width="100" align="left">&nbsp;&nbsp;</td>
                    <td width="50" align="right">&nbsp;&nbsp;</td>
                    <td width="50">&nbsp;&nbsp;</td> 
                    <?php
					}
					$c++;
					$d++;
					  }
					  ?>
                  </tr>
                  <?php
				  $k++;
				  
				  	}  $d++;
					?>
					</table>
                    <?php
				  $n++;
				  $_SESSION['list_no_5'] = $i;
				  }
				  
				  ?>
                
                <br />
              <br></div>
               <div class="wizard_frame">
               <label class="label_std">S7 Timber</label>
                 <?php 
				  $i=0;
				 					  				
					  $table_name = $_SESSION['db_prefix']."_store_items";
					  $size_query = "SELECT store_item_id, width, depth, class FROM $table_name WHERE subCategory='timber' AND class='S7' AND width > '50' AND depth < '50' GROUP BY `depth`, `width` , `class`  ";
					  $size_result = mySQL_query($size_query);
					  $size_num = mysql_num_rows($size_result);
					 
					  $n=0;	
					  
					  while ($n<$size_num) {
						$width = mysql_result($size_result, $n, "width");
						$_SESSION['S7_width'.$n]=$width;  
						$depth = mysql_result($size_result, $n, "depth");
						$class = mysql_result($size_result, $n, "class");
						$cap_timber = $depth.'x'.$width.' ('.$class.')';
						
						$table_name = $_SESSION['db_prefix']."_store_items";
						$name_query = "SELECT store_item_id, width, depth, length, class, quantity FROM $table_name WHERE subCategory='timber' AND width = '".$width."' AND depth = '".$depth."'  AND class='S7' AND quantity>0 ORDER BY length ASC";
						//echo $name_query;
						$name_result = mySQL_query($name_query);
						$name_num = mysql_num_rows($name_result);
						
						$table_name = $_SESSION['db_prefix']."_captured_timber";
						$required_query = "SELECT SUM(cap_timber_length) AS required_length  FROM $table_name WHERE cap_timber = '".$cap_timber."' AND cap_timber_group = 'Trusses' AND cap_job ='". $_SESSION['job_no']."'  ";
						$required_result = mySQL_query($required_query);
						$_SESSION['required_length2_'.$n] = mysql_result($required_result, 0, "required_length");
					  ?>
                 <table width="650" border="0">
                   <tr style="background-color:#CCC;">
                     <td width="465"><label class="label_std" style="font-size:14px;"><?php echo $depth." x ".$width."&nbsp;(".$class.")" ?></label>
                       - current stock in meters</td>
                     <td width="175" align="right">Quoted length: <?php echo $_SESSION['required_length2_'.$n] ?> m</td>
                   </tr>
                 </table>
                 <table width="600" id="table_resume_wizard3">
                   <?php	
					  $d=0;    
					  $k=0;
					  
					  while ($k<$name_num) {
					  
					  ?>
                   <tr>
                     <?php
					  $c=0;
					  
					  while ($c<3) {
						  //echo ">>> c=".$c."  d=".$d;
						if ($d<$name_num) {  
						$a1 = mysql_result($name_result, $d, "store_item_id"); 
						
						//$a2 = mysql_result($name_result, 0, "item_name");
					  	//$a3 = mysql_result($name_result, $d, "checked"); 
						
					  	$a4 = mysql_result($name_result, $d, "width"); 
					  	$a5 = mysql_result($name_result, $d, "depth"); 
					  	$a6 = mysql_result($name_result, $d, "length");
						$a7 = mysql_result($name_result, $d, "class");
						$a8  = mysql_result($name_result, $d, "quantity");
						$a9 = ($a8*$a6)/1000;
						$a3='no';
						$table_name = $_SESSION['db_prefix']."_cutting_temp";
						$check_query = "SELECT job_id FROM $table_name WHERE job_id='".$_SESSION['job_no']."' AND store_item_id='".$a1."' AND user =  '".$_SESSION['username']."' ";
						$check_result = mySQL_query($check_query);
						$check_num = mysql_num_rows($check_result);
						if ($check_num!=0) {
							$a3='yes';
						}
						//echo "<br>".$a7.$a1;
						$i++;
						}
						else {
							$a1 = "";
							//$a2 = "";
					  		$a3 = "";
					  		$a4 = "";
					  		$a5 = "";
					  		$a6 = "";
							$a8 = "";
							//$c++;
							$k++;
							$d++;
						}
					 
                    if ($d<$name_num) {  ?>
                     <td width='100' align="left"><input type="checkbox" name="<?php echo "check2_".$i ?>" id="<?php echo "check2_".$i ?>" value="<?php echo $a1 ?>" <?php if ($a3=='yes') { ?>  checked="checked" <?php } ?>  >
                       <?php  echo $a6; ?>
                       &nbsp;
                       <input type="hidden" name="<?php echo "item_no2_".$i ?>" id="<?php echo "item_no2_".$i ?>" value="<?php echo $a1 ?>">
                       &nbsp;</td>
                     <td width='50' align="right"><?php echo number_format($a9, 0, '.', ',')?>&nbsp;&nbsp;m</td>
                     <td width="50">&nbsp;&nbsp;</td> 
                     <?php
					}
					else { ?>
						<td width="100" align="left">&nbsp;&nbsp;</td>
                    <td width="50" align="right">&nbsp;&nbsp;</td>
                    <td width="50">&nbsp;&nbsp;</td> 
                    <?php
					
					}
					$c++;
					$d++;
					  }
					  ?>
                   </tr>
                   <?php
				  $k++;
				  
				  	}  $d++;
					?>
                 </table>
                 <?php
				  $n++;
				  $_SESSION['list_no_2'] = $i;
				  }
				  
				  ?>
                 <br />
                 <br>
              </div></td>
            <!--center of tableMain-->
          </tr>
          <tr>
            <td><!--center of tableMain-->
              <table width="660" height="50" align="center" cellpadding="20"  id="table_button_bar">
                <tr>
                  <td width="117"><input type="button" name="lastprev_button" class="imagebutton" value="Prev" onClick="needToConfirm = false;MM_showHideLayers('wait','','show');MM_goToURL('parent','trussesJobWizbase.php?s=&amp;p=2&m=');return document.MM_returnValue"  tabindex="3"/></td>
                  <td width="115">&nbsp;</td>
                  <td width="99">
                    <input name="p" type="hidden" id="p" value="3" />
                    <input name="s" type="hidden" id="s" value="3" />
                  </span></td>
                  <td width="125" align="right"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="needToConfirm = false; cancel_confirmation(1, '../production/production_main.php')" value="Cancel" /></td>
                  <td width="110" align="right"><input type="submit" name="next_button" class="imagebutton" value="Next" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');"  tabindex="2" /></td>
                </tr>
            </table></td>
          </tr>
        </table>
  </table>
  <!--end of tableMain-->
</form>
</div>	
    </body>