<head>
<?php

$table_name = $_SESSION['db_prefix']."_captured_timber";
$bracing_query = "SELECT * FROM $table_name WHERE cap_timber_group = 'Bracing' AND cap_job = '".$_SESSION['job_no']."'  ";
$bracing_result = mySQL_query($bracing_query);
$bracing_num = mysql_num_rows($bracing_result);
$table_name = $_SESSION['db_prefix']."_captured_timber";
$sundries_query = "SELECT * FROM $table_name WHERE cap_timber_group = 'Sundries' AND cap_job = '".$_SESSION['job_no']."' ";
$sundries_result = mySQL_query($sundries_query);
$sundries_num = mysql_num_rows($sundries_result);
?>
<!--style sheets-->
<link rel="stylesheet" href="../window/dhtmlwindow.css" type="text/css" />
<link rel="stylesheet" href="../window/modal.css" type="text/css" />
<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script>

<!--jscript-->
<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="<?php if ($_SESSION['screen']==1) {?>editwindow=dhtmlmodal.open('editBox', 'iframe', '../edit_windows/authorisation_add_bracing.php?cat=Bracing', 'Add item', 'width=500px,height=220px,center=1,resize=0,scrolling=0')
needToConfirm = false; editwindow.onclose=function(){return window}; return false;<?php } ?>  MM_showHideLayers('wait','','hide'); <?php if ($_SESSION['error_3']==1) {?>alertMessage(2, 'authorisationWizbase.php?p=3&s=', 'This item is already in the list and will not be added to the list.<br><br>If you require additional quantity, you should <br>edit the quantity in the list.');<?php }; $_SESSION['error_3']=0 ?>" onFocus="MM_showHideLayers('wait','','hide');  " >
<?php $_SESSION['screen']=0?>


<form id="form1" method="GET" action="authorisationWizbase.php">
<div class="wizard_page_middle_frame">

<div class="wizard_frame"><label style="font-size:18px; font-weight:700;">Bracing</label>
- current stock in meters<br>
<br />  
      <?php 
		  $n=0;	
				$_SESSION['list_5a'] = $bracing_num;
					  while ($n<$_SESSION['list_5a']) {
						    
				 			$_SESSION['bracing_name_'.$n] = mysql_result($bracing_result, $n, "cap_timber_name");
				 			$_SESSION['bracing_line'.$n] = mysql_result($bracing_result, $n, "cap_timber_id");
				 			$_SESSION['bracing_depth'.$n] = mysql_result($bracing_result, $n, "cap_depth");
				 			$_SESSION['bracing_width'.$n] = mysql_result($bracing_result, $n, "cap_width");
				 			$_SESSION['bracing_class'.$n] = mysql_result($bracing_result, $n, "cap_class");
				 			$_SESSION['bracing_type_'.$n] = $_SESSION['bracing_depth'.$n]."x".$_SESSION['bracing_width'.$n]." (".$_SESSION['bracing_class'.$n].")"; 
						    $_SESSION['bracing_length_'.$n] = mysql_result($bracing_result, $n, "cap_timber_length");
												
						$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 = '".$_SESSION['bracing_width'.$n]."' AND depth = '".$_SESSION['bracing_depth'.$n]."'  AND class='".$_SESSION['bracing_class'.$n]."' AND quantity>0 ORDER BY length ASC";
						
				 
				 $table_name = $_SESSION['db_prefix']."_timber_meter_price";
				 $meter_price_query = "SELECT price FROM $table_name WHERE timber = '".$_SESSION['bracing_type_'.$n]."'  ";
				 $meter_price_result = mySQL_query($meter_price_query);
				 $meter_price_num = mysql_num_rows($meter_price_result);
				 if ($meter_price_num>0) {
				 		$_SESSION['bracing_meter_price_'.$n] = mysql_result($meter_price_result, 0, "price");
				 }
				 else {
					 $_SESSION['bracing_meter_price_'.$n] =0;
				 }
						
						
						$name_result = mySQL_query($name_query);
						$name_num = mysql_num_rows($name_result);
						$_SESSION['item_num'.$n]=$name_num;
						
					  ?>
                      <table width="650" >
                      <tr style="background-color:#CCC;">       
                      <td colspan="3">
                      <label class="label_std" style="font-size:14px;"><?php echo $_SESSION['bracing_name_'.$n] ?></label>
                       </td>
                      <td width="244" align="right">Quoted length: <?php echo $_SESSION['bracing_length_'.$n]  ?> m&nbsp;</td>
                      </tr>
                      </table>
                      <?php if ( $_SESSION['list_5a']>0) { ?>
                      <table 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) {  
						$item_id = mysql_result($name_result, $d, "store_item_id"); 
												
					  	$a5 = mysql_result($name_result, $d, "quantity"); 
					  	$a6 = mysql_result($name_result, $d, "length");
						$a7 = ($a6*$a5)/1000;
//						
					 
                    ?> 
                    <?php //$_SESSION['check'.($n+10).($d+10)]='no'; ?>        
                    <td width='64' align="left"><input type="checkbox" name="<?php echo "check".($n+10).($d+10) ?>" id="<?php echo "check".($n+10).($d+10) ?>"  <?php if ($_SESSION['check'.($n+10).($d+10)]=='yes') {?> checked="checked" <?php } ?> <?php $_SESSION['item_id'.($n+10).($d+10)] = $item_id ?>  >
                    <?php  echo $a6; ?>&nbsp;&nbsp;&nbsp; </td>
                    <td width='142' align="right"><?php echo number_format($a7, 0, '.', ',');?>&nbsp;m&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td> 
                    <?php
					}
					else { ?>
						<?php
					}
					$c++;
					$d++;
					  }
					   
					  ?>
                  </tr>
                  <?php
				  $k++;
				  
				  	}  $d++;
				 	
				  $_SESSION['list2m_bracing'.$n]=$d;
				  $n++;
				  }
				  $_SESSION['list2n_bracing'] = $n;
				
				  ?>
                
              </table>
              <?php } ?>
          <input name="add_bracing_button" type="submit" class="imagebutton" id="add_bracing_button" value="Add" onClick=" needToConfirm = false; this.form.action='authorisationWiz3_save.php?'"/>
            </div>
            
        
<div class="wizard_spacer_frame" style="height:10px;"></div>
<br>
<div class="wizard_frame">
  <label style="font-size:18px; font-weight:700;">Sundries</label>
  - current stock in meters<br>
  
  <?php 
				 			 
					  $n=0;	
					  $_SESSION['list_5b'] = $sundries_num;
					  
					  while ($n<$_SESSION['list_5b']) {
						    
				 			$_SESSION['sundries_name_'.$n] = mysql_result($sundries_result, $n, "cap_timber_name");
				 			$_SESSION['sundries_line'.$n] = mysql_result($sundries_result, $n, "cap_timber_id");
				 			$_SESSION['sundries_depth'.$n] = mysql_result($sundries_result, $n, "cap_depth");
				 			$_SESSION['sundries_width'.$n] = mysql_result($sundries_result, $n, "cap_width");
				 			$_SESSION['sundries_class'.$n] = mysql_result($sundries_result, $n, "cap_class");
				 			$_SESSION['sundries_type_'.$n] = $_SESSION['sundries_depth'.$n]."x".$_SESSION['sundries_width'.$n]." (".$_SESSION['sundries_class'.$n].")"; 
						    $_SESSION['sundries_length_'.$n] = mysql_result($sundries_result, $n, "cap_timber_length");
							
												
						$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 = '".$_SESSION['sundries_width'.$n]."' AND depth = '".$_SESSION['sundries_depth'.$n]."'  AND class='".$_SESSION['sundries_class'.$n]."' AND quantity>0 ORDER BY length ASC";
						
						$table_name = $_SESSION['db_prefix']."_timber_meter_price";
				 $meter_price_query = "SELECT price FROM $table_name WHERE timber = '".$_SESSION['sundries_type_'.$n]."'  ";
				 
				 
				 $meter_price_result = mySQL_query($meter_price_query);
				 $meter_price_num = mysql_num_rows($meter_price_result);
				 if ($meter_price_num>0) {
				 $_SESSION['sundries_meter_price_'.$n] = mysql_result($meter_price_result, 0, "price");
				 }
				 else {
					 $_SESSION['sundries_meter_price_'.$n]=0;
				 }
				 						
						$name_result = mySQL_query($name_query);
						$name_num = mysql_num_rows($name_result);
						$_SESSION['item2_num'.$n]=$name_num;
						
					  ?>
  <table width="650" >
    <tr style="background-color:#CCC;">
      <td colspan="3"><label class="label_std" style="font-size:14px;"><?php echo $_SESSION['sundries_name_'.$n] ?></label></td>
      <td width="244" align="right">Quoted length: <?php echo $_SESSION['sundries_length_'.$n]  ?> m&nbsp;</td>
    </tr>
  </table>
  <?php if ( $_SESSION['list_5b']>0) { ?>
  <table  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) {  
						$item_id = mysql_result($name_result, $d, "store_item_id"); 
												
					  	$a5 = mysql_result($name_result, $d, "quantity"); 
					  	$a6 = mysql_result($name_result, $d, "length");
						$a7 = ($a6*$a5)/1000;
//						
					 
                    ?>
      <td width='72' align="left"><input type="checkbox" name="<?php echo "check2".($n+10).($d+10) ?>" id="<?php echo "check2".($n+10).($d+10) ?>"  <?php if ($_SESSION['check2_'.($n+10).($d+10)]=='yes') {?> checked="checked" <?php } ?> <?php $_SESSION['item2_id'.($n+10).($d+10)] = $item_id ?>  >
        <?php  echo $a6; ?>
         </td>
      <td width='134' align="right"><?php echo number_format($a7, 0, '.', ',');?>&nbsp;m&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td>
      <?php
					}
					else { ?>
      <?php
					}
					$c++;
					$d++;
					  }
					   
					  ?>
    </tr>
    <?php
				  $k++;
				  
				  	}  $d++;
				 	
				  $_SESSION['list2m_sundries'.$n]=$d;
				  $n++;
				  }
				  $_SESSION['list2n_sundries'] = $n;
				
				  ?>
  </table>
 <?php } ?> <br>
<br>

<input name="add_sundries_button" type="submit" class="imagebutton" id="add_sundries_button" value="Add" onClick="needToConfirm = false; this.form.action='authorisationWiz3_save.php'">
    <br>
</div>
<br>

<div class="wizard_spacer_frame" style="height:10px;"></div>
<div class="wizard_frame">
              <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','authorisationWizbase.php?s=&amp;p=2&screen=0');return document.MM_returnValue"  tabindex="2"/></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" /></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"  tabindex="3"/></td>
                  <td width="110" align="right"><input type="submit" name="next_button" class="imagebutton" value="Next" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');"  tabindex="1" /></td>
                </tr>
            </table>
 </div> 
</div>           
</form>

<!--form validation-->
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("S5_length_text","req","Please enter total length for S5 timber");
  frmvalidator.addValidation("S7_length_text","req","Please enter total length for S7 timber");
</script>
	
    </body>