<head>
<?php

$table_name = $_SESSION['db_prefix']."_cash_job_lines";
$timber_query = "SELECT store_item_id, quantity FROM $table_name WHERE quote_no = '".$_SESSION['job_no']."' AND truss_item = 'Timber'";
$timber_result = mySQL_query($timber_query);
$timber_num = mysql_num_rows($timber_result);

?>
<!--style sheets-->

<!--jscript-->
<script language="JavaScript" src="../jscript/numbers_only.js"  type="text/javascript"></script>  
<script type="text/javascript">
function validate_required(input,alerttxt,maxvalue)
{
with (input)
  {
  if (value>maxvalue)
    {
    alertMessage(1, 'cash_authorisationWizbase.php?p=2&s=', 'The authorised amount exceeds the allowed amount, the entry will be cleared.<br><br>Please enter a valid amount.');
	input.value = "";
	return false;
	}
  else
    {
    return true;
    }
  }
}
</script>

<script>
function del_all() {
	
	for (var i=0; i < 25; i++) {
		    document.getElementById('quantity_text_'+i).value=document.getElementById('quantity'+i).value;
	}
}
</script>


</head>
<?php include('../include/wait.php') ?>
<link href="../css/wait.css" rel="stylesheet" type="text/css">
<body onLoad="MM_showHideLayers('wait','','hide');" onFocus="MM_showHideLayers('wait','','hide')";>
<div class="page_middle_frame">
<form action="cash_authorisationWizbase.php" method="get" name="form1" id="form1">
<table id="tableMain" width="595">
    <!--begin of tableMain-->
    <tr>
      <td><!--center of tableMain-->

        <div class="scroll_frame_medium" style="height:340px; width:640px;">
          <table width="599">
               <tr>
               <td><label class="label_std" style="font-size:14px;">Timber:</label></td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td align="right"><input name="button" type="button" class="imagebutton" id="button" onClick="del_all();" value="Authorise all" checked="checked" ></td>
              </tr>
               <tr>
                 <td>&nbsp;</td>
                 <td>&nbsp;</td>
                 <td colspan="2"><label class="label_std">On order</label></td>
                 <td><label class="label_std">To authorise</label></td>
               </tr>
             <?php 
				  $i=0;
				  while ($i<$timber_num) { 
				       
						$store_item_id = mysql_result($timber_result, $i, "store_item_id");					
						$quantity = mysql_result($timber_result, $i, "quantity");
						$table_name = $_SESSION['db_prefix']."_store_items";
						$item_name_query = "SELECT item_name, unit FROM $table_name WHERE store_item_id = '".$store_item_id."' ";
						$item_name_result = mySQL_query($item_name_query);
						$item_name = mysql_result($item_name_result, 0, "item_name"); 
						$unit = mysql_result($item_name_result, 0, "unit"); 
						
						$table_name = $_SESSION['db_prefix']."_cash_authorisation_lines_temp";
						$quantity_query = "SELECT quantity FROM $table_name WHERE store_item_id = '".$store_item_id."' AND user_name = '".$_SESSION['username']."'  ";
						$quantity_result = mySQL_query($quantity_query);
						$quantity_num = mysql_num_rows($quantity_result);
						if ($quantity_num!='') {
						       $auth_quantity = mysql_result($quantity_result, 0, "quantity");
						}
						else {
							$auth_quantity = '0';
						}
								
				 ?>
             <tr>
               <td colspan="2"><label class="label_std" ><?php echo $item_name ?></label>
                 <input type="hidden" name="store_item_id<?php echo $i?>" id="store_item_id<?php echo $i?>" value="<?php echo $store_item_id ?>">
               </td>
               <td width="37" align="right"><input name="quantity<?php echo $i?>" id="quantity<?php echo $i?>" type="hidden" value="<?php echo number_format($quantity, 0, '.', '')?>"><label for="textfield"><?php echo number_format($quantity, 0, '.', '')?></label></td>
               <td width="58">&nbsp;&nbsp;<?php echo $unit ?></td>
               <td width="231"><input name="quantity_text_<?php echo $i?>" type="text" class="text60" id="quantity_text_<?php echo $i?>" style="text-align:right" onKeyPress="return numbersonly(this, event)"  value="<?php echo number_format($auth_quantity, 0, '.', '') ?>" autocomplete="off" autofocus tabindex="<?php echo $i+1 ?>" onKeyUp="validate_required(quantity_text_<?php echo $i?>, 'The authorised amount exceeds the allowed amount, the entry will be cleared.' +'\n'+ 'Please enter a valid amount.', <?php echo $quantity ?>)">
&nbsp;&nbsp;<?php echo $unit ?></td>
             </tr>
             <?php
			  $i++;
             }
             ?>
           </table>
          <input type="hidden" name="line2" id="line2" value="<?php echo $timber_num ?>">
          <br>
<br>
<?php if ($timber_num==0) { ?><img src="../images/exclamation.png" width="24" height="24">There is no timber on this order.<?php } ?>
                  </div>
      </td>
      </tr>
      <tr>
      <td><table width="590" height="50" align="center" 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','cash_authorisationWizbase.php?s=&amp;p=1');return document.MM_returnValue"  tabindex="<?php echo $i+3 ?>"/></td>
          <td width="115">&nbsp;</td>
          <td width="99"><input name="p" type="hidden" id="p" value="2" />
            <input name="s" type="hidden" id="s" value="2" />
            </span></td>
          <td width="125" align="right"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="needToConfirm = false; cancel_confirmation(1, '../sales/sales_main.php');" value="Cancel" tabindex="<?php echo $i+4 ?>" /></td>
          <td width="110" align="right"><input type="submit" name="next_button" class="imagebutton" value="Next" onClick="needToConfirm = false;  MM_showHideLayers('wait','','show');" tabindex="<?php echo $i+2 ?>"/></td>
        </tr>
      </table></td>
      </tr>
      </table>
</form>
</div>
</body>      