<!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" />
  
<script language="JavaScript" src="../jscript/gen_validatorv4_2.js"  type="text/javascript" xml:space="preserve"></script>
<script language="JavaScript" src="../jscript/go_to_url.js"  type="text/javascript"></script> 

<?php

//include('../include/db.php');
include('../include/session.php');	
//include('../include/formValidations.php');

$job_no = $_GET['job_no'];

$table_name = $_SESSION['db_prefix']."_store_items";
$timber_query = "SELECT store_item_id, item_name, class, width, depth, length FROM $table_name WHERE subCategory='Timber' AND class='S5' AND width > '75' GROUP BY width";
$timber_result = mySQL_query($timber_query);
$timber_num = mysql_num_rows($timber_result);

$table_name = $_SESSION['db_prefix']."_store_items";
$timber2_query = "SELECT store_item_id, item_name, class, width, depth, length FROM $table_name WHERE subCategory='Timber' AND class='S7' GROUP BY width";
$timber2_result = mySQL_query($timber2_query);
$timber2_num = mysql_num_rows($timber2_result);

$table_name = $_SESSION['db_prefix']."_store_items";
$timber3_query = "SELECT store_item_id, item_name, class, width, depth, length FROM $table_name WHERE subCategory='Timber' AND class='La' GROUP BY width";
$timber3_result = mySQL_query($timber3_query);
$timber3_num = mysql_num_rows($timber3_result);


?>


<style>
label.label_std{
	margin-left:5px;
    line-height:20px;
	padding-top:6px;
    color:#000;
    text-shadow:1px 1px 1px #fff;
    font:bold 12px Arial;
}

input.imagebutton{
	background-color:#E1E1E1;
	width: 100px;
	height: 24px;
	border:solid;
	border-width:1px;
	border-color:#FB6808;
	cursor:pointer;
	color:#000000;
	font:bold 12px Arial;
	-moz-border-radius: 5px;
	-webkit-border-radius: 5px;
	border-radius: 5px;
	-moz-box-shadow:0px 0px 0px #CCC;
	-webkit-box-shadow:0px 0px 0px #CCC;
	box-shadow:0px 0px 0px #CCC;
	
}

input.imagebutton{
	background-color:#E1E1E1;
	width: 100px;
	height: 24px;
	border:solid;
	border-width:1px;
	border-color:#FB6808;
	cursor:pointer;
	color:#000000;
	font:bold 12px Arial;
	-moz-border-radius: 5px;
	-webkit-border-radius: 5px;
	border-radius: 5px;
	-moz-box-shadow:0px 0px 0px #CCC;
	-webkit-box-shadow:0px 0px 0px #CCC;
	box-shadow:0px 0px 0px #CCC;
	
}

input.imagebutton:hover{
	background-color:#E4E4E4;
	width: 100px;
	height: 24px;
	border:solid;
	border-width:2px;
	border-color:#FB6808;
	cursor:pointer;
	color:#000000;
	font:bold 12px Arial;
	-moz-border-radius: 5px;
	-webkit-border-radius: 5px;
	border-radius: 5px;
	-moz-box-shadow:5px 5px 5px #666;
	-webkit-box-shadow:5px 5px 5px #666;
	box-shadow:5px 5px 5px #666;
	
}

input.imagebutton1 {	background-color:#E1E1E1;
	width: 100px;
	height: 24px;
	border:solid;
	border-width:1px;
	border-color:#FB6808;
	cursor:pointer;
	color:#000000;
	font:bold 12px Arial;
	-moz-border-radius: 5px;
	-webkit-border-radius: 5px;
	border-radius: 5px;
	-moz-box-shadow:0px 0px 0px #CCC;
	-webkit-box-shadow:0px 0px 0px #CCC;
	box-shadow:0px 0px 0px #CCC;
}
input.imagebutton1 {	background-color:#E1E1E1;
	width: 100px;
	height: 24px;
	border:solid;
	border-width:1px;
	border-color:#FB6808;
	cursor:pointer;
	color:#000000;
	font:bold 12px Arial;
	-moz-border-radius: 5px;
	-webkit-border-radius: 5px;
	border-radius: 5px;
	-moz-box-shadow:0px 0px 0px #CCC;
	-webkit-box-shadow:0px 0px 0px #CCC;
	box-shadow:0px 0px 0px #CCC;
}

input.text60 {
	width:60px;
}


</style>



</head>

<body>
 
    <form action="captured_edit_add_timber_save.php" method="get" name="form1" target="_top" id="form1">
    <table width="372" border="0" >
      <tr>
        <td width="169" height="37"><label class="label_std">timber item</label></td>
        <td colspan="3"><label class="label_std">total length in m</label></td>
      </tr>
      <?php 
				  $i=0;
				  while ($i<$timber_num) {
						$width = mysql_result($timber_result, $i, "width");  
						$depth = mysql_result($timber_result, $i, "depth");
						$class = mysql_result($timber_result, $i, "class");
						//$_SESSION['timber_width_'.$i] = $width;
//						$_SESSION['timber_depth_'.$i] = $depth;
//						$_SESSION['timber_class_'.$i] = $class;
						//$_SESSION['type_'.$i]=$depth."x".$width." (".$class.")";
						$type=$depth."x".$width." (".$class.")";
						
						
						$table_name = $_SESSION['db_prefix']."_timber_meter_price";
						$meter_price_query = "SELECT price FROM $table_name WHERE timber = '".$type."'  ";
						$meter_price_result = mySQL_query($meter_price_query);
						$meter_price = mysql_result($meter_price_result, 0, "price");
						
						$table_name = $_SESSION['db_prefix']."_captured_timber";
						$timber_check_query = "SELECT cap_timber_id FROM $table_name WHERE cap_timber_group = 'Trusses' AND cap_job = '".$job_no."' AND cap_class = 'S5'  ";
						$timber_check_result = mySQL_query($timber_check_query);
						$timber_check_num = mysql_num_rows($timber_check_result);
												
						
						if ($timber_check_num>0) {
								$table_nameS5 = $_SESSION['db_prefix']."_captured_timber";
							}
						else {
								$table_nameS5 = $_SESSION['db_prefix']."_captured_timber_done";
						}
															
						
						$qty_query = "SELECT cap_timber_length FROM $table_nameS5 WHERE cap_timber = '".$type."' AND cap_job = '".$job_no."' AND cap_timber_group = 'Trusses' ";
						$qty_result = mySQL_query($qty_query);
						$qty_num = mysql_num_rows($qty_result);
						if ($qty_num==1) {
						$cap_timber_length = mysql_result($qty_result, 0, "cap_timber_length");
						}
						else {
							$cap_timber_length=0;
						}
						
				 ?>
      <tr>
        <td><label class="label_std" ><?php echo $type ?>
          <input type="hidden" name="type_text_<?php echo $i?>" id="type_text_<?php echo $i?>" value="<?php echo $type ?>" />
          <input type="hidden" name="width_text_<?php echo $i?>" id="width_text_<?php echo $i?>" value="<?php echo $width ?>" />
          <input type="hidden" name="depth_text_<?php echo $i?>" id="depth_text_<?php echo $i?>" value="<?php echo $depth ?>" />
          <input type="hidden" name="class_text_<?php echo $i?>" id="class_text_<?php echo $i?>" value="<?php echo $class ?>" />
        </label></td>
        <td colspan="3"><label for="textfield"></label>
          <input name="length_text_<?php echo $i?>" type="text" class="text60" id="length_text_<?php echo $i?>" style="text-align:right" onkeypress="return isNumberKey(event)" onchange=" this.value = this.value.replace (/(\...).*/, '$1')" value="<?php echo $cap_timber_length ?>" autocomplete="off" onfocus = "this.select();" />
          &nbsp;&nbsp;
          <label class="label_std">m</label>
        <input name="meter_price_text_<?php echo $i?>" type="hidden" value="<?php echo $meter_price ?>" /></td>
      </tr>
      <?php
			  $i++;
             }
             ?>
             <input name="line_num1" type="hidden" value="<?php echo $i ?>" />
             <input name="$type1" type="hidden" value="<?php echo $type ?>" />
      <tr>
        <td>&nbsp;</td>
        <td colspan="3">&nbsp;</td>
      </tr>
      <?php 
				  $j=0;
				  while ($j<$timber2_num) {
						$width2 = mysql_result($timber2_result, $j, "width");  
						$depth2 = mysql_result($timber2_result, $j, "depth");
						$class2 = mysql_result($timber2_result, $j, "class");
						//$_SESSION['timber_width_'.$i] = $width;
//						$_SESSION['timber_depth_'.$i] = $depth;
//						$_SESSION['timber_class_'.$i] = $class;
						//$_SESSION['type_'.$i]=$depth."x".$width." (".$class.")";
						$type2=$depth2."x".$width2." (".$class2.")";
						
						
						$table_name = $_SESSION['db_prefix']."_captured_timber";
						$timber_check_query = "SELECT cap_timber_id FROM $table_name WHERE cap_timber_group = 'Trusses' AND cap_job = '".$job_no."' AND cap_class = 'S7'  ";
						$timber_check_result = mySQL_query($timber_check_query);
						$timber_check_num = mysql_num_rows($timber_check_result);
												
						$table_name = $_SESSION['db_prefix']."_timber_meter_price";
						$meter_price_query = "SELECT price FROM $table_name WHERE timber = '".$type."'  ";
						$meter_price_result = mySQL_query($meter_price_query);
						$meter_price2 = mysql_result($meter_price_result, 0, "price");
		
						if ($timber_check_num>0) {
								$table_nameS7 = $_SESSION['db_prefix']."_captured_timber";
							}
						else {
								$table_nameS7 = $_SESSION['db_prefix']."_captured_timber_done";
						}
															
						
						$qty_query = "SELECT cap_timber_length FROM $table_nameS7 WHERE cap_timber = '".$type2."' AND cap_job = '".$job_no."' AND cap_timber_group = 'Trusses' ";
						$qty_result = mySQL_query($qty_query);
						$qty_num = mysql_num_rows($qty_result);
						if ($qty_num==1) {
						$cap_timber_length = mysql_result($qty_result, 0, "cap_timber_length");
						}
						else {
							$cap_timber_length=0;
						}
				 ?>
      <tr>
        <td><label class="label_std"><?php echo $type2 ?>
          <input type="hidden" name="type2_text_<?php echo $j?>" id="type2_text_<?php echo $j?>" value="<?php echo $type2 ?>" />
          <input type="hidden" name="width2_text_<?php echo $j?>" id="width2_text_<?php echo $j?>" value="<?php echo $width2 ?>" />
          <input type="hidden" name="depth2_text_<?php echo $j?>" id="depth2_text_<?php echo $j?>" value="<?php echo $depth2 ?>" />
          <input type="hidden" name="class2_text_<?php echo $j?>" id="class2_text_<?php echo $j?>" value="<?php echo $class2 ?>" /></label></td>
        <td colspan="3"><label for="textfield"></label>
          <input name="length2_text_<?php echo $j?>" type="text" id="length2_text_<?php echo $j?>" style="text-align:right"  class="text60" onkeypress="return isNumberKey(event)" onchange=" this.value = this.value.replace (/(\...).*/, '$1')" value="<?php echo $cap_timber_length ?> " autocomplete="off" onfocus = "this.select();" onblur="<?php if ($j==$timber2_num-1) { ?> document.getElementById('next_button').focus();<?php } ?>" />
          &nbsp;&nbsp;
          <label class="label_std">m</label>
          <input name="meter2_price_text_<?php echo $j?>" type="hidden" value="<?php echo $meter_price2 ?>" /></td>
      </tr>
      <?php
			  $j++;
             }
             ?>
             <input name="line_num2" type="hidden" value="<?php echo $i ?>" />
             <!--<input name="$type2" type="hidden" value="<?php echo $type ?>" />-->
      <tr>
        <td>&nbsp;</td>
        <td colspan="3">&nbsp;</td>
      </tr>
      <?php 
				  $j=0;
				  while ($j<$timber3_num) {
						$width3 = mysql_result($timber3_result, $j, "width");  
						$depth3 = mysql_result($timber3_result, $j, "depth");
						$class3 = mysql_result($timber3_result, $j, "class");
						//$_SESSION['timber_width_'.$i] = $width;
//						$_SESSION['timber_depth_'.$i] = $depth;
//						$_SESSION['timber_class_'.$i] = $class;
						//$_SESSION['type_'.$i]=$depth."x".$width." (".$class.")";
						$type3=$depth3."x".$width3." (".$class3.")";
						
						
						$table_name = $_SESSION['db_prefix']."_captured_timber";
						$timber_check_query = "SELECT cap_timber_id FROM $table_name WHERE cap_timber_group = 'Laminated' AND cap_job = '".$job_no."' AND cap_class = 'S7'  ";
						$timber_check_result = mySQL_query($timber_check_query);
						$timber_check_num = mysql_num_rows($timber_check_result);
												
						$table_name = $_SESSION['db_prefix']."_timber_meter_price";
						$meter_price_query = "SELECT price FROM $table_name WHERE timber = '".$type."'  ";
						$meter_price_result = mySQL_query($meter_price_query);
						$meter_price3 = mysql_result($meter_price_result, 0, "price");
		
						if ($timber_check_num>0) {
								$table_nameLa = $_SESSION['db_prefix']."_captured_timber";
							}
						else {
								$table_nameLa = $_SESSION['db_prefix']."_captured_timber_done";
						}
															
						
						$qty_query = "SELECT cap_timber_length FROM $table_nameLa WHERE cap_timber = '".$type3."' AND cap_job = '".$job_no."' AND cap_timber_group = 'Trusses' ";
						$qty_result = mySQL_query($qty_query);
						$qty_num = mysql_num_rows($qty_result);
						if ($qty_num==1) {
						$cap_timber_length = mysql_result($qty_result, 0, "cap_timber_length");
						}
						else {
							$cap_timber_length=0;
						}
				 ?>
      <tr>
        <td><label class="label_std"><?php echo $type2 ?>
          <input type="hidden" name="type3_text_<?php echo $j?>" id="type3_text_<?php echo $j?>" value="<?php echo $type3 ?>" />
          <input type="hidden" name="width3_text_<?php echo $j?>" id="width3_text_<?php echo $j?>" value="<?php echo $width3 ?>" />
          <input type="hidden" name="depth3_text_<?php echo $j?>" id="depth3_text_<?php echo $j?>" value="<?php echo $depth3 ?>" />
          <input type="hidden" name="class3_text_<?php echo $j?>" id="class3_text_<?php echo $j?>" value="<?php echo $class3 ?>" /></label></td>
        <td colspan="3"><label for="textfield"></label>
          <input name="length3_text_<?php echo $j?>" type="text" id="length3_text_<?php echo $j?>" style="text-align:right"  class="text60" onkeypress="return isNumberKey(event)" onchange=" this.value = this.value.replace (/(\...).*/, '$1')" value="<?php echo $cap_timber_length ?> " autocomplete="off" onfocus = "this.select();" onblur="<?php if ($j==$timber3_num-1) { ?> document.getElementById('next_button').focus();<?php } ?>" />
          &nbsp;&nbsp;
          <label class="label_std">m</label>
          <input name="meter3_price_text_<?php echo $j?>" type="hidden" value="<?php echo $meter_price3 ?>" /></td>
      </tr>
      <?php
			  $j++;
             }
             ?>
             <input name="line_num3" type="hidden" value="<?php echo $j ?>" />       
             
            
      <tr id="summation">
        <td>&nbsp;</td>
        <td width="123" align="right">&nbsp;</td>
        <td width="59" align="right">&nbsp;</td>
        <td width="3" align="right">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="4" align="center"><input name="finish_add_button" type="submit" id='finish_add_button' value="Finish" class="imagebutton"  />
        
          <input name="cancel_button" type="button" id="cancel_button" class="imagebutton" onclick="
          MM_goToURL('parent','../production/captured_edit.php?job_no=<?php echo $job_no?>&edit=1&screen=0&sub_category=&save_message=0');
          return document.MM_returnValue;
          " 
          value="Cancel" />
          <?php echo $job_no?>
          <input name="sub_category" type="hidden" value="timber" />
      <input type="hidden" name="job_no" id="job_no" value="<?php echo $job_no?>" /></td>
      </tr>
    </table>
</form>


</body>
</html>