<?php 
include('../include/session.php');
$job_no = $_GET['job_no'];

$sub_category=$_GET['cat'];
$quantity=$_GET['qty_text'];



if ($sub_category=='Bracing') {
$bracing_num = $_GET['bracing_select'];	
$table_name = $_SESSION['db_prefix']."_list_bracing";
$name_query = "SELECT item_name, width, depth, class FROM $table_name WHERE item_id = '".$bracing_num."' ";
$name_result = mySQL_query($name_query);
$bracing_name = mysql_result($name_result, 0, "item_name");
$bracing_width = mysql_result($name_result, 0, "width");
$bracing_depth = mysql_result($name_result, 0, "depth");
$bracing_class = mysql_result($name_result, 0, "class");


if ($sub_category=='Bracing') {
	
	$table_name = $_SESSION['db_prefix']."_captured_timber";
	$table_name2 = $_SESSION['db_prefix']."_captured_timber_edit_temp";
	$check_query = "SELECT cap_timber_id FROM $table_name WHERE cap_timber_group='bracing' AND cap_timber_name= '".$bracing_name."' AND cap_job = '".$job_no."' UNION SELECT cap_timber_id FROM $table_name2 WHERE cap_timber_group='bracing' AND cap_timber_name= '".$bracing_name."' AND cap_job = '".$job_no."'";
	//echo '<br>'.$check_query;
					$check_result = mySQL_query($check_query);
					$check_num = mysql_num_rows($check_result);
					//echo '<br>'.$check_num;
					
				if ($check_num==0) {
						$timber_query = "INSERT INTO $table_name2 (cap_timber_group, cap_timber_name, cap_timber_length, cap_job, cap_class, cap_width, cap_depth) VALUES ('Bracing','".$bracing_name."', '".$quantity."', '".$job_no."', '".$bracing_class."', '".$bracing_width."', '".$bracing_depth."' )";
					//echo '<br>'.$timber_query;
						execsql($timber_query);
				}
		
		else {
			?>
            <script>
			alert('This item is already in the list and will not be added to the list.\r\n\r\nIf you require additional quantity, you should edit the quantity in the list. ');
			</script>
            <?php 
		}
}
}


if ($sub_category=='Sundries') {
$sundries_num = $_GET['bracing_select'];	
$table_name = $_SESSION['db_prefix']."_list_sundries";
$name_query = "SELECT item_name, width, depth, class FROM $table_name WHERE item_id = '".$sundries_num."' ";
$name_result = mySQL_query($name_query);
$sundries_name = mysql_result($name_result, 0, "item_name");
$sundries_width = mysql_result($name_result, 0, "width");
$sundries_depth = mysql_result($name_result, 0, "depth");
$sundries_class = mysql_result($name_result, 0, "class");



if ($sub_category=='Sundries') {
	$table_name = $_SESSION['db_prefix']."_captured_timber";
	$table_name2 = $_SESSION['db_prefix']."_captured_timber_edit_temp";
	$check_query = "SELECT cap_timber_id FROM $table_name WHERE cap_timber_group='sundries' AND cap_timber_name= '".$sundries_name."' AND cap_job = '".$job_no."' UNION SELECT cap_timber_id FROM $table_name2 WHERE cap_timber_group='sundries' AND cap_timber_name= '".$sundries_name."' AND cap_job = '".$job_no."'";
	//echo '<br>'.$check_query;
					$check_result = mySQL_query($check_query);
					$check_num = mysql_num_rows($check_result);
					//echo '<br>'.$check_num;
					
				if ($check_num==0) {
						$timber_query = "INSERT INTO $table_name2 (cap_timber_group, cap_timber_name, cap_timber_length, cap_job, cap_class, cap_width, cap_depth) VALUES ('Sundries','".$sundries_name."', '".$quantity."', '".$job_no."', '".$sundries_class."', '".$sundries_width."', '".$sundries_depth."' )";
					//echo '<br>'.$timber_query;
						execsql($timber_query);
				}
		
		else {
			?>
            <script>
			alert('This item is already in the list and will not be added to the list.\r\n\r\nIf you require additional quantity, you should edit the quantity in the list. ');
			</script>
            <?php 
		}
}
}



		//if (isset($_POST['next_add_button']) )
//	   { ?>
      <script>
	//   window.location="../production/captured_edit.php?job_no=<?php echo $job_no ?>&screen=0&sub_category=<?php if ($sub_category=='Bracing') { echo '#bracing'; } else { echo '#sundries';}?>";
//		</script>
        <?php		 
//	   }
//	   else {
		   ?>
		   <script language="javascript" type="text/javascript">
         window.location="../production/captured_edit.php?job_no=<?php echo $job_no ?>&screen=0&edit=1&sub_category=<?php if ($sub_category=='Bracing') { echo '#bracing'; } else { echo '#sundries';}?>";
</script>
<?php
	//   }
	   ?>
