<?php


session_start();


if($HTTP_SESSION_VARS['dbName']==""){
header("location:../index.php");
}

print <<< HERE

<HTML>
<HEAD>
<TITLE> Vehicle List </TITLE>

<style type="text/css">

table.master th { font-size: 14px; 
                  font-weight: bold;
                  font-family:Times-New-Roman;
				  border-top: 2 solid #000000;
				  border-bottom: 1 solid #000000;
				 }
table.master td { font-size: 14px; 
                  font-family:Times-New-Roman;
                 }
				 
table.master td.reportfooter { font-size: 14px; 
							   font-weight: bold;
							   font-family:Times-New-Roman;
							   border-top: 1 solid #000000;
							  }
</style>


</HEAD>

<BODY>
HERE;

include("config.inc.php");



$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass'])
		or die("Could not connect to DB");

mysql_select_db($HTTP_SESSION_VARS['dbName'],$connection) or die("Could not find DB");

						
$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2, ".
             " Date_Format(Setup_VatStartDate,'%Y%m%d') As Setup_VatStartDate, ifNull(Setup_VatPercentage,0) As Setup_VatPercentage from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}
	//User Access
$querylog=" select ifNull(login_belongstogrp,0) As FI_BelongsToGrp from ".$HTTP_SESSION_VARS['dbLabel'].".login where user_account='".$HTTP_SESSION_VARS['useraccount']."' and Upper(Login_Schema) = Upper('".$HTTP_SESSION_VARS['dbName']."')  ";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

$now=current_server_time($connection);
$dt=split(" ",$now[0]);
$printdate=split("-",$dt[0]);




	echo "<table border=0 width=100% cellspacing=0 cellpadding=0><tr><td align='left'>";
	echo "<table border=0 width='650' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
		  <col width=100>
		  <col width=100>
		  <col width=200>
		  <col width=80>
		  <col width=75>
		  <col width=150>
		  <col width=150>
		  
		  ";    
	

	echo "<tr><td height='60'><img src='img/imgheader1.jpg' width='115' height='50' /></td><td align='center' colspan=4><b><font size=5>Vehicle List</font></td><td align='right' colspan=2><font size='2'><b>Printed&nbsp;Date&nbsp;&amp;&nbsp;Time:</b>&nbsp;&nbsp;";
	echo $printdate[2]."/".$printdate[1]."/".$printdate[0];
	echo "<br>".$dt[1]." ".$dt[2];
	echo "</font></td></tr>";
	

	echo "<tr >";
	echo "  <th align='left' >Number</th>";
	echo "  <th align='left' >Make</th>";
	echo "  <th align='left' >Model</th>";
	echo "  <th align='left' >Year</th>";
	echo "  <th align='left' >Color</th>";
	echo "  <th align='left' >Driver</th>";
	echo "  <th align='left' >Acquisition Date</th>";
	echo "</tr>";
	


	

$query="select 
vehicle_id, null, vehicle_make, vehicle_model, vehicle_year, vehicle_color
, vehicletype_id, vehicle.fueltype_id,fueltype_description, vehicle.employee_id,concat(employee.employee_firstname,' ',employee_lastname), vehicle_note, vehicle_active, null
, insurance_reference, null, insurance_startdate, insurance_enddate, vehicle_platenumber
, null, date_format(vehicle_acquisitiondate,'%d/%m/%Y'), vehicle_odometertype, vehicle_odometeracuisition, null
, null, null, null, vehicle_licensereference, null
, license_startdate, license_enddate, null, null, null
from vehicle left join employee on employee.employee_id = vehicle.employee_id
 left join fueltype on fueltype.fueltype_id = vehicle.fueltype_id
";


	$result= mysql_query($query, $connection);
	$totalrows= mysql_num_rows($result)  or die(mysql_error());
	
	
    while($row=mysql_fetch_array($result)){

		
		$vehicle_platenumber=$row[18];
		$vehicle_make=$row[2];
		$vehicle_model=$row[3];
		$vehicle_year=$row[4];
		$vehicle_color=$row[5];
		$employee_name=$row[10];
		$vehicle_acquisitiondate=$row[20];
		
		
		echo "<tr>";
		echo "  <td align='left' >$vehicle_platenumber</td>";
		echo "  <td align='left' >$vehicle_make</td>";
		echo "  <td align='left' >$vehicle_model</td>";
		echo "  <td align='left' >$vehicle_year</td>";
		echo "  <td align='left' >$vehicle_color</td>";
		echo "  <td align='left' >$employee_name</td>";
		echo "  <td align='left' >$vehicle_acquisitiondate</td>";
		echo "</tr>";

	}

echo "<tr height='35'><td colspan='8' class='reportfooter'>Total Records: $totalrows </td></tr>";	
echo "</table></table>";
	
	

function current_server_time($connection){

  $string="Select date_format(NOW(),'%Y-%m-%d %h:%i %p') ";
  $result=mysql_query($string,$connection) or die(mysql_error());
  $now=mysql_fetch_row($result);

  return $now;
}

print <<< HERE

<script language=javascript>
if (typeof(window.print) != 'undefined')
{
    window.print();
}
</script>
</BODY>
</HTML>
HERE;
?>
	


				 
				  
				  