<!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" />


<?php
include ("../navigation/header.php");
include ("../navigation/store_sidebar.php");

	$s = $_GET['s'];
	$p = $_GET['p'];
	$_SESSION['p']=$p;
	$_SESSION['s']=$s;
	
	
	if (isset($_POST['prev_button']) )
	   {
		 $_SESSION['p']= $_SESSION['p']-1;
	   }
		 
	if (isset($_POST['next_button']) )
	  {
		$_SESSION['p']=$_SESSION['p']+1;
	  }
	
	
	if ($s==1) {
	  	$_SESSION['supplier_id'] = $_POST['supplier_id_select'];	
	   	$_SESSION['del_note'] = $_POST['del_note_text'];
		$_SESSION['value'] = $_POST['value_text'];	
		$_SESSION['transport'] = $_POST['transport_text'];	
		$_SESSION['receive_date'] = $_POST['receive_date'];	
		
	   			
		$table_name = $_SESSION['db_prefix']."_suppliers";
		$name_query = "SELECT account_name FROM $table_name WHERE supplier_id = '".$_SESSION['supplier_id']."' ";
		$name_result = mySQL_query($name_query);
		$_SESSION['sup_name'] = mysql_result($name_result, 0, "account_name");
		
			     
	};
	
	if($s==2) {
		$i=1;
		//$_SESSION['list_no_2']=$_SESSION['list_no_2']+1;
		
		while ($i<$_SESSION['list_no_2']) {
		$store_item_id = $_POST['item_no'.$i];
		//echo "<br>number: ".$store_item_id;
		//echo $store_item_id."<br>";
		
		$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']."_receive_store_lines_temp";	
		$exist_query = "SELECT receive_line_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']."_receive_store_lines_temp";		
		$check_query = "INSERT INTO $table_name2 (category, sub_category, store_item_id, depth, width, length, class, user ) VALUES ('Direct materials', 'Timber', '".$store_item_id."', '".$depth."', '".$width."', '".$length."', '".$class."', '".$_SESSION['username']."') ";
		execsql($check_query);
		//echo "<br>(1)".$check_query;
		}
		}
		else {
			$table_name2 = $_SESSION['db_prefix']."_receive_store_lines_temp";	
			$delete_query = "DELETE FROM $table_name2 WHERE  store_item_id = '".$store_item_id."'  AND user =  '".$_SESSION['username']."' "; 
			execsql($delete_query);
		 }
		$i++;
		}
		
	    $_SESSION['list_no_5']=$_SESSION['list_no_5'];
        //echo $_SESSION['list_no_5']."<br><br>";
        $j=1;
		while ($j<$_SESSION['list_no_5']) {
        $store_item_id = $_POST['item_block_s7'.$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['block_s7'.$j]) ) {
			    $table_name = $_SESSION['db_prefix']."_receive_store_lines_temp";
				$exist_query = "SELECT receive_line_id FROM $table_name 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']."_receive_store_lines_temp";
				$check_query = "INSERT INTO $table_name2 (category, sub_category, store_item_id, depth, width, length, class, user ) VALUES ('Direct materials', 'Timber', '".$store_item_id."', '".$depth."', '".$width."', '".$length."', '".$class."', '".$_SESSION['username']."') ";
				
				execsql($check_query);
				//echo "<br>(2)".$check_query;
				}
		  }
		  else {
			    $table_name = $_SESSION['db_prefix']."_receive_store_lines_temp";
				$delete_query = "DELETE FROM $table_name WHERE  store_item_id = '".$store_item_id."' AND user =  '".$_SESSION['username']."'  "; 
				execsql($delete_query);
				
		 }
		   
	 $j++;
		}
		
	$_SESSION['list_no_6']=$_SESSION['list_no_6'];
        //echo '<br>*****6 '.$_SESSION['list_no_6'];
        $j=1;
		while ($j<$_SESSION['list_no_6']) {
        $store_item_id = $_POST['item_block_bg'.$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['block_bg'.$j]) ) {
			    $table_name = $_SESSION['db_prefix']."_receive_store_lines_temp";
				$exist_query = "SELECT receive_line_id FROM $table_name 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']."_receive_store_lines_temp";
				$check_query = "INSERT INTO $table_name2 (category, sub_category, store_item_id, depth, width, length, class, user ) VALUES ('Direct materials', 'Timber', '".$store_item_id."', '".$depth."', '".$width."', '".$length."', '".$class."', '".$_SESSION['username']."') ";
				//echo '<br>*****'.$check_query;
				execsql($check_query);
				//echo "<br>(2)".$check_query;
				}
		  }
		  else {
			    $table_name = $_SESSION['db_prefix']."_receive_store_lines_temp";
				$delete_query = "DELETE FROM $table_name WHERE  store_item_id = '".$store_item_id."' AND user =  '".$_SESSION['username']."'  "; 
				execsql($delete_query);
				
		 }
		   
	 $j++;
		}
		
	$_SESSION['list_no_7']=$_SESSION['list_no_7'];
	//echo '<br>*****7 '.$_SESSION['list_no_7'];
        $j=1;
		while ($j<$_SESSION['list_no_7']) {
        $store_item_id = $_POST['item_block_la'.$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['block_la'.$j]) ) {
			    $table_name = $_SESSION['db_prefix']."_receive_store_lines_temp";
				$exist_query = "SELECT receive_line_id FROM $table_name 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']."_receive_store_lines_temp";
				$check_query = "INSERT INTO $table_name2 (category, sub_category, store_item_id, depth, width, length, class, user ) VALUES ('Direct materials', 'Timber', '".$store_item_id."', '".$depth."', '".$width."', '".$length."', '".$class."', '".$_SESSION['username']."') ";
				//echo '<br>*****'.$check_query;
				execsql($check_query);
				//echo "<br>(2)".$check_query;
				}
		  }
		  else {
			    $table_name = $_SESSION['db_prefix']."_receive_store_lines_temp";
				$delete_query = "DELETE FROM $table_name WHERE  store_item_id = '".$store_item_id."' AND user =  '".$_SESSION['username']."'  "; 
				execsql($delete_query);
				
		 }
		   
	 $j++;
		}
		
	 
	}
	
	if($s==3) {
		$k=0;
		while ($k<$_SESSION['list_no_3']) {
			$store_item_id = $_POST['store_item_id'.$k]; 
			$class = $_POST['class_text'.$k];
			$quantity = $_POST['qty_text'.$k];
			if ($class=='La') { 
			$job_no = $_POST['jobno_select'.$k];
			}
			else {
			$job_no = '';
			}
						
			$table_name = $_SESSION['db_prefix']."_receive_store_lines_temp";
			$qty_query = "UPDATE $table_name SET quantity = '".$quantity."', job_no = '".$job_no."' WHERE  user =  '".$_SESSION['username']."' AND store_item_id = '".$store_item_id."'   ";
			execsql($qty_query);
			$k++;
		}
		
	//$m=0;
//		while ($m<$_SESSION['list_no_6']) {
//			$store_item_id = $_POST['store_item_id'.$m]; 
//			$quantity = $_POST['qty_text'.$m];
//			
//			$table_name = $_SESSION['db_prefix']."_receive_store_lines_temp";
//			$qty_query = "UPDATE $table_name SET quantity = '".$quantity."' WHERE  user =  '".$_SESSION['username']."' AND store_item_id = '".$store_item_id."'   "; 
//			execsql($qty_query);
//			$m++;
//		} 
	 
	};
	

	
	
	?>
 <!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/wizard.css" />
<!--reference to main.css removed--> 
<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 type="text/javascript" src="../window/dhtmlwindow.js"></script>
<script type="text/javascript" src="../window/modal.js"></script>
<script type="text/javascript" src="../jscript/jquery.1.4.2.js"></script>
<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 language="JavaScript" src="../jscript/numbers_only_decimal.js"  type="text/javascript"></script>  



<body>
<div class="main_frame">
<table id="tableMain" width="595">
  <!--begin of tableMain-->
  <tr>
    <td ><div class="page_head_frame">
      <label class="label_page_head">Receiving timber </label>&nbsp;&nbsp;<label class="label_page_head_2"><?php echo $_SESSION['sup_name'] ?></label></div>
      <br /><br />
<br /><br />
<div class="wizard_paging_frame">
<table align="left">
      <tr>
      <td>
      <?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 />
        Supplier</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 />
        Supplier</div></div>
      <?php } ?>
      
      </td>
      <td>
      <?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 />
      Timber items</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 />
        Timber items</div></div>
      <?php } ?>
     </td>
      <td>
      <?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 />
      Quantity</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 />Quantity</div></div>
      <?php } ?>
      </td>
      <td>
      <?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 />Finish</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 />Finish</div></div>
      <?php } ?>
       </td>
      
      </tr>
      </table>
      </div>
        </td>
    <!--center of tableMain-->
  </tr>
  <tr>
    <td><!--center of tableMain-->
      <?php 
	if ($_SESSION['p']==1) { include("receivingTimberWiz1.php"); }
	if ($_SESSION['p']==2) { include("receivingTimberWiz2.php"); }
	if ($_SESSION['p']==3) { include("receivingTimberWiz3.php"); }
	if ($_SESSION['p']==4) { include("receivingTimberWiz6.php"); }
	//if ($_SESSION['p']==5) { include("receivingTimberWiz5.php"); }
//	if ($_SESSION['p']==6) { include("receivingTimberWiz6.php"); }
    ?></td>
  </tr>
</table>
</div>
<?php include ('../navigation/side_bar.php'); ?>

</body>
