<? 
ob_start();
session_start();
require("wp-config.php");
$data24url="https://api.data24-7.com/v/2.0";
$data24user="globallimos";
$data24pass="Mgn19822014";

$step=$_REQUEST["step"];
$fleets_category_id=$_REQUEST["fleets_category_id"];
if($step==501){
	$pickup_date=date('Y-m-d');				
	$pickup_time=$_REQUEST["pickup_time"];
	$dropup=$_REQUEST["dropup_time"];		
	$type=$_REQUEST["type"];
	$pickup_time=getDPTimeF($pickup_time,$type);	
	$dropup=getDPTimeF($dropup,$type);	
	$timeHr=round(get_time_difference($pickup_date,$pickup_time,$pickup_date,$dropup));
	if($timeHr<=9){
		$timeHr="0".$timeHr;
	}
	echo trim($timeHr);
}elseif($step==502){
	$pickup_date=date('Y-m-d');
	 $pickup_time=$_REQUEST["pickup_time"];
	 $type=$_REQUEST["type"];
	 if($type==''){
		$type=2;
	 }
	 $pickup_time=getDPTimeF($pickup_time,$type);	
		 
	 $pickup_timeA=explode(':',$pickup_time,2); 
	 $no_of_hrs=$_REQUEST["no_of_hrs"];
	 $pickup_time_hour=$pickup_timeA[0];
	 $pickup_time_minute=$pickup_timeA[1];
	 if($pickup_time_minute=='null'){
		$pickup_time_minute='00';
	 }
	 $add_minute=($no_of_hrs*60) +$pickup_time_minute; 
	 $totHrs=$no_of_hrs+$pickup_time_hour;
	 $timeStamp = mktime($totHrs, $pickup_time_minute,0,0,0,0);	
	 //$myTime = date("Y-m-d H:i:s A", $timeStamp);
		
	// $timeStamp = mktime(0,$add_minute,0,0,0,0);
	 if($type==1){
		$myTime = date("h:i A", $timeStamp);
	 }else{
		$myTime = date("H:i", $timeStamp);
	 }
	 //echo $totHrs."<br>";
	 //echo $pickup_time_minute."<br>";
	 //echo $myTime."<br>";
	 /*$dropoffTimeA=explode(":",$myTime,2);
	 $drop_off_time_hour=$dropoffTimeA[0];
	 $drop_off_time_minute=$dropoffTimeA[1];*/
	// echo '1|'.$myTime.'|'.$drop_off_time_minute;
	 echo '1|'.$myTime; 	
}elseif($step==503){
 $email=$_REQUEST["email"];
 if($email!=''){
	$url=$data24url.'?user='.$data24user.'&pass='.$data24pass.'&api=E&p1='.$email.'';
	$string = get_url_contents($url);
	$xml = new SimpleXMLElement($string);
	if (!$xml) {
		echo "Failed loading XML\n";
		foreach(libxml_get_errors() as $error) {
			echo "\t", $error->message;
		}
		exit();
	}
	$status=$xml->results->result[0]->status;
	if($status=='OK'){
		$EmailValid=$xml->results->result[0]->valid;
		$EmailReason=$xml->results->result[0]->reason;
		echo '<font color="green">Valid email address!</font>';	
	}else{
		echo '<font color="red">Invalid email address!</font>';	
	}
 } 
}elseif($step==504){
 $phone=$_REQUEST["phone"];
 if($phone!=''){
 	$url=$data24url.'?user='.$data24user.'&pass='.$data24pass.'&api=T&p1='.$phone.'';
	$string = get_url_contents($url);
	$xml = new SimpleXMLElement($string);
	if (!$xml) {
		echo "Failed loading XML\n";
		foreach(libxml_get_errors() as $error) {
			echo "\t", $error->message;
		}
		exit();
	}
	$status=$xml->results->result[0]->status;
	if($status=='OK'){
		$PhoneWless=$xml->results->result[0]->wless;
		$PhoneCarrierName=$xml->results->result[0]->carrier_name;
		$PhoneCarrierId=$xml->results->result[0]->carrier_id;
		$PhoneSmsAddress=$xml->results->result[0]->sms_address;
		$PhoneMmsAddress=$xml->results->result[0]->mms_address;
		echo '<font color="green">Valid phone number!</font>';	
	}else{			
		echo '<font color="red">Invalid phone number!</font>';	
	}
 } 
}
function get_url_contents($url){
	$crl = curl_init();
	$timeout = 5;
	curl_setopt ($crl, CURLOPT_URL,$url);
	curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
	$ret = curl_exec($crl);
	curl_close($crl);
	return $ret;
}

function get_time_difference($from_date,$from_time, $to_date,$to_time) 
{ 
    $time1 = strtotime("$from_date $from_time"); 
    $time2 = strtotime("$to_date $to_time"); 
     
    if ($time2 < $time1) 
    { 
        $time2 = $time2 + 86400; 
    } 
     
    return ($time2 - $time1) / 3600; 
     
} 

function getDPTimeF($string,$type) { 
	if($type==1){
		$string=str_replace(" ", ":", $string); 
		$stringA=explode(':',$string,3);
		$timeHr=$stringA[0];
		$timeMin=$stringA[1];
		if($stringA[2]=='PM'){
			$timeHr=$timeHr+12;
		}	
		$newTime=$timeHr.':'.$timeMin.'';
	}else{
		$newTime=$string;
	}
	return($newTime); 
}

?>