<?php

//error_reporting(E_ALL); ini_set('display_errors', 1);

ob_start();

session_start();

require("wp-config.php");

require("fileupload-class.php");

global $wpdb;

$baseSiteUrl='https://www.sacramentolimousineservice.net';

$website='sacramentolimousineservice.net';

$apiKey="1e1c0a7b9491a4s45238591099254058f9";

$apiBaseUrl='https://www.globallimos.com';

$logincheck=date('Y-m-d');

$fromName='Limousine Sacramento';

$fromEmail='info@sacramentolimousineservice.net';

$time=date('Ymdhis');

$ipaddress=$_SERVER['REMOTE_ADDR'];

$sessionid='sls'.session_id();

$actions=$_REQUEST["actions"];

if($actions=='addcustomer'){

	$firstname =$wpdb->_real_escape($_REQUEST['firstname']);	

	$lastname =$wpdb->_real_escape($_REQUEST['lastname']);	

	$email =$wpdb->_real_escape($_REQUEST['email']);	

	$phone =$wpdb->_real_escape($_REQUEST['phone']);	

	$password =$wpdb->_real_escape($_REQUEST['password']);	

	$accounttype =$wpdb->_real_escape($_REQUEST['accounttype']);	

	$phonecountry =$wpdb->_real_escape($_REQUEST['phonecountry']);	

	$serviceid =$wpdb->_real_escape($_REQUEST['serviceid']);	

	$noofpass =$wpdb->_real_escape($_REQUEST['noofpass']);	

	$noofvehicles =$wpdb->_real_escape($_REQUEST['noofvehicles']);	

	$isdiscount =$_REQUEST['isdiscount'];	

	if($isdiscount=="on"){

		$isdiscount=1;

	}else{

		$isdiscount=0;

	}

	

	$address =$wpdb->_real_escape($_REQUEST['Billing_Address']);	

	$city =$wpdb->_real_escape($_REQUEST['Billing_City']);	

	$state =$wpdb->_real_escape($_REQUEST['Billing_State']);	

	$zipcode =$wpdb->_real_escape($_REQUEST['postal_code']);

	$businessname =$wpdb->_real_escape($_REQUEST['businessname']);		

	$jobtitle =$wpdb->_real_escape($_REQUEST['jobtitle']);	

	$typeofbusiness =$wpdb->_real_escape($_REQUEST['typeofbusiness']);	

	$hearaboutus =$wpdb->_real_escape($_REQUEST['hearaboutus']);

	

	

	$annualvolume =$wpdb->_real_escape($_REQUEST['annualvolume']);

	$annualvolumeusd =$wpdb->_real_escape($_REQUEST['annualvolumeusd']);

	$travelers =$wpdb->_real_escape($_REQUEST['travelers']);

	$transportto =$wpdb->_real_escape($_REQUEST['transportto']);

	$notes =$wpdb->_real_escape($_REQUEST['notes']);

	

	$rtnPageUrl='/register/?msg=2';

	if($accounttype=='MeetingEvents'){		

		$rtnPageUrl='/meeting-events/?msg=2';		

		$password=$phone;

	}elseif($accounttype=='CorporateAccount'){		

		$rtnPageUrl='/account-application/?cstfirstname='.$firstname.'&cstlastname='.$lastname.'&businessname='.$businessname.'&msg=2';

		$password=$phone;

	}elseif($accounttype=='TravelAgent'){		

		$rtnPageUrl='/travel-agencies/?msg=2';

		$password=$phone;

	}		

	if($email!='' && $phone!=''){		

		$md5password=md5($password);

		

		///////////////////Global Limos///////////////////////////

		$apiUrl=$apiBaseUrl."/api/customers/add.php?apikey=".$apiKey."&time=".$time;

		$postdata=$postdata.'&firstname='.$firstname.'';

		$postdata=$postdata.'&email='.$email.'';

		$postdata=$postdata.'&lastname='.$lastname.'';

		$postdata=$postdata.'&phone='.$phone.'';

		$postdata=$postdata.'&password='.$password.'';

		$postdata=$postdata.'&isdiscount='.$isdiscount.'';

		$postdata=$postdata.'&ipaddress='.$ipaddress.'';

		$postdata=$postdata.'&accounttype='.$accounttype.'';

		$postdata=$postdata.'&website='.$website.'';

		$postdata=$postdata.'&refid='.$customers_id.'';

		$postdata=$postdata.'&address='.$address.'';

		$postdata=$postdata.'&city='.$city.'';

		$postdata=$postdata.'&state='.$state.'';

		$postdata=$postdata.'&zipcode='.$zipcode.'';

			

		$postdata=$postdata.'&phonecountry='.$phonecountry.'';

		$postdata=$postdata.'&serviceid='.$serviceid.'';

		$postdata=$postdata.'&noofpass='.$noofpass.'';

		$postdata=$postdata.'&noofvehicles='.$noofvehicles.'';

			

		$postdata=$postdata.'&businessname='.$businessname.'';

		$postdata=$postdata.'&jobtitle='.$jobtitle.'';

		$postdata=$postdata.'&typeofbusiness='.$typeofbusiness.'';

		$postdata=$postdata.'&hearaboutus='.$hearaboutus.'';

		

		$postdata=$postdata.'&annualvolume='.$annualvolume.'';

		$postdata=$postdata.'&annualvolumeusd='.$annualvolumeusd.'';

		$postdata=$postdata.'&travelers='.$travelers.'';

		$postdata=$postdata.'&transportto='.$transportto.'';

		$postdata=$postdata.'&notes='.$notes.'';

		//print_r($postdata);

		//exit();	

		$resp=GetApiData($apiUrl,$postdata);			

		$responseJO=json_decode($resp);

		$errorcode=$responseJO->errorcode;		

		///////////////////Global Limos///////////////////////////	

		if($errorcode=="100"){

			$customers_id=$responseJO->customers_id;

			setcookie("cookCustomersName", $firstname, time() + (86400 * 30), "/");

			setcookie("cookCustomersId", $customers_id, time() + (86400 * 30), "/");	

			header("location: /customer-page.php");		

		}else{

			header("location: ".$rtnPageUrl."");		

		}

		exit();	

	}else{	

		header("location: ".$rtnPageUrl."");

		exit();						

	}		

}elseif($actions=='logincustomer'){

	$email =$wpdb->_real_escape($_REQUEST['email']);	

	$password =$wpdb->_real_escape($_REQUEST['password']);		

	$md5password=md5($password);

	

	$apiUrl=$apiBaseUrl."/api/customers/login.php?apikey=".$apiKey."&time=".$time;

	$postdata=$postdata.'&email='.$email.'';

	$postdata=$postdata.'&password='.$md5password.'';

	$resp=GetApiData($apiUrl,$postdata);

	$responseJO=json_decode($resp);

	$errorcode=$responseJO->errorcode;						

	if($errorcode == "100"){

		$status=$responseJO->status;	

		$errorcode=$responseJO->errorcode;		

		if($status == 1){

			$customers_id=$responseJO->customers_id;

			$customers_name=$responseJO->customers_name;

			setcookie("cookCustomersName", $customers_name, time() + (86400 * 30), "/");

			setcookie("cookCustomersId", $customers_id, time() + (86400 * 30), "/");				

			header("location: /customer-page.php");

			exit();

		}else{

			header("location: /sign-in/?msg=1");

			exit();

		}			

	}else{

		header("location: /sign-in/?msg=2");

		exit();

	}

}elseif($actions=='resetyourpasswordcustomer'){

	$v_code =$wpdb->_real_escape($_REQUEST['v_code']);	

	$password =$wpdb->_real_escape($_REQUEST['password1']);		

	$apiUrl=$apiBaseUrl."/api/customers/resetyourpassword.php?apikey=".$apiKey."&time=".$time;

	$postdata=$postdata.'&v_code='.$v_code.'';

	$postdata=$postdata.'&password='.$password.'';

	$resp=GetApiData($apiUrl,$postdata);

	$responseJO=json_decode($resp);

	$errorcode=$responseJO->errorcode;						

	if($errorcode == "100"){

		header("location: /resetyourpassword/?msg=1");

		exit();	

	}else{

		header("location: /resetyourpassword/?msg=2&code=".$v_code);

		exit();

	}	

}elseif($actions=='forgotyourpasswordcustomer'){

	$email =$wpdb->_real_escape($_REQUEST['email']);

	$apiUrl=$apiBaseUrl."/api/customers/forgotyourpassword.php?apikey=".$apiKey."&time=".$time;

	$postdata=$postdata.'&email='.$email.'';

	$resp=GetApiData($apiUrl,$postdata);

	$responseJO=json_decode($resp);

	$errorcode=$responseJO->errorcode;						

	if($errorcode == "100"){

		////////////////////Send Email//////////////////////

		$v_code=$responseJO->v_code;		

		$customers_email=$responseJO->customers_email;

		$customers_name=$responseJO->customers_name;

		

		

		$subject="Password Reset Request from ".$website;

		$link='<a href="'.$baseSiteUrl.'/resetyourpassword/?code='.$v_code.'" target="_blank">Reset Password</a>';

		$mailbody="Dear <b>".$customers_name."</b>,<br><br> <b>Click at the link below to reset your password for login at ".$website."</b><br><br>".$link."<br><br>Thanks";

		

		$headers[] = 'From: '.$fromName.' <'.$fromEmail.'>';

		$headers[] = 'Content-Type: text/html; charset=UTF-8';

		//$headers[] = 'Cc: John Q Codex <jqc@wordpress.org>'; 

		wp_mail( $customers_email, $subject, $mailbody, $headers );



		////////////////////Send Email//////////////////////

		header("location: /forgotyourpassword/?msg=1");

		exit();	

	}else{

		header("location: /forgotyourpassword/?msg=2");

		exit();

	}

}elseif($actions=='logoutcustomer'){		

	unset($_COOKIE['cookCustomersName']);

	setcookie('cookCustomersName', '', time() - 3600, '/');

	unset($_COOKIE['cookCustomersId']);

	setcookie('cookCustomersId', '', time() - 3600, '/');

	header("location: /sign-in/");

	exit();

}elseif($actions=='createlead'){

	$apiUrl=$apiBaseUrl."/api/leads/add.php?apikey=".$apiKey."&time=".$time;

	$paaddress = trim($_REQUEST['paaddressJP']);

	$pacity = trim($_REQUEST['pacityJP']);

	$pastate = trim($_REQUEST['pastateJP']);

	$pazip = trim($_REQUEST['pazipJP']);

	$pickupdate = trim($_REQUEST['pickupdateJP']);

	$pickuptime = trim($_REQUEST['pickuptimeJP']);

	

	$pickupdateAP = trim($_REQUEST['pickupdateAPJP']);

	$pickuptimeAP = trim($_REQUEST['pickuptimeAPJP']);	

	$pickupfnumberAP = trim($_REQUEST['pickupfnumberAPJP']);	

	$pickupfromAP = trim($_REQUEST['pickupfromAPJP']);		

	$dropofftype = trim($_REQUEST['dropofftypeJP']);



	$dropoffairportfn = trim($_REQUEST['dropoffairportfnJP']);

	$dropoffaddressAP = trim($_REQUEST['dropoffaddressAPJP']);

	$dropoffairportname = trim($_REQUEST['dropoffairportnameJP']);

	$numberofpassP1 = trim($_REQUEST['numberofpassP1JP']);	

		

	$numberofpassP2 = trim($_REQUEST['numberofpassP2JP']);	

	$autocomplete_DA = trim($_REQUEST['autocomplete_DAJP']);

	$daaddress = trim($_REQUEST['daaddressJP']);

	$dacity = trim($_REQUEST['dacityJP']);

	$dastate = trim($_REQUEST['dastateJP']);

	$dazip = trim($_REQUEST['dazipJP']);		

	$numberofhour = trim($_REQUEST['numberofhourJP']);

	$numberofpassP3 = trim($_REQUEST['numberofpassP3JP']);		

	$servicetype = trim($_REQUEST['servicetypeJP']);	

	$firstname=trim($_REQUEST['firstnameJP']);	

	$lastname=trim($_REQUEST['lastnameJP']);	

	$cstemail = trim($_REQUEST['cstemailJP']);

	$cstphone = trim($_REQUEST['cstphoneJP']);

	$fleets_id = trim($_REQUEST['fleets_idJP']);

	$rate_fleets_id = trim($_REQUEST['rate_fleets_idJP']);		

	$notes = trim($_REQUEST['notesJP']);		

	

	$sessionid=session_id();

	$ipaddress=$_SERVER['REMOTE_ADDR'];

	$domainname=$website;

	

	$card_number=trim($_REQUEST['card_numberJP']);

	$security_code=trim($_REQUEST['security_codeJP']);

	$expiration_date_month=trim($_REQUEST['expiration_date_monthJP']);

	$expiration_date_year=trim($_REQUEST['expiration_date_yearJP']);

	$postal_code=trim($_REQUEST['postal_codeJP']);

	$Name_On_Card=trim($_REQUEST['Name_On_CardJP']);

	$airportratefleetssearchid=trim($_REQUEST['airportratefleetssearchidJP']);



	$postdata=$postdata.'&postal_code='.$postal_code.'';

	$postdata=$postdata.'&expiration_date_year='.$expiration_date_year.'';

	$postdata=$postdata.'&expiration_date_month='.$expiration_date_month.'';

	$postdata=$postdata.'&security_code='.$security_code.'';

	$postdata=$postdata.'&card_number='.$card_number.'';

	$postdata=$postdata.'&domainname='.$domainname.'';

	$postdata=$postdata.'&ipaddress='.$ipaddress.'';

	$postdata=$postdata.'&sessionid='.$sessionid.'';

	$postdata=$postdata.'&notes='.$notes.'';

	$postdata=$postdata.'&rate_fleets_id='.$rate_fleets_id.'';

	$postdata=$postdata.'&fleets_id='.$fleets_id.'';

	$postdata=$postdata.'&cstphone='.$cstphone.'';	

	$postdata=$postdata.'&cstemail='.$cstemail.'';

	$postdata=$postdata.'&lastname='.$lastname.'';

	$postdata=$postdata.'&firstname='.$firstname.'';

	$postdata=$postdata.'&servicetype='.$servicetype.'';

	$postdata=$postdata.'&numberofpassP3='.$numberofpassP3.'';

	$postdata=$postdata.'&dazip='.$dazip.'';

	$postdata=$postdata.'&dastate='.$dastate.'';

	$postdata=$postdata.'&dacity='.$dacity.'';

	$postdata=$postdata.'&daaddress='.$daaddress.'';

	$postdata=$postdata.'&numberofhour='.$numberofhour.'';

	$postdata=$postdata.'&autocomplete_DA='.$autocomplete_DA.'';

	$postdata=$postdata.'&numberofpassP2='.$numberofpassP2.'';

	$postdata=$postdata.'&numberofpassP1='.$numberofpassP1.'';

	$postdata=$postdata.'&dropoffairportname='.$dropoffairportname.'';

	$postdata=$postdata.'&dropoffaddressAP='.$dropoffaddressAP.'';

	$postdata=$postdata.'&dropoffairportfn='.$dropoffairportfn.'';

	$postdata=$postdata.'&dropofftype='.$dropofftype.'';

	$postdata=$postdata.'&pickupfromAP='.$pickupfromAP.'';

	$postdata=$postdata.'&pickupfnumberAP='.$pickupfnumberAP.'';

	$postdata=$postdata.'&pickuptimeAP='.$pickuptimeAP.'';

	$postdata=$postdata.'&pickupdateAP='.$pickupdateAP.'';	

	$postdata=$postdata.'&pickuptime='.$pickuptime.'';

	$postdata=$postdata.'&pickupdate='.$pickupdate.'';

	$postdata=$postdata.'&pazip='.$pazip.'';

	$postdata=$postdata.'&pacity='.$pacity.'';

	$postdata=$postdata.'&pastate='.$pastate.'';

	$postdata=$postdata.'&paaddress='.$paaddress.'';

	$postdata=$postdata.'&searchfrom='.$searchfrom.'';

	$postdata=$postdata.'&Name_On_Card='.$Name_On_Card.'';

	$postdata=$postdata.'&airportratefleetssearchid='.$airportratefleetssearchid.'';

	$resp=GetApiData($apiUrl,$postdata);	

}elseif($actions=='changepasswordcustomer'){

	$customers_id=$wpdb->_real_escape($_REQUEST['customersid']);	

	$password =$wpdb->_real_escape($_REQUEST['cstpassword']);		

	if($customers_id != ""){		

		///////////////////Global Limos///////////////////////////

		

		$updatetype='changepassword';

		$apiUrl=$apiBaseUrl."/api/customers/update.php?apikey=".$apiKey."&time=".$time;

		$postdata=$postdata.'&customers_id='.$customers_id.'';

		$postdata=$postdata.'&password='.$password.'';

		$postdata=$postdata.'&updatetype='.$updatetype.'';

		$resp=GetApiData($apiUrl,$postdata);			

		///////////////////Global Limos///////////////////////////	

		echo '<font color="#FF0000" size="+1">Your password has been changed successfully!</font>';

		exit();

	}

}elseif($actions=='updateprofilecustomer'){

	$customers_id=$wpdb->_real_escape($_REQUEST['customersid']);	

	$customers_name =$wpdb->_real_escape($_REQUEST['cstfirstname']);

	$customers_name_l =$wpdb->_real_escape($_REQUEST['cstlastname']);

	$customers_email =$wpdb->_real_escape($_REQUEST['cstemail']);

	$customers_mobile =$wpdb->_real_escape($_REQUEST['cstphone']);

	$customers_zip =$wpdb->_real_escape($_REQUEST['cstzip']);

	$is_discount =$wpdb->_real_escape($_REQUEST['cstisdiscount']);

			

	$accounttype =$wpdb->_real_escape($_REQUEST['accounttype']);	

	$serviceid =$wpdb->_real_escape($_REQUEST['serviceid']);		

	$noofpass =$wpdb->_real_escape($_REQUEST['noofpass']);		

	$noofvehicles =$wpdb->_real_escape($_REQUEST['noofvehicles']);		

	$phonecountry =$wpdb->_real_escape($_REQUEST['phonecountry']);	

	

					

	$address =$wpdb->_real_escape($_REQUEST['Billing_Address']);		

	$city =$wpdb->_real_escape($_REQUEST['Billing_City']);		

	$state =$wpdb->_real_escape($_REQUEST['Billing_State']);	

	if($customers_zip==''){	

		$customers_zip =$wpdb->_real_escape($_REQUEST['postal_code']);		

	}

	$jobtitle =$wpdb->_real_escape($_REQUEST['jobtitle']);		

	$typeofbusiness =$wpdb->_real_escape($_REQUEST['typeofbusiness']);		

	$hearaboutus =$wpdb->_real_escape($_REQUEST['hearaboutus']);		

	$department =$wpdb->_real_escape($_REQUEST['department']);		

	$noofpeopleauth =$wpdb->_real_escape($_REQUEST['noofpeopleauth']);		

	$notesforus =$wpdb->_real_escape($_REQUEST['notesforus']);		

	$notesfordrivers =$wpdb->_real_escape($_REQUEST['notesfordrivers']);		

	$notesforcustomer =$wpdb->_real_escape($_REQUEST['notesforcustomer']);		

	$custaccounttype =$wpdb->_real_escape($_REQUEST['custaccounttype']);		

	$cstpriority =$wpdb->_real_escape($_REQUEST['cstpriority']);		

	$webaccess =$wpdb->_real_escape($_REQUEST['webaccess']);	

	$mainactwebaccess =$wpdb->_real_escape($_REQUEST['mainactwebaccess']);	

	$rentalagreement =$wpdb->_real_escape($_REQUEST['rentalagreement']);	

	$paymentmethod =$wpdb->_real_escape($_REQUEST['paymentmethod']);

	$paymentterms =$wpdb->_real_escape($_REQUEST['paymentterms']);

	if($customers_id != ""){

		///////////////////Global Limos///////////////////////////

		

		$updatetype='fullupdate';

		$apiUrl=$apiBaseUrl."/api/customers/update.php?apikey=".$apiKey."&time=".$time;

		$postdata=$postdata.'&customers_id='.$customers_id.'';

		$postdata=$postdata.'&updatetype='.$updatetype.'';

		$postdata=$postdata.'&firstname='.$customers_name.'';

		$postdata=$postdata.'&lastname='.$customers_name_l.'';

		$postdata=$postdata.'&email='.$customers_email.'';

		$postdata=$postdata.'&phone='.$customers_mobile.'';

		$postdata=$postdata.'&zipcode='.$customers_zip.'';

		$postdata=$postdata.'&isdiscount='.$is_discount.'';	

		

		$postdata=$postdata.'&accounttype='.$accounttype.'';				

		$postdata=$postdata.'&phonecountry='.$phonecountry.'';

		$postdata=$postdata.'&serviceid='.$serviceid.'';

		$postdata=$postdata.'&noofpass='.$noofpass.'';

		$postdata=$postdata.'&noofvehicles='.$noofvehicles.'';

		

		$postdata=$postdata.'&address='.$address.'';

		$postdata=$postdata.'&city='.$city.'';

		$postdata=$postdata.'&state='.$state.'';

		$postdata=$postdata.'&typeofbusiness='.$typeofbusiness.'';

		$postdata=$postdata.'&jobtitle='.$jobtitle.'';

		$postdata=$postdata.'&hearaboutus='.$hearaboutus.'';

		$postdata=$postdata.'&department='.$department.'';

		$postdata=$postdata.'&noofpeopleauth='.$noofpeopleauth.'';

		$postdata=$postdata.'&notesforus='.$notesforus.'';

		$postdata=$postdata.'&notesfordrivers='.$notesfordrivers.'';

		$postdata=$postdata.'&notesforcustomer='.$notesforcustomer.'';

		$postdata=$postdata.'&custaccounttype='.$custaccounttype.'';

		$postdata=$postdata.'&cstpriority='.$cstpriority.'';

		$postdata=$postdata.'&webaccess='.$webaccess.'';

		$postdata=$postdata.'&mainactwebaccess='.$mainactwebaccess.'';

		$postdata=$postdata.'&rentalagreement='.$rentalagreement.'';

		$postdata=$postdata.'&paymentmethod='.$paymentmethod.'';

		$postdata=$postdata.'&paymentterms='.$paymentterms.'';

		$resp=GetApiData($apiUrl,$postdata);	

		///////////////////Global Limos///////////////////////////	

		echo '<font color="#FF0000" size="+1">Your profile successfully updated!</font>';

		exit();

	}

}elseif($actions=='uploadprofileimagecustomer'){

	$customers_id=$wpdb->_real_escape($_REQUEST['customersid']);				

	if($customers_id != ""){	

		$my_uploader = new uploader('en');

		$my_uploader->upload('profileimage', '');

		$my_uploader->save_file("uploads/customers", 2);

		if ($my_uploader->error) {

			print($my_uploader->error . "<br><br>\n");

		} else {

			print("Thanks for uploading " . $my_uploader->file['name'] . "<br><br>\n");

		}

		$profileimage = $my_uploader->file['name'];

		if($profileimage!=''){	

			$filedata=$baseSiteUrl.'/uploads/customers/'.$profileimage;				

			$apiUrl=$apiBaseUrl."/api/customers/uploadprofileimage.php?apikey=".$apiKey."&time=".$time;	

			$postdata=$postdata.'&customers_id='.$customers_id.'';

			$postdata=$postdata.'&filedata='.$filedata.'';

			$postdata=$postdata.'&filename='.$profileimage.'';

			$resp=GetApiData($apiUrl,$postdata);

			

			//if(file_exists("uploads/customers/".$profileimage)){

				//unlink("uploads/customers/".$profileimage);

			//}

		}

		header("location: /customer-page.php");

		exit();	

	}

}elseif($actions=='gotocorporate1'){

	$cstname=$wpdb->_real_escape($_REQUEST['cstname1']);

	$businessname=$wpdb->_real_escape($_REQUEST['businessname1']);				

	$cstnameA=explode(' ',$cstname,2);

	$cstfirstname=$cstnameA[0];

	$cstlastname=$cstnameA[1];

	header("location: /account-application/?cstfirstname=".$cstfirstname."&cstlastname=".$cstlastname."&businessname=".$businessname."");

	exit();		

}elseif($actions=='gotocorporate2'){

	$cstname=$wpdb->_real_escape($_REQUEST['cstname2']);

	$businessname=$wpdb->_real_escape($_REQUEST['businessname2']);				

	$cstnameA=explode(' ',$cstname,2);

	$cstfirstname=$cstnameA[0];

	$cstlastname=$cstnameA[1];

	header("location: /account-application/?cstfirstname=".$cstfirstname."&cstlastname=".$cstlastname."&businessname=".$businessname."");

	exit();	

}elseif($actions=='getdiscountandleads'){
	$codeTop=$_REQUEST["codeTop"];
	if($codeTop=='top'){	
		$cstnameA=explode(' ',$wpdb->_real_escape($_REQUEST['cstnameT']),2);			
		$firstname=$cstnameA[0];	
		$lastname=$cstnameA[1];
		$email =$wpdb->_real_escape($_REQUEST['cstemailT']);	
		$phone =$wpdb->_real_escape($_REQUEST['cstphoneT']);
		$guid =$wpdb->_real_escape($_REQUEST['guidTop']);
		$phonecode1=$wpdb->_real_escape($_REQUEST['phonecode1']);
		$phone=str_replace('-','',$phone);
		$phone=str_replace('(','',$phone);
		$phone=str_replace(')','',$phone);
		$phone=str_replace(' ','',$phone);
		$phone=str_replace('+1','',$phone);
		
		/*$apiUrl=$apiBaseUrl."/twiliocall.php?apikey=".$apiKey."&time=".$time;
		$postdata=$postdata.'&phone='.$phone.'';	
		$respTW=GetApiData($apiUrl,$postdata);			
		$responseJOTW=json_decode($respTW);
		$caller_first_name=$responseJOTW->caller_first_name;
		$caller_last_name=$responseJOTW->caller_last_name;*/
		if($caller_first_name!=''){
			$firstname=$caller_first_name;		
		}else{
			$firstname='NA';	
		}
		if($caller_last_name!=''){
			$lastname=$caller_last_name;		
		}else{	
			$lastname='NA';			
		}
		
		$email=$phone.'@sacramentolimousineservice.net';
	}elseif($codeTop=='ExitPopup'){			
		$phone =$wpdb->_real_escape($_REQUEST['cstphoneExitPopup']);
		$guid =$wpdb->_real_escape($_REQUEST['guidExitPopup']);
		$phonecode1 =$wpdb->_real_escape($_REQUEST['phonecode1ExitPopup']);
		$phone=str_replace('-','',$phone);
		$phone=str_replace('(','',$phone);
		$phone=str_replace(')','',$phone);
		$phone=str_replace(' ','',$phone);
		$phone=str_replace('+1','',$phone);
		
		/*$apiUrl=$apiBaseUrl."/twiliocall.php?apikey=".$apiKey."&time=".$time;
		$postdata=$postdata.'&phone='.$phone.'';	
		$respTW=GetApiData($apiUrl,$postdata);			
		$responseJOTW=json_decode($respTW);
		$caller_first_name=$responseJOTW->caller_first_name;
		$caller_last_name=$responseJOTW->caller_last_name;*/
		if($caller_first_name!=''){
			$firstname=$caller_first_name;		
		}else{
			$firstname='NA';	
		}
		if($caller_last_name!=''){
			$lastname=$caller_last_name;		
		}else{	
			$lastname='NA';			
		}
		
		$email=$phone.'@sacramentolimousineservice.net';
		$phonecode1=$wpdb->_real_escape($_REQUEST['phonecode1ExitPopup']);
	}else{		
		$cstnameA=explode(' ',$wpdb->_real_escape($_REQUEST['cstnameB']),2);			
		$firstname=$cstnameA[0];	
		$lastname=$cstnameA[1];
		$email =$wpdb->_real_escape($_REQUEST['cstemailB']);	
		$phone =$wpdb->_real_escape($_REQUEST['cstphoneB']);
		$guid =$wpdb->_real_escape($_REQUEST['guidB']);			
		$phonecode1=$wpdb->_real_escape($_REQUEST['phonecode1']);
	}	
	$phonecountry=$wpdb->_real_escape($_REQUEST['phonecountry']);	
	$password =$wpdb->_real_escape($phone);	
	$accounttype='PersonalAccount';	
	$serviceid=0;	
	$noofpass=0;	
	$noofvehicles=0;	
	$isdiscount=1;	
	
	$address='';	
	$city='';	
	$state='';	
	$zipcode='';
	$businessname='';		
	$jobtitle='';	
	$typeofbusiness='';	
	$hearaboutus='';
	
	$rtnPageUrl='/vehicle-selection/';
	if($email!='' && $phone!=''){		
		///////////////////Global Limos///////////////////////////
		$apiUrl=$apiBaseUrl."/api/customers/add.php?apikey=".$apiKey."&time=".$time;
		$postdata=$postdata.'&firstname='.$firstname.'';
		$postdata=$postdata.'&email='.$email.'';
		$postdata=$postdata.'&lastname='.$lastname.'';
		$postdata=$postdata.'&phone='.$phone.'';
		$postdata=$postdata.'&password='.$password.'';
		$postdata=$postdata.'&isdiscount='.$isdiscount.'';
		$postdata=$postdata.'&ipaddress='.$ipaddress.'';
		$postdata=$postdata.'&accounttype='.$accounttype.'';
		$postdata=$postdata.'&website='.$website.'';
		$postdata=$postdata.'&refid='.$customers_id.'';
		$postdata=$postdata.'&address='.$address.'';
		$postdata=$postdata.'&city='.$city.'';
		$postdata=$postdata.'&state='.$state.'';
		$postdata=$postdata.'&zipcode='.$zipcode.'';
			
		$postdata=$postdata.'&phonecountry='.$phonecountry.'';
		$postdata=$postdata.'&phonecode1='.$phonecode1.'';
		$postdata=$postdata.'&serviceid='.$serviceid.'';
		$postdata=$postdata.'&noofpass='.$noofpass.'';
		$postdata=$postdata.'&noofvehicles='.$noofvehicles.'';
			
		$postdata=$postdata.'&businessname='.$businessname.'';
		$postdata=$postdata.'&jobtitle='.$jobtitle.'';
		$postdata=$postdata.'&typeofbusiness='.$typeofbusiness.'';
		$postdata=$postdata.'&hearaboutus='.$hearaboutus.'';		
		$postdata=$postdata.'&rsvguid='.$guid.'';	
		$resp=GetApiData($apiUrl,$postdata);			
		$responseJO=json_decode($resp);
		$customers_id=$responseJO->customers_id;
		//print_r($responseJO);
		///////////////////Global Limos///////////////////////////			
		if($customers_id!=''){
			if($firstname=='NA'){
				$firstname=$phone;
			}
			setcookie("cookCustomersId", $customers_id, time() + (86400 * 30), "/");	
			setcookie("cookCustomersName", $firstname, time() + (86400 * 30), "/");			
		}
		if($guid!=''){
			header("location: /vehicle-selection/?guid=".$guid);
		}else{
			header("location: /");
		}
		exit();						
	}	
}elseif($actions=='apisearchfleets'){

	$customers_id=$_REQUEST['customers_id'];

	$sessionidAPI=$sessionid;

	$searchfrom=$_REQUEST['searchfrom'];	

	$services_id =$wpdb->_real_escape($_REQUEST['services_id']);

	$autocomplete =$wpdb->_real_escape($_REQUEST['autocomplete']);

	$street_number =$wpdb->_real_escape($_REQUEST['street_number']);

	$route =$wpdb->_real_escape($_REQUEST['route']);

	$locality =$wpdb->_real_escape($_REQUEST['locality']);

	$administrative_area_level_1 =$wpdb->_real_escape($_REQUEST['administrative_area_level_1']);

	$postal_code =$wpdb->_real_escape($_REQUEST['postal_code']);

	$autocomplete_DA =$wpdb->_real_escape($_REQUEST['autocomplete_DA']);

	$street_number_DA =$wpdb->_real_escape($_REQUEST['street_number_DA']);

	$route_DA =$wpdb->_real_escape($_REQUEST['route_DA']);

	$locality_DA =$wpdb->_real_escape($_REQUEST['locality_DA']);

	$administrative_area_level_1_DA =$wpdb->_real_escape($_REQUEST['administrative_area_level_1_DA']);

	$postal_code_DA =$wpdb->_real_escape($_REQUEST['postal_code_DA']);

	$pickup_date =$wpdb->_real_escape($_REQUEST['pickup_date']);

	$pickup_timeH =$wpdb->_real_escape($_REQUEST['pickup_timeH']);

	$pickup_timeM =$wpdb->_real_escape($_REQUEST['pickup_timeM']);

	$dropup_timeH =$wpdb->_real_escape($_REQUEST['dropup_timeH']);

	$dropup_timeM =$wpdb->_real_escape($_REQUEST['dropup_timeM']);

	$no_of_passengers =$wpdb->_real_escape($_REQUEST['no_of_passengers']);

	$is_round_trip =$wpdb->_real_escape($_REQUEST['is_round_trip']);			

	$roundTripPickupdateAP =$wpdb->_real_escape($_REQUEST['roundTripPickupdateAP']);	

	$roundTripPickuptimeAP =$wpdb->_real_escape($_REQUEST['roundTripPickuptimeAP']);		

	$is_business =$wpdb->_real_escape($_REQUEST['is_business']);		

	$no_of_hrs =$wpdb->_real_escape($_REQUEST['no_of_hrs']);	

	$websiteAPI=$website;

	$ipaddressAPI=$_SERVER['REMOTE_ADDR'];

	$isAirPort=0;
	if($services_id == 1000 || $services_id == 1001 || $services_id == 1002){	
		$isAirPort=1;		
	}			

	if($pickup_date!=''){

		///////////////////Global Limos///////////////////////////

		$apiUrl=$apiBaseUrl."/createsearch.php?apikey=".$apiKey."&time=".$time;

		$postdata=$postdata.'&customers_id='.$customers_id.'';

		$postdata=$postdata.'&searchfrom='.$searchfrom.'';

		$postdata=$postdata.'&services_id='.$services_id.'';

		$postdata=$postdata.'&autocomplete='.$autocomplete.'';

		$postdata=$postdata.'&street_number='.$street_number.'';

		$postdata=$postdata.'&route='.$route.'';

		$postdata=$postdata.'&locality='.$locality.'';

		$postdata=$postdata.'&administrative_area_level_1='.$administrative_area_level_1.'';			

		$postdata=$postdata.'&postal_code='.$postal_code.'';				

		$postdata=$postdata.'&autocomplete_DA='.$autocomplete_DA.'';

		$postdata=$postdata.'&street_number_DA='.$street_number_DA.'';

		$postdata=$postdata.'&route_DA='.$route_DA.'';

		$postdata=$postdata.'&locality_DA='.$locality_DA.'';

		$postdata=$postdata.'&administrative_area_level_1_DA='.$administrative_area_level_1_DA.'';

		$postdata=$postdata.'&postal_code_DA='.$postal_code_DA.'';

		$postdata=$postdata.'&pickup_date='.$pickup_date.'';

		$postdata=$postdata.'&pickup_timeH='.$pickup_timeH.'';

		$postdata=$postdata.'&pickup_timeM='.$pickup_timeM.'';

		$postdata=$postdata.'&dropup_timeH='.$dropup_timeH.'';

		$postdata=$postdata.'&dropup_timeM='.$dropup_timeM.'';

		$postdata=$postdata.'&roundTripPickuptimeAP='.$roundTripPickuptimeAP.'';

		$postdata=$postdata.'&no_of_passengers='.$no_of_passengers.'';

		$postdata=$postdata.'&is_round_trip='.$is_round_trip.'';

		$postdata=$postdata.'&roundTripPickupdateAP='.$roundTripPickupdateAP.'';

		$postdata=$postdata.'&roundTripPickuptimeAP='.$roundTripPickuptimeAP.'';

		$postdata=$postdata.'&is_business='.$is_business.'';

		$postdata=$postdata.'&no_of_hrs='.$no_of_hrs.'';

		$postdata=$postdata.'&websiteAPI='.$websiteAPI.'';

		$postdata=$postdata.'&ipaddressAPI='.$ipaddressAPI.'';

		$postdata=$postdata.'&sessionidAPI='.$sessionidAPI.'';

		$postdata=$postdata.'&rtnurlAPI='.$rtnurlAPI.'';

		//print_r($postdata);

		//exit();

		$resp=GetApiData($apiUrl,$postdata);			

		//print_r($resp);

		///////////////////Global Limos///////////////////////////	

		//echo $baseSiteUrl;

		/*if($isAirPort==0){

			if($customers_id=="" || $customers_id==0){

				header("location: ".$baseSiteUrl."/discount/?guid=".$resp);

				exit();	

			}

		}*/

		header("location: ".$baseSiteUrl."/vehicle-selection/?guid=".$resp);

		exit();

	}

}elseif($actions=='converttoreservation'){

	$sessionidAPI=$sessionid;

	$guid=$_REQUEST["guid"];

	$reservation_id=$_REQUEST["reservation_id"];	

	$rate_fleets_id=$_REQUEST["rate_fleets_id"];

	$cust_p_email=$wpdb->_real_escape($_REQUEST["cust_p_email"]);

	$phone_number=$wpdb->_real_escape($_REQUEST["phone_number"]);

	$pa_location=$wpdb->_real_escape($_REQUEST["pa_location"]);

	$da_location=$wpdb->_real_escape($_REQUEST["da_location"]);

	$pa_address=$wpdb->_real_escape($_REQUEST["pa_address"]);

	$pa_city=$wpdb->_real_escape($_REQUEST["pa_city"]);

	$pa_state=$wpdb->_real_escape($_REQUEST["pa_state"]);

	$pa_zip=$wpdb->_real_escape($_REQUEST["pa_zip"]);		

	

	$autocomplete_DA=$wpdb->_real_escape($_REQUEST["autocomplete_DA"]);

	$da_location=$autocomplete_DA;

			

	$street_number_DA=$wpdb->_real_escape($_REQUEST["street_number_DA"]);

	$route_DA=$wpdb->_real_escape($_REQUEST["route_DA"]);

	$locality_DA=$wpdb->_real_escape($_REQUEST["locality_DA"]);

	$administrative_area_level_1_DA=$wpdb->_real_escape($_REQUEST["administrative_area_level_1_DA"]);

	$postal_code_DA=$wpdb->_real_escape($_REQUEST["postal_code_DA"]);

	$country_DA=$wpdb->_real_escape($_REQUEST["country_DA"]);

		

	$da_address=$wpdb->_real_escape($_REQUEST["da_address"]);

	if($da_address==""){

		$da_address=$street_number_DA." ".$route_DA;

	}

	

	$da_city=$locality_DA;

	$da_state=$administrative_area_level_1_DA;

	$da_zip=$postal_code_DA;



	$Payment_Method=$wpdb->_real_escape($_REQUEST["Payment_Method"]);

	$Payment_Status=$wpdb->_real_escape($_REQUEST["Payment_Status"]);

	$card_number=$wpdb->_real_escape($_REQUEST["card_number"]);

	$expiration_date_month=$wpdb->_real_escape($_REQUEST["expiration_date_month"]);

	$expiration_date_year=$wpdb->_real_escape($_REQUEST["expiration_date_year"]);

	

	$Name_On_Card=$wpdb->_real_escape($_REQUEST["Name_On_Card"]);

	$Last_Name_On_Card=$wpdb->_real_escape($_REQUEST["Last_Name_On_Card"]);

	$Name_On_Card=$Name_On_Card.' '.$Last_Name_On_Card;

	$CC_Type=$wpdb->_real_escape($_REQUEST["CC_Type"]);

	$Billing_Address=$wpdb->_real_escape($_REQUEST["Billing_Address"]);

	$Billing_State=$wpdb->_real_escape($_REQUEST["Billing_State"]);

	$postal_code=$wpdb->_real_escape($_REQUEST["postal_code"]);

	$Company_Name=$wpdb->_real_escape($_REQUEST["Company_Name"]);

	$Billing_City=$wpdb->_real_escape($_REQUEST["Billing_City"]);

	$Billing_Phone=$wpdb->_real_escape($_REQUEST["Billing_Phone"]);

	$x_first_name=$wpdb->_real_escape($_REQUEST["x_first_name"]);

	$x_last_name=$wpdb->_real_escape($_REQUEST["x_last_name"]);

	$x_card_code=$wpdb->_real_escape($_REQUEST["x_card_code"]);

	$x_amount=$wpdb->_real_escape($_REQUEST["x_amount"]);

	

	$websiteAPI=$website;			

	if($reservation_id!=''){

		///////////////////Global Limos///////////////////////////

		$apiUrl=$apiBaseUrl."/booking/converttoreservation?apikey=".$apiKey."&time=".$time;

		$postdata=$postdata.'&websiteAPI='.$websiteAPI.'';

		$postdata=$postdata.'&guid='.$guid.'';

		$postdata=$postdata.'&rate_fleets_id='.$rate_fleets_id.'';

		$postdata=$postdata.'&reservation_id='.$reservation_id.'';

		$postdata=$postdata.'&cust_p_email='.$cust_p_email.'';

		$postdata=$postdata.'&phone_number='.$phone_number.'';

		$postdata=$postdata.'&pa_location='.$pa_location.'';

		$postdata=$postdata.'&da_location='.$da_location.'';

		$postdata=$postdata.'&pa_address='.$pa_address.'';			

		$postdata=$postdata.'&pa_city='.$pa_city.'';				

		$postdata=$postdata.'&pa_state='.$pa_state.'';

		$postdata=$postdata.'&pa_zip='.$pa_zip.'';

		$postdata=$postdata.'&autocomplete_DA='.$da_location.'';

		$postdata=$postdata.'&street_number_DA='.$street_number_DA.'';

		$postdata=$postdata.'&route_DA='.$route_DA.'';

		$postdata=$postdata.'&locality_DA='.$locality_DA.'';

		$postdata=$postdata.'&administrative_area_level_1_DA='.$administrative_area_level_1_DA.'';

		$postdata=$postdata.'&postal_code_DA='.$postal_code_DA.'';

		$postdata=$postdata.'&country_DA='.$country_DA.'';

		$postdata=$postdata.'&da_address='.$da_address.'';

		

		$postdata=$postdata.'&Payment_Method='.$Payment_Method.'';

		$postdata=$postdata.'&Payment_Status='.$Payment_Status.'';

		$postdata=$postdata.'&card_number='.$card_number.'';

		$postdata=$postdata.'&expiration_date_month='.$expiration_date_month.'';

		$postdata=$postdata.'&expiration_date_year='.$expiration_date_year.'';

		$postdata=$postdata.'&Name_On_Card='.$Name_On_Card.'';

		$postdata=$postdata.'&Last_Name_On_Card='.$Last_Name_On_Card.'';

		$postdata=$postdata.'&CC_Type='.$CC_Type.'';

		$postdata=$postdata.'&Billing_Address='.$Billing_Address.'';

		$postdata=$postdata.'&Billing_State='.$Billing_State.'';

		$postdata=$postdata.'&postal_code='.$postal_code.'';

		$postdata=$postdata.'&Company_Name='.$Company_Name.'';

		$postdata=$postdata.'&Billing_City='.$Billing_City.'';

		$postdata=$postdata.'&Billing_Phone='.$Billing_Phone.'';

		$postdata=$postdata.'&x_first_name='.$x_first_name.'';

		$postdata=$postdata.'&x_last_name='.$x_last_name.'';

		$postdata=$postdata.'&x_card_code='.$x_card_code.'';

		$postdata=$postdata.'&x_amount='.$x_amount.'';

		$resp=GetApiData($apiUrl,$postdata);	

		//print_r($resp);		

		///////////////////Global Limos///////////////////////////	
		$apiUrl=$apiBaseUrl."/api/customers/loginwithleadid.php?apikey=".$apiKey."&time=".$time;
		$postdata=$postdata.'&reservation_id='.$reservation_id.'';
		$resp=GetApiData($apiUrl,$postdata);
		$responseJO=json_decode($resp);
		$errorcode=$responseJO->errorcode;						
		if($errorcode == "100"){
			$status=$responseJO->status;	
			$errorcode=$responseJO->errorcode;		
		
			$customers_id=$responseJO->customers_id;
			$customers_name=$responseJO->customers_name;
			setcookie("cookCustomersName", $customers_name, time() + (86400 * 30), "/");
			setcookie("cookCustomersId", $customers_id, time() + (86400 * 30), "/");							
		}
		header("location: /thank-you/?revid=".$reservation_id);

		exit();

	}

}elseif($actions=='addvendors'){	

	$business_name =$wpdb->_real_escape($_REQUEST['business_name']);

	$address =$wpdb->_real_escape($_REQUEST['address']);

	$city =$wpdb->_real_escape($_REQUEST['city']);

	$state =$wpdb->_real_escape($_REQUEST['state']);

	$zip =$wpdb->_real_escape($_REQUEST['zip']);

	$phone =$wpdb->_real_escape($_REQUEST['phone']);

	$web_url =$wpdb->_real_escape($_REQUEST['web_url']);

	$email =$wpdb->_real_escape($_REQUEST['email']);

	$recentlyopened =$wpdb->_real_escape($_REQUEST['recentlyopened']);

	$firstname =$wpdb->_real_escape($_REQUEST['firstname']);

	$lastname =$wpdb->_real_escape($_REQUEST['lastname']);

	$years_in_business =$wpdb->_real_escape($_REQUEST['years_in_business']);

	$insuredvehicles =$wpdb->_real_escape($_REQUEST['insuredvehicles']);

	$publicdisplaydba =$wpdb->_real_escape($_REQUEST['publicdisplaydba']);

	$prefferedcontactphone =$wpdb->_real_escape($_REQUEST['prefferedcontactphone']);

	$prefferedcontactphone =$wpdb->_real_escape($_REQUEST['prefferedcontactphone']);

	$ipaddressAPI=$_SERVER['REMOTE_ADDR'];			

	if($phone!=''){

		///////////////////Global Limos///////////////////////////

		$apiUrl=$apiBaseUrl."/vendors/addvendors?apikey=".$apiKey."&time=".$time;

		$postdata=$postdata.'&ipaddressAPI='.$ipaddressAPI.'';

		$postdata=$postdata.'&business_name='.$business_name.'';

		$postdata=$postdata.'&address='.$address.'';

		$postdata=$postdata.'&city='.$city.'';

		$postdata=$postdata.'&state='.$state.'';

		$postdata=$postdata.'&zip='.$zip.'';

		$postdata=$postdata.'&phone='.$phone.'';

		$postdata=$postdata.'&web_url='.$web_url.'';			

		$postdata=$postdata.'&email='.$email.'';				

		$postdata=$postdata.'&recentlyopened='.$recentlyopened.'';

		$postdata=$postdata.'&firstname='.$firstname.'';

		$postdata=$postdata.'&lastname='.$lastname.'';

		$postdata=$postdata.'&years_in_business='.$years_in_business.'';

		$postdata=$postdata.'&insuredvehicles='.$insuredvehicles.'';

		$postdata=$postdata.'&publicdisplaydba='.$publicdisplaydba.'';

		$postdata=$postdata.'&prefferedcontactphone='.$prefferedcontactphone.'';

		$postdata=$postdata.'&prefferedcontactphone='.$prefferedcontactphone.'';		

		$resp=GetApiData($apiUrl,$postdata);			

		//print_r($resp);

		///////////////////Global Limos///////////////////////////	

		header("location: ".$baseSiteUrl."/affiliates-thanks/?refid=".$resp);

		exit();

	}

}elseif($actions=='forcelogincustomer'){

	$customers_id =$_REQUEST['customers_id'];	

	

	$apiUrl=$apiBaseUrl."/api/customers/forcelogin.php?apikey=".$apiKey."&time=".$time;

	$postdata=$postdata.'&customers_id='.$customers_id.'';

	$resp=GetApiData($apiUrl,$postdata);

	$responseJO=json_decode($resp);

	$errorcode=$responseJO->errorcode;						

	if($errorcode == "100"){

		$status=$responseJO->status;	

		$errorcode=$responseJO->errorcode;		

	

		$customers_id=$responseJO->customers_id;

		$customers_name=$responseJO->customers_name;

		setcookie("cookCustomersName", $customers_name, time() + (86400 * 30), "/");

		setcookie("cookCustomersId", $customers_id, time() + (86400 * 30), "/");				

		header("location: /customer-page.php");

		exit();		

	}else{

		header("location: /sign-in/?msg=2");

		exit();

	}

}elseif($actions=='update_card_authorizion'){

	$reservation_id=$_REQUEST["reservation_id"];

	$guid=$_REQUEST["guid"];

	$rfid=$_REQUEST["rfid"];

	$a_tandc=1;

	$Name_On_Card=$wpdb->_real_escape($_REQUEST["Name_On_Card"]);

	$CC_Type=$wpdb->_real_escape($_REQUEST["CC_Type"]);

	$Company_Name=$wpdb->_real_escape($_REQUEST["Company_Name"]);

	$card_number=$wpdb->_real_escape($_REQUEST["card_number"]);

	$expiration_date_month=$wpdb->_real_escape($_REQUEST["expiration_date_month"]);

	$expiration_date_year=$wpdb->_real_escape($_REQUEST["expiration_date_year"]);

	$Payment_Method=$wpdb->_real_escape($_REQUEST["Payment_Method"]);

	$Billing_Address=$wpdb->_real_escape($_REQUEST["Billing_Address"]);

	$Billing_State=$wpdb->_real_escape($_REQUEST["Billing_State"]);

	$postal_code=$wpdb->_real_escape($_REQUEST["postal_code"]);

	$Billing_City=$wpdb->_real_escape($_REQUEST["Billing_City"]);

	$Billing_Phone=$wpdb->_real_escape($_REQUEST["Billing_Phone"]);

	$signature_copy=$wpdb->_real_escape($_REQUEST["signature_copy"]);

	$signature=$wpdb->_real_escape($_REQUEST["signature"]);

	$a_date=$wpdb->_real_escape($_REQUEST["a_date"]);

	$ip_address=$wpdb->_real_escape($_REQUEST["ip_address"]);

	$security_code=$wpdb->_real_escape($_REQUEST["security_code"]);



	$my_uploader_1 = new uploader('en');

	$my_uploader_1->upload('card_copy', '');

	$my_uploader_1->save_file("uploads/reservation", 2);

	if ($my_uploader_1->error) {

		print($my_uploader_1->error . "<br><br>\n");

	} else {

		print("Thanks for uploading " . $my_uploader_1->file['name'] . "<br><br>\n");

	}

	$card_copy=$my_uploader_1->file['name'];

	

	$my_uploader_2 = new uploader('en');

	$my_uploader_2->upload('idp_copy', '');

	$my_uploader_2->save_file("uploads/reservation", 2);

	if ($my_uploader_2->error) {

		print($my_uploader_2->error . "<br><br>\n");

	} else {

		print("Thanks for uploading " . $my_uploader_2->file['name'] . "<br><br>\n");

	}

	$idp_copy=$my_uploader_2->file['name'];

	

	if($idp_copy!=''){	

		$filedata=$baseSiteUrl.'/uploads/reservation/'.$idp_copy;	

		$filedata1=$baseSiteUrl.'/uploads/reservation/'.$card_copy;				

		$apiUrl=$apiBaseUrl."/api/customers/contractuploadfile.php?apikey=".$apiKey."&time=".$time;	

		$postdata=$postdata.'&reservation_id='.$reservation_id.'';

		$postdata=$postdata.'&filedata='.$filedata.'';

		$postdata=$postdata.'&filedata1='.$filedata1.'';

		$postdata=$postdata.'&idp_copy='.$idp_copy.'';

		$postdata=$postdata.'&card_copy='.$card_copy.'';

		$postdata=$postdata.'&a_tandc='.$a_tandc.'';

		$postdata=$postdata.'&Name_On_Card='.$Name_On_Card.'';

		$postdata=$postdata.'&CC_Type='.$CC_Type.'';

		$postdata=$postdata.'&Company_Name='.$Company_Name.'';

		$postdata=$postdata.'&signature='.$signature.'';

		$postdata=$postdata.'&a_date='.$a_date.'';

		$postdata=$postdata.'&ip_address='.$ip_address.'';

		$postdata=$postdata.'&security_code='.$security_code.'';

		$resp=GetApiData($apiUrl,$postdata);			

		//if(file_exists("uploads/customers/".$profileimage)){

				//unlink("uploads/customers/".$profileimage);

		//}

	}	

	header("location: /contractthanks?guid=".$guid."&rfid=".$rfid);

	exit();	



}elseif($actions=='sendcontractrsv'){

	$guid =$_REQUEST['guid'];	

	$rfid =$_REQUEST['rfid'];	

	$auth =$_REQUEST['auth'];	

	$customers_id =$_REQUEST['customers_id'];	

	

	$apiUrl=$apiBaseUrl."/api/customers/forcelogin.php?apikey=".$apiKey."&time=".$time;

	$postdata=$postdata.'&customers_id='.$customers_id.'';

	$resp=GetApiData($apiUrl,$postdata);

	$responseJO=json_decode($resp);

	$errorcode=$responseJO->errorcode;						

	if($errorcode == "100"){

		$status=$responseJO->status;	

		$errorcode=$responseJO->errorcode;		

	

		$customers_id=$responseJO->customers_id;

		$customers_name=$responseJO->customers_name;

		setcookie("cookCustomersName", $customers_name, time() + (86400 * 30), "/");

		setcookie("cookCustomersId", $customers_id, time() + (86400 * 30), "/");

						

		header("location: /contract/?guid=".$guid."&rfid=".$rfid."&auth=".$auth."");

		exit();		

	}else{

		header("location: /sign-in/?msg=2");

		exit();

	}

}elseif($actions=='updatepareservation'){
	$updatepaaddress =$wpdb->_real_escape($_REQUEST['updatepaaddress']);
	$updatedaaddress =$wpdb->_real_escape($_REQUEST['updatedaaddress']);
	$reservation_id =$wpdb->_real_escape($_REQUEST['reservation_id']);
	$apiUrl=$apiBaseUrl."/api/leads/updatepareservation.php?apikey=".$apiKey."&time=".$time;
	$postdata=$postdata.'&reservation_id='.$reservation_id.'';
	$postdata=$postdata.'&updatedaaddress='.$updatedaaddress.'';
	$postdata=$postdata.'&updatepaaddress='.$updatepaaddress.'';
	$resp=GetApiData($apiUrl,$postdata);
	$responseJO=json_decode($resp);
	$errorcode=$responseJO->errorcode;						
	exit();
}elseif($actions=='updateExitPopupLeds'){
	$phone =$wpdb->_real_escape($_REQUEST['cstphoneExitPopup']);
	$guid =$wpdb->_real_escape($_REQUEST['guidExitPopup']);
	$phonecode1 =$wpdb->_real_escape($_REQUEST['phonecode1ExitPopup']);
	$phone=str_replace('-','',$phone);
	$phone=str_replace('(','',$phone);
	$phone=str_replace(')','',$phone);
	$phone=str_replace(' ','',$phone);
	$phone=str_replace('+1','',$phone);
	$firstname='NA';	
	$lastname='NA';	
	$email=$phone.'@a1limosf.com';
	$phonecountry=$phonecode1;	
	$password =$wpdb->_real_escape($phone);	
	$accounttype='PersonalAccount';	
	$serviceid=0;	
	$noofpass=0;	
	$noofvehicles=0;	
	$isdiscount=1;	
	
	$address='';	
	$city='';	
	$state='';	
	$zipcode='';
	$businessname='';		
	$jobtitle='';	
	$typeofbusiness='';	
	$hearaboutus='';
	if($email!='' && $phone!=''){		
		///////////////////Global Limos///////////////////////////
		$apiUrl=$apiBaseUrl."/api/customers/add.php?apikey=".$apiKey."&time=".$time;
		$postdata=$postdata.'&firstname='.$firstname.'';
		$postdata=$postdata.'&email='.$email.'';
		$postdata=$postdata.'&lastname='.$lastname.'';
		$postdata=$postdata.'&phone='.$phone.'';
		$postdata=$postdata.'&password='.$password.'';
		$postdata=$postdata.'&isdiscount='.$isdiscount.'';
		$postdata=$postdata.'&ipaddress='.$ipaddress.'';
		$postdata=$postdata.'&accounttype='.$accounttype.'';
		$postdata=$postdata.'&website='.$website.'';
		$postdata=$postdata.'&refid='.$customers_id.'';
		$postdata=$postdata.'&address='.$address.'';
		$postdata=$postdata.'&city='.$city.'';
		$postdata=$postdata.'&state='.$state.'';
		$postdata=$postdata.'&zipcode='.$zipcode.'';
			
		$postdata=$postdata.'&phonecountry='.$phonecountry.'';
		$postdata=$postdata.'&phonecode1='.$phonecode1.'';
		$postdata=$postdata.'&serviceid='.$serviceid.'';
		$postdata=$postdata.'&noofpass='.$noofpass.'';
		$postdata=$postdata.'&noofvehicles='.$noofvehicles.'';
			
		$postdata=$postdata.'&businessname='.$businessname.'';
		$postdata=$postdata.'&jobtitle='.$jobtitle.'';
		$postdata=$postdata.'&typeofbusiness='.$typeofbusiness.'';
		$postdata=$postdata.'&hearaboutus='.$hearaboutus.'';		
		$postdata=$postdata.'&rsvguid='.$guid.'';	
		$resp=GetApiData($apiUrl,$postdata);			
		$responseJO=json_decode($resp);
		$customers_id=$responseJO->customers_id;
		//print_r($responseJO);
		///////////////////Global Limos///////////////////////////			
		if($customers_id!=''){
			if($firstname=='NA'){
				$firstname=$phone;
			}
			setcookie("cookCustomersId", $customers_id, time() + (86400 * 30), "/");	
			setcookie("cookCustomersName", $firstname, time() + (86400 * 30), "/");			
		}
		if($guid!=''){			
		}else{
			$sessionidAPI=$sessionid;
			$searchfrom='Web';	
			$services_id=35;
			$autocomplete='321 Nut Tree Rd';
			$street_number ='321';
			$route ='Nut Tree Rd';
			$locality ='acaville';
			$administrative_area_level_1='CA';
			$postal_code='95687';
			$autocomplete_DA='';
			$street_number_DA='';
			$route_DA='';
			$locality_DA='';
			$administrative_area_level_1_DA='';
			$postal_code_DA='';
			$pickup_date=date('m/d/Y');
			$pickup_timeH=date('H');
			$pickup_timeM='00';	
			$no_of_hrs=4;
			
			$add_minute=($no_of_hrs*60)+$pickup_timeM; 
			$totHrs=$no_of_hrs+$pickup_timeH;
			$timeStamp = mktime($totHrs, $pickup_time_minute,0,0,0,0);	
			 
			$dropup_timeH=date("H", $timeStamp);
			$dropup_timeM='00';
			$no_of_passengers=10;
			$is_round_trip=0;			
			$roundTripPickupdateAP='';	
			$roundTripPickuptimeAP='';		
			$is_business='';	
						
			$webcampaignid='';
			$websitecampaignname='';	
			if($websitecampaignname!=''){
				$websiteAPI=$websitecampaignname;
			}else{
				$websiteAPI=$website;
			}			
			$ipaddressAPI=$_SERVER['REMOTE_ADDR'];	
			$isAirPort=0;		
			if($pickup_date!=''){
				///////////////////Global Limos///////////////////////////
				$apiUrl=$apiBaseUrl."/createsearch.php?apikey=".$apiKey."&time=".$time;
				$postdata=$postdata.'&customers_id='.$customers_id.'';
				$postdata=$postdata.'&searchfrom='.$searchfrom.'';
				$postdata=$postdata.'&services_id='.$services_id.'';
				$postdata=$postdata.'&autocomplete='.$autocomplete.'';
				$postdata=$postdata.'&street_number='.$street_number.'';
				$postdata=$postdata.'&route='.$route.'';
				$postdata=$postdata.'&locality='.$locality.'';
				$postdata=$postdata.'&administrative_area_level_1='.$administrative_area_level_1.'';			
				$postdata=$postdata.'&postal_code='.$postal_code.'';				
				$postdata=$postdata.'&autocomplete_DA='.$autocomplete_DA.'';
				$postdata=$postdata.'&street_number_DA='.$street_number_DA.'';
				$postdata=$postdata.'&route_DA='.$route_DA.'';
				$postdata=$postdata.'&locality_DA='.$locality_DA.'';
				$postdata=$postdata.'&administrative_area_level_1_DA='.$administrative_area_level_1_DA.'';
				$postdata=$postdata.'&postal_code_DA='.$postal_code_DA.'';
				$postdata=$postdata.'&pickup_date='.$pickup_date.'';
				$postdata=$postdata.'&pickup_timeH='.$pickup_timeH.'';
				$postdata=$postdata.'&pickup_timeM='.$pickup_timeM.'';
				$postdata=$postdata.'&dropup_timeH='.$dropup_timeH.'';
				$postdata=$postdata.'&dropup_timeM='.$dropup_timeM.'';
				$postdata=$postdata.'&roundTripPickuptimeAP='.$roundTripPickuptimeAP.'';
				$postdata=$postdata.'&no_of_passengers='.$no_of_passengers.'';
				$postdata=$postdata.'&is_round_trip='.$is_round_trip.'';
				$postdata=$postdata.'&roundTripPickupdateAP='.$roundTripPickupdateAP.'';
				$postdata=$postdata.'&roundTripPickuptimeAP='.$roundTripPickuptimeAP.'';
				$postdata=$postdata.'&is_business='.$is_business.'';
				$postdata=$postdata.'&no_of_hrs='.$no_of_hrs.'';
				$postdata=$postdata.'&websiteAPI='.$websiteAPI.'';
				$postdata=$postdata.'&ipaddressAPI='.$ipaddressAPI.'';
				$postdata=$postdata.'&sessionidAPI='.$sessionidAPI.'';
				$postdata=$postdata.'&rtnurlAPI='.$rtnurlAPI.'';
				$postdata=$postdata.'&webcampaignid='.$webcampaignid.'';
				//print_r($postdata);
				//exit();
				$resp=GetApiData($apiUrl,$postdata);			
				//print_r($resp);
				///////////////////Global Limos///////////////////////////	
				//echo $baseSiteUrl;
				/*if($isAirPort==0){
					if($customers_id=="" || $customers_id==0){
						header("location: ".$baseSiteUrl."/discount/?guid=".$resp);
						exit();	
					}
				}*/				
			}
		}
		exit();						
	}
}elseif($actions=='checkphonevaild'){
	$phone =$wpdb->_real_escape($_REQUEST['phone']);
	if($phone!=''){
		$phone=str_replace('+1','',$phone);
		$is_invalid=0;
		if(strlen($phone) < 10){
			$is_invalid=1;
		}else{
			$pos = strpos($phone,"0000");
			if ($pos === true) {
				$is_invalid=1;
			} else {
				$pos2 = strpos($phone,"1111");
				if ($pos2 === true) {
					$is_invalid=1;
				} else {			
					$pos3 = strpos($phone,"2222");
					if ($pos3 === true) {
						$is_invalid=1;
					} else {			
						$pos4 = strpos($phone,"3333");
						if ($pos4 === true) {
							$is_invalid=1;
						} else {					
							$pos5 = strpos($phone,"4444");
							if ($pos5 === true) {
								$is_invalid=1;
							} else {									
								$pos6 = strpos($phone,"5555");
								if ($pos6 === true) {
									$is_invalid=1;
								} else {											
									$pos7 = strpos($phone,"6666");
									if ($pos7 === true) {
										$is_invalid=1;
									} else {												
										$pos8 = strpos($phone,"7777");
										if ($pos8 === true) {
											$is_invalid=1;
										} else {													
											$pos9 = strpos($phone,"8888");
											if ($pos9 === true) {
												$is_invalid=1;
											} else {														
												$pos10 = strpos($phone,"9999");
												if ($pos10 === true) {
													$is_invalid=1;
												} else {
													$is_invalid=0;
												}
											}
										}
									}
								}	
							}
						}	
					}
				}	
			}					
		}
	}
	echo $is_invalid;
	exit();	
}
function GetApiData($apiUrl,$postdata){
	$post = urldecode($postdata);
	$curl = curl_init($apiUrl);
			
	curl_setopt($curl, CURLOPT_POST, true);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
	curl_setopt($curl, CURLOPT_USERAGENT , 'Mozilla 5.0');
	curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
	curl_setopt($curl, CURLOPT_VERBOSE , true);			
	$resp = curl_exec($curl);	
	return $resp;
}
function DateForDB($strval){
	$strvalA=explode("/",$strval,3);
	$strval=$strvalA[2].'-'.$strvalA[0].'-'.$strvalA[1];
	return $strval;
}
?>