<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link href="../css/main.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script>
<script language="javascript" src="../jscript/calendar.js"></script>
<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/upper_case.js"  type="text/javascript"></script>  
<script language="JavaScript" src="../jscript/numbers_only.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/show_hide_layers.js"  type="text/javascript"></script>   

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

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

$vehicle_id = $_GET['vehicle_id'];

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

$table_name = $_SESSION['db_prefix']."_vehicle";
$select_query = "SELECT vehicle_id, registration_no, make, model FROM $table_name WHERE disposal_date = '2030-01-01'  ORDER BY registration_no ASC ";
  $arrId = array ();
  $arrName = array ();
  $select_result = execsql($select_query);
  $select_num = mysql_num_rows($select_result);
  $a = 0;
  while ($a < $select_num) {
    $arrId[$a] = mysql_result($select_result, $a, "vehicle_id");
    $arrName[$a] = mysql_result($select_result, $a, "registration_no").' '.mysql_result($select_result, $a, "make").' '.mysql_result($select_result, $a, "model");
    $a++;
  }
  
$table_name = $_SESSION['db_prefix']."_list_fuel_provider";
    $position_query = "SELECT item_name FROM $table_name ORDER BY item_name ASC";
  $arrId1 = array ();
  $arrName1 = array ();
  $position_result = execsql($position_query);
  if ($position_result!="") {
  $position_num = mysql_num_rows($position_result);
  $b = 0;
  while ($b < $position_num) {
    $arrId1[$b] = mysql_result($position_result, $b, "item_name");
    $arrName1[$b] = mysql_result($position_result, $b, "item_name");
    $b++;
  }
  }  
  
$table_name = $_SESSION['db_prefix']."_employee";
$select_query = "SELECT emp_id, emp_first_name, emp_last_name FROM $table_name";
  $arrId2 = array ();
  $arrName2 = array ();
  $select_result = execsql($select_query);
  $select_num = mysql_num_rows($select_result);
  $a = 0;
  while ($a < $select_num) {
    $arrId2[$a] = mysql_result($select_result, $a, "emp_id");
    $arrName2[$a] = mysql_result($select_result, $a, "emp_first_name").' '.mysql_result($select_result, $a, "emp_last_name");
    $a++;
  }  
  
  
if ($vehicle_id!='') {
$table_name = $_SESSION['db_prefix']."_vehicle";
$vehicle_query = "SELECT vehicle_id, registration_no, make, model, fuel FROM $table_name WHERE vehicle_id ='".$vehicle_id."' ";
$vehicle_result = mySQL_query($vehicle_query);
$vehicle_num = mysql_num_rows($vehicle_result);  
$vehicle_name = mysql_result($vehicle_result, 0, "registration_no").' '.mysql_result($vehicle_result, 0, "make").' '.mysql_result($vehicle_result, 0, "model");
$fuel = mysql_result($vehicle_result, 0, "fuel");   
}
else {
  $vehicle_name='';
  $fuel='';
}


$table_name = $_SESSION['db_prefix']."_presets";
$diesel_price_query = "SELECT preset_value FROM $table_name WHERE preset_name = 'Diesel' ";
$diesel_price_result = mySQL_query($diesel_price_query);
$diesel_price_num = mysql_num_rows($diesel_price_result);
if ($diesel_price_num!=0) {
$diesel_price = mysql_result($diesel_price_result, 0, "preset_value");
}
else
{
  $diesel_price = '';;
}

$table_name = $_SESSION['db_prefix']."_presets";
$petrol_price_query = "SELECT preset_value FROM $table_name WHERE preset_name = 'Petrol' ";
$petrol_price_result = mySQL_query($petrol_price_query);
$petrol_price_num = mysql_num_rows($petrol_price_result);
if ($petrol_price_num!=0) {
$petrol_price = mysql_result($petrol_price_result, 0, "preset_value");
}
else
{
  $petrol_price = '';;
}

if ($fuel=='petrol') {$fuel_price = $petrol_price;} 
if ($fuel=='diesel') {$fuel_price = $diesel_price;} 

?>
</head>



<?php
include ("../navigation/header.php");
$page_name = "Transport-fuel";
include ("../navigation/access.php");
if ($permission_num==1) {
  include ("../navigation/transport_sidebar.php");
?>

<body onload="<?php if ($vehicle_id=='') { ?> document.getElementById('hidden_frame').style.display = 'none'; <?php } else { ?> document.getElementById('hidden_frame').style.display = 'block'; <?php } ?>">


<div class="main_frame"  style="height:auto; min-height:570px;">

<div class="page_head_frame">
        <table width="809" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><label class="label_page_head">Fuel recording</label></td>
            </tr>
        </table>
      </div>
        <br /><br />
        <div class="page_middle_frame">
<div class="page_inside_frame"><form name="form1" id="form1" action="fuel_rec.php" method="get"> <label class="label_std">Select vehicle:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
  <select name="vehicle_select" class="select200" onchange="window.location.href= this.form.vehicle_select.options[this.form.vehicle_select.selectedIndex].value" >
    <option value=""></option>
    <?php
          for ($i = 0; $i < count($arrId); $i++) {
        echo "<option value=fuel_rec.php?vehicle_id=".$arrId[$i].">".$arrName[$i]."</option>";
  }
?>
  </select>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</form>
</div>
<div class="hidden_frame" id="hidden_frame">
<form action="fuel_rec_save.php" method="GET" name="form2" id="form2">
<div class="page_inside_frame">
  Fuel for:&nbsp;&nbsp; <label class="label_caption_green"> <?php echo $vehicle_name; ?></label>
  <br><br>
  <table width="645"  id="table_display">
    <tr>
      <td width="158" height="29">Fuel intake  date: 
        <label class="star">*</label></td>
      <td colspan="3"><?php 
          //instantiate class and set properties
    $myCalendar = new tc_calendar("record_date", true);
    $myCalendar->setIcon("../images/iconCalendar.gif");
    $myCalendar->setDate($d, $m, $y);
    $myCalendar->setYearInterval(2020, 2099);
    //output the calendar
    $myCalendar->writeScript();
?></td>
      </tr>
    <tr>
      <td height="43">Fuel type:</td>
      <td colspan="3">
        <input type="text" name="fuel_type_text" id="fuel_type_text" readonly value="<?php echo $fuel; ?>" style="border:hidden; width:100px;">        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Current price/ltr: P 
        <input type="text" name="fuel_price_text" id="fuel_price_text" value="<?php echo $fuel_price ?>" style="border:hidden; width:50px;" readonly></td>
      </tr>
    <tr>
      <td height="43">Qty: 
        <label class="star">*</label></td>
      <td width="164"><input name="qty_text" type="text" class="text60" id="qty_text" onKeyPress="return isNumberKey(event)" onkeyup=" this.value = this.value.replace (/(\...).*/, '$1')"> 
        &nbsp;ltr.</td>
      <td width="93">km reading: 
        <label class="star">*</label></td>
      <td width="210"><input name="mileage_text" type="text" class="text100" id="mileage_text" onkeypress="return numbersonly(this, event)">
        &nbsp;&nbsp;km</td>
      
    </tr>
    <tr>
      <td height="43">Oil:</td>
      <td><input name="oil_qty_text" type="text" class="text60" id="oil_qty_text" onKeyPress="return isNumberKey(event)" onkeyup=" this.value = this.value.replace (/(\...).*/, '$1')">
&nbsp;ltr.</td>
      <td>Price oil: (total)</td>
      <td><input name="oil_price_text" type="text" class="text100" id="oil_price_text" onKeyPress="return isNumberKey(event)" onkeyup=" this.value = this.value.replace (/(\...).*/, '$1')"></td>
    </tr>
    <tr>
      <td height="43">Other:</td>
      <td><input name="other_text" type="text" class="text150" id="other_text" maxlength="20" ></td>
      <td>Price: (total)</td>
      <td><input name="other_price_text" type="text" class="text100" id="other_price_text" onKeyPress="return isNumberKey(event)" onkeyup=" this.value = this.value.replace (/(\...).*/, '$1')"></td>
    </tr>
    <tr>
      <td height="43">Provider: 
        <label class="star">*</label></td>
      <td colspan="3"><select name="provider_select" class="select200"  id="provider_select" >
        <option value="  " selected> </option>
        <?php
          for ($j = 0; $j < count($arrId1); $j++) {
        echo "<option value=" . "\"" . $arrId1[$j] . "\"" . ">" . $arrName1[$j] . "</option>";
  }
?>
      </select></td>
    </tr>
    <tr>
      <td height="43">Fuel book no: 
        <label class="star">*</label></td>
      <td><input name="reference_text" type="text" class="text100" id="reference_text" onkeyup="ToUpper(this)"></td>
      <td>Received by: 
        <label class="star">*</label></td>
      <td><select name="received_select" class="select200"  id="received_select" >
        <option value="  " selected> </option>
        <?php
          for ($j = 0; $j < count($arrId2); $j++) {
        echo "<option value=" . "\"" . $arrId2[$j] . "\"" . ">" . $arrName2[$j] . "</option>";
  }
?>
      </select></td>
    </tr>
    <tr>
      <td height="58">Notes:</td>
      <td colspan="3"><textarea name="notes_text" cols="50" rows="3" class="text_box" id="notes_text"></textarea></td>
      </tr>
</table>
  
</div>
<div class="page_inside_frame">
  <table width="645" border="0">
    <tr>
      <td width="20"></td>
      <td width="615" align="right"><input type="hidden" name="vehicle_id_text" id="vehicle_id_text" value="<?php echo $vehicle_id ?>" />
        <input name="button2" type="button" class="imagebutton" id="button2" onclick="cancel_confirmation(3, '../transport/transport_main.php?date=0');" value="Close"/>
        <input name="save_button"  id="save_button" type="submit" class="imagebutton" value="Save &amp; New" onclick="needToConfirm = false; confirmRefresh();" />
        <input name="save_close_button"  id="save_close_button" type="submit" class="imagebutton" value="Save &amp; Close" onclick="needToConfirm = false; confirmRefresh();" /></td>
    </tr>
  </table>
</div>
</form> 
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form2");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("fuel_price_text","req","- fuel price. (To be set in the presets page)");
  frmvalidator.addValidation("qty_text","req","- quantity.");
  frmvalidator.addValidation("mileage_text","req","- km meter reading.");
  frmvalidator.addValidation("provider_select","req","- provider.");
  frmvalidator.addValidation("reference_text","req","- reference.");
  frmvalidator.addValidation("received_select","req","- received by.");
  
</script>
</div>     
</div>
</div>





<?php } else {
    $_SESSION['denied_return'] = "transport/transport_main.php?date=";  
    include ("../navigation/transport_sidebar.php");?>
  <body onLoad="accessdenied(); return false">  
  </body>
<?php }
?>


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