<?php


session_start();


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

print <<< HERE

<HTML>
<HEAD>
<TITLE> Vehicle Movement 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='950' cellspacing=0 cellpadding=5 class='master' style='table-layout:fixed;' >
		  <col width=100>
		  <col width=350>
		  <col width=200>
 
		  ";    
	

	echo "<tr>
	<td height='60'><img src='img/imgheader1.jpg' width='115' height='50' /></td>
	<td align='center' colspan=1><b><font size=5>Vehicle Movement</font></td>
	<td align='right' colspan=1><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  colspan=10 align='left' ></th>";
	echo "</tr>";
	


	
	$query="select  date_format(vehiclemovement_start,'%d/%m/%Y') as vehiclemovement_start
					,date_format(vehiclemovement_start,'%H:%i:%s') as starttime
					, date_format(vehiclemovement_end,'%d/%m/%Y') as vehiclemovement_end
					, date_format(vehiclemovement_end,'%H:%i:%s') as endtime		
					,place.fromplace_name as fromplace_name
					,placeto.toplace_name as toplace_name
					,vehicle.vehicle_platenumber
					,vehicle.vehicle_make	
							,concat(employee.employee_firstname,' ',employee.employee_lastname)
							,vehiclemovement_reference
				 from vehiclemovement 
				 left join employee on employee.employee_id=vehiclemovement.employee_id 
				 left join place on place.place_id=vehiclemovement.place_id 
				 left join place as placeto on placeto.place_id=vehiclemovement.place_id 
				 left join vehicle on vehicle.vehicle_id=vehiclemovement.vehicle_id 
				 where vehiclemovement_id = $vehiclemovement_id	 ";

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

		
		$vehiclemovement_start=$row[0];
		$starttime=$row[1];
		$vehiclemovement_end=$row[2];
		$endtime=$row[3];
		$fromplace_name=$row[4];
		$toplace_name=$row[5];
		$vehicle_platenumber=$row[6];
		$vehicle_make=$row[7];
		$employee=$row[8];
		$vehiclemovement_reference=$row[9];
		
		
		echo "<tr>";
		echo "  <td><b>Reference:</b></td><td align='left' >$vehiclemovement_reference</td>";
		echo "</tr>";
		
		echo "<tr>";
		echo "  <td><b>Destination:</b></td><td align='left' >$fromplace_name -> $toplace_name</td>";
		echo "</tr>";
		
		echo "<tr>";
		echo "  <td><b>Plate#:</b></td><td align='left' >$vehicle_platenumber</td>";
		echo "</tr>";
		
		echo "<tr>";
		echo "  <td><b>Vehicle Make:</b></td><td align='left' >$vehicle_make</td>";
		echo "</tr>";
		
		echo "<tr>";
		echo "  <td><b>Driver:</b></td><td align='left' >$employee</td>";
		echo "</tr>";
		
		echo "<tr>";
		echo "  <td><b>Starting Date:</b></td><td align='left' >$vehiclemovement_start $starttime</td>";
		echo "</tr>";
		
		
		echo "</tr>";

	}

echo "<tr height=250><td colspan=10><table width='900' border=0> <col width=150><col width=250><col width=250>";
echo " <tr> <td></td><td align='left' ><hr></hr></td><td align='left' ><hr></td></tr>";
echo "  <tr><td></td><td align='center' >Driver Signature</td><td align='center' >Manager Signature</td></tr>";

echo "</table>";
echo "</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;
?>
	


				 
				  
				  