<?php

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


include("config.inc.php");
include("function.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");



//User Access
$querylog=" select ifNull(FI_PlaceApp,0) As FI_PlaceApp, ifNull(FI_PlaceDel,0) As FI_PlaceDel,".
          "ifNull(FI_PlaceMod,0) As FI_PlaceMod 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);
}

//echo $querylog;
//Read From Setup Table							
$querysetup= " select grid_color1, grid_color2,maxperpage,base1,base2,DecimalBase,DecimalBase1,DecimalBase2,maxperpage from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}



$querylog="SELECT FI_Place as loginaccess from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['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);
	}
	
	
if ($loginaccess=='' or $loginaccess==0)
	header("location:menu.php");
	
	

//Access Mode On Insert/Edit/Delete
$InsMode = '';
if ($FI_PlaceApp == 0)
	$InsMode = ' disabled ';


if(!isset($actionmode))
$actionmode='';


if($mode=='editmode'){

$query_edit=" select Place_id,fromPlace_name ,toplace_name,place_millage,place_millagetype".
				"  from Place where Place_Id='".$Place_Id."'";
						  
//echo $query_edit;exit;
	$resultedit = mysql_query($query_edit, $connection);
	while($row=mysql_fetch_array($resultedit)){
		$Place_Id=$row[0];
		$fromplace_name=$row[1];
		$toplace_name=$row[2];
		$place_millage=$row[3];
		$place_millagetype=$row[4];
		
	}
	$mode='edit';
}

 


if($mode==''){
$status='disabled';
$dis='disabled';

}

if($mode=='view'){

$status='readonly';
$dis='disabled';

}

if($mode=='insert')
$status='';

print <<<HERE

<head>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
<LINK REL="stylesheet" TYPE="text/css" MEDIA="all" HREF="tabs.css">
<script type="text/javascript" src="js/tabsClass/tabber.js"></script>
<link rel="stylesheet" href="js/tabsClass/tabber.css" type="text/css" />

<script type="text/javascript">

var tabberOptions = {
  'manualStartup':true,
  'onClick': function(argsObj) {

    var t = argsObj.tabber; /* Tabber object */
    var id = t.id; /* ID of the main tabber DIV */
    var i = argsObj.index; /* Which tab was clicked (0 is the first tab) */
    var e = argsObj.event; /* Event object */
	
	if (id == 'tab1') document.getElementById('PTabIndex').value = i;
  },

  /* Optional: set an ID for each tab navigation link */
  'addLinkId': true
};

</script>
<script type="text/javascript" language="javascript">


function openvehicle(){
	win = window.open('Form_VehicleList.php?str=vehiclemovement', 'Form_VehicleSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=775,height=450,top=100,left=100');		


}

function openemp(){
	win = window.open('Form_EmployeeList.php?str=vehiclemovement', 'Form_EmployeeSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=775,height=450,top=100,left=100');		


}

function assignemployeename(vmode){

			document.vehiclemovement.action="Form_VehicleMovement.php?actionmode="+vmode;
			document.vehiclemovement.submit();
}

function editmode () {
document.vehiclemovement.actionmode.value='edit';
	document.vehiclemovement.action="Form_VehicleMovement.php";
	document.vehiclemovement.submit();
}

function AddvehicleMovement () {
            ClearForm('All');
			document.vehiclemovement.actionmode.value='insert';
			document.vehiclemovement.action="Form_VehicleMovement.php";
			document.vehiclemovement.submit();
}


function dosubmit(){
				document.vehiclemovement.submit();
}

function CancelRecord () {


if (confirm ( "Are you sure you want to Cancel Page?")){
	ClearForm('All');
			document.vehiclemovement.action="Form_VehicleMovement.php?actionmode=";
				document.vehiclemovement.submit();
}
}






function setnow() {
  var currentDate = new Date();
  var day =  ("0" + currentDate.getDate()).slice(-2);
  var month =  ("0" + parseInt(currentDate.getMonth() + 1)).slice(-2) ;
  var year = currentDate.getFullYear();
  
  var hours = ("0" + currentDate.getHours()).slice(-2);
  var minutes = ("0" + currentDate.getMinutes()).slice(-2);
  var seconds = ("0" + currentDate.getSeconds()).slice(-2);
  

  document.vehiclemovement.vehiclemovement_end.value= day + '/' + month + '/' + year;
  
  document.vehiclemovement.endtime.value= hours + ':' + minutes + ':' + seconds;
}


function SubmitRecord() {



if (document.vehiclemovement.vehicle_id.value=='' )
		{alert('Unable to save : check missing field Code ');
		document.getElementById("vehicle_name").focus();
		}
		

		else {
		
		document.vehiclemovement.action="Form_VehicleMovement_Actions.php";
		document.vehiclemovement.submit();
		
		}


}

function addcharges(){
if (document.vehiclemovement.vehiclemovement_id.value!='')
	{
	var str = '';
	var vehiclemovementid = document.vehiclemovement.vehiclemovement_id.value;
	win = window.open('Form_VehicleMovementCharges.php?vehiclemovement_id='+vehiclemovementid, 'Form_ChargesSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=650,height=450,top=100,left=100');		
	//win = window.open('Form_VehicleMovementCharges.php?vehicle_id='+vehicleid);		
	}
}

function additems(){
if (document.vehiclemovement.vehiclemovement_id.value!='')
	{
	var str = '';
	var vehiclemovementid = document.vehiclemovement.vehiclemovement_id.value;
	win = window.open('Form_VehicleMovementItems.php?vehiclemovement_id='+vehiclemovementid, 'Form_ItemsSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=650,height=450,top=100,left=100');		
	//win = window.open('Form_VehicleCharges.php?vehicle_id='+vehicleid);		
	}
}
function ClearPage(){
	if (confirm ( "Are you sure you want to Clear Page?"))
	{
		ClearForm('All');
		

		x.actionmode.value='';
		x.action='Form_VehicleMovement.php';
		x.submit();
	}	
}

//All= All form; D= Detail Part
function ClearForm(Option){
    x = document.vehiclemovement;
	
	x.vehiclemovement_id.value=''
	x.vehiclemovement_reference.value=''
	x.vehiclemovement_start.value='';
	x.vehiclemovement_end.value='';
	x.place_id.value='';
	x.vehicle_id.value='';
	x.employee_id.value='';
	x.vehicle_name.value='';
	x.vehiclemovement_millagetype.value='';
	x.vehiclemovement_millage.value='';
	x.vehicle_platenumber.value='';
	x.starttime.value='00:00:00';
	x.endtime.value='00:00:00';
	
}


function SearchForvehicleMovement(){
    ClearForm('All');
    x = document.vehiclemovement;
    win = window.open('Form_VehicleMovementSearch.php', 'Form_VehicleMovementSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=775,height=450,top=100,left=100');		
	win.creator = self;
	win.focus();		
			
}
   function PrintPreview() {
	var str = '';
	
	str = 'Form_VehicleMovementPreview.php';
	window.open(str);

}

function SubmitRecordCharges() {
    var x = document.vehiclemovement;
	
	var vmode=x.modedt.value;	
	if (vmode=='add_vehiclemovementcharges')
		x.modedt.value = 'add_vehiclemovementcharges';
	else if (vmode=='edit_vehiclemovementcharges')
		x.modedt.value = 'edit_vehiclemovementcharges';
		
	if (x.charges_id.value =="")
	{
	alert("Charges is mandatory!");
	x.charges_name.focus();
	return 0;
	}
	x.action="Form_VehicleMovement_Actions.php";
	x.submit();
	}
	
	

function UpdateDetailCharges(Code){


	x = document.vehiclemovement;
	x.modedt.value='edit_vehiclemovementcharges';
	x.vehiclemovementcharges_id.value=Code; 
	 
	x.action="Form_VehicleMovement.php?vTabFocus=Charges";
	x.submit();
}

function DeleteDetail(Code){


if (confirm ( "Are you sure you want to Delete This Record ?"))
	{
		x = document.vehiclemovement;
		x.modedt.value='delete_vehiclemovementcharges';
		x.vehiclemovementcharges_id.value=Code; 
		x.action="Form_VehicleMovement_Actions.php?vTabFocus=Charges";
		x.submit();
	}
}

function showcharges(str){
  window.open('Form_TrackingChargesList.php?str='+str,'mywindow','width=500,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}



function SubmitRecordItem() {
    var x = document.vehiclemovement;
	
	var vmode=x.modedtitems.value;	
	if (vmode=='add_vehiclemovementitems')
		x.modedtitems.value = 'add_vehiclemovementitems';
	else if (vmode=='edit_vehiclemevementitems')
		x.modedtitems.value = 'edit_vehiclemovementitems';
		
	if (x.item_code.value =="")
	{
	alert("Item is mandatory!");
	x.item_code.focus();
	return 0;
	}
	x.action="Form_VehicleMovement_Actions.php";
	x.submit();
	}
	
	



function showitems(str){
  window.open('Form_TrackingItemsList.php?str='+str,'mywindow','width=500,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}


function UpdateDetailItem(Code){


	x = document.vehiclemovement;
	x.modedtitems.value='edit_vehiclemovementitems';
	x.vehiclemovementitems_id.value=Code; 
	 
	x.action="Form_VehicleMovement.php?vTabFocus=Items";
	x.submit();
}

function DeleteDetailItems(Code){


if (confirm ( "Are you sure you want to Delete This Record ?"))
	{
		x = document.vehiclemovement;
		x.modedtitems.value='delete_vehiclemovementitems';
		
		x.vehiclemovementitems_id.value=Code; 
		x.action="Form_VehicleMovement_Actions.php";
		x.submit();
	}
}


function SetWh(whId){
	
	document.Place.Place_Id.value=whId;
	document.Place.message.value='';
	document.Place.actionmode.value='';
	
	document.Place.mode.value='editmode';
	document.Place.submit();
}



</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Add Vehicle Movement</title>

<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
body {
	margin-top: 2px;
	margin-left: 1px;
}
a:link {
	text-decoration: none;
	color: #0000FF;
}
a:visited {
	text-decoration: none;
	color: #0000FF;
}
a:hover {
	text-decoration: none;
	color: #0000FF;
}
a:active {
	text-decoration: none;
	color: #0000FF;
}

.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}
.style15 {color: #5151FF; font-size: 10px;}
.style16 {
	font-size: 16px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style17 {font-size: 9px}
.style25 {color: #999999; font-weight: bold; font-size: 10px; }
.style26 {color: #FF0000}
.style27 {color: #999999 ;font-size: 10px;}
.style28 {color: #FFFFFF ;font-size: 10px;}

</style>

<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>

</head>
<body >
<form name='vehiclemovement' method='post'>
<input type=hidden name='mode' value='$mode'>
<input type=hidden name='actionmode' value='$actionmode'>
<input type=hidden name='modedt' value='$modedt'>
<input type=hidden name='modedtitems' value='$modedtitems'>
<input type=hidden name='message' value='$message'>
<input type='hidden' name='PTabIndex' id='PTabIndex' value='$PTabIndex'>
HERE;


if($mode==''){
$status='disabled';
$dis='disabled';

}

if($mode=='view'){

$status='readonly';
$dis='disabled';

}

if($mode=='insert')
$status='';

//$style= "style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'";

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' class='layout-width'>";
include_once("header.php");
echo" <tr><td  valign='top'>";

include_once("sidemenu.php");
echo"  </td></tr>";


echo" <tr style='height:26px;'>
		<td  valign='top' id='content-top'>
			<table border='0' cellpadding='0' cellspacing='0' style='table-layout:fixed; height:26px;' class='layout-width'>
			<tr style='height:26px;'>
				<td style='width:38px; height:26px;'>&nbsp;</td>
				<td valign='middle' style='width:300px; height:26px;'><span class='title'>Vehicle Movement</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";

	 
	
echo"<tr>
		<td  height='18'  valign='top' id='content-top2'>";
			
			
echo"</td></tr>";

	echo"<tr><td id='content-body'>";			
				

		 
			
	
			echo"<button type='button'  value='Add vehicleMovement'";  	
			
			if($actionmode=='insert' or $actionmode=='edit')
			echo "disabled ";
			
			echo"onclick='AddvehicleMovement()' $style title='Add vehicleMovement' $InsMode><span><span>Add vehicleMovement</span></span></button>" ;
			
			
				
	/*	echo"	<button type='button'  value='Charges'";  	
			if ($actionmode=='')
						echo " disabled ";	
			echo"onclick='addcharges()' $style title='Add Charges' $InsMode><span><span>Charges</span></span></button>" ;		
			
			
	echo"	<button type='button'  value='Items'";  	
			if ($actionmode=='')
						echo " disabled ";	
			echo"onclick='additems()' $style title='Add Items' $InsMode><span><span>Items</span></span></button>" ;		*/
			
echo"           <button type='button' id='btnClear' name='BtnClear' value='Clear Page' ";

echo"  onclick='ClearPage();' $style title='Clear Page'><span><span>Clear Page</span></span></button>";

				
echo"           <button type='button' name='btnCancel' id='btnCancel' value='Cancel' ";//cancel
				if ($actionmode=='' )
					echo " disabled ";
				echo" onclick='CancelRecord();' $style title='Cancel Changes'><span><span>Cancel</span></span></button>";
				
				
		if($actionmode=='view'){
echo"           <button type='button' name='btnEdit' id='btnEdit' value='Edit' ";//Edit
				
				
				echo" onclick='editmode();' $style	title='Edit vehicleMovement' /><span><span>Edit</span></span></button>";
	}
else	{
echo"           <button type='button' name='btnPost' id='btnPost' value='Save' ";//post
				if ($actionmode=='')
						echo " disabled ";
				
				echo" onclick='SubmitRecord();' $style	title='Save Changes' /><span><span>Save</span></span></button>";}

echo"           <button name='btnSearch' type='button' id='btnSearch' value='Search' onclick='SearchForvehicleMovement();' $style title='Search vehicleMovement' ";
                if ($actionmode=='edit' or $actionmode=='insert') 
				    echo " disabled ";
			
		        echo " /><span><span>Search</span></span></button>";

				
echo" 			<button name='btnPrint' type='button' id='btnPrint' value='Print' onclick='PrintPreview();' $style title='Print' ";
				if ($actionmode=='edit' or $actionmode=='insert') echo " disabled ";
						echo" onclick='PrintPreview();' $style	title='Print' /><span><span>Print</span></span></button>";

						echo"</td>";
				

			 
			 
			 
 
	 
			 

echo"</td></tr>";	

echo"<tr><td align=center id='content-body'>";

echo"<table border=0 width=90%><td width=3%></td><td>";




if($actionmode=='edit' or $actionmode=='view'){

	$query_edit="select vehicleMovement_id
					, date_format(vehiclemovement_start,'%d/%m/%Y') as vehiclemovement_start
					, date_format(vehiclemovement_end,'%d/%m/%Y') as vehiclemovement_end
					,vehiclemovement.place_id , null, vehiclemovement.vehicle_id,vehiclemovement.employee_id
					,place.fromplace_name as fromplace_name
					,place.toplace_name as toplace_name
					,vehicle.vehicle_platenumber
					,vehicle.vehicle_make
					, date_format(vehiclemovement_start,'%H:%i:%s') as starttime	
					, date_format(vehiclemovement_end,'%H:%i:%s') as endtime	
					, place.place_millage, place.place_millagetype
					,vehiclemovement.vehiclemovement_millage,vehiclemovement.vehiclemovement_millagetype
					,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 vehicle on vehicle.vehicle_id=vehiclemovement.vehicle_id 
				 where vehicleMovement_id='".$vehiclemovement_id."'";

	//echo $query_edit;
	$resultedit = mysql_query($query_edit, $connection)  or die(mysql_error());
	while($row=mysql_fetch_array($resultedit)){

		$vehiclemovement_id = $row[0];
		$vehiclemovement_start=$row[1];
		$vehiclemovement_end=$row[2];
		$place_id=$row[3];
		$toplace_id=$row[4];
		$vehicle_id=$row[5];
		$employee_id=$row[6];
		$fromplace_name=$row[7];
		$toplace_name=$row[8];
		$vehicle_platenumber=$row[9];
		$vehicle_make=$row[10];
		$starttime=$row[11];
		$endtime=$row[12];
		$vehiclemovement_millage=$row[15];
		$vehiclemovement_millagetype=$row[16];
		$vehiclemovement_reference=$row[17];
	}
}




if($actionmode==''){
$status='disabled';
$dis='disabled';

}

if($actionmode=='view'){

$status='readonly';
$dis='disabled';

}

if($actionmode=='insert')
$status='';

$style= "style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'";
 
 
 

echo"	<div class='tabber' id='tab1' style='width:990px; margin-top:10px; float:left; text-align:left;'>";

//$tabs = new tabs("vehicle");

//$tabs->start("Vehicle");
	  echo"	<div class='tabbertab'>
				<h2 title='Vehicle'>Vehicle</h2>";	
	echo"		<div id='datagrid-d' style='width:980px; height:200px; margin-top:5px; border:1px solid gray;'>";
	
echo"  
      <table border='0'  width='950px' align='center' valign='top'>
      <col width=100>
      <col width=250>
      <col width=120>
      <col width=250>
      
		 ";
echo"<tr bgcolor='#F7F7F7' height='35'>  
	<td valign='center' align='left' ><span class='style1'>Reference&nbsp;<span class='style26'></span></span>";
	 echo"</td>";

 echo"
		     <td>
			  <input type='text' name='vehiclemovement_reference' id='vehiclemovement_reference' value='$vehiclemovement_reference' style='font-size:12px; width:100px; height:18px;' readonly  />
			  </td><td></td><td></td>";

		 
echo"<tr bgcolor='#F7F7F7' height='35'>
             <td valign='center' align='left' ><span class='style1'>Start Date/Time&nbsp;<span class='style26'></span></span>";
	
			 echo"</td>";
			 
			 if($actionmode=='insert'){
					if ($vehiclemovement_start=='')
						{
							$today = date('d/m/Y');
							$vehiclemovement_start = $today;
						}	
					}			
				
					
			 echo"
		     <td>
			  <input type='text' name='vehiclemovement_start' id='vehiclemovement_start' value='$vehiclemovement_start' style='font-size:12px; width:100px; height:18px;' $status  />
			  ";
print <<<HERE
  	  <A HREF="#" onClick="displayCalendar(document.vehiclemovement.vehiclemovement_start,'dd/mm/yyyy',this); return false;" NAME="anchor1" ID="anchor1" >
HERE;
  echo"<image src='./img/cal.gif' border=0 align=center ></image></A>";			
			
			  if ($actionmode!=''){
	         $vehiclemovement_start = "disabled";
	         }

			if ($time=='')
				$time = date('H:i:s');
			
			
			
			echo" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
		
			if ($actionmode=='insert')
			if ($starttime=='00:00' or $starttime=='00:00:00' or $starttime=='')
				$starttime = date('H:i:s');
			
			if ($endtime=='00:00' or $endtime=='00:00')
				$endtime = '00:00:00';
				
				
			echo"<input type='time' name='starttime' $status  value='$starttime'></td>";
			

			echo"
             <td valign='center' align='left'><span class='style1'>End Date/Time&nbsp;<span class='style26'></span></span></td>
			 		 ";
	
			
			 		
				
					
			 echo"
		     <td>
			  <input type='text' name='vehiclemovement_end' id='vehiclemovement_end' value='$vehiclemovement_end' style='font-size:12px; width:100px; height:18px;' $status  />
			  ";
print <<<HERE
  	  <A HREF="#" onClick="displayCalendar(document.vehiclemovement.vehiclemovement_end,'dd/mm/yyyy',this); return false;" NAME="anchor1" ID="anchor1" >
HERE;
  echo"<image src='./img/cal.gif' border=0 align=center ></image></A>";			
			
			  if ($actionmode!=''){
	         $vehiclemovement_end = "disabled";
	         }
			 
			 echo" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			 
				
	 echo"<input type='time' name='endtime' $status  value='$endtime'> &nbsp;&nbsp;&nbsp;&nbsp;<u onMouseOver=\"style.cursor='pointer'\" onclick='setnow()'>Now</u></td>";
			echo" </tr>";
			
			
echo"<tr bgcolor='#F7F7F7'  height='35'><td valign='center' align='left' ><span class='style1'>From Place&nbsp;<span class='style26'>*</span></span></td>";

echo"<td>
<select   name='place_id' onchange=dosubmit(); value='".htmlspecialchars($place_id, ENT_QUOTES)."' style='font-size:12px; width:250px; height:18px;'  $status maxlength='15' />";
	
	$queryplace="select place_id,fromplace_name,toplace_name from place order by fromplace_name
				 ";
	$resultplace = mysql_query($queryplace, $connection);
	echo"<option value=''></option>";
	while($rowplace=mysql_fetch_array($resultplace)){
	echo"<option value='$rowplace[0]' ";
		if ($rowplace[0]==$place_id)
			echo " selected ";
	echo">$rowplace[1] -----> $rowplace[2]</option>";
	
	}



echo"</select >
";



	
$query1="select place_millagetype,place_millage from place where place_id = '".$place_id."'";
$result1 = mysql_query($query1, $connection);
$row1=mysql_fetch_array($result1);
echo "<font color=red>( ".$row1[1]." ".$row1[0] ." )</font>";

if($vehiclemovement_millage=='' and ($actionmode=='insert'))
	$vehiclemovement_millage = $row1[1];
	
if($vehiclemovement_millagetype=='' and ( $actionmode=='insert'))
	$vehiclemovement_millagetype = $row1[0];	


if ($vehiclemovement_millagetype=='Hrs')
	$s1=' selected ';
else	
if ($vehiclemovement_millagetype=='Km')
	$s2=' selected ';
else
if ($vehiclemovement_millagetype=='Miles')
	$s3=' selected ';
	
echo"
</td><td><span class='style1'>Millage</span></td><td><input type='text' name='vehiclemovement_millage' $status  value='$vehiclemovement_millage'>
<select name='vehiclemovement_millagetype' $status >
<option></option>
<option $s1>Hrs</option>
<option $s2>Km</option>
<option $s3>Miles</option>
</select>
</td></tr>";



	
	$queryvehicle = "select vehicle_id,vehicle_platenumber,employee.employee_id,concat(employee.employee_firstname,' ',employee.employee_lastname) from vehicle left join employee on employee.employee_id=vehicle.employee_id order by vehicle_platenumber";
	$resultvehicle = mysql_query($queryvehicle, $connection);
	



			
				
	echo"<tr bgcolor='#F7F7F7'  height='35'><td valign='center' align='left' ><span class='style1'>Vehicle&nbsp;<span class='style26'></span></span></td>";
		
	
	echo"     <td colspan=1><span class='style1'>";			
					{
					$queryvehicleemployee = "select vehicle_make,vehicle_platenumber from vehicle where vehicle_id = '".$vehicle_id."' ";
					//echo $queryvehicle;
					$resultvehicleemployee = mysql_query($queryvehicleemployee, $connection);
					while($vehicleemployee=mysql_fetch_row($resultvehicleemployee)){
					$vehicle_name = $vehicleemployee[0];
					$vehicle_platenumber = $vehicleemployee[1];
					}
					}
					if ($actionmode=='view' or $actionmode=='')
						$btnstatus = 'disabled';
				echo"</span>
				<input type='text' name='vehicle_platenumber' size=13  readonly value='$vehicle_platenumber'>
				<input type='text' name='vehicle_name'  readonly value='$vehicle_name'>
				<input type='hidden' name='vehicle_id' $status  style='border:0px;width:150px' readonly value='$vehicle_id'>
				<img src='img/scroll-down-1.png'  onMouseOver=\"style.cursor='pointer'\"   onMouseOver=\"style.cursor='pointer'\"  $btnstatus name='btnvehicle' onclick='openvehicle()'>
				</td>
				
				";
				
	

echo"<td><span class='style1'>Employee&nbsp;<span class='style26'></span></span></td>";
	
		
	
	 
	//if ($employee_id=='')
		if ($vehicle_id!='' and $employee_id =='')
			{
				$queryvehicleemployee = "select employee_id from vehicle where vehicle_id = '".$vehicle_id."' ";
				$resultvehicleemployee = mysql_query($queryvehicleemployee, $connection);
				$vehicleemployee=mysql_fetch_row($resultvehicleemployee);
				$employee_id = $vehicleemployee[0];
			}
	
	$queryemployee = "select employee_id,concat(employee_firstname,' ',employee_lastname) from employee where employee_id = '$employee_id'";
	
	$resultemployee = mysql_query($queryemployee, $connection);
	$employee=mysql_fetch_row($resultemployee);
	$employee_name = $employee[1];
	
	echo"     <td ><span class='style1'></span>
				<input type='hidden' name='employee_id'  value='$employee_id'>
				<input type='text' name='employee_name' $status  value='$employee_name'>
				<img src='img/scroll-down-1.png' name='btnvehicle' $btnstatus value='...' onclick='openemp()'>
				</td></tr>";
			
		/*		
	echo"<tr><td><span class='style1'>Charges&nbsp;<span class='style26'></span></span></td>";
	
		
	$querycharges = "select charges_id,charges_name from charges order by charges_name";
	$resultcharges = mysql_query($querycharges, $connection);
	
	
	
	echo"     <td ><span class='style1'><select name='charges_id' id='charges_id' style='height:20px; width:160px; font-size:10px;' $status >";
				echo"<option></option>";
				while($charges=mysql_fetch_row($resultcharges)){
				echo"<option ";
					if ($charges_id==$charges[0])
						echo " selected ";
					echo" value='$charges[0]'>$charges[1] </option>";
				}
				echo"</select></span></td></tr>";

				*/
	echo"</table>";
	
	
	echo"		</div>"; 	
	echo"	</div>";
		
	//$tabs->start("Charges");
	echo"	<div class='tabbertab'>
				<h2 title='Charges'>Charges</h2>";	
	echo"		<div id='datagrid-d' style='width:780px; height:350px; margin-top:5px; border:1px solid gray;'>";


echo"<table border=0 width='100%'>";
echo '<tr><td colspan="9" align="left" valign="top">';


print <<< HERE
       </td>
      </tr>
HERE;


print <<< HERE
		<tr><th height="15" colspan="9" align="center" valign="top"><span class="style3">Add Charges</span></th></tr>
		<tr bgcolor='#F7F7F7' >	
			 <td colspan='9' align='center'><font size='1' color='#FF0000' face='Verdana'><b>$message</b></font></td></tr>			 
       <tr>
      <td>
HERE;



if ($vehiclemovementcharges_id != ''){
$querydt= " select vehiclemovementcharges_id, vehiclemovement.vehicle_id
			,vehiclemovementcharges_note
			,vehicle.vehicle_platenumber,vehicle_make,charges.charges_name
			,charges.charges_id,charges.charges_name,vehiclemovementcharges_amount
			from vehiclemovementcharges 
			left join charges on charges.charges_id = vehiclemovementcharges.charges_id
			left join vehiclemovement on vehiclemovement.vehiclemovement_id = vehiclemovementcharges.vehiclemovement_id
			left join vehicle on vehicle.vehicle_id = vehiclemovement.vehicle_id
			 where vehiclemovementcharges_id='".$vehiclemovementcharges_id."' ";
		
	
    $resultdt = mysql_query($querydt, $connection)  or die(mysql_error());
	while($rowdt=mysql_fetch_row($resultdt)){
        $vehiclemovementcharges_id=$rowdt[0];
		$vehicle_id=$rowdt[1];
		$vehiclemovementcharges_note=$rowdt[2];
		$vehicle_platenumber=$rowdt[3];
		$vehicle_make=$rowdt[4];
		$charges_id=$rowdt[6];
		$charges_name=$rowdt[7];
		$vehiclemovementcharges_amount=$rowdt[8];
	}
}

echo"
<input type=hidden name='charges_id' value='$charges_id'>
<input type=hidden name='message' value='$message'>
<input type=hidden name='vehiclemovementcharges_id' value='$vehiclemovementcharges_id'>
";

$querydt= " select vehiclemovementcharges_id,vehicle_platenumber, vehicle_make, vehicle_platenumber 
			, vehiclemovementcharges_note ,vehiclemovementcharges_amount,charges_name
			from vehiclemovementcharges 
			left join vehiclemovement on vehiclemovement.vehiclemovement_id = vehiclemovementcharges.vehiclemovement_id
			left join vehicle on vehicle.vehicle_id = vehiclemovement.vehicle_id
			left join charges on charges.charges_id = vehiclemovementcharges.charges_id
		    where vehiclemovement.vehiclemovement_id='".$vehiclemovement_id."' ";



	echo"<table border='0' style='table-layout:fixed' align='left' valign='top'>
		  <col width=160>
		  <col width=120>
		  <col width=400>";

		  $query=" select vehicle_platenumber,vehicle_make from vehicle ,vehiclemovement
					where vehiclemovement.vehiclemovement_id= '".$vehiclemovement_id."'
					and vehicle.vehicle_id = vehiclemovement.vehicle_id
					";
		  $result = mysql_query($query, $connection) or die(mysql_error());
		  $row=mysql_fetch_array($result);
		  
		  
echo "<tr bgcolor='#F7F7F7'><td colspan=4><span class='style1'>Vehicle:   ".$row[0]." ".$row[1]."&nbsp;</span></td></tr>";

echo"<tr bgcolor='#F7F7F7'><td valign='center' align='left' ><span class='style1'>Charges&nbsp;<span class='style26'></span></span></td>";


{
echo"<td><input type='text' name='charges_name'  value='$charges_name' size='13'>";
echo"</label></td>";	
echo"<td colspan='2'><label>";
echo"<img src='img/scroll-down-1.png' title=' Select Vehicle '  width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick=showcharges()>";
echo"</label></td></tr>";
}


echo"<tr bgcolor=#F7F7F7><td><span class='style1'>Amount</span></td><td colspan=2><input type=text name='vehiclemovementcharges_amount' value='$vehiclemovementcharges_amount'  $status>";
echo"</td></tr>";				


	
echo"<tr bgcolor=#F7F7F7 ><td><span class='style1'>Note</span></td><td colspan=2><textarea  name='vehiclemovementcharges_note'   style='width:400px;height:50px'>$vehiclemovementcharges_note</textarea></td></tr>";

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


			
	echo"<tr><td ><table border=0 align=left width=100%> <tr bgcolor=#FFFFFF height='35'>";
		
	

	echo"<td align='center'><button type='button' name='btnPost' id='btnPost' value='Submit Charges' ";//post
	echo" onclick='SubmitRecordCharges();'  	title='Save Changes' /><span><span>Submit Charges</span></span></button></td>";

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


		echo"<tr><td valign='top' colspan=5>";
echo "<table style='table-layout:fixed' border=0>
		<col width=20>
		<col width=20>
		<col width=100>
		<col width=100>
		<col width=435>
		";
		
		
echo "<tr bgcolor='#F7F7F7'><td>&nbsp;</td><td>&nbsp;</td><td><span class='style27'>Charges&nbsp;<span class='style26'></span></span></td>
		<td><span class='style27'>Amount&nbsp;<span class='style26'></span></span></td>
		<td><span class='style27'>Note &nbsp;<span class='style26'></span></span></td>
		
      </tr>";
	  
	 

//echo $querydt;
$resultdt = mysql_query($querydt, $connection) or die(mysql_error());
while($rowsdt=mysql_fetch_array($resultdt)){
			    
	$ct+=1;

	if($ct%2==0)
		$Color="style='background-color:".$grid_color1."'";
	else			
		$Color="style='background-color:".$grid_color2."'";	
						
				
	echo "<tr ".$Color." >";
	echo "	<td align='center' valign='center'><span class='style15'><img src='img/edit.png'  onMouseOver=\"style.cursor='pointer'\" onclick=UpdateDetailCharges('".$rowsdt[0]."') title='Edit Record'  ></span></td>";
	echo "	<td align='center' valign='center'><span class='style15'><img src='img/delete.png'  onMouseOver=\"style.cursor='pointer'\" onclick=DeleteDetail('".$rowsdt[0]."') title='Delete Record'  ></span></td>";
	echo "	<td align='left'><span class='style15'>".$rowsdt[6]."</span></td>";
	echo "	<td align='left'><span class='style15'>".$rowsdt[5]."</span></td>";
	echo "	<td align='left'><span class='style15'>".$rowsdt[4]."</span></td>";
	
	
	echo "</tr>";
						
}	
	  
echo"</table>";						
echo"</table>";						
			
		echo"		</div>"; 	
	echo"	</div>";
	
	//$tabs->start("Items");	
	
	echo"	<div class='tabbertab'>
				<h2 title='Items'>Items</h2>";	
	echo"		<div id='datagrid-d' style='width:780px; height:350px; margin-top:5px; border:1px solid gray;'>";
	
echo"<table border=0 width='100%'>";
echo '<tr><td colspan="9" align="left" valign="top">';


print <<< HERE
       </td>
      </tr>
HERE;


print <<< HERE
		<tr><th height="15" colspan="9" align="center" valign="top"><span class="style3">Add Items</span></th></tr>
		<tr bgcolor='#F7F7F7' >	
			 <td colspan='9' align='center'><font size='1' color='#FF0000' face='Verdana'><b>$message</b></font></td></tr>			 
       <tr>
      <td>
HERE;



if ($vehiclemovementitems_id != ''){
$querydt= " select vehiclemovementitems_id, vehiclemovement.vehicle_id
			,vehiclemovementitems_note
			,vehicle.vehicle_platenumber,vehicle_make,items.item_description
			,items.item_code,items.item_description,vehiclemovementitems_quantity
			from vehiclemovementitems 
			left join items on items.item_code = vehiclemovementitems.item_code
			left join vehiclemovement on vehiclemovement.vehiclemovement_id = vehiclemovementitems.vehiclemovement_id
			left join vehicle on vehicle.vehicle_id = vehiclemovement.vehicle_id
			
			 where vehiclemovementitems_id='".$vehiclemovementitems_id."' 
			 
			 ";
		
	
    $resultdt = mysql_query($querydt, $connection)  or die(mysql_error());
	while($rowdt=mysql_fetch_row($resultdt)){
        $vehiclemovementitems_id=$rowdt[0];
		$vehicle_id=$rowdt[1];
		$vehiclemovementitems_note=$rowdt[2];
		$vehicle_platenumber=$rowdt[3];
		$vehicle_make=$rowdt[4];
		$item_code=$rowdt[6];
		$item_description=$rowdt[7];
		$vehiclemovementitems_quantity=$rowdt[8];
	}
}

echo"
<input type=hidden name='vehiclemovement_id' value='$vehiclemovement_id'>

<input type=hidden name='message' value='$message'>
<input type=hidden name='vehiclemovementitems_id' value='$vehiclemovementitems_id'>
";

$querydt= " select vehiclemovementitems_id,vehicle_platenumber, vehicle_make, vehicle_platenumber 
			, vehiclemovementitems_note ,vehiclemovementitems_quantity,items.item_description,items.item_code
			from vehiclemovementitems 
			left join vehiclemovement on vehiclemovement.vehiclemovement_id = vehiclemovementitems.vehiclemovement_id
			left join vehicle on vehicle.vehicle_id = vehiclemovement.vehicle_id
			left join items on items.item_code = vehiclemovementitems.item_code
		    where vehiclemovement.vehiclemovement_id='".$vehiclemovement_id."' ";



	echo"<table border='0' style='table-layout:fixed' align='left' valign='top'>
		  <col width=160>
		  <col width=120>
		  <col width=400>";

		  $query=" select vehicle_platenumber,vehicle_make from vehicle ,vehiclemovement
					where vehiclemovement.vehiclemovement_id= '".$vehiclemovement_id."'
					and vehicle.vehicle_id = vehiclemovement.vehicle_id
					";
					
		  $result = mysql_query($query, $connection) or die(mysql_error());
		  $row=mysql_fetch_array($result);
		  
		  
echo "<tr bgcolor='#F7F7F7'><td colspan=4><span class='style1'>Vehicle:   ".$row[0]." ".$row[1]."&nbsp;</span></td></tr>";

echo"<tr bgcolor='#F7F7F7'><td valign='center' align='left' ><span class='style1'>Items&nbsp;<span class='style26'></span></span></td>";


{
echo"<td >
<input type=text name='item_code' value='$item_code' style='width:150px'></td><td><table><tr><td>
<input type='text' name='item_description'  value='$item_description' size='13' style='width:250px'></td><td>";

echo"<img src='img/scroll-down-1.png' title=' Select Vehicle '  width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick=showitems()></td></tr></table>";
echo"</td></tr>";
}


echo"<tr bgcolor=#F7F7F7><td><span class='style1'>Quantity</span></td><td colspan=2><input type=text name='vehiclemovementitems_quantity' value='$vehiclemovementitems_quantity'  $status>";
echo"</td></tr>";				


	
echo"<tr bgcolor=#F7F7F7 ><td><span class='style1'>Note</span></td><td colspan=2><textarea  name='vehiclemovementitems_note' $status style='width:400px;height:50px'>$vehiclemovementitems_note</textarea></td></tr>";

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


			
	echo"<tr><td ><table border=0 align=left width=100%> <tr bgcolor=#D8D8D8 height='35'>";
		
	

	echo"<td align='center'><button type='button' name='btnPost' id='btnPost'   ";//post
	echo" onclick='SubmitRecordItem();'  title='Save Changes' /><span><span>Submit Item</span></span></td>";

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


		echo"<tr><td valign='top' colspan=5>";
echo "<table style='table-layout:fixed' border=0>
		<col width=20>
		<col width=20>
		<col width=100>
		<col width=300>
		<col width=100>
		<col width=200>
		";
		
		
echo "<tr bgcolor='#F7F7F7'><td>&nbsp;</td><td>&nbsp;</td>
<td><span class='style27'>Item&nbsp;<span class='style26'></span></span></td>
<td><span class='style27'>&nbsp;<span class='style26'></span></span></td>
		<td><span class='style27'>Quantity&nbsp;<span class='style26'></span></span></td>
		<td><span class='style27'>Note &nbsp;<span class='style26'></span></span></td>
		
      </tr>";
	  
	 

//echo $querydt;
$resultdt = mysql_query($querydt, $connection) or die(mysql_error());
while($rowsdt=mysql_fetch_array($resultdt)){
			    
	$ct+=1;

	if($ct%2==0)
		$Color="style='background-color:".$grid_color1."'";
	else			
		$Color="style='background-color:".$grid_color2."'";	
						
				
	echo "<tr ".$Color." >";
	echo "	<td align='center' valign='center'><span class='style15'><img src='img/edit.png'  onMouseOver=\"style.cursor='pointer'\" onclick=UpdateDetailItem('".$rowsdt[0]."') title='Edit Record'  ></span></td>";
	echo "	<td align='center' valign='center'><span class='style15'><img src='img/delete.png'  onMouseOver=\"style.cursor='pointer'\" onclick=DeleteDetailItems('".$rowsdt[0]."') title='Delete Record'  ></span></td>";
	echo "	<td align='left'><span class='style15'>".$rowsdt[7]."</span></td>";
	echo "	<td align='left'><span class='style15'>".$rowsdt[6]."</span></td>";
	echo "	<td align='left'><span class='style15'>".$rowsdt[5]."</span></td>";
	echo "	<td align='left'><span class='style15'>".$rowsdt[4]."</span></td>";
	
	
	echo "</tr>";
						
}	
	  
echo"</table></td></tr>";			
echo"</table>";			
	
	echo"</td></tr>";	
	
	
	echo"		</div>"; 	
	echo"	</div>";
	echo"	</div>";
	echo"</td></tr></table>";

	
	 
			 
		  

print <<< HERE
      
      </tr>  <tr height='30'><td align='center' id='content-bottom' ></td></tr>
	  </table>
HERE;
echo"<script type=\"text/javascript\" language=\"javascript\">";
echo"	tabberAutomatic(tabberOptions);";
echo"   vTabIndex = document.getElementById('PTabIndex').value; ";
echo"	if (document.getElementById('tab1')) document.getElementById('tab1').tabber.tabShow(vTabIndex); ";
echo"</script>";

print <<<HERE
</form>
</body>

HERE;

?>