<?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>Insurance</td>
    <td>Tax</td>
    <td>Fittness</td>   
	<td>Pollution</td>   
	<td>Service</td>  
	<td>National Permit</td>
	<td>State Permit</td>
    <td>Edit</td>
    <td>Delete</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='';
$typenames='';
$model='';
$regowner='';
$capacity='';
$insurestat='';
$taxstat='';
$fitstat='';
$pollstat='';
$servstat='';
if(isset($_REQUEST['billno'])){
$veh_num=$_REQUEST['billno'];
}

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

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

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

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

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

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

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

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

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

$todaydate = date("Y-m-d");
$i=1;
$sq_arr="select * from cf_vehicle where  (idate < NOW() + INTERVAL 5 DAY AND idate >= NOW()  or tdate < NOW() + INTERVAL 5 DAY AND tdate >= NOW() or fitdate < NOW() + INTERVAL 5 DAY AND fitdate >= NOW() or pollution_date < NOW() + INTERVAL 5 DAY AND pollution_date >= NOW() or service_date < NOW() + INTERVAL 5 DAY AND service_date >= NOW() or national_permit_dt < NOW() + INTERVAL 5 DAY AND national_permit_dt >= NOW() or state_permit_dt < NOW() + INTERVAL 5 DAY AND state_permit_dt >= NOW())  ";
if($veh_num!=''){
$sq_arr.=" and vehiclenum = '".$veh_num."' ";
}

if($typenames!=''){
$sq_arr.=" and type like '%".$typenames."%' ";
}

if($model!=''){
$sq_arr.=" and manufacture like '%".$model."%' ";
}

if($typenames!=''){
$sq_arr.=" and type like '%".$typenames."%' ";
}

if($capacity!=''){
$sq_arr.=" and maxcapacity like '%".$capacity."%' ";
}

if($insurestat!=''){

	if($insurestat == 'Expired')
	{
		$sq_arr.=" and idate < '".$todaydate."' ";
	}
	else
	{
		$sq_arr.=" and idate > '".$todaydate."'";
	}
}

if($taxstat!=''){

	if($taxstat == 'Expired')
	{
		$sq_arr.=" and tdate < '".$todaydate."'";
	}
	else
	{
		$sq_arr.=" and tdate > '".$todaydate."'";
	}
}

if($fitstat!=''){

	if($fitstat == 'Expired')
	{
		$sq_arr.=" and fitdate < '".$todaydate."'";
	}
	else
	{
		$sq_arr.=" and fitdate > '".$todaydate."'";
	}
}

if($pollstat!=''){

	if($pollstat == 'Expired')
	{
		$sq_arr.=" and pollution_date < '".$todaydate."'";
	}
	else
	{
		$sq_arr.=" and pollution_date > '".$todaydate."'";
	}
}

if($servstat!=''){

	if($servstat == 'Expired')
	{
		$sq_arr.=" and service_date < '".$todaydate."'";
	}
	else
	{
		$sq_arr.=" and service_date > '".$todaydate."'";
	}
}

/*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']));
  ?> 
  <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>
    <?php 
		$insval = '';
		$insdate = $res['idate'];
		if($insdate != '0000-00-00')
		{
		if($insdate < $todaydate)
		   {
				$insval =  "Expired";
		   }
		   else
		   {
		   		$insval =  "Not Expired";
		   }
		 }  
	?>    
    <td><?php echo $insval;?></td>
    <?php 
		$taxval = '';
		$taxdate = $res['tdate'];
		if($taxdate != '0000-00-00')
		{
		if($taxdate < $todaydate)
		   {
				$taxval =  "Expired";
		   }
		   else
		   {
		   		$taxval =  "Not Expired";
		   }
		 }  
	?>    
    <td><?php echo $taxval;?></td>
    
    
    <?php 
		$fitval = '';
		$fitdate = $res['fitdate'];
		if($fitdate != '0000-00-00')
		{
		if($fitdate < $todaydate)
		   {
				$fitval =  "Expired";
		   }
		   else
		   {
		   		$fitval =  "Not Expired";
		   }
		 }  
	?>    
    <td><?php echo $fitval;?></td>
	
	<?php 
		$pollval = '';
		$polldate = $res['pollution_date'];
		if($polldate != '0000-00-00')
		{
		if($polldate < $todaydate)
		   {
				$pollval =  "Expired";
		   }
		   else
		   {
		   		$pollval =  "Not Expired";
		   }
		}   
	?>    
    <td><?php echo $pollval;?></td>
	
	
	 <?php 
		$serval = '';
		$serdate = $res['service_date'];
		if($serdate != '0000-00-00')
		{
		if($serdate < $todaydate)
		   {
				$serval =  "Expired";
		   }
		   else
		   {
		   		$serval =  "Not Expired";
		   }
		 }  
	?>    
    <td><?php echo $serval;?></td>
	
	<?php 
		$natval = '';
		$natdate = $res['national_permit_dt'];
		if($natdate != '0000-00-00')
		{
		if($natdate < $todaydate)
		   {
				$natval =  "Expired";
		   }
		   else
		   {
		   		$natval =  "Not Expired";
		   }
		 }  
	?>    
    <td><?php echo $natval;?></td>
	
	<?php 
		$stateval = '';
		$statedate = $res['state_permit_dt'];
		if($statedate != '0000-00-00')
		{
		if($statedate < $todaydate)
		   {
				$stateval =  "Expired";
		   }
		   else
		   {
		   		$stateval =  "Not Expired";
		   }
		 }  
	?>    
    <td><?php echo $stateval;?></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>
   
   <td align="center" class="tr_td_r" ><a href="vechicle-list.php?del=delete&id=<?php echo $res['id']; ?>" onClick="return confirm('Do you really want to delete this field?');"><img src="images/delete.png" title="delete" /></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>