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


$veh_num='';
$sdate_12 ='';
$page='1';
include("include/config.php");
require_once "include/Database_functions.php";
$sqlObj=new sqlclass();
$msg = '';

if(isset($_REQUEST['del']) && $_REQUEST['del']=='delete')
{
	$id = $_REQUEST['id'];
	$sql=mysql_query("update cf_tripsheet set delete_status = '1' where trip_id='$id'");
	$sql3=mysql_query("update cf_account_hire set del_stat = '1' where trip_id='$id'");
	header("location:tripsheet-pending.php?msg=Successfully sended to Recycle Bin");
}

function sendSms($message,$mobile)
{
		$ch = curl_init();
				
		curl_setopt($ch,CURLOPT_URL,  "http://59.162.167.52/api/MessageCompose");
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch,CURLOPT_POSTFIELDS,"admin=info@aadhocc.co.uk&user=support@groupmukkadan.com:L1K3J3&senderID=TEST SMS&receipientno=$mobile&msgtxt=$message&state=4");
		$buffer = curl_exec($ch);
		if(empty ($buffer))
		{ echo " buffer is empty "; }
		else
		{ //echo $buffer; 
		
		}
		curl_close($ch);


	}

if(isset($_REQUEST['tripid']))
{
	$tripid = $_REQUEST['tripid'];
	
	$vechno = $_REQUEST['vechno'];
	$sqlsms = mysql_query("update cf_tripsheet set sms_status = '1'  where trip_id = '$tripid' ");
	
	//$sq_tripsheetsub="select * from cf_tripsheetsub where trip_id = '$tripid'";
	$sq_tripsheetsub="select * from cf_tripsheetsub where trip_id = '$tripid'";
	$arr1=mysql_query($sq_tripsheetsub);
	while($res=mysql_fetch_array($arr1))
	{	
		$dealer = $res['trip_dealer'];
		$sq_dealer=mysql_query("select * from cf_reseller where res_name = '$dealer'");
		$row = mysql_fetch_array($sq_dealer);
		$mobile = $row['re_phoneno'];
		$message = "The goods with the invoice no ".$res['invoice_no']." - ".$res['invoice_date']."  has been dispached in  ".$vechno." on ".$res['invoice_date']." - Group Mukkadan.";
		sendSms($message,$mobile);
	
	}
	
	
	
	
}


?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Transport Integrated Logistic System</title>
<link href="css/styles.css" rel="stylesheet"  />
<link href="css/menu.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="css/datepick/themes/chosen.css">
<link type="text/css" href="css_date/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
<script type='text/javascript' src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="js/trippopup.js" type="text/javascript"></script>


<script type='text/javascript' src="js/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" />

<script type="text/javascript" src="scripts_date/jquery-calendar-1.7.2.js"></script>

<script>
$(document).ready(function(){
$('#tripdate').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});
});

$(document).ready(function(){
$('#fromdate').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});
});

$(document).ready(function(){
$('#todate').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});
});

/*function drivername()
{
	alert(document.frmname.clientid.value);
}*/



</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(val)
{ 
 	 var page=val;	
	 var vechicle_no='';
	 var tripdate='';	 
	 var fromdate='';
	 var todate='';
	 var client_code='';
	 var tripsheetno='';
	 //var con_person='';
	 	
	 if(document.trip_frm.vechicle_no){
	 vechicle_no= document.trip_frm.vechicle_no.value;
	 }
	 
	 if(document.trip_frm.tripdate){
	 tripdate= document.trip_frm.tripdate.value;
	 }
	 
	 if(document.trip_frm.fromdate){
	 fromdate= document.trip_frm.fromdate.value;
	 }
	 
	 if(document.trip_frm.todate){
	 todate= document.trip_frm.todate.value;
	 }
	 
	 if(document.trip_frm.client_code){
	 client_code= document.trip_frm.client_code.value;
	 }
	 
	 if(document.trip_frm.tripsheetno){
	 tripsheetno= document.trip_frm.tripsheetno.value;
	 }
	 
	 var strURL="ajax/tripsheetpending_data.php?&page="+page;
		if(vechicle_no!=''){
		strURL+="&vechicle_no="+vechicle_no;
		}
	
		if(tripdate!=''){
		strURL+="&tripdate="+tripdate;
		}
		
		if(fromdate!=''){
		strURL+="&fromdate="+fromdate;
		}
		
		if(todate!=''){
		strURL+="&todate="+todate;
		}
		
		if(client_code!=''){
		strURL+="&client_code="+client_code;
		}
		
		if(tripsheetno!=''){
		strURL+="&tripsheetno="+tripsheetno;
		}
	
	
	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);
   }
 
   
}
</script>

</head>

<body>
<!------------------popup area (view, edit)--------------->
<div class="viewEmployeePopup login-popup"  id="login-box">
<a href="#" class="close"><img src="images/close.png" class="btn_close" title="Close Window" alt="Close" /></a>
   <div id="popupid"></div>
   
     
    </div>


<!---------------popup area ends------------------>
<div class="wrapper">
   <div>
<?php 
	include("header.php");
?>
 
</div>
 
 <div class="tabbedArea">
   
  <div class="tabBody">
   <h1>Tripsheet List</h1>
   <?php
   		$i=1;

if(($_SESSION['typename'] == 'SuperAdmin')) {
	$sq_arr="select * from cf_tripsheet where trip_status = 0 and delete_status = 0 ";	
}

if(($_SESSION['typename'] == 'SubAdmin')) {
	$userids = $_SESSION['admin_id'];
	$sq_arr="select * from cf_tripsheet where trip_status = 0 and delete_status = 0 and trip_userid = '$userids' "; 	
}

$sq_arr.=" order by trip_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;
}

$pagetot='';
$grandtot='';
$array=mysql_query($sq_arr);
$sumarray=mysql_query($query);
	while($rw1 = mysql_fetch_array($sumarray))
	{
		$grandtot = $grandtot + $rw1['advt_amt'];
	}
   ?>
   <form name="trip_frm" id="trip_frm" method="post"  >
   <div class="searchBox" style="width:93%; margin-right:0px;  padding:0px; ">
   <div style="padding:20px;">
    <div class="searchField">
     <p class="input1">Vehicle No</p>
       
   <select class="chzn-select restselect input3" name="vechicle_no">
     <option value="">Vehicle No</option>
     	 <?php 
        	$sq_vechicle="select * from cf_vehicle";
			$arr1=mysql_query($sq_vechicle);
			while($resvechicle=mysql_fetch_array($arr1))
			{
		?>
			<option value="<?=$resvechicle['vehiclenum']?>" ><?=$resvechicle['vehiclenum']?></option>
        <?php
				}
	 ?>
     </select>
     <!--<input type="text" name="client_name" id="client_name" class="input1" />-->
    </div>
    
    <?php
		if($_SESSION['typename'] == 'SuperAdmin')
		 {
	 ?>
    <div class="searchField" style="padding-left:20px;">
    <?php
		//echo $_SESSION['admin_id'];
		//echo $_SESSION['typename'];
	?>
     <p class="input1">Client Code</p>
     <select class="input1" name="client_code" id="client_code" style="width:110px;">
     <option value="">Client Code</option>
     	 <?php 
		 	$sq_clientcd="select * from cf_client";			
			$arr2=mysql_query($sq_clientcd);
			while($resclient=mysql_fetch_array($arr2))
			{
			?>
				<option value="<?=$resclient['client_sub_id']?>" ><?=$resclient['client_newcode']?></option>
        	<?php
			}
	 	?>    	
		
     </select>
    </div>
    <?php } ?>
    
    <div class="searchField" style="padding-left:20px;">
     
     <p class="input1">TripSheet No </p>
     <select class="chzn-select restselect input3" name="tripsheetno">
     <option value="">Tripsheet No</option>
     	 <?php 
        	$sq_tripno="select * from cf_tripsheet where trip_status = 0 and delete_status = 0";
			$arrtripno1=mysql_query($sq_tripno);
			while($restripno=mysql_fetch_array($arrtripno1))
			{
		?>
			<option value="<?=$restripno['trip_newsrno']?>" ><?=$restripno['trip_newsrno']?></option>
        <?php
				}
	 ?>
     </select>
     
     
     <!--<input type="text" name="tripsheetno" id="tripsheetno" style="width:120px;"  class="input1" />-->
    </div>
        
    <div class="searchField" style="padding-left:20px;">
     <p class="input1">Trip Date</p>
     <input type="text" name="tripsdate" id="tripdate" style="width:75px;" maxlength="100" class="input1" />
    </div>
    
    <div class="searchField" style="padding-left:20px;">
     <p class="input1">From Date</p>
     <input type="text" name="fromdate" id="fromdate" style="width:75px;" maxlength="100" class="input1" />
    </div>
    
    <div class="searchField" style="padding-left:20px;">
     <p class="input1">To Date</p>
     <input type="text" name="todate" id="todate" style="width:75px;" maxlength="100" class="input1" />
    </div>
       
    <div class="searchField">
     <input name="button" type="button" class="input1" onClick="Searchdate(1);" value="search" />
    </div>
  
   </div>
   </div>
   </form>
   
   <div id="list">
   <div style="margin-right:100px; margin-top:15px; font-weight:bold;color: #009999; text-align:right;">Total:<?=$grandtot?></div>
   <table  border="0" cellspacing="0" cellpadding="0" class="tableList" style="margin-top:10px;">
  <tr class="heading">
    <td>No</td>   
    <td>Trip No</td> 
    <td>Trip Date</td>
    <td>Vehicle No</td>
    <td>Driver Name</td>
    <td>Trip Route</td>
    <td>Advance Amount</td> 
    <td>Trip Status</td> 
    <td>Sms</td> 
    <td>Edit</td>
    <td>Delete</td>
  </tr>
  
  <?php

  


if($array && mysql_num_rows($array)>0){
$pagecnt=$start;
while($res=mysql_fetch_array($array))
{
$pagecnt++;

  ?> 
  <tr>
    <td><?php echo $pagecnt;?></td>
    <td><?php echo $res['trip_newsrno'];?></td>
    <td><a href="#login-box" class="login-window"><?php echo date('d-m-Y', strtotime($res['trip_date']));?></a></td>
    <td><a href="#login-box" class="login-window" data-id=<?php echo $res['trip_id'];?>><?php echo $res['trip_vechno'];?></a></td>
    <td><?php if($res['trip_driver']!='')echo $res['trip_driver'];else echo '--'; ?></td>
    <?php 
		$triprouteid = $res['trip_route_id'];
		$sq_route=mysql_query("select * from cf_route where route_id = '$triprouteid'  ");
		$row2 = mysql_fetch_array($sq_route);
		$routename = $row2['route_name'];
	?>	
    
    
    <td><?php if($routename!='')echo $routename;else echo '--'; ?></td>
    <?php 
		$locationid = $res['trip_location'];
		$sq_arr=mysql_query("select * from cf_district where district_id = '$locationid'  ");
		$row = mysql_fetch_array($sq_arr);
    ?>    
   
    <td><?php if($res['advt_amt']!='')echo $res['advt_amt'];else echo '--'; ?></td>
          
     <td class="tr_td_b">
      <a href="add-tripsheet.php?page=<?php echo $page; ?>&tripid=<?php echo $res['trip_id']; ?>&ab=<?php echo $i;?>" style="color:#FF9900">Pending </a> 
     </td>    
      <td class="tr_td_b" bordercolor="#993333">
      <?php    
   		if($res['sms_status'] == '1')
		{ ?>
      <a href="tripsheet-pending.php?tripid=<?php echo $res['trip_id']; ?>&vechno=<?=$res['trip_vechno']?>"style="color:#006633" title="Sms sended" >Send Sms</a> 
      <?php } else { ?>
      <a href="tripsheet-pending.php?tripid=<?php echo $res['trip_id']; ?>&vechno=<?=$res['trip_vechno']?>"style="color:#993333" title="Sms not sended" >Send Sms</a> 
      <?php } ?>
     </td>  
   <?php 
  // if($res['trip_status']!='1')
  // {
   ?>
   <td class="tr_td_b">
	<a href="add-tripsheet.php?page=<?php echo $page; ?>&tripid=<?php echo $res['trip_id']; ?>&ab=<?php echo $i;?>" target="_blank"><img src="images/edit.png" title="edit"></a>
   </td>
  <?php /*?> <?php } else { ?>
   <td class="tr_td_b"><img src="images/no-edit.png" title="Can't Edit"></td>
   <?php } 
   ?>
   
   <?php 
   if($res['trip_status']!='1')
   {
   ?><?php */?>
   <td class="tr_td_r" ><a href="tripsheet-pending.php?del=delete&id=<?php echo $res['trip_id']; ?>" onClick="return confirm('Are you sure you want to send to Recycle Bin?');"><img src="images/delete.png" title="Delete"></a></td>
    <?php /*?><?php } else { ?>
   <td class="tr_td_r" ><img src="images/no-delete.png" title="Can't Delete"></td>
    <?php } ?><?php */?>
  </tr>
  <?php 
  $pagetot = $pagetot + $res['advt_amt'];
    }}
  ?>
 
  <!--<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>-->
 <tr class="heading">
    <td></td>    
    <td></td>   
    <td></td>
    <td></td>
    <td></td>
    <td>Page Total</td> 
    <td><?=$pagetot?></td> 
    <td></td> 
    <td></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">
 <div class="quickLink">
  <img src="images/quickLinks.gif" border="0" usemap="#Map">
<map name="Map"><area shape="rect" coords="5,6,39,50" href="#"><area shape="rect" coords="7,62,41,111" href="#"><area shape="rect" coords="3,122,43,172" href="#"><area shape="rect" coords="4,186,42,237" href="javascript:parent.history.back();"><area shape="rect" coords="3,247,43,300" href="javascript:parent.history.forward();"></map>
 </div>

</div>-->

<div class="quicLInksCover">
 <?php 
	include("leftlink.php");
?>

</div>
</body>
</html>
<!----------------------- script for autocomplete------------------------------>
		<script src="js/chosen.jquery.min.js" type="text/javascript">
		</script>
		<script type="text/javascript"> 
			$(".chzn-select").chosen({search_contains: true}); 
		</script>

<!----------------end of script -------------------------------->
