<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--style sheets--> 
<link href="../css/main.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="../css/scroll_table.css" />
<!--jscript-->

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

$table_name = $_SESSION['db_prefix']."_vehicle";
$service_query = "SELECT vehicle_id, registration_no, make, model, clock_reading, last_service_mileage, service_interval, department FROM $table_name ";
$service_result = mySQL_query($service_query);
$service_num = mysql_num_rows($service_result);


?>
<script type="text/javascript" src="../jscript/tablesort.js"></script>
<script language="javascript" src="../jscript/calendar.js"></script>
</head>
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />
<body>
<?php
include ("../navigation/header.php");
$page_name = "Transport-main";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/transport_sidebar.php");
    include ('../include/tooltip.php');
	?>

<div class="main_frame">

  <div class="page_head_frame">
      <table width="809" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="385"><label class="label_page_head">Service status</label></td>
            <td width="253">&nbsp;</td>
            <td width="171" align="right">&nbsp;</td>
          </tr>
        </table>
      </div>
<div class="page_middle_frame">

<div class="page_inside_frame">
<!--jscript-->
<script type="text/javascript" language="javascript" src="../jscript/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				$('#scroll_table').dataTable( {
					"sScrollY": "500px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 0, "asc" ]],
					"aoColumns": [
								{"bSortable": true},
                              	{"bSortable": true},
								{"bSortable": true},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true}
								 ]
				} );
			} );
		</script>
<table id="scroll_table" class="data_display">
  <thead>
  <tr>
    <th width="105">Registration no</th>
    <th width="78">Vehicle</th>
    <th width="82">Current km</th>
    <th width="77">Last service</th>
    <th width="89">Interval</th>
    <th width="185">Status</th>
    <th width="27">&nbsp;</th>
  </tr>
  </thead>
  <?php
$i=0;
$v8='';
while ($i<$service_num) {
    $v1 = mysql_result($service_result, $i, "vehicle_id");
	$v2 = mysql_result($service_result, $i, "registration_no");
	$v3 = mysql_result($service_result, $i, "make");
	$v4 = mysql_result($service_result, $i, "model");
	$v5 = mysql_result($service_result, $i, "clock_reading");
	$v6 = mysql_result($service_result, $i, "last_service_mileage");
	$v7 = mysql_result($service_result, $i, "service_interval");
	
	$department = mysql_result($service_result, $i, "department");
	$clock_reading = number_format(mysql_result($service_result, $i, "clock_reading"), 0, '.', ',');

$vehicleTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Make/model:</td><td width=175>".$v3.' '.$v4."</td></tr><tr><td>Department:</td><td>".$department."</td></tr><tr><td>Km reading:</td><td>".$clock_reading."km</td></tr></table><br><b>Click for details</b>"; 
	
	if (($v5-$v6)>=$v7) {$v8='Overdue by '.(($v5-$v6)-$v7).'km'; $v9 = '<img src=../images/round_red.png width=12 height=12>';}
	else {
	if (($v5-$v6)>=($v7-1000)) {$v8='Due in '.($v7-($v5-$v6)).'km'; $v9 = '<img src=../images/round_orange.png width=12 height=12>';}
	else {
	if (($v5-$v6)<$v7) {$v8='OK'; $v9 = '<img src=../images/round_green.png width=12 height=12>';}
	}
}
	
?>
  <tr>
    <td><a href="vehicle_details.php?vehicle_id=<?php echo $v1?>" onMouseover="ddrivetip('<?php echo $vehicleTT ?>  ', 200)"; onMouseout="hideddrivetip()"><?php echo $v2 ?></a></td>
    <td><?php echo $v3.' '.$v4 ?></td>
    <td><?php echo $v5 ?></td>
    <td><?php echo $v6 ?></td>
    <td><?php echo $v7 ?></td>
    <td><?php echo $v8 ?></td>
    <td align="center"><?php echo $v9 ?></td>
  </tr>
  <?php
$i++;
}
?>
</table>
</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>