<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

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

$edit_date = date("Y-m-d");
$edit_date = strtotime($edit_date);
$d = date("d", $edit_date ) ;
$m = date("m", $edit_date ) ;
$y = date("Y", $edit_date ) ;

$page = $_GET['page'];
	
if ($page=='job_card') {
$reference='m_edit_job_card.php?edit=0&job_card_no=';	
$page_name_this='Edit job card';
$table_name = $_SESSION['db_prefix']."_compiled_jobs";
$table_name2 = $_SESSION['db_prefix']."_mworks_jobs";
$jobQuery = "SELECT $table_name.job_card_no, $table_name.project, $table_name.cust_id  FROM $table_name, $table_name2 WHERE $table_name2.compiled='yes' AND $table_name2.supplied IS NULL  AND ($table_name.mworks='yes' OR $table_name.mworks='only') AND $table_name.job_card_no = $table_name2.job_card_no ORDER BY job_card_no DESC";
$jobResult = execsql($jobQuery);
$jobNum = mysql_num_rows($jobResult);
	$w = 0;
	$arrId4 = array ();
	$arrName4 = array ();
	while ($w < $jobNum) {
		$cust_id = mysql_result($jobResult, $w, "cust_id"); 
		$table_name2 = $_SESSION['db_prefix']."_customer";
		$customer_query = "SELECT * FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
		$customer_result = mySQL_query($customer_query);
		$customer_num = mysql_num_rows($customer_result);	
		$a1 = mysql_result($customer_result, 0, "account_type");
			if ($a1=="corporate") { 
				$cust_name = mysql_result($customer_result, 0, "comp_name"); 
			} 
			else {
				$cust_name = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 			}
		
		
		
		$arrId4[$w] = mysql_result($jobResult, $w, 'job_card_no');
		$arrName4[$w] = mysql_result($jobResult, $w, 'job_card_no').' '.$cust_name;
		$w++;
	}
}

if ($page=='fuel') {
$reference='edit_fuel_rec.php?fuel_id=';
$page_name_this='Edit fuel receipt';
$table_name = $_SESSION['db_prefix']."_fuel_supply";
$receipt_query = "SELECT fuel_id, vehicle_id, reference FROM $table_name ORDER BY fuel_id DESC";
$receipt_result = mySQL_query($receipt_query);
$receipt_num = mysql_num_rows($receipt_result);

	$w = 0;
	$arrId2 = array ();
	$arrName2 = array ();
	while ($w < $receipt_num) {
		$arrId2[$w] = mysql_result($receipt_result, $w, 'fuel_id');
				$fuel_id = mysql_result($receipt_result, $w, "fuel_id");
				$vehicle_id = mysql_result($receipt_result, $w, "vehicle_id");
				$fuel_reference = mysql_result($receipt_result, $w, "reference");
				$table_name = $_SESSION['db_prefix']."_vehicle";
				$name_query = "SELECT registration_no, make, model FROM $table_name WHERE vehicle_id = '".$vehicle_id."'  ";
				$name_result = mySQL_query($name_query);
				$reg_no = mysql_result($name_result, 0, "registration_no");
				$make = mysql_result($name_result, 0, "make");
				$model = mysql_result($name_result, 0, "model");
		$arrName2[$w] = $fuel_id.' -  '.$fuel_reference.'&nbsp;&nbsp;&nbsp;'.$reg_no.' '.$make.' '.$model;
		$w++;
	}
}

?>
</head>

<body>
<?php
include ("../navigation/header.php");
$page_name = "Production-edit job card";
include ("../navigation/access.php");
if ($permission_num==1) {
	include ("../navigation/production_sidebar.php");
?>
<div class="main_frame">
<div class="page_head_frame">
        <table width="630" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="385"><label class="label_page_head">Select to edit</label></td>
            <td align="right">&nbsp;</td>
          </tr>
        </table>
      </div>

<div class="page_middle_frame"><br />

<?php 
if ($page=='job_card') { ?>
<div class="page_inside_frame">
  <label class="label_std" style="font-size:16px;"><?php echo $page_name_this?></label>
  <br />
  <br />
  <form action="" method="get">
  
    <label class="label_std"> Select job card to edit : &nbsp;&nbsp;</label>
    <select name="vehicle_select" autofocus class="selectbox300" id="vehicle_select" onchange="window.location.href= this.form.vehicle_select.options[this.form.vehicle_select.selectedIndex].value"> 
      <option value=" " selected="selected" >&nbsp;</option>
      <?php
    	for ($j = 0; $j < count($arrId4); $j++) {
			echo "<option value=".$reference.$arrId4[$j].">".$arrName4[$j]."</option>";	
		}
     ?>
    </select>
  
  </form>
  <br />
  <br />
<br />
<br />
<br />
</div>
<?php } ?>


<?php 
if ($page=='fuel') { 
?>
<div class="page_inside_frame">
  <label class="label_std" style="font-size:16px;"><?php echo $page_name_this ?></label>
  <br />
  <br />
  <form action="" method="get">
  
    <label class="label_std"> Select <?php echo $page_name_this ?> to edit : &nbsp;&nbsp;</label>
    <select name="fuel_id_select" autofocus class="selectbox300" id="fuel_id_select" onchange="window.location.href= this.form.fuel_id_select.options[this.form.fuel_id_select.selectedIndex].value"> 
      <option value=" " selected="selected" >&nbsp;</option>
      <?php
    	for ($j = 0; $j < count($arrId2); $j++) {
			echo "<option value=".$reference.$arrId2[$j].">".$arrName2[$j]."</option>";	
		}
     ?>
    </select>
  
  </form>
  <br />
  <br />
<br />
<br />
<br />
</div>
<?php } ?>

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


<?php } else {
    $_SESSION['denied_return'] = "production/production_main.php";	
    include ("../navigation/production_sidebar.php");?>
    <?php include ('../navigation/side_bar.php'); ?>
	<body onLoad="accessdenied(); return false">	
	</body>
<?php }
?>

</body>
</html>