<?php

$i=1;
include("../include/config.php");
require_once "../include/Database_functions.php";
?>
  <table  border="0" cellspacing="0" cellpadding="0" class="tableList">
  <tr class="heading">
    <td>No</td>    
    <td>Vehicle Number</td>
    <td>Manufacture</td>  
    <td>Capacity</td>  
   	<td>Present Km</td>
	<td>Gearoil Changed Km</td>
	<td>Upcoming Change Km</td>
	<td>Gearoil Status</td>       
    <td>Edit</td>
  </tr>
  
  <?php
if(isset($_REQUEST['todate_12'])){
$sdate_12=$_REQUEST['todate_12'];
$todate_12=explode("-",$sdate_12);
$sdate=$todate_12[2].'-'.$todate_12[1].'-'.$todate_12[0];
}
$veh_num='';
$gear_oil='';
$gearstat='';

if(isset($_REQUEST['veh_num'])){
$veh_num=$_REQUEST['veh_num'];
}

if(isset($_REQUEST['gear_oil'])){
$gear_oil=$_REQUEST['gear_oil'];
}


$todaydate = date("Y-m-d");
$i=1;
$sq_arr="select * from cf_vehicle where open_km > 0 and gear_change > 0 and gear > 0  ";
if($veh_num!=''){
$sq_arr.=" and vehiclenum = '".$veh_num."' ";
}

if($gear_oil ==''){
	$sq_arr.=" and open_km > (gear_change+gear-500)";
}

if($gear_oil!=''){

	if($gear_oil == 'Expired')
	{
		$sq_arr.=" and open_km > (gear_change+gear) ";
	}
	else
	{
		$sq_arr.=" and open_km > (gear_change+gear-500)";
	}
}




/*if($sdate_12!=''){
$sq_arr.=" and date='".$sdate."' ";
}*/
$sq_arr.=" order by id desc ";
$query=$sq_arr;
//echo $query;
$function="Searchdate";
include("../paging.php");
$sq_arr.=" LIMIT $start, $limit";

if(isset($_REQUEST['page'])){
$page=$_REQUEST['page'];
}else{
$page=10;
}

$array=mysql_query($sq_arr);
if($array && mysql_num_rows($array)>0){
while($res=mysql_fetch_array($array))
{

$dd=date("m-d-Y",strtotime($res['add_date']));
		$insval = '';
		$openkm = $res['open_km'];
		$gear = $res['gear'];
		$gear_change = $res['gear_change'];
		$gearval = $gear+$gear_change;
  ?> 
  <tr>
    <td><?php echo $res['id'];?></td>
    
    <td><a href="#login-box" class="login-window"  data-id=<?php echo $res['id'];?>><?php echo $res['vehiclenum'];?></a></td>
    <td><?php if($res['manufacture']!='')echo $res['manufacture'];else echo '--'; ?></td>
    <td><?php if($res['maxcapacity']!='')echo $res['maxcapacity'];else echo '--'; ?></td>
    <td><?php if($res['open_km']!='')echo $res['open_km'];else echo '--'; ?></td>
	  <td><?php if($res['gear_change']!='')echo $res['gear_change'];else echo '--'; ?></td>
	   <td><?php echo $gearval; ?></td>
	 <?php 
		
		
		if($openkm > $gearval)
		   {
				$insval =  "Expired";
		   }
		   else
		   {
		   		$insval =  "Upcoming";
		   }
	?>    
    <td><?php echo $insval;?></td>
   
    <td align="center" class="tr_td_b"><a href="vechicle-details-entry.php?page=<?php echo $page; ?>&id=<?php echo $res['id']; ?>&ab=<?php echo $i;?>"><img src="images/edit.png" title="edit"></a></td>
   
  </tr>
  <?php 
    }}
  ?>
 
  <!--<tr>
    <td><input type="checkbox">2</td>
    <td>2323d</td>
    <td>jinesh</td>
    <td>jose</td>
    <td>9443274636</td>
    <td>email@gmail.com</td>
    <td>design</td>
    <td>designer</td>
    <td>23/4/11</td>
    <td><div class="deletedStat"></div></td>
    <td><a href="#">
      <div class="actEdit"></div><div class="actDelete"></div>
    </a></td>
  </tr>-->

   
</table>
  
   <div align="right" style="padding-top:10px;"><?=$pagination?></div>
   <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
   <script type="text/javascript" src="../js/jqmin1.js"></script>
<script src="../js/popup1.js" type="text/javascript"></script>