<!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" />


<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/main.css" />
<link rel="stylesheet" href="../css/dhtmlwindow.css" type="text/css" />
<link rel="stylesheet" href="../css/modal.css" type="text/css" />
<link href="../css/wait.css" rel="stylesheet" type="text/css">

<!--jscript-->
<script type="text/javascript" src="../css/modal.js"></script>
<script type="text/javascript" src="../css/dhtmlwindow.js"></script>
<script language="JavaScript" src="../jscript/confirm_exit.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/show_hide_layers.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script> 


<?php
include ("../navigation/header.php");
$page_name = "Production-edit authorisation";
include ("../navigation/access.php");



if ($permission_num==1) {
	include ("../navigation/production_sidebar.php");

$job_no = $_GET['job_no'];
$_SESSION['edit_start'] = $_GET['edit'];
$screen= $_GET['screen'];
$sub_category=$_GET['sub_category'];
$quote='no';

if ($_SESSION['edit_start']==0) {
		$table_name = $_SESSION['db_prefix']."_captured_mitek_edit_temp";
		$delete_query = "DELETE FROM $table_name WHERE cap_job='".$job_no."' AND user = '".$_SESSION['username']."' "; 
		execsql($delete_query);
		
		$table_name = $_SESSION['db_prefix']."_authorised_timber_edit_temp";
		$delete_query = "DELETE FROM $table_name WHERE job_no='".$job_no."' AND user = '".$_SESSION['username']."' ";
		execsql($delete_query);

		$table_name = $_SESSION['db_prefix']."_captured_sundries_edit_temp";
		$delete_query = "DELETE FROM $table_name WHERE cap_job='".$job_no."' AND user = '".$_SESSION['username']."' "; 
		execsql($delete_query);
}

$table_name = $_SESSION['db_prefix']."_captured_jobs";
$job_query = "SELECT * FROM $table_name WHERE job_no = '".$job_no."' ";
$job_result = mySQL_query($job_query);
$cust_id = mysql_result($job_result, 0, "cust_id");	
$complete_alert=0;

if (($sub_category=='Mitek') OR ($sub_category=='Sundries')) {
	$file_open = '../edit_windows/authorisation_edit_add.php?category=Direct materials&sub_category='.$sub_category.'&job_no='.$job_no;
}

if ($sub_category=='Bracing')  {
	$file_open = '../edit_windows/authorisation_edit_add_bracing.php?cat=Bracing&show=0&bracing_select=&job_no='.$job_no;
}

if ($sub_category=='Sundries2')  {
	$file_open = '../edit_windows/authorisation_edit_add_bracing.php?cat=Sundries&show=0&bracing_select=&job_no='.$job_no;
}
?>




<?php
$table_name = $_SESSION['db_prefix']."_captured_jobs";
$cust_id_query = "SELECT cust_id, designer FROM $table_name WHERE job_no = '".$job_no."' ";
$cust_id_result = mySQL_query($cust_id_query);
$cust_id = mysql_result($cust_id_result, 0, "cust_id");
$designer = mysql_result($cust_id_result, 0, "designer");

$table_name = $_SESSION['db_prefix']."_customer";
$name_query = "SELECT comp_name FROM $table_name WHERE cust_id = '".$cust_id."' ";
$name_result = mySQL_query($name_query);
$name = mysql_result($name_result, 0, "comp_name");


$table_name = $_SESSION['db_prefix']."_captured_mitek";
$mitek_check_query = "SELECT  cap_mitek_id FROM $table_name WHERE cap_job = '".$job_no."'  ";
$mitek_check_result = mySQL_query($mitek_check_query);
$mitek_check_num = mysql_num_rows($mitek_check_result);
if ($mitek_check_num!=0) { 
$table_name = $_SESSION['db_prefix']."_captured_mitek";
$complete_mitek=0;
}
else {
$table_name = $_SESSION['db_prefix']."_captured_mitek_done";
$complete_mitek=1;
$complete_alert=$complete_alert+1;
}
$table_name2 = $_SESSION['db_prefix']."_captured_mitek_edit_temp";
$mitek_query = "SELECT cap_mitek_id, cap_item_id,cap_quantity, auth_quantity FROM $table_name WHERE cap_job = '".$job_no."' UNION ALL SELECT cap_mitek_id, cap_item_id,cap_quantity, auth_quantity FROM $table_name2 WHERE cap_job = '".$job_no."' AND user = '".$_SESSION['username']."' ";
$mitek_result = mySQL_query($mitek_query);
$mitek_num = mysql_num_rows($mitek_result);


$table_name = $_SESSION['db_prefix']."_authorised_timber";
$bracing_check_query = "SELECT  auth_id FROM $table_name WHERE auth_timber_group = 'bracing' AND job_no = '".$job_no."'  ";
$bracing_check_result = mySQL_query($bracing_check_query);
$bracing_check_num = mysql_num_rows($bracing_check_result);
if ($bracing_check_num!=0) { 
$table_name = $_SESSION['db_prefix']."_authorised_timber";
$complete_bracing=0;
}
else {
$table_name = $_SESSION['db_prefix']."_authorised_timber_done";
$complete_bracing=1;
$complete_alert=$complete_alert+1;
}


$table_name2 = $_SESSION['db_prefix']."_authorised_timber_edit_temp";
$bracing_query = "SELECT auth_timber_name FROM $table_name WHERE auth_timber_group = 'bracing' AND job_no = '".$job_no."' AND store_item_id <> 0 GROUP BY auth_timber_name UNION SELECT auth_timber_name FROM $table_name2 WHERE auth_timber_group = 'bracing' AND job_no = '".$job_no."' AND store_item_id <> 0  AND user = '".$_SESSION['username']."' GROUP BY auth_timber_name";
$bracing_result = mySQL_query($bracing_query);
$bracing_num = mysql_num_rows($bracing_result);



$table_name = $_SESSION['db_prefix']."_authorised_timber";
$sundries_check_query = "SELECT  auth_id FROM $table_name WHERE auth_timber_group = 'sundries' AND job_no = '".$job_no."'  ";
$sundries_check_result = mySQL_query($sundries_check_query);
$sundries_check_num = mysql_num_rows($sundries_check_result);
if ($sundries_check_num!=0) { 
$table_name = $_SESSION['db_prefix']."_authorised_timber";
$complete_sundries=0;
}
else {
$table_name = $_SESSION['db_prefix']."_authorised_timber_done";
$complete_sundries=1;
$complete_alert=$complete_alert+1;
}
$table_name2 = $_SESSION['db_prefix']."_authorised_timber_edit_temp";
$sundries_query = "SELECT auth_timber_name FROM $table_name WHERE auth_timber_group = 'sundries' AND job_no = '".$job_no."' AND store_item_id <> 0  GROUP BY auth_timber_name UNION SELECT auth_timber_name FROM $table_name2 WHERE auth_timber_group = 'sundries' AND job_no = '".$job_no."' AND store_item_id <> 0 AND user = '".$_SESSION['username']."'  GROUP BY auth_timber_name";
$sundries_result = mySQL_query($sundries_query);
$sundries_num = mysql_num_rows($sundries_result);



$table_name = $_SESSION['db_prefix']."_captured_sundries";
$additional_check_query = "SELECT  cap_sundries_id FROM $table_name WHERE cap_job = '".$job_no."'  ";
$additional_check_result = mySQL_query($additional_check_query);
$additional_check_num = mysql_num_rows($additional_check_result);
if ($additional_check_num!=0) { 
$table_name = $_SESSION['db_prefix']."_captured_sundries";
$complete_additional=0;
}
else {
$table_name = $_SESSION['db_prefix']."_captured_sundries_done";
$complete_additional=1;
$complete_alert=$complete_alert+1;
}
$table_name2 = $_SESSION['db_prefix']."_captured_sundries_edit_temp";
$additional_query = "SELECT * FROM $table_name WHERE cap_job = '".$job_no."' UNION ALL SELECT * FROM $table_name2 WHERE cap_job = '".$job_no."' AND user = '".$_SESSION['username']."' ";

$additional_result = mySQL_query($additional_query);
$additional_num = mysql_num_rows($additional_result);
?>
<?php include ('../include/wait.php'); ?>

</head>


<body onload="<?php if ($screen==1) { ?> editwindow=dhtmlmodal.open('editBox', 'iframe', '<?php echo $file_open ?>', 'Add item', 'width=500px,height=400px,center=1,resize=0,scrolling=0')
needToConfirm = false; editwindow.onclose=function(){return window}; return false;<?php } ?>; <?php if ($complete_alert==4) { ?> alertMessage(1, '', 'This job is completed.<br>Any additions and/or edits are not effecting the reserved stock figures, but do have effect on the final job costing.')<?php } ?>; MM_showHideLayers('wait','','hide') " >


<div class="main_frame" style="height:auto;">
  <table id="tableMain" > <!--begin of tableMain-->
    <tr>
      <td width="830" height="62" valign="top" ><div class="page_head_frame">
        
        <table width="809" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="472"><label class="label_page_head">Edit Job Authorisation:</label>
              &nbsp;&nbsp;&nbsp;<label class="label_page_head_2"><?php echo $name ?></label></td>
            <td width="208"><label style="font-size:24px; color:#FB6808;"><?php echo "J".$job_no ?></label></td>
            </tr>
        </table>
      </div>
        <br />

<br /></td> <!--center of tableMain-->
</tr>
<tr>
<td height="93"> <!--center of tableMain-->
<div class="page_middle_frame">
<?php 
		include ('../include/customer_block.php');
		echo '<br>';
		include ('../include/job_block.php')
		?>
</div><br />
<br />
<br />
<br />
<br />
<br />
<form name="form1" id="form1" action="authorisation_edit_save.php" method="POST">
   <div class="page_middle_frame">
 <table width="675" id="table_details_display" > 
              <tr>
                <td align="left" valign="top"><label class="label_std">Mitek products:<a name="mitek" id="mitek"></a></label></td>
                <td colspan="2" align="left" valign="top"><label class="label_std">Quoted</label></td>
                <td colspan="2" align="left" valign="top"><label class="label_std">Edit Authorised </label>
                                  <input name="edit_job_no" type="hidden" value="<?php echo $job_no?>" /></td>
              </tr>
              <?php 
				  $i=0;
				   while ($i<$mitek_num) { 
					    $_SESSION['edit_mitek_line'.$i] = mysql_result($mitek_result, $i, "cap_mitek_id");
					    $_SESSION['edit_mitek_item_id'.$i] = mysql_result($mitek_result, $i, "cap_item_id");
												
						if ($_SESSION['edit_start']==0) {
						$_SESSION['edit_mitek_quantity_'.$i] =  mysql_result($mitek_result, $i, "auth_quantity");	
						if ($_SESSION['edit_mitek_quantity_'.$i]=='') {
						       $_SESSION['edit_mitek_quantity_'.$i] = mysql_result($mitek_result, $i, "cap_quantity");
						}
						if ($_SESSION['edit_mitek_quantity_'.$i]=='0') {
						       $_SESSION['edit_mitek_quantity_'.$i] = mysql_result($mitek_result, $i, "auth_quantity");
						}
						}
						
						if ($_SESSION['edit_mitek_line'.$i]=='0') {
							  
							     $_SESSION['edit_mitek_quantity_'.$i] = mysql_result($mitek_result, $i, "auth_quantity");
						}
												
						$quantity = mysql_result($mitek_result, $i, "cap_quantity");
						$table_name = $_SESSION['db_prefix']."_store_items";
						$item_name_query = "SELECT item_name, unit FROM $table_name WHERE store_item_id = '".$_SESSION['edit_mitek_item_id'.$i]."' ";
						$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"); 
	
				 ?>
             <tr>
               <td width="341"><?php echo $item_name ?><input name="cap_item_id<?php echo $i?>" id="cap_item_id<?php echo $i?>" type="hidden" value="<?php echo $_SESSION['edit_mitek_item_id'.$i] ?>" /></td>
               <td width="65" style="border-right:hidden"><div align="right"><?php echo $quantity ?></div></td>
               <td width="96">&nbsp;&nbsp;<?php echo $unit?></td>
               <td width="115" align="right"><input name="mitek_edit<?php echo $i?>" type="text" class="text60" id="mitek_edit<?php echo $i?>" value="<?php echo $_SESSION['edit_mitek_quantity_'.$i] ?>" onfocus = "this.select();" style="text-align:right; " autocomplete="off"/></td>
               <td width="34" align="center"><?php echo $unit?></td>
             </tr>
              <?php
						
			  $i++;
             }
			 ?>
             <input name="mitek_num" type="hidden" value="<?php echo $i;?>" />
            </table>
<?php if (($complete_mitek==0) OR ($complete_alert!=4) ) {?>
   <input name="mitek_button" type="submit" class="imagebutton" id="mitek_button" value="Add" onclick=" needToConfirm = false; this.form.action='authorisation_edit_temp_save.php'; MM_showHideLayers('wait','','show');"/>
<?php } ?>   
 <input name="mitek_num" id="mitek_num" type="hidden" value="<?php echo $mitek_num?>" />

          </div>
          
          
  <div class="page_middle_frame">
    <table width="676" align="left" id="table_details_display" >
      <tr style="border-bottom:double">
        <td><label class="label_std">Bracing<a name="bracing" id="bracing"></a></label></td>
        <td width="72">Item</td>
        <td colspan="2">Authorised </td>
        <td>Total </td>
        <td colspan="2">Edit Authorised</td>
      </tr>
      <?php 
			 $j=0;
			 $temp_name = '';
			 $tot_length=0;
			 while ($j<$bracing_num) {
				 $bracing_name = mysql_result($bracing_result, $j, "auth_timber_name");
				 
				 	$table_name = $_SESSION['db_prefix']."_authorised_timber";
					$bracing_check_query = "SELECT  auth_id FROM $table_name WHERE auth_timber_group = 'bracing' AND job_no = '".$job_no."'  ";
					$bracing_check_result = mySQL_query($bracing_check_query);
					$bracing_check_num = mysql_num_rows($bracing_check_result);
					if ($bracing_check_num!=0) { 
							$table_name = $_SESSION['db_prefix']."_authorised_timber";
					}
					else {
					$table_name = $_SESSION['db_prefix']."_authorised_timber_done";
					}
				 	$table_name2 = $_SESSION['db_prefix']."_authorised_timber_edit_temp";
					$bracing_sub_query = "SELECT * FROM $table_name WHERE  auth_timber_name = '".$bracing_name."'  AND job_no = '".$job_no."' AND store_item_id>0   UNION ALL SELECT * FROM $table_name2 WHERE  auth_timber_name = '".$bracing_name."'  AND job_no = '".$job_no."' AND store_item_id>0 AND user = '".$_SESSION['username']."' ";
					$bracing_sub_result = mySQL_query($bracing_sub_query);
					$bracing_sub_num = mysql_num_rows($bracing_sub_result);
					$k=0;
					$temp_name = '';
					$tot_length=0;
					while ($k<$bracing_sub_num) {
					$store_item_id = mysql_result($bracing_sub_result, $k, "store_item_id");
				 
				 		$_SESSION['edit_bracing_line'.$j.$k] = mysql_result($bracing_sub_result, $k, "auth_id");
						
					    $_SESSION['edit_bracing_item_id'.$j.$k] = mysql_result($bracing_sub_result, $k, "store_item_id");
											
						if ($_SESSION['edit_start']==0) {
							     $_SESSION['edit_bracing_quantity_'.$j.$k] =  mysql_result($bracing_sub_result, $k, "reserved");	
						if ($_SESSION['edit_bracing_quantity_'.$j.$k]=='') {
							
						       $_SESSION['edit_bracing_quantity_'.$j.$k] = mysql_result($bracing_sub_result, $k, "cap_quantity");
						}
						if ($_SESSION['edit_bracing_quantity_'.$j.$k]=='0') {
						       $_SESSION['edit_bracing_quantity_'.$j.$k] = mysql_result($bracing_sub_result, $k, "reserved");
						}
						}
						
						if ($_SESSION['edit_bracing_line'.$j.$k]=='0') {
							  
							     $_SESSION['edit_bracing_quantity_'.$j.$k] = mysql_result($bracing_sub_result, $k, "reserved");
						}
				 		 						 
				 					 	
					$quantity = mysql_result($bracing_sub_result, $k, "reserved");
				 
				 	if ($store_item_id!='0') {
					$table_name = $_SESSION['db_prefix']."_store_items";
					$item_query = "SELECT item_name, length FROM $table_name WHERE store_item_id = '".$store_item_id."' ";
					$item_result = mySQL_query($item_query);
					$item_name = mysql_result($item_result, 0, "item_name");
					$length = mysql_result($item_result, 0, "length");
					$sub_tot_length = $length*$quantity;
					$tot_length = $tot_length + $sub_tot_length;
													 
					 
					}
					else {
						$item_name = '';
						$length=0;
						$sub_tot_length='';
						$tot_length = 0;
					}
						
					
			 ?>
              
        
           
      <tr>
        <td width="230"><?php if ($temp_name!=$bracing_name) { echo $bracing_name;} ?><?php $temp_name=$bracing_name; ?>
          
          <input name="bracing_name<?php echo $j?>" type="hidden" id="bracing_name<?php echo $j?>" value="<?php echo $bracing_name?>" />
          <input name="bracing_sub_num<?php echo $j?>" type="hidden" value="<?php echo $k+1?>" />
          
          <input type="hidden" name="bracing_store_item_id<?php echo $j.$k?>" id="bracing_store_item_id<?php echo $j.$k?>" value="<?php echo $store_item_id?>" /></td>
        <td align="left" ><?php echo $length;?></td>
        <td width="66" style="border-right:hidden"><?php  if($length!=0) { echo $quantity.' no';}?></td>
        <td width="62" align="right"><?php echo number_format($length/1000, 2, '.', ',').'  m'; ?></td>
        <td width="101" align="right"><?php echo number_format($sub_tot_length/1000, 2, '.', ',') ?></td>
        <td width="81" align="right"><input name="bracing_edit<?php echo $j.$k?>" type="text" class="text60" id="bracing_edit<?php echo $j.$k?>" value="<?php echo $_SESSION['edit_bracing_quantity_'.$j.$k] ?>" onfocus = "this.select();"  style="text-align:right; " autocomplete="off"/></td>
        <td width="32" align="center">no</td>
      </tr>
      <?php 
			 $k++;
			 }
			 $j++;
			 }
			 ?>
      
    </table>
   <p><br />
<br />
<br />

<br />
<?php if (($complete_bracing==0) OR ($complete_alert!=4) ) {?>
   <input name="bracing_button" type="submit" class="imagebutton" id="bracing_button" value="Add" onclick=" needToConfirm = false; this.form.action='authorisation_edit_temp_save.php'; MM_showHideLayers('wait','','show');"/>
<?php } ?>   
   <input name="bracing_num" type="hidden" id="bracing_num" value="<?php echo $bracing_num?>" />
   
   </p>
   
   
 </p>
  </div>
  <div class="page_middle_frame">
    <table width="676" align="left" id="table_details_display" >
      <tr style="border-bottom:double">
        <td><label class="label_std">Sundries</label>
          <a name="sundries2" id="sundries2"></a></td>
        <td width="72">Item</td>
        <td colspan="2">Authorised </td>
        <td>Total </td>
        <td colspan="2">Edit Authorised</td>
      </tr>
      <?php 
			 $j=0;
			 $temp_name = '';
			 $tot_length=0;
			 while ($j<$sundries_num) {
				 $sundries_name = mysql_result($sundries_result, $j, "auth_timber_name");
				 
				 	$table_name = $_SESSION['db_prefix']."_authorised_timber";
					$sundries_check_query = "SELECT  auth_id FROM $table_name WHERE auth_timber_group = 'sundries' AND job_no = '".$job_no."'  ";
					$sundries_check_result = mySQL_query($sundries_check_query);
					$sundries_check_num = mysql_num_rows($sundries_check_result);
					if ($sundries_check_num!=0) { 
					$table_name = $_SESSION['db_prefix']."_authorised_timber";
					}
					else {
					$table_name = $_SESSION['db_prefix']."_authorised_timber_done";
					}
				 $table_name2 = $_SESSION['db_prefix']."_authorised_timber_edit_temp";
					$sundries_sub_query = "SELECT * FROM $table_name WHERE  auth_timber_name = '".$sundries_name."'  AND job_no = '".$job_no."' AND store_item_id>0   UNION ALL SELECT * FROM $table_name2 WHERE  auth_timber_name = '".$sundries_name."'  AND job_no = '".$job_no."' AND store_item_id>0 AND user = '".$_SESSION['username']."' ";
					$sundries_sub_result = mySQL_query($sundries_sub_query);
					$sundries_sub_num = mysql_num_rows($sundries_sub_result);
					$k=0;
					$temp_name = '';
					$tot_length=0;
					while ($k<$sundries_sub_num) {
					$store_item_id = mysql_result($sundries_sub_result, $k, "store_item_id");
				 
				 		$_SESSION['edit_sundries_line'.$j.$k] = mysql_result($sundries_sub_result, $k, "auth_id");
						
					    $_SESSION['edit_sundries_item_id'.$j.$k] = mysql_result($sundries_sub_result, $k, "store_item_id");
											
						if ($_SESSION['edit_start']==0) {
							     $_SESSION['edit_sundries_quantity_'.$j.$k] =  mysql_result($sundries_sub_result, $k, "reserved");	
						if ($_SESSION['edit_sundries_quantity_'.$j.$k]=='') {
							
						       $_SESSION['edit_sundries_quantity_'.$j.$k] = mysql_result($sundries_sub_result, $k, "cap_quantity");
						}
						if ($_SESSION['edit_sundries_quantity_'.$j.$k]=='0') {
						       $_SESSION['edit_sundries_quantity_'.$j.$k] = mysql_result($sundries_sub_result, $k, "reserved");
						}
						}
						
						if ($_SESSION['edit_sundries_line'.$j.$k]=='0') {
							  
							     $_SESSION['edit_sundries_quantity_'.$j.$k] = mysql_result($sundries_sub_result, $k, "reserved");
						}
				 		 						 
				 					 	
					$quantity = mysql_result($sundries_sub_result, $k, "reserved");
				 
				 	if ($store_item_id!='0') {
					$table_name = $_SESSION['db_prefix']."_store_items";
					$item_query = "SELECT item_name, length FROM $table_name WHERE store_item_id = '".$store_item_id."' ";
					$item_result = mySQL_query($item_query);
					$item_name = mysql_result($item_result, 0, "item_name");
					$length = mysql_result($item_result, 0, "length");
					$sub_tot_length = $length*$quantity;
					$tot_length = $tot_length + $sub_tot_length;
													 
					 
					}
					else {
						$item_name = '';
						$length=0;
						$sub_tot_length='';
						$tot_length = 0;
					}
						
					
			 ?>
      
      <input name="sundries_sub_num<?php echo $j;?>" type="hidden" value="<?php echo $k+1;?>" />
      <tr>
        <td width="230"><?php if ($temp_name!=$sundries_name) { echo $sundries_name;} ?>
          <?php $temp_name=$sundries_name; ?>
          <input name="sundries_name<?php echo $j?>" type="hidden" id="sundries_name<?php echo $j?>" value="<?php echo $sundries_name?>" />
          <input type="hidden" name="sundries_store_item_id<?php echo $j.$k?>" id="sundries_store_item_id<?php echo $j.$k?>" value="<?php echo $store_item_id?>" /></td>
        <td align="left" ><?php echo $length;?></td>
        <td width="66" style="border-right:hidden"><?php  if($length!=0) { echo $quantity.' no';}?></td>
        <td width="62" align="right"><?php echo number_format($length/1000, 2, '.', ',').'  m'; ?></td>
        <td width="101" align="right"><?php echo number_format($sub_tot_length/1000, 2, '.', ',') ?></td>
        <td width="81" align="right"><input name="sundries_edit<?php echo $j.$k?>" type="text" class="text60" id="sundries_edit<?php echo $j.$k?>" value="<?php echo $_SESSION['edit_sundries_quantity_'.$j.$k] ?>" onfocus = "this.select();"  style="text-align:right; " autocomplete="off"/></td>
        <td width="32" align="center">no</td>
      </tr>
      <?php 
			 $k++;
			 }
			 $j++;
			 }
			 ?>
    </table>
    <p><br />
      <br />
      <br />
      <br />
      <?php if (($complete_sundries==0) OR ($complete_alert!=4) ) {?>
      <input name="sundries_button" type="submit" class="imagebutton" id="sundries_button" value="Add" onclick=" needToConfirm = false; this.form.action='authorisation_edit_temp_save.php';MM_showHideLayers('wait','','show')"/>
      <?php } ?> 
      <input name="sundries_num" type="hidden" id="sundries_num" value="<?php echo $sundries_num?>" />
     
    </p>
    </p>
  </div>
  <div class="page_middle_frame">

 <table width="675" id="table_details_display" >
   <tr>
     <td align="left" valign="top"><label class="label_std">Additional Sundries<a name="sundries" id="sundries"></a></label></td>
     <td colspan="2" align="left" valign="top"><label class="label_std">Quoted</label></td>
     <td colspan="3" align="left" valign="top"><label class="label_std">Edit Authorised</label></td>
   </tr> 
             <?php 
				  $m=0;
				  while ($m<$additional_num) { 
					    
						$_SESSION['edit_additional_line'.$m] = mysql_result($additional_result, $m, "cap_sundries_id");
					    $_SESSION['edit_additional_item_id'.$m] = mysql_result($additional_result, $m, "cap_item_id");
												
						if ($_SESSION['edit_start']==0) {
						$_SESSION['edit_additional_quantity_'.$m] =  mysql_result($additional_result, $m, "auth_quantity");	
						if ($_SESSION['edit_additional_quantity_'.$m]=='') {
						       $_SESSION['edit_additional_quantity_'.$m] = mysql_result($additional_result, $m, "cap_quantity");
						}
						if ($_SESSION['edit_additional_quantity_'.$m]=='0') {
						       $_SESSION['edit_additional_quantity_'.$m] = mysql_result($additional_result, $m, "auth_quantity");
						}
						}
						
						if ($_SESSION['edit_additional_line'.$m]=='0') {
							  
							     $_SESSION['edit_additional_quantity_'.$m] = mysql_result($additional_result, $m, "auth_quantity");
						}
						
						
						
						$_additional_quantity = mysql_result($additional_result, $m, "cap_quantity");
						$_additional_auth_quantity = mysql_result($additional_result, $m, "auth_quantity");
						$table_name = $_SESSION['db_prefix']."_store_items";
						$item_name_query = "SELECT item_name, unit FROM $table_name WHERE store_item_id = '".$_SESSION['edit_additional_item_id'.$m]. "' ";
						$item_name_result = mySQL_query($item_name_query);
						$item_name_num = mysql_num_rows($item_name_result);
						if ($item_name_num!=0) {
						$item_name = mysql_result($item_name_result, 0, "item_name"); 
						$unit = mysql_result($item_name_result, 0, "unit"); 
						}
				 ?>
             <tr>
               <td width="283"><?php echo $item_name ?>
                <input name="additional_item<?php echo $m?>" id="additional_item<?php echo $m?>" type="hidden" value="<?php echo $_SESSION['edit_additional_item_id'.$m]?>" /></td>
               <td width="57" style="border-right:hidden" ><div align="right"><?php echo $_additional_quantity?></div></td>
               <td width="175"><?php echo $unit ?></td>
               <td width="103" align="right"><input name="additional_edit<?php echo $m?>" type="text" class="text60" id="additional_edit<?php echo $m?>" value="<?php echo $_SESSION['edit_additional_quantity_'.$m] ?>" onfocus = "this.select();"  style="text-align:right;" autocomplete="off"/></td>
               <td width="31" align="center"></td>
               <td width="33" align="right"><?php echo $unit ?></td>
             </tr>
              <?php
					
			  $m++;
             }
			?>
            <input name="additional_num" type="hidden" value="<?php echo $m;?>" />
    </table>
<?php if (($complete_additional==0) OR ($complete_alert!=4) ) {?>
   <input name="additional_button" type="submit" class="imagebutton" id="additional_button" value="Add" onclick=" needToConfirm = false; this.form.action='authorisation_edit_temp_save.php'; MM_showHideLayers('wait','','show');" />
<?php } ?>
    
  </div>
  <div class="page_middle_frame">
    <table width="645" border="0">
      <tr>
      <td width="20"></td>
      <td width="615" align="right">
      <input type="hidden" name="complete_alert" id="complete_alert"  value="<?php echo $complete_alert ?>"/>
      <input type="hidden" name="complete_mitek" id="complete_mitek"  value="<?php echo $complete_mitek ?>"/>
      <input type="hidden" name="complete_bracing" id="complete_bracing"  value="<?php echo $complete_bracing ?>"/>
      <input type="hidden" name="complete_sundries" id="complete_sundries"  value="<?php echo $complete_sundries ?>"/>
      <input type="hidden" name="complete_additional" id="complete_additional"  value="<?php echo $complete_additional ?>"/>
        <input type="hidden" name="job_no" id="job_no" value="<?php echo $job_no ?>" />
        <input name="button2" type="button" class="imagebutton" id="button2" onclick="cancel_confirmation(3, '../production/production_main.php');" value="Close"/>
        <input name="save_button"  id="save_button" type="submit" class="imagebutton" value="Save " onclick="needToConfirm = false; confirmRefresh();" />
        <input name="save_close_button"  id="save_close_button" type="submit" class="imagebutton" value="Save &amp; Close" onclick="needToConfirm = false; confirmRefresh();" /></td>
    </tr>
</table>
  </div>
  </form>
  </td>
</tr>

</table>  <!--end of tableMain-->
  
</div>


<?php include ('../navigation/side_bar.php'); ?>




</body>
<?php } else {
$_SESSION['denied_return'] = "production/production_main.php";	
include ("../navigation/production_sidebar.php");?>
	<body onload="accessdenied(); return false">
    <?php include ('../navigation/side_bar.php'); ?>
	</body>
<?php }
?>
</html>