<?php 
include('../include/session.php');
$n=0;

if (isset($_GET['add_bracing_button']) )
	   {
		 $_SESSION['cat']= 'Bracing';
	   }
		 
	if (isset($_GET['add_sundries_button']) )
	  {
		$_SESSION['cat']='Sundries';
	  }

while ($n<$_SESSION['list_5a']) {
	$table_name = $_SESSION['db_prefix']."_authorised_timber_temp";
//if ($_SESSION['s']==3) {
	$m=0;
	while ($m<20) {
		if(isset($_GET['check'.($n+10).($m+10)]) ) {
				$_SESSION['check'.($n+10).($m+10)] = 'yes';
				$check_query = "SELECT auth_id FROM $table_name WHERE auth_timber_group='bracing' AND auth_timber_name= '".$_SESSION['bracing_name_'.$n]."' AND store_item_id = '".$_SESSION['item_id'.($n+10).($m+10)]."' AND job_no = '".$_SESSION['job_no']."' AND user =  '".$_SESSION['username']."' ";
					$check_result = mySQL_query($check_query);
					$check_num = mysql_num_rows($check_result);
					
				if ($check_num==0) {
						$timber_query = "INSERT INTO $table_name (auth_timber_group, auth_timber_name, store_item_id, reserved, delivered, job_no, user) VALUES ('bracing','".$_SESSION['bracing_name_'.$n]."','".$_SESSION['item_id'.($n+10).($m+10)]."', '".$_SESSION['bracing_qty'.($n+10).($m+10)]."', '0', '".$_SESSION['job_no']."', '".$_SESSION['username']."' )";
					//echo '<br>'.$timber_query;
						execsql($timber_query);
				}
		}
		else {
			$_SESSION['check'.($n+10).($m+10)] = 'no';
		}
		$m++;
}
$n++;
}

$n=0;
while ($n<$_SESSION['list_5b']) {
	
	$table_name = $_SESSION['db_prefix']."_authorised_timber_temp";
//if ($_SESSION['s']==3) {
	$m=0;
	while ($m<20) {
		if(isset($_GET['check2'.($n+10).($m+10)]) ) {
				$_SESSION['check2_'.($n+10).($m+10)] = 'yes';
				$check_query = "SELECT auth_id FROM $table_name WHERE auth_timber_group='sundries' AND auth_timber_name= '".$_SESSION['sundries_name_'.$n]."' AND store_item_id = '".$_SESSION['item_id'.($n+10).($m+10)]."' AND job_no = '".$_SESSION['job_no']."' AND user =  '".$_SESSION['username']."' ";
					$check_result = mySQL_query($check_query);
					$check_num = mysql_num_rows($check_result);
					
				if ($check_num==0) {
					
						$timber_query = "INSERT INTO $table_name (auth_timber_group, auth_timber_name, store_item_id, reserved, delivered, job_no, user) VALUES ('sundries','".$_SESSION['sundries_name_'.$n]."','".$_SESSION['item_id'.($n+10).($m+10)]."', '".$_SESSION['sundries_qty'.($n+10).($m+10)]."', '0', '".$_SESSION['job_no']."', '".$_SESSION['username']."' )";
					//echo '<br>'.$timber_query;
						execsql($timber_query);
				}
		}
		else {
			$_SESSION['check2_'.($n+10).($m+10)] = 'no';
		}
		$m++;
}
$n++;
}
$_SESSION['screen']=1;
?>

<script language="javascript" type="text/javascript">
         window.location="authorisationWizbase.php?p=3&s=";
</script>



