<?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");


include("config.inc.php");



if ($modedt=='' and $actionmode=='edit')
	$modedt = 'add_employeevehicle';
	
if ($modedtaccidents=='' and $actionmode=='edit')
	$modedtaccidents = 'add_employeeaccidents';
	
 
 

//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_employee 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);
	}

$querysetup="select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2 from setup";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
extract($rowsetup);
}

if ($loginaccess=='' or $loginaccess==0)
	header("location:menu.php");

//User Access
$querylog=" select ifNull(FI_employeeApp,0) As FI_employeeApp, ifNull(FI_employeeDel,0) As FI_employeeDel, ".
          " ifNull(FI_employeeMod,0) As FI_employeeMod from ".$HTTP_SESSION_VARS['dbLabel'].".login where user_account='".$HTTP_SESSION_VARS['useraccount']."' and Upper(Login_Schema) = Upper('".$HTTP_SESSION_VARS['dbName']."')  ";
//echo $querylog; exit;
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

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


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


//Read From Setup Table							
$querysetup= " select grid_color1, grid_color2 from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

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

//Access Mode On Insert/Edit/Delete
$DelMode = '';
$ModMode = '';
if ($FI_employeeDel == 0)
	$DelMode = ' disabled ';
if ($FI_employeeMod == 0)
	$ModMode = ' disabled ';
	
	
if($actionmode=='edit' or $actionmode=='view'){

	$query_edit="select 
					employee_id, null, null, employee_firstname, employee_lastname
					, date_format(employee_birthdate,'%d/%m/%Y'), null, employee_licensenumber
					,date_format(employee_licenseexpirydate,'%d/%m/%Y')			
					, employee_note, employee_country, employee_city, employee_address, employee_telephone1
					, employee_telephone2
					from employee where employee_id='".$employee_id."'";

	 
	//echo $query_edit;
	$resultedit = mysql_query($query_edit, $connection);
	while($row=mysql_fetch_array($resultedit)){
			$employee_id = $row[0];
		
			$employee_firstname = $row[3];
			$employee_lastname = $row[4];
			$employee_birthdate =$row[5];
			
			$employee_licensenumber =$row[7];
			$employee_licenseexpirydate =$row[8];
			$employee_note =$row[9];
			$employee_country =$row[10];
			$employee_city =$row[11];
			$employee_address =$row[12];
			$employee_telephone1 =$row[13];
			$employee_telephone2 =$row[14];
			
	}
}



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" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<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 editmode () {
document.employee.actionmode.value='edit';
	document.employee.action="Form_Employee.php";
	document.employee.submit();
}

function addemployee () {
            ClearForm('All');
			document.employee.actionmode.value='insert';
			document.employee.action="Form_Employee.php?actionmode=insert";
			document.employee.submit();
}




function CancelRecord () {


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



function addvehicles(){
if (document.employee.employee_id.value!='')
	{
	var str = '';
	var employeeid = document.employee.employee_id.value;
	win = window.open('Form_EmployeeVehicle.php?employee_id='+employeeid, 'Form_EmployeeSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=775,height=450,top=100,left=100');		
	//win = window.open('Form_EmployeeVehicle.php?employee_id='+employeeid);		
	}
}

function addaccidents(){
if (document.employee.employee_id.value!='')
	{
	var str = '';
	var employeeid = document.employee.employee_id.value;
	win = window.open('Form_Employeeaccidents.php?employee_id='+employeeid+'&opener=employee', 'Form_EmployeeSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=775,height=450,top=100,left=100');		
	//win = window.open('Form_EmployeeVehicle.php?employee_id='+employeeid);		
	}
}

function SubmitRecord() {
		document.employee.action="Form_Employee_Actions.php";
		document.employee.submit();
}


function ClearPage(){
	if (confirm ( "Are you sure you want to Clear Page?"))
	{
		ClearForm('All');
		

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

//All= All form; D= Detail Part
function ClearForm(Option){
    x = document.employee;

x.employee_id.value='';
x.employee_firstname.value='';
x.employee_lastname.value='';
x.employee_birthdate.value='';
x.employee_licensenumber.value='';
x.employee_licenseexpirydate.value='';
x.employee_note.value='';
x.employee_country.value='';
x.employee_city.value='';
x.employee_address.value='';
x.employee_telephone1.value='';
x.employee_telephone2.value='';
x.employeevehicle_id.value='';
x.employeeaccident_id.value='';
x.PRef.value='';


	
	
}





   function PrintPreview() {
	var str = '';
	
	str = 'Form_EmployeePreview.php';
	window.open(str);

}




function Edit_Record(employeeId){

	document.employee.actionmode.value='edit';
	document.employee.employee_id.value=employeeId;
	document.employee.action="Form_Employee.php?mode=edit&employee_id="+employeeId;
	document.employee.submit();
}




function SetNextPage(startrange,perpage){
	document.employee.action='Form_Employee.php?PRef=&startrange='+startrange+'&perpage='+perpage;
	document.employee.submit();
}

function SetPrvPage(startrange,perpage){
	document.employee.action='Form_Employee.php?PRef=&startrange='+startrange+'&perpage='+perpage;
	document.employee.submit();
}

function set_limit(){

	perpage=document.employee.perpage.value;
	document.employee.action='Form_Employee.php?perpage='+perpage;
	document.employee.submit();
}



function confirm_delete(Code, employeeId) {
	var strReplaceAll = Code;
	var intIndexOfMatch = strReplaceAll.indexOf( "%20" );

	while (intIndexOfMatch != -1){
		strReplaceAll = strReplaceAll.replace( "%20", " " )
		intIndexOfMatch = strReplaceAll.indexOf( "%20" );
	}
	Code= strReplaceAll;
				
	
	if (confirm ( "Are you sure you want to Delete the employee " + Code + "?"))
	{
		document.employee.action="Form_Employee_Actions.php?actionmodedelete=delete&employeeid="+employeeId;
		document.employee.submit();
	}
	
	
							
}	


function SubmitRecordVehicle() {
    var x = document.employee;
	
		x.actionmode.value='edit';
		
		
		if (x.modedt.value=='')
		x.modedt.value = 'add_employeevehicle';
	else if (x.modedt.value=='edit_employeevehicle')
		x.modedt.value = 'edit_employeevehicle';
		
	if (x.vehicle_id.value =="")
	{
	alert("Vehicle is mandatory!");
	x.vehicle_platenumber.focus();
	return 0;
	}
	x.action="Form_Employee_Actions.php";
	x.submit();
	}
	
	
function showvehicle(str){
  window.open('Form_vehiclelist.php?str='+str,'mywindow','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}


function UpdateDetailVehicle(Code){
	x = document.employee;
	x.modedt.value='edit_employeevehicle';
	x.employeevehicle_id.value=Code;  
	x.action="Form_Employee.php?vTabFocus=Vehicle%20Driven";
	x.submit();
}

function DeleteDetailVehicle(Code){


if (confirm ( "Are you sure you want to Delete This Record ?"))
	{
		x = document.employee;
		x.modedt.value='delete_employeevehicle';
		x.employeevehicle_id.value=Code; 
		x.action="Form_Employee_Actions.php";
		x.submit();
	}
}




function SubmitRecordAccidents() {
    var x = document.employee;
	
	var vmode=x.modedtaccidents.value;	

	if (vmode=='add_employeeaccident')
		vmode = 'add_employeeaccident';
	else if (vmode=='edit_employeeaccidents')
		vmode = 'edit_employeeaccidents';
		
	if (x.vehicle_idaccidents.value =="")
	{
	alert("Vehicle is mandatory!");
	x.vehicle_platenumber.focus();
	return 0;
	}
	
	x.action="Form_Employee_Actions.php";
	x.submit();
	}
	
	



function showvehicleaccidents(){
window.open('Form_vehiclelistAccidents.php','mywindow','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}


function UpdateDetailAccidents(Code){


	x = document.employee;
	x.modedtaccidents.value='edit_employeeaccidents';
	x.employeeaccident_id.value=Code; 
	x.action="Form_Employee.php?vTabFocus=Accidents";
	x.submit();
}

function DeleteDetailAccidents(Code){

if (confirm ( "Are you sure you want to Delete This Record ?"))
	{
		x = document.employee;
		x.modedtaccidents.value='delete_employeeaccidents';
		x.employeeaccident_id.value=Code; 
		x.action="Form_Employee_Actions.php";
		x.submit();
	}
}

</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Add Employee</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;
}
.style11 {color: #999999; font-weight: bold; }
.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>
<LINK REL="stylesheet" TYPE="text/css" MEDIA="all" HREF="tabs.css">
</head>
<body >
<form enctype="multipart/form-data" method="post" name="employee">
<input type=hidden name='actionmode' value='$actionmode'>
<input type=hidden name='modedt' value='$modedt'>
<input type=hidden name='modedtaccidents' value='$modedtaccidents'>
<input type=hidden name='message' value='$message'>
<input type=hidden name='employee_id' value='$employee_id'>
<input type='hidden' name='PTabIndex' id='PTabIndex' value='$PTabIndex'>
HERE;



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"<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'>Employee</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"<table border=0 align=left width=800> <tr>

			 ";
			
	
			echo"	<td align=left>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button type='button'  value='Add Employee'";  	
			
			if($actionmode=='insert' or $actionmode=='edit')
			echo "disabled ";
			
			echo"onclick='addemployee()'  title='Add Employee' $InsMode><span><span>Add Employee</span></span></button>" ;
	
	
		/*echo"	<button type='button'  value='Vehicles Driven'";  	
			if ($actionmode=='')
						echo " disabled ";	
			echo"onclick='addvehicles()'   title='Add Vehicle' $InsMode><span><span>Vehicles Driven</span></span></button>" ;
			
		echo"	<button type='button'  ";  	
			if ($actionmode=='')
						echo " disabled ";	
			echo"onclick='addaccidents()'   title='Add Accident' $InsMode><span><span>Accidents</span></span></button>" ;	*/		
	
echo"           <button type='button' id='btnClear' name='BtnClear' value='Clear Page' ";

echo"  onclick='ClearPage();' 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();'   title='Cancel Changes'><span><span>Cancel</span></span></button>";
				
				
		if($actionmode=='view'){
echo"           <input type='button' name='btnEdit' id='btnEdit' value='Edit' ";//Edit
				
				
				echo" onclick='editmode();' $style	title='Edit Employee' />";
	}
else	{
echo"           <button type='button' name='btnPost' id='btnPost' value='Save' ";//post
				if ($actionmode=='')
						echo " disabled ";
				
				echo" onclick='SubmitRecord();' title='Save Changes' /><span><span>Save</span></span></button>";}


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

						echo"</td>";
				

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



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

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

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





  echo"	<div class='tabbertab'>
				<h2 title='Vehicle'>Employee</h2>";	
	echo"		<div id='datagrid-d' style='width:980px; height:250px; margin-top:5px; border:0px solid gray;'>";
 


	
//1st column	  
echo"  
        <table border='0' width='950px' align='left' valign='top'><tr>
		<td width='280px' valign=top>";
echo"<table border='0' align='left' valign='top'>";

echo"<tr bgcolor='#F7F7F7'><td><span class='style1'>First Name</span></td><td><input type='text' name='employee_firstname' value='$employee_firstname' $status></td></tr>";		
echo"<tr bgcolor='#F7F7F7'><td><span class='style1'>Last Name</span></td><td><input type='text' name='employee_lastname' value='$employee_lastname' $status></td></tr>";		


						

echo"<tr bgcolor=#F7F7F7><td><span class='style1'>Birth Date</span></td><td><input type=text name='employee_birthdate' value='$employee_birthdate'  $status>";
print <<<HERE
  	  <A HREF="#" onClick="displayCalendar(document.employee.employee_birthdate,'dd/mm/yyyy',this); return false;" NAME="anchor1" ID="anchor1" >
HERE;
  echo"<image src='./img/cal.gif' border=0 align=center ></image></A>";			
echo"</td></tr>";				
			
echo"<tr bgcolor=#F7F7F7 ><td><span class='style1'>Note</span></td><td><textarea  name='employee_note' $status style='height:50px'>$employee_note</textarea></td></tr>";				
echo"</table>";


echo"</td>";
//2nd column	  
echo"<td width='350px'  valign=top>";
echo"<table>";
echo"<tr  bgcolor='#F7F7F7'><td><span class='style1'>License Number</span></td><td><input type=text name='employee_licensenumber' value='$employee_licensenumber' $status></td></tr>";

echo"<tr bgcolor=#F7F7F7><td><span class='style1'>License Expiry Date</span></td><td><input type=text name='employee_licenseexpirydate' value='$employee_licenseexpirydate' $status>";
print <<<HERE
  	  <A HREF="#" onClick="displayCalendar(document.employee.employee_licenseexpirydate,'dd/mm/yyyy',this); return false;" NAME="anchor1" ID="anchor1" >
HERE;
  echo"<image src='./img/cal.gif' border=0 align=center ></image></A>";		
echo"</td></tr>";
//echo"<tr bgcolor=#F7F7F7 height='30px'> <td></td><td bgcolor=#F7F7F7></tD></tr>";
echo"<tr bgcolor=#F7F7F7><td><span class='style1'>Country</span></td><td><input type=text name='employee_country' value='$employee_country' $status></td></tr>";				
echo"<tr bgcolor=#F7F7F7><td><span class='style1'>City</span></td><td><input type=text name='employee_city' value='$employee_city' $status></td></tr>";
echo"<tr bgcolor=#F7F7F7><td><span class='style1'>Address</span></td><td><input type=text name='employee_address' value='$employee_address' $status></td></tr>";

echo"<tr bgcolor=#F7F7F7><td><span class='style1'>Tel1.</span></td><td><input type=text name='employee_telephone1' value='$employee_telephone1' $status></td></tr>";
echo"<tr bgcolor=#F7F7F7><td><span class='style1'>Tel2.</span></td><td><input type=text name='employee_telephone2' value='$employee_telephone2' $status>";
echo"</td></tr>";





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

//3rd column	  	
echo"<td width='300px' valign=top>";		  
echo"<table>";

echo"<tr  bgcolor='#F7F7F7'><td colspan='2'><span class='style1'>
	Image";
	echo'<input name="MAX_FILE_SIZE" value="102400" type="hidden">';
echo'<input name="image" accept="image/jpeg" type="file">';
	
	echo"</td>
	</tr>";

	
echo"<tr><td colspan='2'><span class='style1'>
	
	<image src='./employeeimage.php?employeeid=$employee_id' border=0 width='300px' height='200px' align=center ></image></A>
	
	</td>
	</tr>";
echo"</table>";
echo"</td>";
echo"</tr>";
echo"</table>";
	echo"		</div>"; 	
	echo"	</div>";
	
	
		echo"	<div class='tabbertab'>
				<h2 title='vehicledriven'>Vehicle Driven</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 Vehicles</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 ($employeevehicle_id != ''){
$querydt= " select employeevehicle_id, employeevehicle.employee_id, vehicle_platenumber,vehicle_make
			, date_format(employeevehicle_startdate,'%d/%m/%Y') , date_format(employeevehicle_enddate,'%d/%m/%Y'), employeevehicle_note,employeevehicle.vehicle_id
			from employeevehicle left join vehicle on vehicle.vehicle_id = employeevehicle.vehicle_id
		    where employeevehicle_id='".$employeevehicle_id."' ";
			
	
    $resultdt = mysql_query($querydt, $connection) or die(mysql_error());
	while($rowdt=mysql_fetch_row($resultdt)){
        $employeevehicle_id=$rowdt[0];
		$employee_id=$rowdt[1];
		$vehicle_id=$rowdt[7];
		$vehicle_platenumber=$rowdt[2];
		$vehicle_make=$rowdt[3];
		$employeevehicle_startdate=$rowdt[4];
		$employeevehicle_enddate=$rowdt[5];
		$employeevehicle_note=$rowdt[6];
	}
}

echo"
<input type=hidden name='vehicle_id' value='$vehicle_id'>
<input type=hidden name='message' value='$message'>
<input type=hidden name='employeevehicle_id' value='$employeevehicle_id'>

";

$querydt= " select employeevehicle_id, employeevehicle.employee_id, vehicle_platenumber,vehicle_make ,vehicle_platenumber
			, date_format(employeevehicle_startdate,'%d/%m/%Y'), date_format(employeevehicle_enddate,'%d/%m/%Y'), employeevehicle_note
			from employeevehicle left join vehicle on vehicle.vehicle_id = employeevehicle.vehicle_id
		    where employeevehicle.employee_id='".$employee_id."' ";



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

echo "<tr bgcolor='#F7F7F7'><td>&nbsp;</td><td>&nbsp;</td><td colspan='2'></td></tr>";

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

echo"<td><input type='text' name='vehicle_platenumber' $status value='$vehicle_platenumber' size='13' style='width:160px'>";
echo"</label></td>";	
echo"<td colspan='2'><label>";
echo"<input type='text' name='vehicle_make' $status value='$vehicle_make' size='40'>&nbsp;<img src='img/btnopen.jpg' title=' Select Vehicle '  width='15' height='17' border='0'  onMouseOver=\"style.cursor='hand'\" onClick='showvehicle(6); return false'>";
echo"</label></td></tr>";


echo"<tr bgcolor=#F7F7F7><td><span class='style1'>Start Date</span></td><td colspan=2><input type=text name='employeevehicle_startdate' value='$employeevehicle_startdate'  $status>";
print <<<HERE
  	  <A HREF="#" onClick="displayCalendar(document.employee.employeevehicle_startdate,'dd/mm/yyyy',this); return false;" NAME="anchor1" ID="anchor1" >
HERE;
  echo"<image src='./img/cal.gif' border=0 align=center ></image></A>";			
echo"</td></tr>";				

echo"<tr bgcolor=#F7F7F7><td><span class='style1'>End Date</span></td><td colspan=2><input type=text name='employeevehicle_enddate' value='$employeevehicle_enddate'  $status>";
print <<<HERE
  	  <A HREF="#" onClick="displayCalendar(document.employee.employeevehicle_enddate,'dd/mm/yyyy',this); return false;" NAME="anchor1" ID="anchor1" >
HERE;
  echo"<image src='./img/cal.gif' border=0 align=center ></image></A>";			
echo"</td></tr>";				


	
echo"<tr bgcolor=#F7F7F7 ><td><span class='style1'>Note</span></td><td colspan=2><textarea  name='employeevehicle_note' $status style='width:400px;height:50px'>$employeevehicle_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='SubmitRecordVehicle();' 	title='Save Changes' /><span><span>Submit Vehicle</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=100>
		<col width=100>
		<col width=70>
		<col width=500>";
		
		
echo "<tr  class='Search-Label-bg'><td>&nbsp;</td><td>&nbsp;</td><td><span class='style4'>Vehicle #&nbsp;<span class='style26'></span></span></td>
		<td><span class='style4'>Vehicle Name&nbsp;<span class='style26'></span></span></td>
		<td><span class='style4'>Vehicle Plate# &nbsp;<span class='style26'></span></span></td>
		<td><span class='style4'>Start date</span></td>
		<td><span class='style4'>End date</span></td>
		<td><span class='style4'>Note</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='style5'><img src='img/edit.png'  onMouseOver=\"style.cursor='hand'\" onclick=UpdateDetailVehicle('".$rowsdt[0]."') title='Edit Record'  ></span></td>";
	echo "	<td align='center' valign='center'><span class='style5'><img src='img/delete.png'  onMouseOver=\"style.cursor='hand'\" onclick=DeleteDetailVehicle('".$rowsdt[0]."') title='Delete Record'  ></span></td>";
	echo "	<td align='left'><span class='style5'>".$rowsdt[2]."</span></td>";
	echo "	<td align='left'><span class='style5'>".$rowsdt[3]."</span></td>";
	echo "	<td align='left'><span class='style5'>".$rowsdt[4]."</span></td>";
	echo "	<td align='left'><span class='style5'>".$rowsdt[5]."</span></td>";
	echo "	<td align='left'><span class='style5'>".$rowsdt[6]."</span></td>";
	echo "	<td align='left'><span class='style5'>".$rowsdt[7]."</span></td>";
	
	echo "</tr>";
						
}	
	  
echo"</table>";						
		

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

	
		echo"		</div>"; 	
	echo"	</div>";
	
	
	
	
	echo"	<div class='tabbertab'>
				<h2 title='Accident'>Accidents</h2>";	
	echo"		<div id='datagrid-d' style='width:980px; height:300px; 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 Accidents</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 ($employeeaccident_id != ''){
$querydt= " select employeeaccident_id, employeeaccident.employee_id, employeeaccident.vehicle_id
			,employeeaccident_startdate
			,employeeaccident_reference
			,employeeaccident_note
			,vehicle.vehicle_platenumber,vehicle_make
			,employee.employee_id,concat(employee.employee_firstname,employee.employee_lastname) as employee_name
			from employeeaccident left join vehicle on vehicle.vehicle_id = employeeaccident.vehicle_id
			left join employee on employee.employee_id = employeeaccident.employee_id
		    where employeeaccident_id='".$employeeaccident_id."' ";

	
    $resultdt = mysql_query($querydt, $connection) or die(mysql_error());
	while($rowdt=mysql_fetch_row($resultdt)){
        $employeeaccident_id=$rowdt[0];
		$employee_id=$rowdt[1];
		$vehicle_idaccidents=$rowdt[2];
		$employeeaccident_startdate=$rowdt[3];
		$employeeaccident_reference=$rowdt[4];
		$employeeaccident_note=$rowdt[5];
		$vehicle_platenumberaccidents=$rowdt[6];
		$vehicle_makeaccidents=$rowdt[7];
		$employee_unitnumber=$rowdt[8];
		$employee_name=$rowdt[9];
	}
}

echo"
<input type=hidden name='vehicle_idaccidents' value='$vehicle_idaccidents'>
<input type=hidden name='message' value='$message'>
<input type=hidden name='employeeaccident_id' value='$employeeaccident_id'>
<input type=hidden name='opener' value='$opener'>

";

$querydt= " select employeeaccident_id,vehicle_platenumber, vehicle_make, vehicle_platenumber, employeeaccident_startdate 
			, employeeaccident_reference  , employeeaccident_note 
			from employeeaccident left join vehicle on vehicle.vehicle_id = employeeaccident.vehicle_id
			left join employee on employee.employee_id = employeeaccident.employee_id
		    where employeeaccident.employee_id='".$employee_id."' ";



	echo"<table border='0'  align='left' valign='top'>
		  <col width=160>
		  <col width=120>
		  <col width=600>";

echo "<tr bgcolor='#F7F7F7'><td>&nbsp;</td><td>&nbsp;</td><td colspan='2'></td></tr>";

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



echo"<td><input type='text' name='vehicle_platenumberaccidents'  value='$vehicle_platenumberaccidents' size='13' style='width:160px;'>";
echo"</label></td>";	
echo"<td colspan='2'><label>";
echo"<input type='text' name='vehicle_makeaccidents'  value='$vehicle_makeaccidents' size='40'>&nbsp;<img src='img/btnopen.jpg' title=' Select Vehicle '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick=showvehicleaccidents()>";
echo"</label></td></tr>";


echo"<tr bgcolor=#F7F7F7><td><span class='style1'>Date</span></td><td colspan=2><input type=text name='employeeaccident_startdate' value='$employeeaccident_startdate'  $status>";
print <<<HERE
  	  <A HREF="#" onClick="displayCalendar(document.employee.employeeaccident_startdate,'dd/mm/yyyy',this); return false;" NAME="anchor1" ID="anchor1" >
HERE;
  echo"<image src='./img/cal.gif' border=0 align=center ></image></A>";			
echo"</td></tr>";				

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


	
echo"<tr bgcolor=#F7F7F7 ><td><span class='style1'>Note</span></td><td colspan=2><textarea  name='employeeaccident_note' $status style='width:400px;height:50px'>$employeeaccident_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' value='Submit Accident' ";//post
	echo" onclick='SubmitRecordAccidents();' title='Save Changes' /><span><span>Submit Accident</span></span></button></td>";

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


		echo"<tr><td valign='top' colspan=7>";
echo "<table   border=0>
		<col width=20>
		<col width=20>
		<col width=100>
		<col width=100>
		<col width=100>
		<col width=70>
		<col width=350>";
		
		
echo "<tr class='Search-Label-bg'><td>&nbsp;</td><td>&nbsp;</td><td><span class='style4'>Vehicle #&nbsp;<span class='style4'></span></span></td>
		<td><span class='style4'>Vehicle Name&nbsp;<span class='style4'></span></span></td>
		<td><span class='style4'>Start date</span></td>
		<td><span class='style4'>Reference</span></td>
		<td><span class='style4'>Note</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='style5'><img src='img/edit.png'  onMouseOver=\"style.cursor='hand'\" onclick=UpdateDetailAccidents('".$rowsdt[0]."') title='Edit Record'  ></span></td>";
	echo "	<td align='center' valign='center'><span class='style5'><img src='img/delete.png'  onMouseOver=\"style.cursor='hand'\" onclick=DeleteDetailAccidents('".$rowsdt[0]."') title='Delete Record'  ></span></td>";
	echo "	<td align='left'><span class='style5'>".$rowsdt[1]."</span></td>";
	echo "	<td align='left'><span class='style5'>".$rowsdt[2]."</span></td>";
	echo "	<td align='left'><span class='style5'>".$rowsdt[4]."</span></td>";
	echo "	<td align='left'><span class='style5'>".$rowsdt[5]."</span></td>";
	echo "	<td align='left'><span class='style5'>".$rowsdt[6]."</span></td>";
	
	echo "</tr>";
						
}	
	  
echo"</table></td></tr>";						
echo"</table>";						
		
	
			echo"	</div>";		echo"	</div>";
 
	
	
		echo"	</div>";
	
	echo"</td></tR></table>";







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



echo"<tr><td  id='content-body'><table><tr><td width=3% > </tD><td>";




echo"<table border='0' align=left style='table-layout:fixed;width:990px' >
	  <col width=3%>
	  <col width=3%>
	  <col width=22%>
	  <col width=22%>
	  <col width=30%>
	  <col width=20%>
		     
	  <tr bgcolor='#DDDDDD'>
	    <td align='center' colspan='6'><span class='style16'></span></td></tr>
	  <tr bgcolor='#DDDDDD' height=30px>
	    <td align='left' colspan='3'><span class='style1'>Search by Name/No</span></td>
		<td align='left' colspan=2><span class='style1'><input type='text' name='PRef' id='PRef' value='$PRef' size='15' maxlength='30'/><input type='hidden' name='PMode' id='PMode' value='$PMode' size='15' maxlength='30'/></span>
		    <button type='submit' name='Submit' value='Find'  /><span><span>Find</span></span></button>
			<button type='button' name='btnCancel' value='Cancel' onclick='ClearForm();'/><span><span>Cancel</span></span></button></td>
		<td  colspan=1 align='right' valign='center'><span class='style25'>Result per page </span><span class='style1'><select name='perpage' id='perpage' value='$perpage' onchange=set_limit();>";
              


        if ($perpage==20)
			$s20 = 'selected';
		else if ($perpage==30)
			$s30 = 'selected';
		else if ($perpage==40)
			$s40 = 'selected';
		else if ($perpage==50)
			$s50 = 'selected';

			
				
        echo'<option '.$s20.' value="20">20</option>
			 <option '.$s30.' value="30">30</option>
			 <option '.$s40.' value="40">40</option>
			 <option '.$s50.' value="50">50</option>
			 </select></span></td>';
			 
echo" </tr>";

	 echo" <tr bgcolor='#DDDDDD'>
		<td height='15' align='center' colspan='6'><font size='1' color='#FF0000' face='Verdana'><b>".$message."</b></font></td>
	  </tr>	";
	  
	  echo"
	  <tr  class='Search-Label-bg'>
		<td  height='25' align='center'><span class='style4'>&nbsp;</span></td>
		<td  height='25' align='center'><span class='style4'>&nbsp;</span></td>
		<td  height='25' align='left'><span class='style4'>First Name</span></td>";
		
		echo"<td  height='25' align='center' ><span class='style4'>Last Name </span></td>";
		
		echo"<td  height='25' align='center' ><span class='style4'>Address </span></td>";
		
		echo"<td  height='25' align='center' ><span class='style4'>Tel1. </span></td>	";
	  echo"</tr>";
		
$querysearch="select null,
					employee_id,  null, employee_firstname, employee_lastname
					, date_format(employee_birthdate,'%d/%m/%Y'), null, employee_licensenumber
					,date_format(employee_licenseexpirydate,'%d/%m/%Y')			
					, employee_note, employee_country, employee_city, employee_address, employee_telephone1
					, employee_telephone2 from employee ";


$querysearch=$querysearch." where 	employee_firstname like"."('%".$PRef."%')
									or employee_lastname like"."('%".$PRef."%')
									or employee_licensenumber like"."('%".$PRef."%')
									or employee_telephone1 like"."('%".$PRef."%')
									or employee_city like"."('%".$PRef."%')
									 ".

                          "  order by employee_lastname";

$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());
$totalrows = mysql_num_rows($resultsearch);
	
if ($startrange=='')
	$startrange = 0;
if ($perpage=='')
	$perpage = 20;
		
$querysearch = $querysearch." limit ".$startrange.",".$perpage;
$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());		


while($rows=mysql_fetch_array($resultsearch)){
		
	extract($rows);
	$ct+=1;

	if($ct%2==0)
		$Color="style='background-color:".$grid_color1."'";
	else			
		$Color="style='background-color:".$grid_color2."'";	
			

	echo'<tr '.$Color.'>';
	
	
print<<<HERE
	

HERE;
	
	
	
print<<<HERE
	
	
	
<td align=center width='3%'><img border='0' src='img/edit.png' width='20' height='20' title='Edit Detail' onmouseover="this.style.cursor='pointer'" onclick="Edit_Record('$rows[1]')" $ModMode ></td>


<td align=center width='3%'><img border='0' src='img/delete.png' width='20' height='20' title='Delete Detail' onmouseover="this.style.cursor='pointer'" OnClick="confirm_delete('$rows[4]','$rows[1]')" $DelMode></td>



HERE;
	

print<<<HERE


HERE;


echo"
<td ><font face='Arial' size='2' color='#186194'><span class='style5'>$rows[3]&nbsp;</span></font></td>
<td ><font face='Arial' size='2' color='#186194'><span class='style5'>$rows[4]&nbsp;</span></font></td>
<td ><font face='Arial' size='2' color='#186194'><span class='style5'>$rows[12]&nbsp;</span></font></td>
<td ><font face='Arial' size='2' color='#186194'><span class='style5'>$rows[13]&nbsp;</span></font></td>

";
echo"</tr>";


}
echo"</table></td></tR></table></td></tr>";
echo"   <tr><td  id='content-body' colspan='5'>&nbsp;</td></tr>
		<tr><td  id='content-body' colspan=5>
		<table width='100%' border=0>
		<tr><td width='260'>&nbsp;</td>
		<td width='150' align='center'>";
		
		$diff= $startrange - $perpage;
		
		if (($diff) >= 0 ){
			$prvstartrange = $startrange - $perpage;
			echo"<img src='img/arrowleft.jpg' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."')>";
		}
		else
			echo "&nbsp;";
		
		echo"</td><td width='150' align='center'>";
		
		
		if ($startrange <= $totalrows){
			$startrange = $startrange + $perpage;
			if  ($startrange <= $totalrows)
				echo"<img src='img/arrowright.jpg' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange."','".$perpage."')>";
		} else
			echo "&nbsp;";
			
		echo"</td><td width='170'>&nbsp;</td></tr>";
								
echo"</table>";
		
echo"</td></tr>";


print <<< HERE
      
    <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;

?>














