Advertisement
Guest User

ajaxations.php

a guest
Dec 21st, 2012
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.85 KB | None | 0 0
  1. <?php
  2.  
  3. //alert("ajaxations.php");
  4. //require_once(dirname(__FILE__).'/library/config.php');
  5.  
  6. require_once('config.php');
  7.  
  8. $ajaxact = (isset($_REQUEST['ajaxact']) && trim($_REQUEST['ajaxact'])!='' )?trim($_REQUEST['ajaxact']):'';
  9. //alert("$ajaxact");
  10. //alert($ajaxact);
  11.  
  12.  
  13. if( $ajaxact!='' ){
  14.     $jsonStr = '';
  15.    
  16.     switch($ajaxact){
  17.         case 'chkcalculcdist':
  18.             $jsonStr = checkCalculateDistance();
  19.         break;
  20.        
  21.         case 'validatecartype':
  22.             $jsonStr = validateCarType();
  23.         break;
  24.        
  25.     }
  26.    
  27.     echo($jsonStr);
  28. }
  29. ?>
  30. <?php
  31. function checkCalculateDistance(){
  32.         //alert("checkCalculateDistance");
  33.     //echo "checkCalculateDistance";
  34.         $errCount   = 0;
  35.    
  36.     $fromloctyp    = (isset($_REQUEST['fromloctyp']) && trim($_REQUEST['fromloctyp'])!='' )?trim($_REQUEST['fromloctyp']):'';
  37.     $fromlocval    = (isset($_REQUEST['fromlocval']) && trim($_REQUEST['fromlocval'])!='' )?trim($_REQUEST['fromlocval']):'';
  38.     $fromlocvalext = (isset($_REQUEST['fromlocvalext']) && trim($_REQUEST['fromlocvalext'])!='' )?trim($_REQUEST['fromlocvalext']):'';
  39.    
  40.     //$finfromlocval = ($fromlocvalext!='' && $fromloctyp=='pin')?$fromlocval.' '.$fromlocvalext:$fromlocval;
  41.     $finfromlocval = $fromlocval;
  42.    
  43.     $toloctyp      = (isset($_REQUEST['toloctyp']) && trim($_REQUEST['toloctyp'])!='' )?trim($_REQUEST['toloctyp']):'';
  44.     $tolocval      = (isset($_REQUEST['tolocval']) && trim($_REQUEST['tolocval'])!='' )?trim($_REQUEST['tolocval']):'';
  45.     $tolocvalext   = (isset($_REQUEST['tolocvalext']) && trim($_REQUEST['tolocvalext'])!='' )?trim($_REQUEST['tolocvalext']):'';
  46.    
  47.     //$fintolocval   = ($tolocvalext!='' && $toloctyp=='pin')?$tolocval.' '.$tolocvalext:$tolocval;
  48.     $fintolocval   = $tolocval;
  49.    
  50.     $vehicletype   = (isset($_REQUEST['vehicletype']) && trim($_REQUEST['vehicletype'])!='' )?trim($_REQUEST['vehicletype']):'';
  51.    
  52.     if($fromloctyp!='' && $finfromlocval!='' && $toloctyp!='' && $fintolocval!='' && $vehicletype!=''){
  53.        
  54.         if(intval($finfromlocval)>0 && $fromloctyp!='pin'){
  55.             $whereFrom = "locationid='".intval($finfromlocval)."' AND pointtypefk='".$fromloctyp."'";
  56.         }
  57.         else{
  58.             $whereFrom = "pincode='".strtoupper(trim($finfromlocval))."' AND pointtypefk='".$fromloctyp."'";
  59.         }
  60.        
  61.         $sqlLocFrom = "SELECT * FROM ".LOCATIONS." WHERE ".$whereFrom;
  62.         $GLOBALS['odb']->query($sqlLocFrom);
  63.         $rowLocFrom = $GLOBALS['odb']->getfetcharray();
  64.         $GLOBALS['odb']->freeresult();
  65.        
  66.         if(count($rowLocFrom)<=0){
  67.             $errCount++;
  68.             $latFrom     = '';
  69.             $lonFrom     = '';
  70.             $pointIdFrom = '';
  71.         }
  72.         else{
  73.             $latFrom     = trim($rowLocFrom[0]['latitude']);
  74.             $lonFrom     = trim($rowLocFrom[0]['longitude']);
  75.             $pointIdFrom = trim($rowLocFrom[0]['locationid']);
  76.         }
  77.        
  78.         if(intval($fintolocval)>0 && $toloctyp!='pin'){
  79.             $whereTo = "locationid='".intval($tolocval)."' AND pointtypefk='".$toloctyp."'";
  80.         }
  81.         else{
  82.             $whereTo = "pincode='".strtoupper(trim($fintolocval))."' AND pointtypefk='".$toloctyp."'";
  83.         }
  84.        
  85.         $sqlLocTo = "SELECT * FROM ".LOCATIONS." WHERE ".$whereTo;
  86.         $GLOBALS['odb']->query($sqlLocTo);
  87.         $rowLocTo = $GLOBALS['odb']->getfetcharray();
  88.         $GLOBALS['odb']->freeresult();
  89.        
  90.         if(count($rowLocTo)<=0){
  91.             $errCount++;
  92.             $latTo     = '';
  93.             $lonTo     = '';
  94.             $pointIdTo = '';
  95.         }
  96.         else{
  97.             $latTo     = trim($rowLocTo[0]['latitude']);
  98.             $lonTo     = trim($rowLocTo[0]['longitude']);
  99.             $pointIdTo = trim($rowLocTo[0]['locationid']);
  100.         }
  101.        
  102.         $jsonArray = array();
  103.        
  104.         if($errCount>0){
  105.             $jsonArray['flag'] = 'error';
  106.             $jsonArray['msg']  = 'suplied location/postcode are invalid';
  107.         }
  108.         else{
  109.             $sqlHasRate = "SELECT rateid FROM ".FIXEDRATES." WHERE frompointidfk='".$pointIdFrom."' AND topointidfk='".$pointIdTo."' AND cartypeidfk='".$vehicletype."' AND flag='1'";
  110.             $GLOBALS['odb']->query($sqlHasRate);
  111.             $numHasRate = $GLOBALS['odb']->getnumrows();
  112.             $GLOBALS['odb']->freeresult();
  113.            
  114.             $calcDistance = ($numHasRate>0)?false:true;
  115.            
  116.             if(!$calcDistance){
  117.                 $jsonArray['flag'] = 'no';
  118.                 $jsonArray['msg']  = '';
  119.                                // alert("$calcDistance");
  120.             }
  121.             else{
  122.                 if( $latFrom!='' && $lonFrom!='' && $latTo!='' && $lonTo!='' ){
  123.                     $jsonArray['flag']    = 'yes';
  124.                     $jsonArray['latfrom'] = trim($latFrom);
  125.                     $jsonArray['lonfrom'] = trim($lonFrom);
  126.                     $jsonArray['latto']   = trim($latTo);
  127.                     $jsonArray['lonto']   = trim($lonTo);
  128.                     $jsonArray['msg']     = '';
  129.                 }
  130.                 else{
  131.                     $jsonArray['flag']    = 'error';
  132.                     $jsonArray['latfrom'] = '';
  133.                     $jsonArray['lonfrom'] = '';
  134.                     $jsonArray['latto']   = '';
  135.                     $jsonArray['lonto']   = '';
  136.                     $jsonArray['msg']     = 'supplied location/postcode are invalid';
  137.                 }
  138.             }
  139.         }
  140.     }
  141.     else{
  142.         $jsonArray['flag'] = 'error';
  143.         $jsonArray['msg']  = 'suplied locations are invalid';
  144.     }
  145.    
  146.     require_once('Json.php');
  147.     $jsonStr = Zend_Json::encode($jsonArray);
  148.    
  149.     return($jsonStr);
  150. }
  151. ?>
  152. <?php
  153. function validateCarType(){
  154.     $errCount   = 0;
  155.    
  156.     $cartyp     = (isset($_REQUEST['cartyp']) && trim($_REQUEST['cartyp'])!='' )?trim($_REQUEST['cartyp']):'';
  157.    
  158.     $fromloctyp    = (isset($_REQUEST['fromloctyp']) && trim($_REQUEST['fromloctyp'])!='' )?trim($_REQUEST['fromloctyp']):'';
  159.     $fromlocval    = (isset($_REQUEST['fromlocval']) && trim($_REQUEST['fromlocval'])!='' )?trim($_REQUEST['fromlocval']):'';
  160.     $fromlocvalext = (isset($_REQUEST['fromlocvalext']) && trim($_REQUEST['fromlocvalext'])!='' )?trim($_REQUEST['fromlocvalext']):'';
  161.    
  162.     //$finfromlocval = ($fromlocvalext!='' && $fromloctyp=='pin')?$fromlocval.' '.$fromlocvalext:$fromlocval;
  163.     $finfromlocval = $fromlocval;
  164.    
  165.     $toloctyp    = (isset($_REQUEST['toloctyp']) && trim($_REQUEST['toloctyp'])!='' )?trim($_REQUEST['toloctyp']):'';
  166.     $tolocval    = (isset($_REQUEST['tolocval']) && trim($_REQUEST['tolocval'])!='' )?trim($_REQUEST['tolocval']):'';
  167.     $tolocvalext = (isset($_REQUEST['tolocvalext']) && trim($_REQUEST['tolocvalext'])!='' )?trim($_REQUEST['tolocvalext']):'';
  168.    
  169.     //$fintolocval   = ($tolocvalext!='' && $toloctyp=='pin')?$tolocval.' '.$tolocvalext:$tolocval;
  170.     $fintolocval   = $tolocval;
  171.    
  172.     $passengers = (isset($_REQUEST['passengers']) && trim($_REQUEST['passengers'])!='' )?trim($_REQUEST['passengers']):'';
  173.     $luggages   = (isset($_REQUEST['luggages']) && trim($_REQUEST['luggages'])!='' )?trim($_REQUEST['luggages']):'';
  174.    
  175.     if($cartyp!='' && $fromloctyp!='' && $fromlocval!='' && $toloctyp!='' && $tolocval!='' && $passengers!='' && $luggages!=''){
  176.        
  177.         $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'";
  178.        
  179.         //$sqlPayPlan = "SELECT * FROM ".PAYPLANS." WHERE startpointtypefk='".$fromloctyp."' AND endpointtypefk='".$toloctyp."' AND cartypeidfk='".$cartyp."' AND  flag='1'";
  180.         $GLOBALS['odb']->query($sqlPayPlan);
  181.         $datPayPlan = $GLOBALS['odb']->getfetcharray();
  182.         $numVacAvl  = $GLOBALS['odb']->getnumrows();
  183.         $GLOBALS['odb']->freeresult();
  184.        
  185.         if( $numVacAvl==1 ){
  186.             if(intval($passengers)<=0 || intval($passengers)>intval($datPayPlan[0]['toseat'])){
  187.                 $jsonArray = array('flag'=>'deny', 'cartyp'=>'0', 'msg'=>'sitting capacity is '.intval($datPayPlan[0]['toseat']).' for this vehicle' );
  188.             }
  189.             elseif(intval($luggages)>intval($datPayPlan[0]['luggage'])){
  190.                 $jsonArray = array('flag'=>'deny', 'cartyp'=>'0', 'msg'=>'luggage capacity is '.intval($datPayPlan[0]['luggage']).' for this vehicle' );
  191.             }
  192.             else{
  193.                 $jsonArray = array('flag'=>'success', 'cartyp'=>$cartyp);
  194.             }
  195.         }
  196.         else{
  197.             $jsonArray = array('flag'=>'deny', 'cartyp'=>'0', 'msg'=>'please contact us directly on info@theirdomain.com for a quote');
  198.         }
  199.     }
  200.     else{
  201.         $jsonArray = array('flag'=>'failed', 'cartyp'=>'0', 'msg'=>'Please fill up the form properly');
  202.     }
  203.    
  204.     require_once('Json.php');
  205.     $jsonStr = Zend_Json::encode($jsonArray);
  206.    
  207.     return($jsonStr);
  208. }
  209. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement