<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script>
<?php 
include('../include/session.php');
$job_no = $_GET['job_no'];


$job_no = $_GET['job_no'];

$line_num1 = $_GET['line_num1'];
$line_num2 = $_GET['line_num2'];

$i=0;
while ($i<$line_num1) {
	$type = $_GET['type_text_'.$i];
	$price = $_GET['meter_price_text_'.$i];
	$length = $_GET['length_text_'.$i];
	$width = $_GET['width_text_'.$i];
	$depth = $_GET['depth_text_'.$i];
	$class = $_GET['class_text_'.$i];
	
	
$table_name = $_SESSION['db_prefix']."_captured_timber";
$timber_check_query = "SELECT cap_timber_id FROM $table_name WHERE  cap_job = '".$job_no."' ";
$timber_check_result = mySQL_query($timber_check_query);
$timber_check_num = mysql_num_rows($timber_check_result);
if ($timber_check_num>0) {
		$table_nameS5 = $_SESSION['db_prefix']."_captured_timber";
}
else {
		$table_nameS5 = $_SESSION['db_prefix']."_captured_timber_done";
	}

$type_query = "SELECT cap_timber_group FROM $table_name WHERE cap_timber_group = 'Trusses' AND cap_job = '".$job_no."' AND cap_timber = '".$type."' ";
$type_result = mySQL_query($type_query);
$type_num = mysql_num_rows($type_result);
if ($type_num>0) {
	    $update_query = "UPDATE $table_nameS5 SET cap_timber_length = '".$length."' WHERE cap_timber_group = 'Trusses' AND cap_job = '".$job_no."' AND cap_timber = '".$type."' ";
		execsql($update_query);
}
else {
	if ($length>0) {
			$insert_query = "INSERT INTO $table_nameS5 (cap_job, cap_timber_group, cap_timber_name, cap_timber, cap_timber_length, auth_timber_length, prereserved, reserved, cap_width, cap_depth, cap_class, cap_timber_price ) VALUES ('".$job_no."', 'Trusses', 'Trusses', '".$type."', '".$length."', '0', '".$length."', '0', '".$width."', '".$depth."', '".$class."', '".$price."') ";
			execsql($insert_query);
	}
}

$i++;
}

$i=0;
while ($i<$line_num2) {
	$type = $_GET['type2_text_'.$i];
	$price = $_GET['meter2_price_text_'.$i];
	$length = $_GET['length2_text_'.$i];
	$width = $_GET['width2_text_'.$i];
	$depth = $_GET['depth2_text_'.$i];
	$class = $_GET['class2_text_'.$i];
	
	
$table_name = $_SESSION['db_prefix']."_captured_timber";
$timber_check_query = "SELECT cap_timber_id FROM $table_name WHERE  cap_job = '".$job_no."' ";
$timber_check_result = mySQL_query($timber_check_query);
$timber_check_num = mysql_num_rows($timber_check_result);
if ($timber_check_num>0) {
		$table_nameS7 = $_SESSION['db_prefix']."_captured_timber";
}
else {
		$table_nameS7 = $_SESSION['db_prefix']."_captured_timber_done";
	}

$type_query = "SELECT cap_timber_group FROM $table_name WHERE cap_timber_group = 'Trusses' AND cap_job = '".$job_no."' AND cap_timber = '".$type."' ";
$type_result = mySQL_query($type_query);
$type_num = mysql_num_rows($type_result);
if ($type_num>0) {
	    $update_query = "UPDATE $table_nameS5 SET cap_timber_length = '".$length."' WHERE cap_timber_group = 'Trusses' AND cap_job = '".$job_no."' AND cap_timber = '".$type."' ";
		execsql($update_query);
}
else {
	if ($length>0) {
			$insert_query = "INSERT INTO $table_nameS5 (cap_job, cap_timber_group, cap_timber_name, cap_timber, cap_timber_length, auth_timber_length, prereserved, reserved, cap_width, cap_depth, cap_class, cap_timber_price ) VALUES ('".$job_no."', 'Trusses', 'Trusses', '".$type."', '".$length."', '0', '".$length."', '0', '".$width."', '".$depth."', '".$class."', '".$price."') ";
			execsql($insert_query);
	}
}

$i++;
}
	
?>

<script language="javascript" type="text/javascript">
  window.location="../production/captured_edit.php?job_no=<?php echo $job_no ?>&sub_category=&screen=0&edit=1&save_message=0;";
</script>

