<?
ob_start();
session_start();
if(isset($_SESSION['ses_name']))
{
$user=$_SESSION['ses_name'];
}else{
header("location:index.php");
}


$veh_num='';
$sdate_12 ='';
$page='1';$client_main='';
include("include/config.php");
require_once "include/Database_functions.php";
$sqlObj=new sqlclass();
$msg = '';
$client_namek ='';
if(isset($_REQUEST['client_name'])){
$client_namek=mysql_escape_string($_REQUEST['client_name']);
}
if(isset($_REQUEST['del']) && $_REQUEST['del']=='delete')
{
	$id = $_REQUEST['id'];
	if(isset($_REQUEST['client_main']))
	$client_main=$_REQUEST['client_main'];
	$sql=mysql_query("delete from cf_route where route_id='".$id."'");
	header("location:route_list.php?client_main=".$client_main."&page=".$page."&client_name=".$client_namek."&msg=You Have Successfully Deleted");
}

?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Supply Chain Management</title>
<link href="css/styles.css" rel="stylesheet"  />
<link href="css/menu.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jqmin1.js"></script>
<script src="js/popup1.js" type="text/javascript"></script>
<script language="javascript">
function getXMLHTTP()
	 { //fuction to return the xml http object
	var xmlhttp=false;	
		try
		{
		xmlhttp=new XMLHttpRequest();
		}
		catch(e)	
		{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
				}
			catch(e)
			{
				try
				{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1)
				{
				xmlhttp=false;
				}
			}
		}
	return xmlhttp;
	}   


function Searchdate(page,val)
{ 
	var page=page;	
	var strURL="ajax/route_data.php?&page="+page;
	if(val!=''){
	strURL+="&client_name="+val;
	}
	var req = getXMLHTTP();
   if (req)
   {
     req.onreadystatechange = function()
     {
		 
			if ((req.readyState == 0)||(req.readyState == 1)||(req.readyState == 2)||(req.readyState == 3))
      		{
			//document.getElementById('order').innerHTML='<div align="center"><img src="'+path+'images/ajax_loader.gif"/></div>';
			//document.getElementById('Cakeorder').innerHTML='<div align="center"><img src="'+path+'images/ajax_loader.gif"/></div>';
			}
		 
		 
      if (req.readyState == 4)
      {
	 // only if "OK"
	 	if (req.status == 200)
	 	{ 
	   document.getElementById('list').innerHTML=req.responseText;
	//	document.getElementById('Cakeorder').innerHTML=req.responseText;
	 	}
	  else 
	 	{
   	   alert("There was a problem while using XMLHTTP:\n" + req.statusText);

	 }
     }
     }
   req.open("GET", strURL, true);
   req.send(null);
   }
}
//code select
function showClientcodedropdown(str){
var xmlhttp;    
if (str=="")
  {
  document.getElementById("txtcodeshow").innerHTML="";
  Searchdate(1,str);
  return;
  }
  
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("txtcodeshow").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","clientajax_code_dropdown.php?str="+str,true);
xmlhttp.send();
}
</script>
</head>

<body>
<!------------------popup area (view, edit)--------------->



<!---------------popup area ends------------------>
<div class="wrapper">
   <div>
<?php 
	include("header.php");
?>
 
</div>
 
 <div class="tabbedArea" style="position:relative; margin-top:">

  
  <div class="tabBody">
   <h1>Manage Route</h1>
   <form name="district_frm" id="district_frm" method="post"  >
   <div class="searchBox" style="width:93%; margin-right:0px;  padding:0px; ">
   <div style="padding:20px;">
    <div class="searchField">
     <p class="input1">Client</p>
       
   <select class="input1 input3" name="client_name" onChange="showClientcodedropdown(this.value);">
     <option value="">select Client</option>
     	 <?php 
		 if(isset($_REQUEST['client_main']) && $_REQUEST['client_main']!=''){
		 $client_main=mysql_escape_string($_REQUEST['client_main']);
		 }
        	$sq_district="select * from  cf_client_parent";
			$arr=mysql_query($sq_district);
			while($resdistrict=mysql_fetch_array($arr))
			{
		?>
			<option value="<?=$resdistrict['client_id']?>" <? if($client_main==$resdistrict['client_id']){?>selected="selected" <? }?>><?=$resdistrict['client_name']?></option>
        <?php
				}
	 ?>
     </select>
	 
     <!--<input type="text" name="client_name" id="client_name" class="input1" />-->
    </div>
	<div style="padding:20px;">
    <div class="searchField">
     <p class="input1" style="padding-left:50px; " id="txtcodeshow">
     <?
	 if(isset($client_namek) && $client_namek!=''){
	 $sq_arrdrp=mysql_query("select * from cf_client where client_id = '".$client_main."'  ");
	 ?>
	  <select class="input1 input3" name="client_code" id="client_code" onChange="Searchdate('1',this.value);">
                     <option value="">select client</option>
                         <?php 
                            while($resclient_drp=mysql_fetch_array($sq_arrdrp))
                            {
                        ?>
                            <option value="<?=$resclient_drp['client_sub_id']?>" <? if($resclient_drp['client_sub_id']==$client_namek) {?>selected<? }?> ><?=$resclient_drp['client_newcode']?></option>
                        <?php
                                }
                     ?>
    		 </select>
	 <? }else{
	 ?>  
   <select class="input1 input3" name="client_name" onChange="Searchdate('1',this.value);">
     <option value="">select Client Code</option>
     </select>
	 <? }?>
	 </p>
     <!--<input type="text" name="client_name" id="client_name" class="input1" />-->
    </div>
    &nbsp;&nbsp;        
   <!-- <div class="searchField">
     <input name="button" type="button" class="input1" onClick="Searchdate(1);" value="search" />
    </div> -->
  
   </div>
   </div>
   </form>
   <div id="list">
   <table  border="0" cellspacing="0" cellpadding="0" class="tableList" style="margin-left:20px; ">
  <tr class="heading">
    <td width="6%">No</td>    
    <td width="10%">Client</td>
	 <td width="12%">Group</td>
    <td width="9%">Route</td>
	<td width="40%">Towns1</td>
	<td width="11%">Distance(KM)</td>
    <td width="5%" align="center">Edit</td>
    <td width="5%" align="center">Delete</td>
  </tr>
  
  <?php
$townsnames='';

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

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


$sq_arr.=" order by route_id  desc ";
$query=$sq_arr;
//echo $query;
$function="Searchdate";
include("pagingserch.php");
$sq_arr.=" LIMIT $start, $limit";

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

$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']."' ");
$townsnames ='';
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=<?=$_REQUEST['client_main']?>&client_name=<?=$client_namek?>&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=<?=$_REQUEST['client_main']?>&client_name=<?=$client_namek?>&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> 
  </div>
  </div>
 </div>
 <div class="footer"><p>Powered by <a href="http://www.aadhocc.co.uk/" target="_blank">Aadhocc</a></p></div>
 
</div>
<div class="quicLInksCover">
 <?php 
	include("leftlink.php");
?>

</div>
</body>
</html>
