<?php
include("../include/config.php");
require_once "../include/Database_functions.php";
?>

  <table  border="0" cellspacing="0" cellpadding="0" class="tableList" style="margin-left:20px; ">
  <tr class="heading">
    <td>No</td>    
    <td>Client</td>
	 <td>Group</td>
    <td>Route</td>
	<td>Towns</td>
	<td>Distance(KM)</td>
    <td align="center">Edit</td>
    <td align="center">Delete</td>
  </tr>
  
  <?php

$client_name ='';


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



$i=1;
$sq_arr="select * from cf_route where 1 ";
if($client_name!=''){
$sq_arr.=" and route_client_code = '$client_name' ";
}


/*if($sdate_12!=''){
$sq_arr.=" and date='".$sdate."' ";
}*/
$sq_arr.=" order by route_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){
$pagecnt=$start;
while($res=mysql_fetch_array($array))
{
$pagecnt++;
$townqry=mysql_query("select town from cf_route_town   where route_id='".$res['route_id']."' ");
while($objtown=mysql_fetch_object($townqry)){
$townsid=$objtown->town;
$seltown=mysql_query("select district from cf_district where district_id ='".$townsid."'");
$objtownname=mysql_fetch_object($seltown);
$townsnames.=$objtownname->district.',';
}
$townsnames=substr($townsnames,0,-1);
//------------get the clientname-----------------------//
$s=mysql_query("select client_name from cf_client_parent where client_id='".$res['route_client_name']."'");
			$o=mysql_fetch_object($s);
			$sclient_name=$o->client_name;
			//------------get the clientname-----------------------//
$ssub=mysql_query("select client_newcode from cf_client where client_sub_id='".$res['route_client_code']."'");
			$osub=mysql_fetch_object($ssub);
			$sclient_codename=$osub->client_newcode;
  ?> 
  <tr>
    <td><?php echo $pagecnt;?></td>
    <td><a href="#login-box" class="login-window"><?php echo $sclient_codename;?></a></td>
	 <td><a href="#login-box" class="login-window"><?php echo $sclient_name;?></a></td>
    <td><a href="#login-box" class="login-window"><?php echo $res['route_name'];?></a></td>
    <td><a href="#login-box" class="login-window"><?php echo $townsnames;?></a></td>
    <td><a href="#login-box" class="login-window"><?php echo $res['routedistance'];?></a></td>
   <td align="center" class="tr_td_b"><a href="add-route.php?client_main=<?=$res['client_id']?>&client_name=<?=$client_name?>&page=<?php echo $page; ?>&routeid=<?php echo $res['route_id']; ?>&ab=<?php echo $i;?>"><img src="images/edit.png" title="edit"></a></td>
   
   <td align="center" class="tr_td_r" ><a href="route_list.php?client_main=<?=$res['client_id']?>&client_name=<?=$client_name?>&page=<?php echo $page; ?>&del=delete&id=<?php echo $res['route_id']; ?>" onClick="return confirm('Do you really want to delete this field?');"><img src="images/delete.png" title="delete"></a></td>
    
   
  </tr>
  <?php 
    }}else{?>
	 <tr>
    <td class="errorMessage" style="border-right:0px;border-bottom:0px; "><font color="#FF0000">No Records Found</font></td></tr>
	<? }
  ?> 
   
</table>
  
   <div align="right" style="padding-top:10px;"><?=$pagination?></div>