<?php
//alert("ajaxations.php");
//require_once(dirname(__FILE__).'/library/config.php');
require_once('config.php');
$ajaxact = (isset($_REQUEST['ajaxact']) && trim($_REQUEST['ajaxact'])!='' )?trim($_REQUEST['ajaxact']):'';
//alert("$ajaxact");
//alert($ajaxact);
if( $ajaxact!='' ){
$jsonStr = '';
switch($ajaxact){
case 'chkcalculcdist':
$jsonStr = checkCalculateDistance();
break;
case 'validatecartype':
$jsonStr = validateCarType();
break;
}
echo($jsonStr);
}
?>
<?php
function checkCalculateDistance(){
//alert("checkCalculateDistance");
//echo "checkCalculateDistance";
$errCount = 0;
$fromloctyp = (isset($_REQUEST['fromloctyp']) && trim($_REQUEST['fromloctyp'])!='' )?trim($_REQUEST['fromloctyp']):'';
$fromlocval = (isset($_REQUEST['fromlocval']) && trim($_REQUEST['fromlocval'])!='' )?trim($_REQUEST['fromlocval']):'';
$fromlocvalext = (isset($_REQUEST['fromlocvalext']) && trim($_REQUEST['fromlocvalext'])!='' )?trim($_REQUEST['fromlocvalext']):'';
//$finfromlocval = ($fromlocvalext!='' && $fromloctyp=='pin')?$fromlocval.' '.$fromlocvalext:$fromlocval;
$finfromlocval = $fromlocval;
$toloctyp = (isset($_REQUEST['toloctyp']) && trim($_REQUEST['toloctyp'])!='' )?trim($_REQUEST['toloctyp']):'';
$tolocval = (isset($_REQUEST['tolocval']) && trim($_REQUEST['tolocval'])!='' )?trim($_REQUEST['tolocval']):'';
$tolocvalext = (isset($_REQUEST['tolocvalext']) && trim($_REQUEST['tolocvalext'])!='' )?trim($_REQUEST['tolocvalext']):'';
//$fintolocval = ($tolocvalext!='' && $toloctyp=='pin')?$tolocval.' '.$tolocvalext:$tolocval;
$fintolocval = $tolocval;
$vehicletype = (isset($_REQUEST['vehicletype']) && trim($_REQUEST['vehicletype'])!='' )?trim($_REQUEST['vehicletype']):'';
if($fromloctyp!='' && $finfromlocval!='' && $toloctyp!='' && $fintolocval!='' && $vehicletype!=''){
if(intval($finfromlocval)>0 && $fromloctyp!='pin'){
$whereFrom = "locationid='".intval($finfromlocval)."' AND pointtypefk='".$fromloctyp."'";
}
else{
$whereFrom = "pincode='".strtoupper(trim($finfromlocval))."' AND pointtypefk='".$fromloctyp."'";
}
$sqlLocFrom = "SELECT * FROM ".LOCATIONS." WHERE ".$whereFrom;
$GLOBALS['odb']->query($sqlLocFrom);
$rowLocFrom = $GLOBALS['odb']->getfetcharray();
$GLOBALS['odb']->freeresult();
if(count($rowLocFrom)<=0){
$errCount++;
$latFrom = '';
$lonFrom = '';
$pointIdFrom = '';
}
else{
$latFrom = trim($rowLocFrom[0]['latitude']);
$lonFrom = trim($rowLocFrom[0]['longitude']);
$pointIdFrom = trim($rowLocFrom[0]['locationid']);
}
if(intval($fintolocval)>0 && $toloctyp!='pin'){
$whereTo = "locationid='".intval($tolocval)."' AND pointtypefk='".$toloctyp."'";
}
else{
$whereTo = "pincode='".strtoupper(trim($fintolocval))."' AND pointtypefk='".$toloctyp."'";
}
$sqlLocTo = "SELECT * FROM ".LOCATIONS." WHERE ".$whereTo;
$GLOBALS['odb']->query($sqlLocTo);
$rowLocTo = $GLOBALS['odb']->getfetcharray();
$GLOBALS['odb']->freeresult();
if(count($rowLocTo)<=0){
$errCount++;
$latTo = '';
$lonTo = '';
$pointIdTo = '';
}
else{
$latTo = trim($rowLocTo[0]['latitude']);
$lonTo = trim($rowLocTo[0]['longitude']);
$pointIdTo = trim($rowLocTo[0]['locationid']);
}
$jsonArray = array();
if($errCount>0){
$jsonArray['flag'] = 'error';
$jsonArray['msg'] = 'suplied location/postcode are invalid';
}
else{
$sqlHasRate = "SELECT rateid FROM ".FIXEDRATES." WHERE frompointidfk='".$pointIdFrom."' AND topointidfk='".$pointIdTo."' AND cartypeidfk='".$vehicletype."' AND flag='1'";
$GLOBALS['odb']->query($sqlHasRate);
$numHasRate = $GLOBALS['odb']->getnumrows();
$GLOBALS['odb']->freeresult();
$calcDistance = ($numHasRate>0)?false:true;
if(!$calcDistance){
$jsonArray['flag'] = 'no';
$jsonArray['msg'] = '';
// alert("$calcDistance");
}
else{
if( $latFrom!='' && $lonFrom!='' && $latTo!='' && $lonTo!='' ){
$jsonArray['flag'] = 'yes';
$jsonArray['latfrom'] = trim($latFrom);
$jsonArray['lonfrom'] = trim($lonFrom);
$jsonArray['latto'] = trim($latTo);
$jsonArray['lonto'] = trim($lonTo);
$jsonArray['msg'] = '';
}
else{
$jsonArray['flag'] = 'error';
$jsonArray['latfrom'] = '';
$jsonArray['lonfrom'] = '';
$jsonArray['latto'] = '';
$jsonArray['lonto'] = '';
$jsonArray['msg'] = 'supplied location/postcode are invalid';
}
}
}
}
else{
$jsonArray['flag'] = 'error';
$jsonArray['msg'] = 'suplied locations are invalid';
}
require_once('Json.php');
$jsonStr = Zend_Json::encode($jsonArray);
return($jsonStr);
}
?>
<?php
function validateCarType(){
$errCount = 0;
$cartyp = (isset($_REQUEST['cartyp']) && trim($_REQUEST['cartyp'])!='' )?trim($_REQUEST['cartyp']):'';
$fromloctyp = (isset($_REQUEST['fromloctyp']) && trim($_REQUEST['fromloctyp'])!='' )?trim($_REQUEST['fromloctyp']):'';
$fromlocval = (isset($_REQUEST['fromlocval']) && trim($_REQUEST['fromlocval'])!='' )?trim($_REQUEST['fromlocval']):'';
$fromlocvalext = (isset($_REQUEST['fromlocvalext']) && trim($_REQUEST['fromlocvalext'])!='' )?trim($_REQUEST['fromlocvalext']):'';
//$finfromlocval = ($fromlocvalext!='' && $fromloctyp=='pin')?$fromlocval.' '.$fromlocvalext:$fromlocval;
$finfromlocval = $fromlocval;
$toloctyp = (isset($_REQUEST['toloctyp']) && trim($_REQUEST['toloctyp'])!='' )?trim($_REQUEST['toloctyp']):'';
$tolocval = (isset($_REQUEST['tolocval']) && trim($_REQUEST['tolocval'])!='' )?trim($_REQUEST['tolocval']):'';
$tolocvalext = (isset($_REQUEST['tolocvalext']) && trim($_REQUEST['tolocvalext'])!='' )?trim($_REQUEST['tolocvalext']):'';
//$fintolocval = ($tolocvalext!='' && $toloctyp=='pin')?$tolocval.' '.$tolocvalext:$tolocval;
$fintolocval = $tolocval;
$passengers = (isset($_REQUEST['passengers']) && trim($_REQUEST['passengers'])!='' )?trim($_REQUEST['passengers']):'';
$luggages = (isset($_REQUEST['luggages']) && trim($_REQUEST['luggages'])!='' )?trim($_REQUEST['luggages']):'';
if($cartyp!='' && $fromloctyp!='' && $fromlocval!='' && $toloctyp!='' && $tolocval!='' && $passengers!='' && $luggages!=''){
$sqlPayPlan = "SELECT ppl.*, vhc.toseat, vhc.luggage FROM ".PAYPLANS." AS ppl LEFT JOIN ".VEHICLETYPES." AS vhc ON ppl.cartypeidfk=vhc.cartypeid WHERE ppl.startpointtypefk='".$fromloctyp."' AND ppl.endpointtypefk='".$toloctyp."' AND ppl.cartypeidfk='".$cartyp."' AND ppl.flag='1'";
//$sqlPayPlan = "SELECT * FROM ".PAYPLANS." WHERE startpointtypefk='".$fromloctyp."' AND endpointtypefk='".$toloctyp."' AND cartypeidfk='".$cartyp."' AND flag='1'";
$GLOBALS['odb']->query($sqlPayPlan);
$datPayPlan = $GLOBALS['odb']->getfetcharray();
$numVacAvl = $GLOBALS['odb']->getnumrows();
$GLOBALS['odb']->freeresult();
if( $numVacAvl==1 ){
if(intval($passengers)<=0 || intval($passengers)>intval($datPayPlan[0]['toseat'])){
$jsonArray = array('flag'=>'deny', 'cartyp'=>'0', 'msg'=>'sitting capacity is '.intval($datPayPlan[0]['toseat']).' for this vehicle' );
}
elseif(intval($luggages)>intval($datPayPlan[0]['luggage'])){
$jsonArray = array('flag'=>'deny', 'cartyp'=>'0', 'msg'=>'luggage capacity is '.intval($datPayPlan[0]['luggage']).' for this vehicle' );
}
else{
$jsonArray = array('flag'=>'success', 'cartyp'=>$cartyp);
}
}
else{
$jsonArray = array('flag'=>'deny', 'cartyp'=>'0', 'msg'=>'please contact us directly on info@theirdomain.com for a quote');
}
}
else{
$jsonArray = array('flag'=>'failed', 'cartyp'=>'0', 'msg'=>'Please fill up the form properly');
}
require_once('Json.php');
$jsonStr = Zend_Json::encode($jsonArray);
return($jsonStr);
}
?>