<?php
include('../include/session.php');

date_default_timezone_set('Africa/Gaborone');
$entry_date = date("Y-m-d H:i:s", time());

$report_no = $_POST['report_no'];
$type = $_POST['type'];
$production_date = $_POST['production_date'];
//$mix_design_name = $_POST['mix_design_name'];
$tested_by = $_POST['tested_by_select'];
$test_date = $_POST['test_date'];

//$approved_by = $_POST['approved_by_select'];
//$approve_date = $_POST['approve_date'];

if (isset($_POST['flat_checkbox'])) {$flat_type = 1;} else {$flat_type = 0;}
if (isset($_POST['profiled_checkbox'])) {$profiled_type = 1;} else {$profiled_type = 0;}

$colour_1 = $_POST['color_select_1'];
$colour_2 = $_POST['color_select_2'];

if (isset($_POST['true_colour_checkbox'])) {$true_colour = 1;} else {$true_colour = 0;}
if (isset($_POST['antique_checkbox'])) {$antique = 1;} else {$antique = 0;}

$length_L2_1 = $_POST['length_L2_1'];
$length_L2_2 = $_POST['length_L2_2'];
$length_L2_3 = $_POST['length_L2_3'];
$length_L2_4 = $_POST['length_L2_4'];
$length_L2_5 = $_POST['length_L2_5'];
$length_L2_6 = $_POST['length_L2_6'];
$length_L3_1 = $_POST['length_L3_1'];
$length_L3_2 = $_POST['length_L3_2'];
$length_L3_3 = $_POST['length_L3_3'];
$length_L3_4 = $_POST['length_L3_4'];
$length_L3_5 = $_POST['length_L3_5'];
$length_L3_6 = $_POST['length_L3_6'];
$length_L1_1 = $_POST['length_L1_1'];
$length_L1_2 = $_POST['length_L1_2'];
$length_L1_3 = $_POST['length_L1_3'];
$length_L1_4 = $_POST['length_L1_4'];
$length_L1_5 = $_POST['length_L1_5'];
$length_L1_6 = $_POST['length_L1_6'];

$flatness_1 = 0;
$flatness_2 = 0;
$flatness_3 = 0;
$flatness_4 = 0;
$flatness_5 = 0;
$flatness_6 = 0;
if (isset($_POST['flatness_1a'])) {$flatness_1 = 1;}
if (isset($_POST['flatness_1b'])) {$flatness_1 = 2;}
if (isset($_POST['flatness_2a'])) {$flatness_2 = 1;}
if (isset($_POST['flatness_2b'])) {$flatness_2 = 2;}
if (isset($_POST['flatness_3a'])) {$flatness_3 = 1;}
if (isset($_POST['flatness_3b'])) {$flatness_3 = 2;}
if (isset($_POST['flatness_4a'])) {$flatness_4 = 1;}
if (isset($_POST['flatness_4b'])) {$flatness_4 = 2;}
if (isset($_POST['flatness_5a'])) {$flatness_5 = 1;}
if (isset($_POST['flatness_5b'])) {$flatness_5 = 2;}
if (isset($_POST['flatness_6a'])) {$flatness_6 = 1;}
if (isset($_POST['flatness_6b'])) {$flatness_6 = 2;}

if ($type!='SL') {
$width_1 = $_POST['width_1'];
$width_2 = $_POST['width_2'];
$width_3 = $_POST['width_3'];
$width_4 = '';
$width_5 = '';
$width_6 = '';
}
else {
$width_1 = '';
$width_2 = '';
$width_3 = '';
$width_4 = $_POST['width_4'];
$width_5 = $_POST['width_5'];
$width_6 = $_POST['width_6'];
}

if ($type!='SL') {
$nail_1 = $_POST['nail_1'];
$nail_2 = $_POST['nail_2'];
$nail_3 = $_POST['nail_3'];
$nail_4 = '';
$nail_5 = '';
$nail_6 = '';
}
else {
$nail_1 = '';
$nail_2 = '';
$nail_3 = '';
$nail_4 = $_POST['nail_4'];
$nail_5 = $_POST['nail_5'];
$nail_6 = $_POST['nail_6'];
}

$rain_1 = 0;
$rain_2 = 0;
$rain_3 = 0;
$rain_4 = 0;
$rain_5 = 0;
$rain_6 = 0;
if (isset($_POST['rain_1a'])) {$rain_1 = 1;}
if (isset($_POST['rain_1b'])) {$rain_1 = 2;}
if (isset($_POST['rain_2a'])) {$rain_2 = 1;}
if (isset($_POST['rain_2b'])) {$rain_2 = 2;}
if (isset($_POST['rain_3a'])) {$rain_3 = 1;}
if (isset($_POST['rain_3b'])) {$rain_3 = 2;}
if (isset($_POST['rain_4a'])) {$rain_4 = 1;}
if (isset($_POST['rain_4b'])) {$rain_4 = 2;}
if (isset($_POST['rain_5a'])) {$rain_5 = 1;}
if (isset($_POST['rain_5b'])) {$rain_5 = 2;}
if (isset($_POST['rain_6a'])) {$rain_6 = 1;}
if (isset($_POST['rain_6b'])) {$rain_6 = 2;}


$mass_1_1 = $_POST['mass_1_1'];
$mass_1_2 = $_POST['mass_1_2'];
$mass_1_3 = $_POST['mass_1_3'];
$mass_1_4 = $_POST['mass_1_4'];
$mass_1_5 = $_POST['mass_1_5'];
$mass_1_6 = $_POST['mass_1_6'];
$divisions_1_1 = $_POST['divisions_1_1'];
$divisions_1_2 = $_POST['divisions_1_2'];
$divisions_1_3 = $_POST['divisions_1_3'];
$divisions_1_4 = $_POST['divisions_1_4'];
$divisions_1_5 = $_POST['divisions_1_5'];
$divisions_1_6 = $_POST['divisions_1_6'];
$kn_1_1 = $_POST['kn_1_1'];
$kn_1_2 = $_POST['kn_1_2'];
$kn_1_3 = $_POST['kn_1_3'];
$kn_1_4 = $_POST['kn_1_4'];
$kn_1_5 = $_POST['kn_1_5'];
$kn_1_6 = $_POST['kn_1_6'];
$thickness_1_1 = $_POST['thickness_1_1'];
$thickness_1_2 = $_POST['thickness_1_2'];
$thickness_1_3 = $_POST['thickness_1_3'];
$thickness_1_4 = $_POST['thickness_1_4'];
$thickness_1_5 = $_POST['thickness_1_5'];
$thickness_1_6 = $_POST['thickness_1_6'];
$mass_2_1 = $_POST['mass_2_1'];
$mass_2_2 = $_POST['mass_2_2'];
$mass_2_3 = $_POST['mass_2_3'];
$mass_2_4 = $_POST['mass_2_4'];
$mass_2_5 = $_POST['mass_2_5'];
$mass_2_6 = $_POST['mass_2_6'];
$divisions_2_1 = $_POST['divisions_2_1'];
$divisions_2_2 = $_POST['divisions_2_2'];
$divisions_2_3 = $_POST['divisions_2_3'];
$divisions_2_4 = $_POST['divisions_2_4'];
$divisions_2_5 = $_POST['divisions_2_5'];
$divisions_2_6 = $_POST['divisions_2_6'];
$kn_2_1 = $_POST['kn_2_1'];
$kn_2_2 = $_POST['kn_2_2'];
$kn_2_3 = $_POST['kn_2_3'];
$kn_2_4 = $_POST['kn_2_4'];
$kn_2_5 = $_POST['kn_2_5'];
$kn_2_6 = $_POST['kn_2_6'];
$thickness_2_1 = $_POST['thickness_2_1'];
$thickness_2_2 = $_POST['thickness_2_2'];
$thickness_2_3 = $_POST['thickness_2_3'];
$thickness_2_4 = $_POST['thickness_2_4'];
$thickness_2_5 = $_POST['thickness_2_5'];
$thickness_2_6 = $_POST['thickness_2_6'];
$mass_3_1 = $_POST['mass_3_1'];
$mass_3_2 = $_POST['mass_3_2'];
$mass_3_3 = $_POST['mass_3_3'];
$mass_3_4 = $_POST['mass_3_4'];
$mass_3_5 = $_POST['mass_3_5'];
$mass_3_6 = $_POST['mass_3_6'];
$divisions_3_1 = $_POST['divisions_3_1'];
$divisions_3_2 = $_POST['divisions_3_2'];
$divisions_3_3 = $_POST['divisions_3_3'];
$divisions_3_4 = $_POST['divisions_3_4'];
$divisions_3_5 = $_POST['divisions_3_5'];
$divisions_3_6 = $_POST['divisions_3_6'];
$kn_3_1 = $_POST['kn_3_1'];
$kn_3_2 = $_POST['kn_3_2'];
$kn_3_3 = $_POST['kn_3_3'];
$kn_3_4 = $_POST['kn_3_4'];
$kn_3_5 = $_POST['kn_3_5'];
$kn_3_6 = $_POST['kn_3_6'];
$thickness_3_1 = $_POST['thickness_3_1'];
$thickness_3_2 = $_POST['thickness_3_2'];
$thickness_3_3 = $_POST['thickness_3_3'];
$thickness_3_4 = $_POST['thickness_3_4'];
$thickness_3_5 = $_POST['thickness_3_5'];
$thickness_3_6 = $_POST['thickness_3_6'];

$release_1_date = $_POST['release_1_date'];
$release_3_date = $_POST['release_3_date'];
$release_7_date = $_POST['release_7_date'];
$remarks = $_POST['remarks'];


$table_name = $_SESSION['db_prefix']."_dry_tile_spec";
$update_query = "UPDATE $table_name SET


tested_by = '".$tested_by."',
test_date = '".$test_date."',
flat_type = '".$flat_type."',
profiled_type = '".$profiled_type."',
colour_1 = '".$colour_1."',
colour_2 = '".$colour_2."',
true_colour = '".$true_colour."',
antique = '".$antique."',
length_L2_1 = '".$length_L2_1."',
length_L2_2 = '".$length_L2_2."',
length_L2_3 = '".$length_L2_3."',
length_L2_4 = '".$length_L2_4."',
length_L2_5 = '".$length_L2_5."',
length_L2_6 = '".$length_L2_6."',
length_L3_1 = '".$length_L3_1."',
length_L3_2 = '".$length_L3_2."',
length_L3_3 = '".$length_L3_3."',
length_L3_4 = '".$length_L3_4."',
length_L3_5 = '".$length_L3_5."',
length_L3_6 = '".$length_L3_6."',
length_L1_1 = '".$length_L1_1."',
length_L1_2 = '".$length_L1_2."',
length_L1_3 = '".$length_L1_3."',
length_L1_4 = '".$length_L1_4."',
length_L1_5 = '".$length_L1_5."',
length_L1_6 = '".$length_L1_6."',
flatness_1 = '".$flatness_1."',
flatness_2 = '".$flatness_2."',
flatness_3 = '".$flatness_3."',
flatness_4 = '".$flatness_4."',
flatness_5 = '".$flatness_5."',
flatness_6 = '".$flatness_6."',
width_1 = '".$width_1."',
width_2 = '".$width_2."',
width_3 = '".$width_3."',
width_4 = '".$width_4."',
width_5 = '".$width_5."',
width_6 = '".$width_6."',
nail_1 = '".$nail_1."',
nail_2 = '".$nail_2."',
nail_3 = '".$nail_3."',
nail_4 = '".$nail_4."',
nail_5 = '".$nail_5."',
nail_6 = '".$nail_6."',
rain_1 = '".$rain_1."',
rain_2 = '".$rain_2."',
rain_3 = '".$rain_3."',
rain_4 = '".$rain_4."',
rain_5 = '".$rain_5."',
rain_6 = '".$rain_6."',
mass_1_1 = '".$mass_1_1."',
mass_1_2 = '".$mass_1_2."',
mass_1_3 = '".$mass_1_3."',
mass_1_4 = '".$mass_1_4."',
mass_1_5 = '".$mass_1_5."',
mass_1_6 = '".$mass_1_6."',
divisions_1_1 = '".$divisions_1_1."',
divisions_1_2 = '".$divisions_1_2."',
divisions_1_3 = '".$divisions_1_3."',
divisions_1_4 = '".$divisions_1_4."',
divisions_1_5 = '".$divisions_1_5."',
divisions_1_6 = '".$divisions_1_6."',
kn_1_1 = '".$kn_1_1."',
kn_1_2 = '".$kn_1_2."',
kn_1_3 = '".$kn_1_3."',
kn_1_4 = '".$kn_1_4."',
kn_1_5 = '".$kn_1_5."',
kn_1_6 = '".$kn_1_6."',
thickness_1_1 = '".$thickness_1_1."',
thickness_1_2 = '".$thickness_1_2."',
thickness_1_3 = '".$thickness_1_3."',
thickness_1_4 = '".$thickness_1_4."',
thickness_1_5 = '".$thickness_1_5."',
thickness_1_6 = '".$thickness_1_6."',
mass_2_1 = '".$mass_2_1."',
mass_2_2 = '".$mass_2_2."',
mass_2_3 = '".$mass_2_3."',
mass_2_4 = '".$mass_2_4."',
mass_2_5 = '".$mass_2_5."',
mass_2_6 = '".$mass_2_6."',
divisions_2_1 = '".$divisions_2_1."',
divisions_2_2 = '".$divisions_2_2."',
divisions_2_3 = '".$divisions_2_3."',
divisions_2_4 = '".$divisions_2_4."',
divisions_2_5 = '".$divisions_2_5."',
divisions_2_6 = '".$divisions_2_6."',
kn_2_1 = '".$kn_2_1."',
kn_2_2 = '".$kn_2_2."',
kn_2_3 = '".$kn_2_3."',
kn_2_4 = '".$kn_2_4."',
kn_2_5 = '".$kn_2_5."',
kn_2_6 = '".$kn_2_6."',
thickness_2_1 = '".$thickness_2_1."',
thickness_2_2 = '".$thickness_2_2."',
thickness_2_3 = '".$thickness_2_3."',
thickness_2_4 = '".$thickness_2_4."',
thickness_2_5 = '".$thickness_2_5."',
thickness_2_6 = '".$thickness_2_6."',
mass_3_1 = '".$mass_3_1."',
mass_3_2 = '".$mass_3_2."',
mass_3_3 = '".$mass_3_3."',
mass_3_4 = '".$mass_3_4."',
mass_3_5 = '".$mass_3_5."',
mass_3_6 = '".$mass_3_6."',
divisions_3_1 = '".$divisions_3_1."',
divisions_3_2 = '".$divisions_3_2."',
divisions_3_3 = '".$divisions_3_3."',
divisions_3_4 = '".$divisions_3_4."',
divisions_3_5 = '".$divisions_3_5."',
divisions_3_6 = '".$divisions_3_6."',
kn_3_1 = '".$kn_3_1."',
kn_3_2 = '".$kn_3_2."',
kn_3_3 = '".$kn_3_3."',
kn_3_4 = '".$kn_3_4."',
kn_3_5 = '".$kn_3_5."',
kn_3_6 = '".$kn_3_6."',
thickness_3_1 = '".$thickness_3_1."',
thickness_3_2 = '".$thickness_3_2."',
thickness_3_3 = '".$thickness_3_3."',
thickness_3_4 = '".$thickness_3_4."',
thickness_3_5 = '".$thickness_3_5."',
thickness_3_6 = '".$thickness_3_6."',
release_1_date = '".$release_1_date."',
release_3_date = '".$release_3_date."',
release_7_date = '".$release_7_date."',
remarks = '".$remarks."'
WHERE dry_report_no = '".$report_no."' ";
execsql($update_query);

$table_name = $_SESSION['db_prefix']."_tracking_quality";
$trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entry_date."' ,'".$_SESSION['username']."', '91', '".$test_date."', '".$report_no."' ,'','' )";
$trackingResult = mySQL_query($trackingQuery);	

$alert=0;
$alert_line = '';

if ($type=='DR') {$l_min=396; $l_max=404; }
if ($type=='VE') {$l_min=396; $l_max=404; }
if ($type=='SL') {$l_min=396; $l_max=404; }
if ((($length_L2_1<$l_min)||($length_L2_1>$l_max))&&($length_L2_1!='')) {$alert=1; $alert_line = $alert_line.'<br>Length L2 1 is out of specification.';}
if ((($length_L2_2<$l_min)||($length_L2_2>$l_max))&&($length_L2_2!='')) {$alert=1; $alert_line = $alert_line.'<br>Length L2 2 is out of specification.';}
if ((($length_L2_3<$l_min)||($length_L2_3>$l_max))&&($length_L2_3!='')) {$alert=1; $alert_line = $alert_line.'<br>Length L2 3 is out of specification.';}
if ((($length_L2_4<$l_min)||($length_L2_4>$l_max))&&($length_L2_4!='')) {$alert=1; $alert_line = $alert_line.'<br>Length L2 4 is out of specification.';}
if ((($length_L2_5<$l_min)||($length_L2_5>$l_max))&&($length_L2_5!='')) {$alert=1; $alert_line = $alert_line.'<br>Length L2 5 is out of specification.';}
if ((($length_L2_6<$l_min)||($length_L2_6>$l_max))&&($length_L2_6!='')) {$alert=1; $alert_line = $alert_line.'<br>Length L2 6 is out of specification.';}

if ($type=='DR') {$l_min=396; $l_max=404; }
if ($type=='VE') {$l_min=396; $l_max=404; }
if ($type=='SL') {$l_min=396; $l_max=404; }
if ((($length_L3_1<$l_min)||($length_L3_1>$l_max))&&($length_L3_1!='')) {$alert=1; $alert_line = $alert_line.'<br>Length L3 1 is out of specification.';}
if ((($length_L3_2<$l_min)||($length_L3_2>$l_max))&&($length_L3_2!='')) {$alert=1; $alert_line = $alert_line.'<br>Length L3 2 is out of specification.';}
if ((($length_L3_3<$l_min)||($length_L3_3>$l_max))&&($length_L3_3!='')) {$alert=1; $alert_line = $alert_line.'<br>Length L3 3 is out of specification.';}
if ((($length_L3_4<$l_min)||($length_L3_4>$l_max))&&($length_L3_4!='')) {$alert=1; $alert_line = $alert_line.'<br>Length L3 4 is out of specification.';}
if ((($length_L3_5<$l_min)||($length_L3_5>$l_max))&&($length_L3_5!='')) {$alert=1; $alert_line = $alert_line.'<br>Length L3 5 is out of specification.';}
if ((($length_L3_6<$l_min)||($length_L3_6>$l_max))&&($length_L3_6!='')) {$alert=1; $alert_line = $alert_line.'<br>Length L3 6 is out of specification.';}

if ($type=='DR') {$l_min=396; $l_max=404; }
if ($type=='VE') {$l_min=396; $l_max=404; }
if ($type=='SL') {$l_min=396; $l_max=404; }
if ((($length_L1_1<$l_min)||($length_L1_1>$l_max))&&($length_L1_1!='')) {$alert=1; $alert_line = $alert_line.'<br>Length L1 1 is out of specification.';}
if ((($length_L1_2<$l_min)||($length_L1_2>$l_max))&&($length_L1_2!='')) {$alert=1; $alert_line = $alert_line.'<br>Length L1 2 is out of specification.';}
if ((($length_L1_3<$l_min)||($length_L1_3>$l_max))&&($length_L1_3!='')) {$alert=1; $alert_line = $alert_line.'<br>Length L1 3 is out of specification.';}
if ((($length_L1_4<$l_min)||($length_L1_4>$l_max))&&($length_L1_4!='')) {$alert=1; $alert_line = $alert_line.'<br>Length L1 4 is out of specification.';}
if ((($length_L1_5<$l_min)||($length_L1_5>$l_max))&&($length_L1_5!='')) {$alert=1; $alert_line = $alert_line.'<br>Length L1 5 is out of specification.';}
if ((($length_L1_6<$l_min)||($length_L1_6>$l_max))&&($length_L1_6!='')) {$alert=1; $alert_line = $alert_line.'<br>Length L1 6 is out of specification.';}

if ($type=='DR') {$w_min=330; $w_max=338; }
if ($type=='VE') {$w_min=330; $w_max=338; }
if ($type=='SL') {$w_min=329; $w_max=339; }
//if ((($width_1<$w_min)||($width_1>$w_max))&&($width_1!='')) {$alert=1; $alert_line = $alert_line.'<br>Width 1 is out of specification.';}
//if ((($width_2<$w_min)||($width_2>$w_max))&&($width_2!='')) {$alert=1; $alert_line = $alert_line.'<br>Width 2 is out of specification.';}
if ((($width_3<$w_min)||($width_3>$w_max))&&($width_3!='')) {$alert=1; $alert_line = $alert_line.'<br>Width 3 is out of specification.';}
//if ((($width_4<$w_min)||($width_4>$w_max))&&($width_4!='')) {$alert=1; $alert_line = $alert_line.'<br>Width 4 is out of specification.';}
//if ((($width_5<$w_min)||($width_5>$w_max))&&($width_5!='')) {$alert=1; $alert_line = $alert_line.'<br>Width 5 is out of specification.';}
if ((($width_6<$w_min)||($width_6>$w_max))&&($width_6!='')) {$alert=1; $alert_line = $alert_line.'<br>Width 6 is out of specification.';}

if ($type=='DR') {$n_min=14; $n_max=20; }
if ($type=='VE') {$n_min=14; $n_max=20; }
if ($type=='SL') {$n_min=14; $n_max=20; }
if ((($nail_1<$n_min)||($nail_1>$n_max))&&($nail_1!='')) {$alert=1; $alert_line = $alert_line.'<br>Nail hole 1 is out of specification.';}
if ((($nail_2<$n_min)||($nail_2>$n_max))&&($nail_2!='')) {$alert=1; $alert_line = $alert_line.'<br>Nail hole 2 is out of specification.';}
if ((($nail_3<$n_min)||($nail_3>$n_max))&&($nail_3!='')) {$alert=1; $alert_line = $alert_line.'<br>Nail hole 3 is out of specification.';}
if ((($nail_4<$n_min)||($nail_4>$n_max))&&($nail_4!='')) {$alert=1; $alert_line = $alert_line.'<br>Nail hole 4 is out of specification.';}
if ((($nail_5<$n_min)||($nail_5>$n_max))&&($nail_5!='')) {$alert=1; $alert_line = $alert_line.'<br>Nail hole 5 is out of specification.';}
if ((($nail_6<$n_min)||($nail_6>$n_max))&&($nail_6!='')) {$alert=1; $alert_line = $alert_line.'<br>Nail hole 6 is out of specification.';}

if ($alert==1) {
  include('../include/dry_tile_alert.php');
}




if (isset($_POST['save_close_button']) )
	   { ?>
       <script>
	 		 window.location='quality_main.php';
		</script>
        <?php		 
	   }
	   
	if (isset($_POST['save_button']) )
	   {  ?>
       <script>
	         window.location="dry_tile_inspection_sheet.php?report_no=<?php echo $report_no?>&approve=";
	   </script>
        <?php		 
	   }
	   ?>