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

<link href="../css/main.css" rel="stylesheet" type="text/css" />

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


$day = date("Y-m-d");
$today = date('l');
$today_no = date('w');
$this_month = date('m');
$this_year = date('Y');
$no_day = date('t');

$first_day = $this_year.'-'.$this_month.'-01';
$last_day = $this_year.'-'.$this_month.'-'.$no_day;

$table_name2 = $_SESSION['db_prefix']."_vehicle";
$reg_query = "SELECT vehicle_id, registration_no, make, model, department, road_license_date, clock_reading FROM $table_name2 WHERE road_license_date>='".$first_day."' AND road_license_date<='".$last_day."' AND disposal_date = '2030-01-01'" ;
$reg_result = mySQL_query($reg_query);
$reg_num = mysql_num_rows($reg_result);

$table_name2 = $_SESSION['db_prefix']."_vehicle";
$ba_query = "SELECT vehicle_id, registration_no, make, model, department, ba_license_date, clock_reading FROM $table_name2 WHERE ba_license_date>='".$first_day."' AND ba_license_date<='".$last_day."' AND disposal_date = '2030-01-01'" ;
$ba_result = mySQL_query($ba_query);
$ba_num = mysql_num_rows($ba_result);


$table_name2 = $_SESSION['db_prefix']."_vehicle";
$insurance_query = "SELECT vehicle_id, registration_no, make, model, department, insurance, renewal_date, clock_reading FROM $table_name2 WHERE renewal_date>='".$first_day."' AND renewal_date<='".$last_day."' AND disposal_date = '2030-01-01'" ;
$insurance_result = mySQL_query($insurance_query);
$insurance_num = mysql_num_rows($insurance_result);


$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 WHERE disposal_date = '2030-01-01'" ;
$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>

<?php include ('../include/tooltip.php'); ?>
</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");
?>


<div class="main_frame" style="height:auto;">
 <div class="page_head_frame">
      <table width="809" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><label class="label_page_head">Transport 
              <?php echo "today, ".date("d-m-Y", strtotime($day));  ?>
            </label></td>
            <td width="171" align="right">&nbsp;</td>
          </tr>
        </table>
      </div>
 
<div class="page_middle_frame" style="height:auto;">
  <div class="scroll_frame_medium" style="height:150px;">
  Road licenses:
  <table width="640"  id="table_list">
    <tr>
      <th width="119">Registration</th>
      <th width="218">Vehicle</th>
      <th width="327">Department</th>
      <th width="115">Expire</th>
    </tr>
    <?php
	$i=0;
	while ($i<$reg_num) {
		$a0 = mysql_result($reg_result, $i, "vehicle_id");
		$a1 = mysql_result($reg_result, $i, "registration_no");
		$a2 = mysql_result($reg_result, $i, "make");
		$a3 = mysql_result($reg_result, $i, "model");
		$a4 = mysql_result($reg_result, $i, "department");
		$a5 = mysql_result($reg_result, $i, "road_license_date");
		
		$a11 =number_format(mysql_result($reg_result, $i, "clock_reading"), 0, '.', ',') ;
		
		$vehicleTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Make/model:</td><td width=175>".$a2.' '.$a3."</td></tr><tr><td>Department:</td><td>".$a4."</td></tr><tr><td>Km reading:</td><td>".$a11."km</td></tr></table><br><b>Click for details</b>"; 
		?>
    <tr>
      <td><a href="vehicle_details.php?vehicle_id=<?php echo $a0?>" onMouseover="ddrivetip('<?php echo $vehicleTT ?>  ', 200)"; onMouseout="hideddrivetip()"><?php echo $a1 ?></a></td>
      <td><?php echo $a2." ".$a3 ?></td>
      <td><?php echo $a4 ?></td>
      <td align="center"><?php echo date("d-m-Y", strtotime($a5)) ?></td>
    </tr>
    <?php
	$i++;
	}
	?>
</table>
</div>
<div class="scroll_frame_medium" style="height:150px;;">
BA licenses:
  <table width="640"  id="table_list">
    <tr>
      <th width="119">Registration</th>
      <th width="218">Vehicle</th>
      <th width="327">Department</th>
      <th width="115">Expire</th>
    </tr>
    <?php
	$i=0;
	while ($i<$ba_num) {
		$b0 = mysql_result($ba_result, $i, "vehicle_id");
		$b1 = mysql_result($ba_result, $i, "registration_no");
		$b2 = mysql_result($ba_result, $i, "make");
		$b3 = mysql_result($ba_result, $i, "model");
		$b4 = mysql_result($ba_result, $i, "department");
		$b5 = mysql_result($ba_result, $i, "ba_license_date");
		
		$b11 =number_format(mysql_result($ba_result, $i, "clock_reading"), 0, '.', ',') ;
		
		$vehicleTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Make/model:</td><td width=175>".$b2.' '.$b3."</td></tr><tr><td>Department:</td><td>".$b4."</td></tr><tr><td>Km reading:</td><td>".$b11."km</td></tr></table><br><b>Click for details</b>"; 
		?>
    <tr>
      <td><a href="vehicle_details.php?vehicle_id=<?php echo $b0?>" onMouseover="ddrivetip('<?php echo $vehicleTT ?>  ', 200)"; onMouseout="hideddrivetip()"><?php echo $b1 ?></a><a href="vehicle_details.php?vehicle_id=<?php echo $b0?>" onMouseover="ddrivetip('<?php echo $vehicleTT ?>  ', 200)"; onMouseout="hideddrivetip()"></a></td>
      <td><?php echo $b2." ".$b3 ?></td>
      <td><?php echo $b4 ?></td>
      <td align="center"><?php echo date("d-m-Y", strtotime($b5)) ?></td>
    </tr>
    <?php
	$i++;
	}
	?>
</table>
</div>
<div class="scroll_frame_medium" style="height:150px;">
Insurance:
  <table width="640"  id="table_list">
    <tr>
      <th width="117">Registration</th>
      <th width="216">Vehicle</th>
      <th width="163">Department</th>
      <th width="161">Insured with</th>
      <th width="118">Expire</th>
    </tr>
    <?php
	$i=0;
	while ($i<$insurance_num) {
		$a0 = mysql_result($insurance_result, $i, "vehicle_id");
		$a1 = mysql_result($insurance_result, $i, "registration_no");
		$a2 = mysql_result($insurance_result, $i, "make");
		$a3 = mysql_result($insurance_result, $i, "model");
		$a4 = mysql_result($insurance_result, $i, "department");
		$a5 = mysql_result($insurance_result, $i, "insurance");
		$a6 = mysql_result($insurance_result, $i, "renewal_date");
		
		$a11 =number_format(mysql_result($insurance_result, $i, "clock_reading"), 0, '.', ',') ;
		
		$vehicleTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Make/model:</td><td width=175>".$a2.' '.$a3."</td></tr><tr><td>Department:</td><td>".$a4."</td></tr><tr><td>Km reading:</td><td>".$a11."km</td></tr></table><br><b>Click for details</b>"; 
		?>
    <tr>
      <td><a href="vehicle_details.php?vehicle_id=<?php echo $a0?>" onMouseover="ddrivetip('<?php echo $vehicleTT ?>  ', 200)"; onMouseout="hideddrivetip()"><?php echo $a1 ?></a><a href="vehicle_details.php?vehicle_id=<?php echo $a0 ?> " onMouseover="ddrivetip('Click for details', 150)"; onMouseout="hideddrivetip()"></a></td>
      <td><?php echo $a2." ".$a3 ?></td>
      <td><?php echo $a4 ?></td>
      <td><?php echo $a5 ?></td>
      <td align="center"><?php echo date("d-m-Y", strtotime($a6 )) ?></td>
    </tr>
    <?php
	$i++;
	}
	?>
</table>
<br />
</div>
<div class="scroll_frame_medium" style="height:150px;">
Service status:
  <table width="640"  id="table_list">
    <tr>
      <th width="108">Registration no</th>
      <th width="87">Vehicle</th>
      <th width="89">Current km</th>
      <th width="85">Last service</th>
      <th width="101">Interval</th>
      <th width="142">Status</th>
    </tr>
<?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");
	$v8 = mysql_result($service_result, $i, "department");
	
	
		
		$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>".$v8."</td></tr><tr><td>Km reading:</td><td>".number_format($v5, 0, '.', ',')."km</td></tr></table><br><b>Click for details</b>"; 
	
	if (($v5-$v6)>=$v7) {$v8='Overdue by '.(($v5-$v6)-$v7).'km';}
	else {
	if (($v5-$v6)>=($v7-1000)) {$v8='Due in '.($v7-($v5-$v6)).'km';}
	else {
	if (($v5-$v6)<$v7) {$v8='OK';}
	}
}
	if ($v8=='OK') { 
	$i++;
	}
	else {
?>
	
    <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 align="center"><?php echo number_format($v5, 0, '.', ',') ?></td>
      <td align="center"><?php echo number_format($v6, 0, '.', ',') ?></td>
      <td align="center"><?php echo number_format($v7, 0, '.', ',') ?></td>
      <td><?php echo $v8 ?> </td>
    </tr>
<?php
$i++;
}
}
?>
</table>
</div> 
</div> 
</div>

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

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