<?php

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


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");
	
	
//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);
}
if ($modedt=='')
	$modedt='insert';

 

print <<<HERE

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
<script type="text/javascript" language="javascript">

function ShowDetail() {
		if(document.vehicleservice.ShowDt.checked){
			document.vehicleservice.Ledger_ShowDt.value=1;

		}
		else
		{
			document.vehicleservice.Ledger_ShowDt.value=0;

		}
}



function SubmitRecord() {
    var x = document.vehicleservice;
	
	var vmode=x.modedt.value;	
	if (vmode=='insert')
		vmode = 'add_vehicleservice';
	else if (vmode=='edit')
		vmode = 'edit_vehicleservice';
		
	if (x.service_id.value =="")
	{
	alert("Service is mandatory!");
	x.service_description.focus();
	return 0;
	}
	x.action="Form_Vehicle_Actions.php?actionmode="+vmode;
	x.submit();
	}
	
	



function showservice(str){

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


function UpdateDetail(Code){


	x = document.vehicleservice;
	x.modedt.value='edit';
	x.vehicleservice_id.value=Code; 
	 
	x.action="Form_VehicleServices.php";
	x.submit();
}

function DeleteDetail(Code){


if (confirm ( "Are you sure you want to Delete This Record ?"))
	{
		x = document.vehicleservice;
		x.modedt.value='delete';
		x.vehicleservice_id.value=Code; 
		x.action="Form_Vehicle_Actions.php?actionmode=delete_vehicleservice";
		x.submit();
	}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Vehicle Service</title>


<script type="text/javascript" src="dropdown.js"></script>
<link rel="stylesheet" href="default.css" type="text/css" />
<link rel="stylesheet" href="dropdown.css" type="text/css" />
<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 name='vehicleservice' method='post'>
<input type=hidden name='modedt' value='$modedt'>
<input type=hidden name='vehicle_id' value='$vehicle_id'>


HERE;

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

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 Services</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 ($vehicleservice_id != ''){
$querydt= " select vehicleservice_id, vehicleservice.vehicle_id, vehicleservice.service_id
			,date_format(vehicleservice_startdate,'%d/%m/%Y') 
			,vehicleservice_reference
			,vehicleservice_note
			,vehicle.vehicle_platenumber,vehicle_make
			,service.service_description
			,concat(service_frequency,' ',service_repeattype,' or ' ,service_odometer,' (odometer unit)')
			from vehicleservice left join vehicle on vehicle.vehicle_id = vehicleservice.vehicle_id
			left join service on service.service_id = vehicleservice.service_id
		    where vehicleservice_id='".$vehicleservice_id."' ";
		
	
    $resultdt = mysql_query($querydt, $connection);
	while($rowdt=mysql_fetch_row($resultdt)){
        $vehicleservice_id=$rowdt[0];
		$vehicle_id=$rowdt[1];
		$service_id=$rowdt[2];
		$vehicleservice_startdate=$rowdt[3];
		$vehicleservice_reference=$rowdt[4];
		$vehicleservice_note=$rowdt[5];
		$vehicle_platenumber=$rowdt[6];
		$vehicle_make=$rowdt[7];
		$service_description=$rowdt[8];
		$service_frequency=$rowdt[9];
	}
}

echo"
<input type=hidden name='service_id' value='$service_id'>
<input type=hidden name='message' value='$message'>
<input type=hidden name='vehicleservice_id' value='$vehicleservice_id'>
<input type=hidden name='opener' value='$opener'>

";





	echo"<table border='0' cellspacing=5 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='style4'>Service&nbsp;<span class='style26'></span></span></td>";



echo"<td><input type='text' name='service_description'  value='$service_description' size='25'>";
echo"</label></td>";	
echo"<td colspan='2'><label><table><tr><Td>";
echo"<input type='text' name='service_frequency'  value='$service_frequency' size='20'></td><Td><img src='img/scroll-down-1.png' title=' Select Service '  width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick=showservice()></td></tr></table>";
echo"</label></td></tr>";


echo"<tr bgcolor=#F7F7F7><td><span class='style4'>Date</span></td><td colspan=2><input type=text name='vehicleservice_startdate' value='$vehicleservice_startdate'  $status>";
print <<<HERE
  	  <A HREF="#" onClick="displayCalendar(document.vehicleservice.vehicleservice_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='style4'>Reference</span></td><td colspan=2><input type=text name='vehicleservice_reference' value='$vehicleservice_reference'  $status>";
echo"</td></tr>";				


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


echo"<tr bgcolor='#F7F7F7'><td valign='center' align='left' ><span class='style4'>Status</span></td>";
echo"<td>";
echo"<select name='service_status'>";

if ($service_status=='N' or $service_status=='')
	$s1 = ' selected ';
else	
if ($service_status=='C' )
	$s2 = ' selected ';
else if ($service_status=='S' )
	$s3 = ' selected ';
echo"<option value='N' $s1>Not Completed</option>";
echo"<option value='C' $s2>Completed</option>";
echo"<option value='S' $s3>Skipped</option>";

echo"</select >";
echo" </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='SubmitRecord();' title='Save Changes' /><span><span>Submit Record</span></span></td>";

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

	

		echo"<tr ><td valign='top' colspan=5>";
echo "<table style='table-layout:fixed' border=0 width='100%'>
		<col width=20>
		<col width=20>
		<col width=200>
		<col width=175>
		<col width=100>
		<col width=100>
		


		";
		
		
echo "<tr  class='Search-Label-bg'><td>&nbsp;</td><td>&nbsp;</td><td><span class='style4'>Service&nbsp;<span class='style26'></span></span></td>
		<td><span class='style4'>Frequencey&nbsp;<span class='style26'></span></span></td>
		<td><span class='style4'>Date &nbsp;<span class='style26'></span></span></td>
		<td><span class='style4'>Status</span></td>
		
      </tr>";
	  
	 
$querydt= " select vehicleservice_id,service_description,vehicleservice_id,vehicle_platenumber, vehicle_make, vehicle_platenumber, date_format(vehicleservice_startdate,'%d/%m/%Y') 
			, vehicleservice_reference  , vehicleservice_note 
			,concat(service_frequency,' ',service_repeattype,' or ' ,service_odometer,' (odometer unit)')
			,if(service_status='N','Not Completed',if(service_status='C','Completed','Skipped')) 
			from vehicleservice left join vehicle on vehicle.vehicle_id = vehicleservice.vehicle_id
			left join service on service.service_id = vehicleservice.service_id
		    where vehicleservice.vehicle_id='".$vehicle_id."' ";
//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='hand'\" onclick=UpdateDetail('".$rowsdt[0]."') title='Edit Record'  ></span></td>";
	echo "	<td align='center' valign='center'><span class='style15'><img src='img/delete.png'  onMouseOver=\"style.cursor='hand'\" onclick=DeleteDetail('".$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[9]."</span></td>";
	echo "	<td align='left'><span class='style5'>".$rowsdt[6]."</span></td>";
	echo "	<td align='left'><span class='style5'>".$rowsdt[10]."</span></td>";
	//echo "	<td align='left'><span class='style15'>".$rowsdt[8]."</span></td>";
	
	
	echo "</tr>";
						
}	
	  
echo"</table>";						
		

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


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

HERE;

?>