<!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) {
	  $i=0;
	  while ($i<$_SESSION['list_3']) {
		$_SESSION['mitek_line_'.$i] = $_GET['mitek_line_'.$i];
		$_SESSION['quantity_'.$i] = $_GET['quantity_text_'.$i];
		$i++;
	}
	 
	};
	
	if($s==3) {
		if ($_SESSION['set']=="no") {
		$table_name = $_SESSION['db_prefix']."_authorised_timber_temp";
		$n=0;	
		 while ($n<$_SESSION['list2n_bracing']) {
			 $timber_query = "INSERT INTO $table_name (auth_timber_group, auth_timber_name, store_item_id, reserved, delivered, job_no, user) VALUES ('bracing','".$_SESSION['bracing_name_'.$n]."','0', '0', '0', '".$_SESSION['job_no']."', '".$_SESSION['username']."' )";
					//echo '<br>'.$timber_query;
					execsql($timber_query);
		$n++;
	}
		$table_name = $_SESSION['db_prefix']."_authorised_timber_temp";
		$m=0;
		while ($m<$_SESSION['list2n_sundries']) {
			$timber_query = "INSERT INTO $table_name (auth_timber_group, auth_timber_name, store_item_id, reserved, delivered, job_no, user) VALUES ('sundries','".$_SESSION['sundries_name_'.$m]."','0', '0', '0', '".$_SESSION['job_no']."', '".$_SESSION['username']."' )";
					//echo '<br>'.$timber_query;
					execsql($timber_query);
		$m++;
	}
	$_SESSION['set']='yes';
		}
	
		
	}
	
	if($s==4) {
	$n=0;	
		 while ($n<$_SESSION['list2n_bracing']) {
			 
			 $m=0;
			 while ($m<20) {
				 if ($_SESSION['check'.($n+10).($m+10)]== 'yes') {
					
				 $_SESSION['bracing_qty'.($n+10).($m+10)]= $_GET['bracing_qty'.($n+10).($m+10)];
				 	$table_name = $_SESSION['db_prefix']."_authorised_timber_temp";
					
					$check_query = "SELECT auth_id FROM $table_name WHERE auth_timber_group='bracing' AND auth_timber_name= '".$_SESSION['bracing_name_'.$n]."' AND store_item_id = '".$_SESSION['item_id'.($n+10).($m+10)]."' AND job_no = '".$_SESSION['job_no']."' AND user =  '".$_SESSION['username']."' ";
					$check_result = mySQL_query($check_query);
					$check_num = mysql_num_rows($check_result);
					
					if ($check_num==0) {
						$timber_query = "INSERT INTO $table_name (auth_timber_group, auth_timber_name, store_item_id, reserved, delivered, job_no, user) VALUES ('bracing','".$_SESSION['bracing_name_'.$n]."','".$_SESSION['item_id'.($n+10).($m+10)]."', '".$_SESSION['bracing_qty'.($n+10).($m+10)]."', '0', '".$_SESSION['job_no']."', '".$_SESSION['username']."' )";
					//echo '<br>'.$timber_query;
					execsql($timber_query);
					}
					else {
						$update_query = "UPDATE $table_name SET reserved = '".$_SESSION['bracing_qty'.($n+10).($m+10)]."' WHERE auth_timber_group='bracing' AND auth_timber_name= '".$_SESSION['bracing_name_'.$n]."' AND store_item_id = '".$_SESSION['item_id'.($n+10).($m+10)]."' AND job_no = '".$_SESSION['job_no']."' AND user =  '".$_SESSION['username']."' ";
						execsql($update_query);
					}
				 }
				 else {
					 $update_query = "UPDATE $table_name SET reserved = '0' WHERE auth_timber_group='bracing' AND auth_timber_name= '".$_SESSION['bracing_name_'.$n]."' AND store_item_id = '".$_SESSION['item_id'.($n+10).($m+10)]."' AND job_no = '".$_SESSION['job_no']."' AND user =  '".$_SESSION['username']."' ";
						execsql($update_query);
					 $table_name = $_SESSION['db_prefix']."_authorised_timber_temp";
					 //$delete_query = "DELETE FROM $table_name WHERE auth_timber_group='bracing' AND auth_timber_name= '".$_SESSION['bracing_name_'.$n]."'  AND store_item_id = '".$_SESSION['item_id'.($n+10).($m+10)]."' AND job_no = '".$_SESSION['job_no']."' AND user =  '".$_SESSION['username']."' "; 
//					execsql($delete_query);
				 }
				 $m++;
			 }
			 $n++;
		 }
    
	$n=0;
		//echo 'listno:'.$_SESSION['list2n'];
		 while ($n<$_SESSION['list2n_sundries']) {
			 
			 $m=0;
			 while ($m<20) {
				
		if ($_SESSION['check2_'.($n+10).($m+10)]== 'yes') {
				
				    $_SESSION['sundries_qty'.($n+10).($m+10)]= $_GET['sundries_qty'.($n+10).($m+10)];
				 	$table_name = $_SESSION['db_prefix']."_authorised_timber_temp";
					
					$check_query = "SELECT auth_id FROM $table_name WHERE auth_timber_group='sundries' AND auth_timber_name= '".$_SESSION['sundries_name_'.$n]."' AND store_item_id = '".$_SESSION['item2_id'.($n+10).($m+10)]."' AND job_no = '".$_SESSION['job_no']."' AND user =  '".$_SESSION['username']."' ";
					//echo '<br>'.$check_query;
					$check_result = mySQL_query($check_query);
					$check_num = mysql_num_rows($check_result);
										
					if ($check_num==0) {
						//echo '<br>enter'.$n.($m+10);
						$timber_query = "INSERT INTO $table_name (auth_timber_group, auth_timber_name, store_item_id, reserved, delivered, job_no, user) VALUES ('sundries','".$_SESSION['sundries_name_'.$n]."','".$_SESSION['item2_id'.($n+10).($m+10)]."', '".$_SESSION['sundries_qty'.($n+10).($m+10)]."', '0', '".$_SESSION['job_no']."', '".$_SESSION['username']."' )";
						//echo '<br>'.$timber_query;
					execsql($timber_query);
					}
					else {
						//echo '<br>update'.$n.($m+10);
						$update_query = "UPDATE $table_name SET reserved = '".$_SESSION['sundries_qty'.($n+10).($m+10)]."' WHERE auth_timber_group='sundries' AND auth_timber_name= '".$_SESSION['sundries_name_'.$n]."' AND store_item_id = '".$_SESSION['item2_id'.($n+10).($m+10)]."' AND job_no = '".$_SESSION['job_no']."' AND user =  '".$_SESSION['username']."' ";
						execsql($update_query);
						//echo '<br>'.$update_query;
					}
			}
				else {
					 
				//echo '<br>delete'.$n.($m+10);
				$update_query = "UPDATE $table_name SET reserved = '0' WHERE auth_timber_group='sundries' AND auth_timber_name= '".$_SESSION['sundries_name_'.$n]."' AND store_item_id = '".$_SESSION['item2_id'.($n+10).($m+10)]."' AND job_no = '".$_SESSION['job_no']."' AND user =  '".$_SESSION['username']."' ";
						execsql($update_query);
				$table_name = $_SESSION['db_prefix']."_authorised_timber_temp";
					 //$delete_query = "DELETE FROM $table_name WHERE auth_timber_group='sundries' AND auth_timber_name= '".$_SESSION['sundries_name_'.$n]."'  AND store_item_id = '".$_SESSION['item2_id'.($n+10).($m+10)]."' AND job_no = '".$_SESSION['job_no']."' AND user =  '".$_SESSION['username']."' "; 
//					execsql($delete_query);
					//echo '<br>'.$delete_query;
					 }
			
				 $m++;
			 }
			 
			 $n++;
		 }
		
	
	
	}
	
	if($s==5) {
	   $i=0;
	   while ($i<$_SESSION['list_6']) {
		$_SESSION['additional_line_'.$i] = $_GET['additional_line_'.$i];
		$_SESSION['additional_quantity_'.$i] = $_GET['additional_quantity_'.$i];
		$i++;
	   }
	}
	
	if($s==6) {
	
	}
	
	if($s==10) {
		$cap_item_id = $_GET['store_item_select'];
		$auth_quantity = $_GET['quantity_text'];	
		$table_name = $_SESSION['db_prefix']."_captured_mitek";
		$table_name2 = $_SESSION['db_prefix']."_captured_mitek_temp";
		
		$check_query = "SELECT cap_item_id FROM $table_name  WHERE cap_item_id = '".$cap_item_id."' AND cap_job = '".$_SESSION['job_no']."' UNION ALL  SELECT cap_item_id FROM $table_name2  WHERE cap_item_id = '".$cap_item_id."' AND cap_job = '".$_SESSION['job_no']."' ";
		//echo '<br>'.$check_query;
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		
		if ($check_num==0) {	
		$mitek_new_query = "INSERT INTO $table_name2 (cap_mitek_id, cap_job, cap_item_id, cap_quantity, auth_quantity, user ) VALUES ('0', '".$_SESSION['job_no']."', '".$cap_item_id."', '0', '".$auth_quantity."',  '".$_SESSION['username']."'  ) ";
		execsql($mitek_new_query);
		
	   }	
		else {
			$_SESSION['error_2']=1;
		
		} 
		
		if (isset($_GET['next_add_button']) )
	   { ?>
		<script>
	   editwindow=dhtmlmodal.open('editBox', 'iframe', '../edit_windows/authorisation_add.php?category=Direct materials&sub_category=Mitek', 'Add item', 'width=500px,height=220px,center=1,resize=0,scrolling=0')
needToConfirm = false;
		</script>
		<?php		 
	   }
	
	}
	
	if($s==11) {
							
			
		$item_id = $_GET['store_item_select'];
		$auth_quantity = $_GET['quantity_text'];
				
		$table_name = $_SESSION['db_prefix']."_list_bracing";
		$name_query = "SELECT item_name FROM $table_name WHERE item_id = '".$item_id."' ";
		$name_result = mySQL_query($name_query);
		$cap_timber_name = mysql_result($name_result, 0, "item_name");
		
		$table_name2 = $_SESSION['db_prefix']."_captured_timber";
		$check_query = "SELECT cap_timber_name FROM $table_name2 WHERE cap_timber_name = '".$cap_timber_name."' AND cap_job = '".$_SESSION['job_no']."'  ";
		
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		
		if ($check_num==0) {
		$listQuery = "SELECT item_name, width, depth, class FROM $table_name WHERE item_id = '".$item_id."' ";
		$listResult = execsql($listQuery);
		$item_name = mysql_result($listResult, 0, "item_name");
		$width = mysql_result($listResult, 0, "width");
		$depth = mysql_result($listResult, 0, "depth");
		$class = mysql_result($listResult, 0, "class");
		$timber = $depth.'x'.$width.' ('.$class.')';
			
		$table_name = $_SESSION['db_prefix']."_captured_timber";
		$bracing_query = "INSERT INTO $table_name (cap_job, cap_timber_group, cap_timber_name, cap_timber, cap_timber_length, auth_timber_length, cap_depth, cap_width, cap_class ) VALUES ('".$_SESSION['job_no']."', 'Bracing', '".$item_name."', '".$timber."', '0', '".$auth_quantity."', '".$depth."', '".$width."', '".$class."'  ) ";
		execsql($bracing_query);
		
			
	   }	
		else {
			$_SESSION['error_3']=1;
		} 
				
		if (isset($_GET['next_add_bracing']) )
	   { ?>
		<script>
		editwindow=dhtmlmodal.open('editBox', 'iframe', '../edit_windows/authorisation_add_bracing.php?cat=Bracing', 'Add item', 'width=500px,height=220px,center=1,resize=0,scrolling=0')
needToConfirm = false;
		</script>
		<?php
	   }
		
	}
	
	if($s==12) {
		$item_id = $_GET['store_item_select'];
		$auth_quantity = $_GET['quantity_text'];
		
				
		$table_name = $_SESSION['db_prefix']."_list_sundries";
		$name_query = "SELECT item_name FROM $table_name WHERE item_id = '".$item_id."' ";
		$name_result = mySQL_query($name_query);
		$cap_timber_name = mysql_result($name_result, 0, "item_name");
		
		$table_name2 = $_SESSION['db_prefix']."_captured_timber";
		$check_query = "SELECT cap_timber_name FROM $table_name2 WHERE cap_timber_name = '".$cap_timber_name."' AND cap_job = '".$_SESSION['job_no']."'  ";
		
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		
		if ($check_num==0) {
		
		$listQuery = "SELECT item_name, width, depth, class FROM $table_name WHERE item_id = '".$item_id."' ";
		$listResult = execsql($listQuery);
		$item_name = mysql_result($listResult, 0, "item_name");
		$width = mysql_result($listResult, 0, "width");
		$depth = mysql_result($listResult, 0, "depth");
		$class = mysql_result($listResult, 0, "class");
		$timber = $depth.'x'.$width.' ('.$class.')';
			
		$table_name = $_SESSION['db_prefix']."_captured_timber";
		$bracing_query = "INSERT INTO $table_name (cap_job, cap_timber_group, cap_timber_name, cap_timber, cap_timber_length, auth_timber_length, cap_depth, cap_width, cap_class ) VALUES ('".$_SESSION['job_no']."', 'Sundries', '".$item_name."', '".$timber."', '0', '".$auth_quantity."', '".$depth."', '".$width."', '".$class."'  ) ";
		execsql($bracing_query);
		
		}	
		else {
			$_SESSION['error_3']=1;
		} 
		
		if (isset($_GET['next_add_bracing']) )
	   { ?>
		<script>
		editwindow=dhtmlmodal.open('editBox', 'iframe', '../edit_windows/authorisation_add_bracing.php?cat=Sundries', 'Add item', 'width=500px,height=220px,center=1,resize=0,scrolling=0')
needToConfirm = false;
		</script>
		<?php
	   }	
	}
	
	if($s==13) {
		$cap_item_id = $_GET['store_item_select'];
		$auth_quantity = $_GET['quantity_text'];	
		$table_name = $_SESSION['db_prefix']."_captured_sundries";
		$table_name2 = $_SESSION['db_prefix']."_captured_sundries_temp";
		
		$check_query = "SELECT cap_item_id FROM $table_name  WHERE cap_item_id = '".$cap_item_id."' AND cap_job = '".$_SESSION['job_no']."' UNION ALL  SELECT cap_item_id FROM $table_name2  WHERE cap_item_id = '".$cap_item_id."' AND cap_job = '".$_SESSION['job_no']."'  AND user =  '".$_SESSION['username']."'  ";
		//echo '<br>'.$check_query;
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		
		if ($check_num==0) {	
		$sundries_new_query = "INSERT INTO $table_name2 (cap_sundries_id, cap_job, cap_item_id, cap_quantity, auth_quantity, user ) VALUES ('0', '".$_SESSION['job_no']."', '".$cap_item_id."', '0', '".$auth_quantity."' , '".$_SESSION['username']."' ) ";
		execsql($sundries_new_query);
		
	   }	
		else {
			
		$_SESSION['error_5']=1;
		 
		} 
		
		if (isset($_GET['next_add_button']) )
	   { ?>
		<script>
	   editwindow=dhtmlmodal.open('editBox', 'iframe', '../edit_windows/authorisation_add.php?category=Direct materials&sub_category=Sundries', 'Add item', 'width=500px,height=220px,center=1,resize=0,scrolling=0')
needToConfirm = false;

		</script>
		<?php		 
	   }
		
	}

	?>
		
        
        
		</head>

		<body>
<div class="main_frame"  style="height:auto; min-height:550px;"  >
          <table width="595" align="left" id="tableMain">
    <!--begin of tableMain-->
    <tr>
              <td ><div class="page_head_frame">
                  <table width="671" border="0">
                  <tr>
                      <td width="548"><label class="label_page_head">Authorise job </label>
                      &nbsp;&nbsp;&nbsp;
                      <label class="label_page_head_2"><?php echo $_SESSION['name']?></label></td>
                      <td width="113"><label style="font-size:24px; color:#FB6808;"><?php echo "J".$_SESSION['job_no']; ?></label></td>
                    </tr>
                </table>
                  &nbsp;</div>
        <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 />
                          eCo Products Select</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 />
                          eCo Products Select</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 />
                          Bracing / Sundries Select</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 />
                          Bracing / Sundries Select</div>
              </div>
                      <?php } ?></td>
            <td width="59"><?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 />
                          Bracing / Sundries Quantities</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 />
                          Bracing / Sundries Quantities</div>
              </div>
                      <?php } ?></td>
            <td width="30"><?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 />
                          Additional Sundries Select</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 />
                          Additional Sundries Select</div>
              </div>
                      <?php } ?></td>
            <td width="30"><?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 />
                          Finish</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 />
                          Finish</div>
              </div>
                      <?php } ?></td>
          </tr>
                </table>
                </div>
                </td>
            </tr>
    <tr>
              <td><?php 
	if ($_SESSION['p']==1) { include("authorisationWiz1.php"); }
	if ($_SESSION['p']==2) { include("authorisationWiz2.php"); }
	if ($_SESSION['p']==3) { include("authorisationWiz3.php"); }
	if ($_SESSION['p']==4) { include("authorisationWiz4.php"); }
	if ($_SESSION['p']==5) { include("authorisationWiz5.php"); }
	if ($_SESSION['p']==6) { include("authorisationWiz6.php"); }
	
	
    ?></td>
            </tr>
  </table>
        </div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!--end of tableMain-->

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