<?php

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


include("config.inc.php");
include("function.inc.php");
include("form_tracking_functions.php");


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

//$fueltype_id 		 = $_POST["fueltype_id"]; if ($fueltype_id == ""){$fueltype_id = $_GET["fueltype_id"];} 

//User Access
$querylog=" select ifNull(FI_vehicleFuelTypeApp,0) As FI_vehicleFuelTypeApp, ifNull(FI_vehicleFuelTypeDel,0) As FI_vehicleFuelTypeDel,".
          "ifNull(FI_vehicleFuelTypeMod,0) As FI_vehicleFuelTypeMod from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['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_vehicleFuelType as loginaccess from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' 	and Upper(Login_Schema) = Upper('".$_SESSION['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_vehicleFuelTypeApp == 0)
	$InsMode = ' disabled ';


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


if($mode=='editmode'){

$query_edit="select fueltype_id,fueltype_description, ifnull(fuel_amountPerLtr,0) from fueltype 
			where fueltype_id = '".$fueltype_id."'";
						  
//echo $query_edit;exit;
	$resultedit = mysql_query($query_edit, $connection);
	while($row=mysql_fetch_array($resultedit)){

		$fueltype_id			= $row[0];
		$fueltype_description	= $row[1];
		$fueltype_AmntLtr		= $row[2];
		
	}
	$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="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<script type="text/javascript" src="js/tabsClass/tabber.js"></script>
<link rel="stylesheet" href="js/tabsClass/tabber.css" type="text/css" />


<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">

<script type="text/javascript" language="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
			};
			

function calculatetotal(){
	var newqty = document.getElementById('newqty').value;
	var newamount = document.getElementById('newamount').value;
	var total=newqty*newamount;
	document.getElementById('newtotal').value=total;
	
}			
function postchangecarfuel(fueltype_id,carfuel_id){
	
	var mainmode='';
	var newdate = document.getElementById('newdate').value;
	var vehicle_id = document.getElementById('vehicle_id').value;
	var newqty = document.getElementById('newqty').value;
	var newamount = document.getElementById('newamount').value;
	var newtotal = document.getElementById('newtotal').value;
	var newremark = document.getElementById('newremark').value;
	if (newqty==''){alert('quantity is mandatory');
	return false;}
	if (newamount==''){alert('amount is mandatory');
	return false;}

		
		if (carfuel_id=='')
			mainmode='insertcarfuel';
		else mainmode='updatecarfuel';

		
		
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 	
					document.getElementById('fuelresults').innerHTML=xmlhttp.responseText;
					
				}
		}
  }

  

xmlhttp.open("GET","Form_TrackingFuel_Actions.php?mainmode="+mainmode+"&newdate="+newdate+"&newqty="+newqty+"&newamount="+newamount+
"&newtotal="+newtotal+"&newremark="+newremark+"&fueltype_id="+fueltype_id+"&carfuel_id="+carfuel_id+"&vehicle_id="+vehicle_id,true);

xmlhttp.send();


}

function showvehiclelist(str){
	window.open('List_vehicle.php?str='+str,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');

}


function clearfields(fueltype_id){	
	
	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 	
					document.getElementById('fuelresults').innerHTML=xmlhttp.responseText;
					
				}
		}
  }

  

xmlhttp.open("GET","Form_TrackingFuel_Actions.php?mainmode=cleardata"+"&fueltype_id="+fueltype_id,true);

xmlhttp.send();

	
}


function getcarfuel(carfuel_id,fueltype_id){
	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 	
					document.getElementById('fuelresults').innerHTML=xmlhttp.responseText;
					
				}
		}
  }

  

xmlhttp.open("GET","Form_TrackingFuel_Actions.php?mainmode=getcarfuel"+"&carfuel_id="+carfuel_id+"&fueltype_id="+fueltype_id,true);

xmlhttp.send();
	
	
}

function deletecarfuel(carfuel_id,fueltype_id){
	
	if (confirm ( "Are you sure you want to Delete this Record ?")){
	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 	
					document.getElementById('fuelresults').innerHTML=xmlhttp.responseText;
					
				}
		}
  }

  

xmlhttp.open("GET","Form_TrackingFuel_Actions.php?mainmode=deletecarfuel"+"&carfuel_id="+carfuel_id+"&fueltype_id="+fueltype_id,true);

xmlhttp.send();
	}
	
}

function Addfueltype () {
ClearForm('All');
				document.fueltype.mode.value='insert';
				document.fueltype.actionmode.value='insert';
				document.fueltype.action="Form_TrackingFuel.php";
				document.fueltype.submit();
}




function CancelRecord () {


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






function SubmitRecord() {

		
if (document.fueltype.fueltype_description.value=='' )
{
	alert('Unable to save : check missing field Name ');
	document.getElementById("fueltype_description").focus();
}		
	else {
		if (document.fueltype.fueltype_id.value == ''){
			document.fueltype.mode.value = 'insert';
			document.fueltype.actionmode.value = 'insert';
		}
		else if (document.fueltype.fueltype_id.value != ''){
			document.fueltype.mode.value = 'edit';
			document.fueltype.actionmode.value = 'edit';
		}
		document.fueltype.action="Form_TrackingFuel_Actions.php";
		document.fueltype.submit();
		
	}


}


function ClearPage(){
	if (confirm ( "Are you sure you want to Clear Page?"))
	{
		ClearForm('All');
		x.action='Form_TrackingFuel.php';
		x.submit();
	}	
}

//All= All form; D= Detail Part
function ClearForm(Option){
    x = document.fueltype;
	x.fueltype_id.value ='';
	x.mode.value ='';
	x.actionmode.value ='';
	x.fueltype_description.value ='';
	x.fueltype_AmntLtr.value ='';
	}



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

}


function Edit_Record(fueltypeid){

document.fueltype.actionmode.value='edit';
document.fueltype.fueltype_id.value=fueltypeid;
fueltype.action="Form_TrackingFuel.php?mode=edit&fueltype_id="+fueltypeid;
fueltype.submit();
}

function clearform()
{
  document.fueltype.PRef.value='';
  document.fueltype.action='Form_TrackingFuel.php';
  document.fueltype.submit();

}

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

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

function set_limit(){

	perpage=document.fueltype.perpage.value;
	document.fueltype.action='Form_TrackingFuel.php?perpage='+perpage;
	document.fueltype.submit();
}



function confirm_delete(Code, fueltypeId) {
	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 Fuel Type " + Code + "?"))
	{
		document.fueltype.action="Form_TrackingFuel_Actions.php?actionmodedelete=delete&fueltypeid="+fueltypeId;
		document.fueltype.submit();
	}
	
	
							
}



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



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

.style15 {color: #5151FF; font-size: 10px;}
.style26 {color: #FF0000}
.style28 {color: #FFFFFF ;font-size: 10px;}
.style44{
	color: #ffffff;
    font-weight: bold;
    font-size: 12px;
    font-family: Verdana, Arial, Helvetica, sans-serif;
}
/* Hide HTML5 Up and Down arrows. */
input[type="number"]::-webkit-outer-spin-button, input[type="number"]::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
input[type="number"] {
-moz-appearance: textfield;
}
</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='fueltype' method='post'>
<input type=hidden name='mode' value='$mode'>
<input type=hidden name='actionmode' value='$mode'>
<input type=hidden name='message' value='$message'>
<input type=hidden name='fueltype_id' value='$fueltype_id'>
<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'>Fuel type</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";

	 
	
echo"<tr>
		<td  height='34'  valign='top' id='content-top2'>
			<table border='0' cellpadding='0' cellspacing='0' class='layout-width'>
			<tr>
				<td width='38'  height='34'>&nbsp;</td>";
				
			echo "	<td valign='middle' height='34' width='720px'>";
echo"		<button type='button' id='btnClear' name='btnClear' onclick='ClearPage(); return false;' title='Clear Page'><span><span>Clear Page</span></span></button>";


echo"		<button type='button' id='btnPost' name='btnPost' onclick='Addfueltype(); return false;' ";
	if($mode=='insert' or $mode=='edit')
			echo "disabled ";
			
	echo" title='Add Fuel Type' $Insmode><span><span>Add Fuel Type</span></span></button> ";
	
					
echo"<button type='button' name='btnCancel' id='btnCancel'  ";//cancel
				if ($mode=='' )
					echo " disabled ";
				echo" onclick='CancelRecord();'   title='Cancel Changes'><span><span>Cancel</span></span></button>";
	

echo"           <button type='button' name='btnPost' id='btnPost'   ";//post
				if ($mode=='')
						echo " disabled ";
				
				echo" onclick='SubmitRecord();' $style	title='Save Changes' ><span><span>Save</span></span></button>";


				
echo"   </td><td align='center' width='260px'>
	
	<input type='text' name='PRef' id='PRef' value='$PRef' size='13' 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><td align='left'><span class='style1'><b><font size=1>Results/page</b></span>
	 <span class='style1'><select name='perpage' id='perpage' value='$perpage' onchange=set_limit();>";
	 
	if ($startrange=='')
		$startrange = 0;
	if ($perpage=='')
		$perpage = 20;
		
	for($i=10;$i<=$maxperpage;$i=$i+10){
		if($i==$perpage)
			echo "<option value='$i'  selected>$i</option>";
		else echo "<option value='$i'>$i</option>";
		
	} 
	 echo"</td></tr>";
echo"	</table>";
echo"</td></tr>";

echo"<tr><td id='content-body'>";
echo"<table border='0'  align='center' valign='top' width=100% class='tablecontent'>
	<col width=65%>";

echo"   <tr bgcolor='#F7F7F7'><td valign='top'>";	 

 
		  
	
echo"<tr min-height='100'>
			<td align='center' >";
			 echo"   <div class='tabber' id='tab1' style='width: 1100px; min-height:350px; margin-left: 0px;  margin-top:10px; float:left; text-align:left;'> ";
			$styleoption=" style='vertical-align:middle; width:152px; font-family:monospace; font-size:initial ; font-weight:bold;'";
				////
			echo"	<div class='tabbertab'>
					<h2 title='main'>Main</h2>";
		echo"		<div id='datagrid-d1' style='width:1080px; min-height:450px; margin-top:5px; border:0px solid gray;'>";
	
	
	
	
			//begin main
			
	echo "<div id='maindiv' >";
	/////////////
	echo"<table border='0'  align='center' valign='top' width=100% class='tablecontent'>
		<col width=45%><col width=50%><col width=5%>";

			echo"   <tr bgcolor='#F7F7F7'><td valign='top'>";	 

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

			echo"<tr bgcolor='#F7F7F7'><td valign='center' align='left' ><span class='style1'>Name<span class='style26'>*</span></span></td>";
			echo"<td><input type='text' name='fueltype_description' value='".htmlspecialchars($fueltype_description, ENT_QUOTES)."' style='font-size:12px; width:400px; height:18px;'  $status maxlength='40' /></td>
					</tr>";
			echo "<tr bgcolor='#F7F7F7'>
					<td valign='center' align='left'><span class='style1'>Amount Per Liter</span></td>
					<td><input type='number' name='fueltype_AmntLtr' id='fueltype_AmntLtr' value='$fueltype_AmntLtr' $status style='font-size:12px; width:100px; height:18px;'> $base1 </td>
				</tr>";
			echo"</table></td>";

			echo"<td  valign='top' align='right'>";

				echo"<table style='width:450px;background-color:#ffffff;' border='0' cellspacing=0 >
					<tr><td style='width:450px;height: 20px;border-top: 2px solid darkgray;border-left: 2px solid darkgray;border-right: 2px solid darkgray;border-radius: 10px 10px 0px 0px;' ></td>
					</tr>
					 <tr><td  valign='top' style='width:450px;border-left: 2px solid darkgray;border-right: 2px solid darkgray;'>
					 <table style='width:450px;' border='0' cellspacing=0><col width=25><col width=25><col width=260><col width=140>
						<tr height='30px'><td colspan='2'>&nbsp;</td><td align='center'><span class='style1'><b>Description</b></span></td><td align='center'><span class='style1'><b>Amount</b></span></td></tr>
					</table>
				</td>
				
		</tr>";
									 
	echo"<tr><td style='border-left: 2px solid darkgray;border-right: 2px solid darkgray;'>
		<div style='overflow-y:scroll;overflow-x:hidden;height:400px;width:450px;border:0px solid #000000;padding-left:5px;'>
			<table  border='0' width='445px'>
				<col width=25><col width=25><col width=260><col width=135>";
	


$querysearch="select fueltype_id,fueltype_description, ifnull(fuel_amountPerLtr,0) from fueltype ";
$querysearch=$querysearch." where (fueltype_description like"."('%".$PRef."%') )".
                          " order by fueltype_description ";
//echo$querysearch;

	$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)){
		$ct+=1;
		$stylefont='style15';
		if($ct%2==0)
			$Color="style='background-color:".$grid_color1."'";
		else			
			$Color="style='background-color:".$grid_color2."'";	
				
		if($mode=='edit' && $fueltype_id==$rows[0]){
			
			$Color="style='background-color:#1e87a5'";
			$stylefont='style28';
	}	
		
	echo'<tr '.$Color.' height="20px" >';
	
	if($FI_vehicleFuelTypeDel==1)	
print<<<HERE

<td align=center ><img border='0' src='img/c_delete.png' width='9' height='10' title='Delete Record' onmouseover="this.style.cursor='pointer'" OnClick="confirm_delete('$code', '$rows[0]')" $DelMode></td>

HERE;
else print<<<HERE

<td align=center >&nbsp;</td>

HERE;

	if($FI_vehicleFuelTypeMod==1)
		echo"<td align=center> <img border='0' src='img/button_edit.png' width='12' height='12' title='Edit Record' onMouseOver=\"style.cursor='hand'\" onclick=\"SetWh('$rows[0]');\"></td>";
	else echo "<td></td>";
	
	echo "<td><span class='$stylefont' >$rows[1]</span></font></td><td><span class='$stylefont' >$rows[2]</span></font></td>";

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

echo"<tr height='50px'><td style='border-left: 2px solid darkgray;border-right: 2px solid darkgray; border-bottom: 2px solid darkgray;'>
		<table width=100% border='0'><tr><td align='center' width=50%>";
		
		$diff= $startrange - $perpage;
		
		if (($diff) >= 0 ){
			$prvstartrange = $startrange - $perpage;
			echo"<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."')>";
		}
		else
			echo "&nbsp;";
		
		echo"</td><td  align='center'  width=50%>";
		
		
		if ($startrange <= $totalrows){
			$startrange = $startrange + $perpage;
			if  ($startrange <= $totalrows)
				echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange."','".$perpage."')>";
		} else
			echo "&nbsp;";
			
		echo"</td></tr><tr><td style='width:450px;height:20px;'></td></tr></table></td></tr>";
			


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

									
										echo "</div>";
		
		echo "	</div></div>";
			//end main
			//begin fuel
				echo"	<div class='tabbertab'>
					<h2 title='fuel'>Fuel</h2>";
echo"		<div id='datagrid-d1' style='width:1080px; height:450px; margin-top:5px; border:0px solid gray;'>";
		
echo "<div id='fuelresults'>";
		draw_fuel($connection,$fueltype_id,$carfuel_id);
echo "</div>";
		
			
echo "</div></div>";
			//end fuel
echo "</div></td></tr>";

echo "</table> ";

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

print <<< HERE
       </td>
      </tr>  <tr height='30'><td align='center' id='content-bottom' ></td></tr>
	  </table>
HERE;


print <<<HERE
</form>
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>";
echo "</body>";



?>