<?php

session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
if($_SESSION['dbName']==""){
header("location:../index.php");
}

print <<< HERE
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<TITLE> Vehicle List </TITLE>
<script type="text/javascript" language="javascript">

</script>
<style type="text/css">

table.master th { font-size: 14px; 
                  font-weight: bold;
                  font-family:Times-New-Roman;
                }				 
table.master td { font-size: 14px; 
                  font-family:Times-New-Roman;
                 }
table.detail th { font-size: 13px; 
                  font-weight: bold;
                  font-family:Times-New-Roman;
				  border-top:1px solid black;
				  border-bottom:1px solid black;
				  border-left:1px solid black;
                }				 
				 
table.detail td { font-size: 12px; 
                  font-family:Times-New-Roman;
				  border-left:1px solid black;
                 }			
h1.breakhere { page-break-after: auto;}				 
</style>
</HEAD>
<BODY>
HERE;

include("config.inc.php");

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass'],true,65536)	or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

$connection1 = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass'],true,65536)	or die("Could not connect to DB");
mysql_select_db($config['dbName_log'],$connection1) or die("Could not find DB");

if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}

//mysql_set_charset('utf8',$connection);

//Read From Setup Table							
$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2, Setup_vatno, ".
             " Date_Format(Setup_VatStartDate,'%Y%m%d') As Setup_VatStartDate, ifNull(Setup_VatPercentage,0) As Setup_VatPercentage, ".
			 " Company_Name, Company_NameF, Company_Memo, Company_MemoF, Company_Capital, Company_CapitalF ".
			 " from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}






	


$querysetup ="select base1, base2 from ".$config['dbName_log'].".setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultsetup)){
	extract($rowmodule);
}
	
	
$style="style='border:1px solid black; text-align:right;'";
echo"<table border='0' width='1100px' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
		<col width=200>
		<col width=300>
		<col width=300>";
		//T-header
echo"	<tr>
			<td align=' left' valign='top' style='font-size:14px; font-style:italic; font-weight:bold;' colspan=3>
			<table>
			<tr>
			<td rowspan=2><img src='LogoFile.php' ></td>
			<td style='vertical-align: top;'><br><span style='font-size: 20px; font-weight: bold'>$Company_Name</span><br>
			<span style='font-size: 11px;'><pre>".str_replace( '\n', '<br>', $Company_Memo)."</pre></span></td>
			</tr>
			
			</table>
			<td>
			
		<tr>";
		
		//2nd row
		
echo "	<tr>
			<td align='right' colspan='2' valign='top' style='font-size:20px; font-weight:bold;'>Vehicle List <td>
			<td align='left' valign='top' style='font-size:14px; font-style:italic; font-weight:bold;'>
				<td colspan='2'><b>Printed Date:</b>";
			echo date("d/m/Y")."<br>";
				echo "<span><b>Time:</b></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".date("h:i:sa");
				echo "</td>
			<td>";
			
			
		//table header
		
echo "	</tr>

		<tr>
			<td>
			
					
			
				<table  width='1060px' cellspacing='0' cellpadding='1' style=' border: 1px solid black;'>
					<col width=200>
					<col width=200>
					<col width=220>
					<col width=200>
					<col width=200>
					<col width=200>
					<col width=200>
					<col width=200>
					<tr style='background-color:#d3d3d3'>
						
						<td  >Vehicle Code</td>
						<td  >Vehicle Name</td>
						<td>Vehicle Type</td>
						<td>vehicle license</td>
						<td>Insurance Exp.</td>
						<td>Road Worthiness</td>
						<td>Heavy duty</td>
						<td>Hackney</td>
						
						<td  >Location</td>
						
						
					</tr>";
					

$cartype = $_POST['cartype']; if($cartype == '') $cartype = $_GET['cartype'];
$groupby = $_POST['groupby']; if($groupby == '') $groupby = $_GET['groupby'];



if($groupby=='cartype'){
	
	
	$carlistgrp_query="select vehicletype_description from vehicletype ";
	
	$carlistview=mysql_query($carlistgrp_query,$connection);
	while($carlisttype_result=mysql_fetch_array($carlistview)){
		
	

				$carlist_query="select vehicle_platenumber, vehicle_make,vehicletype_description, vehicle_model,license_enddate,insurance_enddate,road_enddate,roadpermit_enddate,
permit_enddate,project_code
 from vehicle inner join vehicletype
where vehicletype.vehicletype_id=vehicle.vehicletype_id
and  vehicletype_description='$carlisttype_result[0]' ";
					$carlist=mysql_query($carlist_query,$connection);
					
					if (!$carlist_result=mysql_fetch_array($carlist))
					{}
						else {
							echo"<tr height='30px'  style='background-color:#d3d3d3'><td> <b>$carlisttype_result[0]</b></td><td></td><td></td><td></td></tr>";}
					
					$carlist=mysql_query($carlist_query,$connection);
					while($carlist_result=mysql_fetch_array($carlist)){
				     if($i%2==0){
		             $color = "style='background-color:#ABD4F1'";
	                   }else{
		             $color = "style='background-color:#EFF1F3'";
	               }
						
						echo "<tr $color height='30px'>
							
							<td  >$carlist_result[0]</td>
							<td >$carlist_result[1]</td>
							<td >$carlist_result[2]</td>
							<td >$carlist_result[4]</td>
							<td >$carlist_result[5]</td>
							<td >$carlist_result[6]</td>
							<td >$carlist_result[7]</td>
							<td >$carlist_result[8]</td>
							<td >$carlist_result[9]</td>"
							;
							echo "<td>$carlist_result[3]</td>";
						echo "
							
						</tr>
						
						<tr style='background-color:white; '>
							
						</tr>";
						 $i++;

}		}}

else if($groupby=='none'){
$carlist_query="select vehicle_platenumber, vehicle_make,vehicletype_description, vehicle_model,license_enddate,insurance_enddate,road_enddate,roadpermit_enddate,
permit_enddate,project_code
 from vehicle inner join vehicletype

where vehicletype.vehicletype_id=vehicle.vehicletype_id
 ";
 if ($cartype!=''){$carlist_query.="and vehicle.vehicletype_id='$cartype'";}

 $carlist=mysql_query($carlist_query,$connection);
					while($carlist_result=mysql_fetch_array($carlist)){
	           if($i%2==0){
		             $color = "style='background-color:#ABD4F1'";
	                   }else{
		             $color = "style='background-color:#EFF1F3'";
	               }
						
						echo "<tr $color height='30px'>
							
							<td  >$carlist_result[0]</td>
							<td >$carlist_result[1]</td>
							<td >$carlist_result[2]</td>
							<td >$carlist_result[4]</td>
							<td >$carlist_result[5]</td>
							<td >$carlist_result[6]</td>
							<td >$carlist_result[7]</td>
							<td >$carlist_result[8]</td>
							<td >$carlist_result[9]</td>"
							;
							echo "<td >$carlist_result[3]</td>";
						echo "
						</tr>
						
						<tr style='background-color:white; '>
							
						</tr>";
						 $i++;
					}
 

 
}

					
echo "			</table>
			</td>
		</tr>
	</table>";
print <<< HERE

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