<?php 
include('../include/session.php');
$mitek_num = $_POST['mitek_num'];
$bracing_num = $_POST['bracing_num'];
$sundries_num = $_POST['sundries_num'];
$additional_num = $_POST['additional_num'];
$job_no = $_POST['job_no'];

$i=0;
while ($i<$mitek_num) {
	$mitek_item_id = $_SESSION['edit_mitek_item_id'.$i];
	$edit_value = $_POST['mitek_edit'.$i];
	$_SESSION['edit_mitek_quantity_'.$i] = $edit_value;
	
	if ($_SESSION['edit_mitek_line'.$i]=='0') {
	$table_name = $_SESSION['db_prefix']."_captured_mitek_edit_temp";
	$mitek_query = "UPDATE $table_name SET auth_quantity = '".$edit_value."' WHERE cap_item_id = '".$mitek_item_id."' AND cap_job = '".$job_no."' AND user = '".$_SESSION['username']."' ";
	//echo '<br>'.$mitek_query;
	execsql($mitek_query);	
	}
	$i++;
}

$i=0;
while ($i<$bracing_num) {
	$j=0;
	$bracing_sub_num = $_POST['bracing_sub_num'.$i];
	
	while ($j<$bracing_sub_num) {
	$bracing_item_id = $_SESSION['edit_bracing_item_id'.$i.$j];
	$edit_value = $_POST['bracing_edit'.$i.$j];
	$_SESSION['edit_bracing_quantity_'.$i.$j] = $edit_value;
	
	if ($_SESSION['edit_bracing_line'.$i.$j]=='0') {
	$table_name = $_SESSION['db_prefix']."_authorised_timber_edit_temp";
	$bracing_query = "UPDATE $table_name SET reserved = '".$edit_value."' WHERE store_item_id = '".$bracing_item_id."' AND job_no = '".$job_no."' AND user = '".$_SESSION['username']."' ";
	//echo '<br>'.$mitek_query;
	execsql($bracing_query);
	}
	$j++;
	}
	$i++;
}

$i=0;
//echo $sundries_num;
while ($i<$sundries_num) {
	$j=0;
	$sundries_sub_num = $_POST['sundries_sub_num'.$i];
	
	while ($j<$sundries_sub_num) {
	$sundries_item_id = $_SESSION['edit_sundries_item_id'.$i.$j];
	$edit_value = $_POST['sundries_edit'.$i.$j];
	$_SESSION['edit_sundries_quantity_'.$i.$j] = $edit_value;
	
	
	
	if ($_SESSION['edit_sundries_line'.$i.$j]=='0') {
	$table_name = $_SESSION['db_prefix']."_authorised_timber_edit_temp";
	$sundries_query = "UPDATE $table_name SET reserved = '".$edit_value."' WHERE store_item_id = '".$sundries_item_id."' AND job_no = '".$job_no."' AND user = '".$_SESSION['username']."' ";
	//echo '<br>'.$mitek_query;
	execsql($sundries_query);
	}
	$j++;
	}
	$i++;
}

$m=0;
while ($m<$additional_num) {
	$additional_item_id = $_SESSION['edit_additional_item_id'.$m];
	$edit_value = $_POST['additional_edit'.$m];
	$_SESSION['edit_additional_quantity_'.$m] = $edit_value;
		
	
	if ($_SESSION['edit_additional_line'.$m]=='0') {
	$table_name = $_SESSION['db_prefix']."_captured_sundries_edit_temp";
	$additional_query = "UPDATE $table_name SET auth_quantity = '".$edit_value."' WHERE cap_item_id = '".$additional_item_id."' AND cap_job = '".$job_no."' AND user = '".$_SESSION['username']."' ";
	execsql($additional_query);	
	}
	$m++;
}

$_SESSION['edit_start']=1;

if (isset($_POST['mitek_button']))  {
		$sub_category = 'Mitek';
		$anchor = 'mitek';	
}

if (isset($_POST['bracing_button']))  {
		$sub_category = 'Bracing';
		$anchor = 'bracing';	
}

if (isset($_POST['sundries_button']))  {
		$sub_category = 'Sundries2';
		$anchor = 'sundries2';	
}

if (isset($_POST['additional_button']))  {
		$sub_category = 'Sundries';
		$anchor = 'sundries';	
}
		  
?>		  

<script language="javascript" type="text/javascript">
    window.location="authorisation_edit.php?screen=1&job_no=<?php echo $job_no?>&edit=1&sub_category=<?php echo $sub_category; ?>#<?php echo $anchor?>";
</script>



