<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/wizard.css" />
<link href="../css/wait.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="../window/dhtmlwindow.css" type="text/css" />
<link rel="stylesheet" href="../window/modal.css" type="text/css" />

<!--jscript-->
<script language="JavaScript" src="../jscript/confirm_exit.js"  type="text/javascript"></script>  
<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/show_hide_layers.js"  type="text/javascript"></script>  
<script type="text/javascript" src="../window/dhtmlwindow.js"></script>
<script type="text/javascript" src="../window/modal.js"></script>

<?php
include ("../navigation/header.php");
include ("../navigation/production_sidebar.php");
	
	$s = $_GET['s'];
	$p = $_GET['p'];
	$error = $_SESSION['error'];
	$_SESSION['p']=$p;
	$_SESSION['s']=$s;
	
	
	if (isset($_GET['prev_button']) )
	   {
		 $_SESSION['p']= $_SESSION['p']-1;
	   }
		 
	if (isset($_GET['next_button']) )
	  {
		$_SESSION['p']=$_SESSION['p']+1;
	  }
	
		
	
	if ($s==1) {
		
			
	}
		
	if($s==2) {
		if ($_SESSION['page_view']=='5') {
		$i=0;
		while ($i<$_SESSION['line_no_2']) {
			 
			$truss_id = $_POST['truss_id_'.$i];
			$truss_qty = $_POST['truss_qty_text_'.$i];
			$span = $_POST['span_text_'.$i];
			$press_points = $_POST['press_points_text_'.$i];
			if (isset($_POST['truss_checkbox_'.$i])) {
				   $select_it = 'yes';
			}
			else {
				 $select_it = 'no';
			}
			if ($select_it<>'add') {		
			$table_name = $_SESSION['db_prefix']."_trusses_temp";
			$check_query = "UPDATE $table_name SET select_it = '".$select_it."', qty = '".$truss_qty."', span = '".$span."', press_points = '".$press_points."' WHERE truss_id = '".$truss_id."' AND  user =  '".$_SESSION['username']."' ";
			execsql($check_query);
			}
		$i++;
		
		}
		
//==================Saving additional truss list
$table_name = $_SESSION['db_prefix']."_trusses_temp";
$delete_query = "DELETE FROM $table_name WHERE user =  '".$_SESSION['username']."' AND job_no = '".$_SESSION['job_no']."' AND select_it = 'add' "; 
execsql($delete_query);

$_SESSION['error2']= 2;
$_SESSION['alert_message']= '';
$line_num = $_POST['line_num'];
$j=0;

while ($j<$line_num) {
if(isset($_POST['line_checkbox'.$j]) ) {	
$type_1_add = $_POST['type_1_add_select'.$j];
$type_2_add = $_POST['type_2_add_select'.$j];
$type_3_add = $_POST['type_3_add_select'.$j];
$quantity_add = $_POST['quantity_add_text'.$j];
$span_add = $_POST['span_add_text'.$j];
$press_points_add = $_POST['press_points_add_text'.$j];
$truss_type_add=$type_1_add.$type_2_add.$type_3_add;


$table_name = $_SESSION['db_prefix']."_trusses_temp";
$check_query = "SELECT truss_type FROM $table_name WHERE truss_type = '".$truss_type_add."' AND user =  '".$_SESSION['username']."' ";
$check_result = mySQL_query($check_query);
$check_num = mysql_num_rows($check_result);
if ($check_num!='0') {
	 $_SESSION['error2']='1';
	 $_SESSION['alert_message']= $_SESSION['alert_message'].'<br>'.$truss_type_add;
}
else
{
$table_name = $_SESSION['db_prefix']."_trusses_temp";
$truss_query = "INSERT INTO $table_name (job_no, truss_type, type_1, type_2, type_3, qty, span, press_points, user, select_it ) VALUES ('".$_SESSION['job_no']."', '".$truss_type_add."', '".$type_1_add."', '".$type_2_add."', '".$type_3_add."', '".$quantity_add."', '".$span_add."', '".$press_points_add."', '".$_SESSION['username']."', 'add') ";
execsql($truss_query);
}

}
$j++;

}
//==================end saving additional truss list		
		}
		
		
if ($_SESSION['page_view']=='6') {
		
$table_name = $_SESSION['db_prefix']."_trusses_temp";
$delete_query = "DELETE FROM $table_name WHERE user =  '".$_SESSION['username']."' AND job_no = '".$_SESSION['job_no']."' "; 
execsql($delete_query);

$_SESSION['error2']= 2;
$_SESSION['alert_message']= '';
$line_num = $_POST['line_num'];
$j=0;

while ($j<$line_num) {
if(isset($_POST['line_checkbox'.$j]) ) {	
$type_1_add = $_POST['type_1_add_select'.$j];
$type_2_add = $_POST['type_2_add_select'.$j];
$type_3_add = $_POST['type_3_add_select'.$j];
$quantity_add = $_POST['quantity_add_text'.$j];
$span_add = $_POST['span_add_text'.$j];
$press_points_add = $_POST['press_points_add_text'.$j];
$truss_type_add=$type_1_add.$type_2_add.$type_3_add;


$table_name = $_SESSION['db_prefix']."_trusses_temp";
$check_query = "SELECT truss_type FROM $table_name WHERE truss_type = '".$truss_type_add."' AND user =  '".$_SESSION['username']."' ";
$check_result = mySQL_query($check_query);
$check_num = mysql_num_rows($check_result);
if ($check_num!='0') {
	 $_SESSION['error2']='1';
	 $_SESSION['alert_message']= $_SESSION['alert_message'].'<br>'.$truss_type_add;
}
else
{
$table_name = $_SESSION['db_prefix']."_trusses_temp";
$truss_query = "INSERT INTO $table_name (job_no, truss_type, type_1, type_2, type_3, qty, span, press_points, user) VALUES ('".$_SESSION['job_no']."', '".$truss_type_add."', '".$type_1_add."', '".$type_2_add."', '".$type_3_add."', '".$quantity_add."', '".$span_add."', '".$press_points_add."', '".$_SESSION['username']."') ";
execsql($truss_query);
}

}
$j++;

}
		
}		
		
		
		
	};
	
	if($s==3) {
			
		$i=1;
		$_SESSION['list_no_5']=$_SESSION['list_no_5']+1;
		//echo $_SESSION['list_no_2']."<br><br>";
		while ($i<$_SESSION['list_no_5']) {
		$store_item_id = $_POST['item_no'.$i];
		//echo "<br>number: ".$store_item_id;
		
		
		$table_name5 = $_SESSION['db_prefix']."_store_items";
		$item_query = "SELECT depth, width, length, class FROM $table_name5 WHERE store_item_id = '".$store_item_id."'  ";
		$item_result = mySQL_query($item_query);
		$depth = mysql_result($item_result, 0, "depth");
		$width = mysql_result($item_result, 0, "width");
		$length = mysql_result($item_result, 0, "length");
		$class = mysql_result($item_result, 0, "class");
		//echo $class;
		
		if(isset($_POST['check'.$i]) ) {
		$table_name2 = $_SESSION['db_prefix']."_cutting_temp";	
		$exist_query = "SELECT cutting_id FROM $table_name2 WHERE  store_item_id = '".$store_item_id."' AND job_id = '".$_SESSION['job_no']."' AND user =  '".$_SESSION['username']."'  ";
		//echo '<br>'.$exist_query;
		$exist_result = mySQL_query($exist_query);
		$exist_num = mysql_num_rows($exist_result);
				
        if ($exist_num==0) { 
		$table_name2 = $_SESSION['db_prefix']."_cutting_temp";		
		$check_query = "INSERT INTO $table_name2 (job_id, store_item_id, depth, width, length, class, user ) VALUES ('".$_SESSION['job_no']."', '".$store_item_id."', '".$depth."', '".$width."', '".$length."', '".$class."', '".$_SESSION['username']."') ";
		execsql($check_query);
		//echo "<br>(1)".$check_query;
		}
		}
		else {
			$table_name2 = $_SESSION['db_prefix']."_cutting_temp";	
			$delete_query = "DELETE FROM $table_name2 WHERE  store_item_id = '".$store_item_id."'  AND user =  '".$_SESSION['username']."' "; 
			execsql($delete_query);
		 }
		$i++;
		}
		
		
		$j=0;
	    $_SESSION['list_no_2']=$_SESSION['list_no_2']+1;
        //echo $_SESSION['list_no_2']."<br><br>";
        $j=1;
		while ($j<$_SESSION['list_no_2']) {
        //$store_item_id = $_GET['item_block'.$j];
		$store_item_id = $_POST['item_no2_'.$j];
		$table_name5 = $_SESSION['db_prefix']."_store_items";
		$item2_query = "SELECT depth, width, length, class FROM $table_name5 WHERE store_item_id = '".$store_item_id."'  ";
		$item2_result = mySQL_query($item2_query);
		
		$depth = mysql_result($item2_result, 0, "depth");
		$width = mysql_result($item2_result, 0, "width");
		$length = mysql_result($item2_result, 0, "length");
		$class = mysql_result($item2_result, 0, "class");
		
        if(isset($_POST['check2_'.$j]) ) {
			    $table_name = $_SESSION['db_prefix']."_cutting_temp";
				$exist_query = "SELECT cutting_id FROM $table_name WHERE  store_item_id = '".$store_item_id."' AND job_id = '".$_SESSION['job_no']."'  AND user =  '".$_SESSION['username']."'  ";
				$exist_result = mySQL_query($exist_query);
				$exist_num = mysql_num_rows($exist_result);
				
             	if ($exist_num==0) { 
				$table_name = $_SESSION['db_prefix']."_cutting_temp";
				$check_query = "INSERT INTO $table_name (job_id, store_item_id, depth, width, length, class, user  ) VALUES ('".$_SESSION['job_no']."', '".$store_item_id."', '".$depth."', '".$width."', '".$length."', '".$class."', '".$_SESSION['username']."' ) ";
				execsql($check_query);
				//echo "<br>(2)".$check_query;
				}
		  }
		  else {
			    $table_name = $_SESSION['db_prefix']."_cutting_temp";
				$delete_query = "DELETE FROM $table_name WHERE  store_item_id = '".$store_item_id."' AND user =  '".$_SESSION['username']."'  "; 
				execsql($delete_query);
				
		 }
		   
	 $j++;
		}
	//$_SESSION['S5_length']=$_GET['S5_length_text'];	
	//$_SESSION['S7_length']=$_GET['S7_length_text'];	
	 
	}
	
	if($s==4) {
			
		
		$i=0;
		while ($i<4) {
		$k=0;
		$list_4a=$_SESSION['list_no_4a'.$i];
		while ($k<$list_4a) {
			$store_item_id = $_POST['store_item_id'.$i.$k];
			$quantity = $_POST['qty_text'.$i.$k];
			//$price = $_POST['price_text'.$k];
			$table_name = $_SESSION['db_prefix']."_cutting_temp";
			$qty_query = "UPDATE $table_name SET quantity = '".$quantity."'  WHERE  job_id = '".$_SESSION['job_no']."' AND store_item_id = '".$store_item_id."'   ";
			execsql($qty_query);
			$k++;
		}
		$i++;
		}
		
		
		
		$j=0;
		while ($j<3) {
		$m=0;	
		$list_4b=$_SESSION['list_no_4b'.$j];
		while ($m<$list_4b) {
			
			$store_item_id = $_POST['store_item_id2_'.$j.$m]; 
			$quantity = $_POST['qty_text2_'.$j.$m];
			
			$table_name = $_SESSION['db_prefix']."_cutting_temp";
			$qty2_query = "UPDATE $table_name SET quantity = '".$quantity."'  WHERE  job_id = '".$_SESSION['job_no']."' AND store_item_id = '".$store_item_id."'   "; 
			execsql($qty2_query);
			$m++;
		}
		$j++;
		}
	
	if (isset($_POST['next_button']) ){
		      if ($_SESSION['S5_length']!=0) {
			  $issued_total1 = $_POST['issued_total1'];
			  
			  if ($_SESSION['S5_length']!=$issued_total1) { 
			        $_SESSION['error3']='yes';?>
				    <script language="javascript" type="text/javascript">
            			window.location="trussesJobWizbase.php?p=4&s=";
					</script>
         <?php }
			  }
			if ($_SESSION['S7_length']!=0) {  
		    $issued_total2 = $_POST['issued_total2'];
			
			  if ($_SESSION['S7_length']!=$issued_total2) { 
			        $_SESSION['error3']='yes';?>
				    <script language="javascript" type="text/javascript">
            			window.location="trussesJobWizbase.php?p=4&s=";
					</script>
         <?php } 
			}
		}
	
	};
	
	if($s==5) {
		
		$i=0;
		
		
		while ($i<$_SESSION['list_no_8']) {
				
	$store_item_id = $_GET['item_no'.$i];
		
		
		if(isset($_GET['check'.$i]) ) {
			
		$table_name2 = $_SESSION['db_prefix']."_plates_temp";	
		$exist_query = "SELECT plate_id FROM $table_name2 WHERE  store_item_id = '".$store_item_id."'  AND user =  '".$_SESSION['username']."' ";
		$exist_result = mySQL_query($exist_query);
		$exist_num = mysql_num_rows($exist_result);	
		
        if ($exist_num==0) { 
		$table_name2 = $_SESSION['db_prefix']."_plates_temp";		
		$check_query = "INSERT INTO $table_name2 (job_id, store_item_id, user ) VALUES ('".$_SESSION['job_no']."', '".$store_item_id."', '".$_SESSION['username']."' ) ";
		
		execsql($check_query);
		}
		}
		else {
			$table_name2 = $_SESSION['db_prefix']."_plates_temp";	
			$delete_query = "DELETE FROM $table_name2 WHERE  store_item_id = '".$store_item_id."'  AND user =  '".$_SESSION['username']."' "; 
			execsql($delete_query);
		 }
		
		$i++;
		}
		
	$_SESSION['plate_area'] = $_GET['plate_area_text'];    
		
	 
	}
	
	if($s==6) {
		
		$k=0;
		while ($k<$_SESSION['list_no_9']) {
			$store_item_id = $_GET['store_item_id'.$k]; 
			$quantity = $_GET['qty_text'.$k];
			
			//$price = $_GET['price_text'.$k];
			$table_name = $_SESSION['db_prefix']."_plates_temp";
			$qty_query = "UPDATE $table_name SET quantity = '".$quantity."'  WHERE   store_item_id = '".$store_item_id."'  AND  user =  '".$_SESSION['username']."' "; 
			execsql($qty_query);
			$k++;
		}
		
	if (isset($_GET['next_button']) ){
		   if($_SESSION['plate_area']!=0) {
			  $issued_total1 = $_GET['issued_total1'];
			  //echo number_format($issued_total1, 6, '.', ',').'<br>';
			  //echo number_format($_SESSION['plate_area'], 6, '.', ',');
			  if (number_format($_SESSION['plate_area'], 3, '.', ',')!=number_format($issued_total1, 3, '.', ',') ) { 
			        $_SESSION['error6']='yes';?>
				    <script language="javascript" type="text/javascript">
					    needToConfirm = false;
            			window.location="trussesJobWizbase.php?p=6&s=";
					</script>
         <?php } 
		   }
		}	
		 
	};
	
	if($s==10) {
		$type_1 = $_GET['type_1_text'];
		$type_2 = $_GET['type_2_text'];
		$type_3 = $_GET['type_3_text'];
		$qty = $_GET['qty_text'];
		$span = $_GET['span_text'];
		//$height = $_GET['height_text'];
		$press_points = $_GET['press_points_text'];
		
		$truss_type = $type_1.$type_2.$type_3;
		
		$table_name = $_SESSION['db_prefix']."_trusses_temp";
		$truss_query = "INSERT INTO $table_name (job_no, truss_type, type_1, type_2, type_3, qty, span, press_points, user ) VALUES ('".$_SESSION['job_no']."', '".$truss_type."', '".$type_1."', '".$type_2."', '".$type_3."', '".$qty."', '".$span."', '".$press_points."', '".$_SESSION['username']."' ) ";
		execsql($truss_query);
		if (isset($_GET['next_add_button']) )
	   { ?>
       <script>
		editwindow=dhtmlmodal.open('editBox', 'iframe', '../edit_windows/trusses_add.php', 'Add line trusses list', 'width=500px,height=200px,center=1,resize=0,scrolling=0')
needToConfirm = false;
		</script>
        <?php		 
	   }
		
	}
	
	if($s==11) {
		$truss_id = $_GET['truss_id'];
		$type_1 = $_GET['type_1_text'];
		$type_2 = $_GET['type_2_text'];
		$type_3 = $_GET['type_3_text'];
		$qty = $_GET['qty_text'];
		$span = $_GET['span_text'];
		$press_points = $_GET['press_points_text'];
		
		$truss_type = $type_1.$type_2.$type_3;
		
		$table_name = $_SESSION['db_prefix']."_trusses_temp";
		$truss_edit_query = "UPDATE $table_name SET truss_type='".$truss_type."', type_1='".$type_1."', type_2='".$type_2."', type_3='".$type_3."', qty='".$qty."', span='".$span."', press_points='".$press_points."' WHERE truss_id = '".$truss_id."' ";
		execsql($truss_edit_query);
	}
	
	if($s==12) {
		$truss_id = $_GET['truss_id'];
		
		$table_name = $_SESSION['db_prefix']."_trusses_temp";
		$delete_query = "DELETE FROM $table_name WHERE truss_id = '".$truss_id."'  AND user =  '".$_SESSION['username']."'  "; 
		execsql($delete_query);
	}
	
	?>
<script language="JavaScript" src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script>
<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script>
</head>

<body>
<div class="main_frame" style="min-height:550px;height:auto; " >
  <table width="595" align="left" id="tableMain">
  <!--begin of tableMain-->
  <tr>
    <td >
    <div class="page_head_frame">
      <table width="681" border="0">
        <tr>
          <td width="548"><label class="label_page_head">Cutting bill </label>
&nbsp;&nbsp;&nbsp;<label class="label_page_head_2"><?php echo $_SESSION['name'] ?></label>
          <td width="122"><label style="font-size:24px; color:#FB6808;"><?php echo "J".$_SESSION['job_no'] ?></label>
           </td>
        </tr>
    </table>
    </div>
      <br /><br /><br /><br /><br />


      <div class="wizard_paging_frame">
      <table align="left">
      <tr>
      <td width="56">
      <?php if ($_SESSION['p']==1) { ?>
      <div class="active_step_frame"><div class="active_step_head_label">&nbsp;1</div>
      <div class="active_step_label"><br /><br /><br />
      Job details</div></div>
      <?php } else { ?>
      <div class="de_active_step_frame"><div class="de_active_step_head_label">&nbsp;1</div>
      <div class="de_active_step_label"><br /><br /><br />
      Job details</div></div>
      <?php } ?>
      
      </td>
      <td width="72">
      <?php if ($_SESSION['p']==2) { ?>
      <div class="active_step_frame"><div class="active_step_head_label">&nbsp;2</div>
      <div class="active_step_label"><br /><br /><br />
      Trusses</div></div>
      <?php } else { ?>
      <div class="de_active_step_frame"><div class="de_active_step_head_label">&nbsp;2</div>
      <div class="de_active_step_label"><br /><br /><br />
      Trusses</div></div>
      <?php } ?>
     </td>
      <td width="68">
      <?php if ($_SESSION['p']==3) { ?>
      <div class="active_step_frame"><div class="active_step_head_label">&nbsp;3</div>
      <div class="active_step_label"><br /><br /><br />
      Select timber</div></div>
      <?php } else { ?>
      <div class="de_active_step_frame"><div class="de_active_step_head_label">&nbsp;3</div>
      <div class="de_active_step_label"><br /><br /><br />
      Select timber</div></div>
      <?php } ?>
      </td>
      <td width="68">
      <?php if ($_SESSION['p']==4) { ?>
      <div class="active_step_frame">
      <div class="active_step_head_label">&nbsp;4</div>
      <div class="active_step_label"><br /><br /><br />
      Qty timber</div></div>
      <?php } else { ?>
      <div class="de_active_step_frame"><div class="de_active_step_head_label">&nbsp;4</div>
      <div class="de_active_step_label"><br /><br /><br />
      Qty timber</div></div>
      <?php } ?>
      </td>
      <td width="68">
      <?php if ($_SESSION['p']==5) { ?>
      <div class="active_step_frame"><div class="active_step_head_label">&nbsp;5</div>
      <div class="active_step_label"><br /><br /><br />
      Select plates</div></div>
      <?php } else { ?>
      <div class="de_active_step_frame"><div class="de_active_step_head_label">&nbsp;5</div>
      <div class="de_active_step_label"><br /><br /><br />
      Select plates</div></div>
      <?php } ?>
      </td>
      <td width="68">
      <?php if ($_SESSION['p']==6) { ?>
      <div class="active_step_frame"><div class="active_step_head_label">&nbsp;6</div>
      <div class="active_step_label"><br /><br /><br />
      Qty plates</div></div>
      <?php } else { ?>
      <div class="de_active_step_frame"><div class="de_active_step_head_label">&nbsp;6</div>
      <div class="de_active_step_label"><br /><br /><br />
      Qty plates</div></div>
      <?php } ?>
      </td>
      <td width="68">
      <?php if ($_SESSION['p']==7) { ?>
      <div class="active_step_frame"><div class="active_step_head_label">&nbsp;7</div>
      <div class="active_step_label"><br /><br /><br />
      Finish</div></div>
      <?php } else { ?>
      <div class="de_active_step_frame"><div class="de_active_step_head_label">&nbsp;7</div>
      <div class="de_active_step_label"><br /><br /><br />
      Finish</div></div>
      <?php } ?>
      </td>
      </tr>
      </table>
      </div>
      </td>
          </tr>
          <tr>
            <td><?php 
	if ($_SESSION['p']==1) { include("trussesJobWiz1.php"); }
	if ($_SESSION['p']==2) { include("trussesJobWiz2.php"); }
	if ($_SESSION['p']==3) { include("trussesJobWiz3.php"); }
	if ($_SESSION['p']==4) { include("trussesJobWiz4.php"); }
	if ($_SESSION['p']==5) { include("trussesJobWiz5.php"); }
	if ($_SESSION['p']==6) { include("trussesJobWiz6.php"); }
	if ($_SESSION['p']==7) { include("trussesJobWiz7.php"); }
		
    ?></td>
          </tr>
    </table>
    </div>
    </td>
  </tr>
</table>

</td>
</tr>
</table>  <!--end of tableMain-->


</body>
<?php include ('../navigation/side_bar.php'); ?>  