connect_error);
$qcon=mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
if($_POST['account']==""){
$query1 = "SELECT token FROM customers WHERE customer_mobile='".$phone."' ORDER BY token DESC LIMIT 0,1";
$result = mysqli_query($conn, $query1);
$row = mysqli_fetch_assoc($result);
$tokencheck = $row['token'];
$success1 = $conn->query($query1);
if (!$success1) {
$updatetoken = 0;
}
$reference = $_POST['hidden_ref'];
$query1 = "SELECT reference FROM jobs WHERE reference='".$reference."' ORDER BY reference DESC LIMIT 0,1";
$result = mysqli_query($conn, $query1);
$row = mysqli_fetch_assoc($result);
$referencecheck = $row['reference'];
if($referencecheck != "") {
$reference = time().rand(10,5000);
}
if( $tokencheck != ""){
$tokencustomerid = $tokencheck;
$updatetoken = 1;
}else{
$updatetoken = 0;
}
$errormessage = '';
$price= 1;
if ($price < 1) {
$errormessage.= "Invalid address.
\n";
$error = true;
}
if (!$_POST['First_Name']) {
$errormessage.= "Please enter your name
\n";
$error = true;
}
$apiEndpoint = \Eway\Rapid\Client::MODE_PRODUCTION; // Use \Eway\Rapid\Client::MODE_PRODUCTION when you go live
$client = \Eway\Rapid::createClient($apiKey, $apiPassword, $apiEndpoint);
//create customer
$firstname = trim($_POST['First_Name']);
$lastname = trim($_POST['Last_Name']);
$fullname = "$firstname $lastname";
if($updatetoken == 0) {
$customer = [
'Title' => 'Mr.',
'FirstName' => $firstname,
'LastName' => $lastname,
'Country' => 'au',
'Email' => trim($_POST['email']),
'CardDetails' => [
'Name' => $fullname,
'Number' => $_POST['EWAY_CARDNUMBER'],
'ExpiryMonth' => $_POST['EWAY_CARDEXPIRYMONTH'],
'ExpiryYear' => $_POST['EWAY_CARDEXPIRYYEAR'],
'CVN' => $_POST['EWAY_CARDCVN']
]
];
/*echo '
';
print_r($customer);
echo ' ';
exit;*/
$response = $client->createCustomer(\Eway\Rapid\Enum\ApiMethod::DIRECT, $customer);
$tokencustomerid = $response->Customer->TokenCustomerID;
}
if($updatetoken == 1) {
$customer = [
'Email' => trim($_POST['email']),
'TokenCustomerID' => $tokencustomerid,
'CardDetails' => [
'Name' => $fullname,
'Number' => $_POST['EWAY_CARDNUMBER'],
'ExpiryMonth' => $_POST['EWAY_CARDEXPIRYMONTH'],
'ExpiryYear' => $_POST['EWAY_CARDEXPIRYYEAR'],
'CVN' => $_POST['EWAY_CARDCVN']
]
];
/*echo '
';
print_r($customer);
echo ' ';
exit;*/
$response = $client->updateCustomer(\Eway\Rapid\Enum\ApiMethod::DIRECT, $customer);
}
$cardnumber = $_POST['EWAY_CARDNUMBER'];
if($cardnumber > 399999999999999) {
$auth = true;
} else {
$auth = false;
}
$transaction = [
'Customer' => [
'TokenCustomerID' => $tokencustomerid,
],
'Payment' => [
'TotalAmount' => $price,
'InvoiceReference' => $_POST['hidden_ref'],
],
'TransactionType' => \Eway\Rapid\Enum\TransactionType::RECURRING,
'Capture' => $auth,
];
$response = $client->createTransaction(\Eway\Rapid\Enum\ApiMethod::DIRECT, $transaction);
$nameq = mysqli_real_escape_string($qcon, $fullname);
$email= $_POST['email'];
$query = "INSERT into customers (customer_name, customer_mobile, token, customer_email, date_added, welcomemess) VALUES ('" . $nameq . "','" . $intphone . "','" . $tokencustomerid . "','" . $email . "','" . date('Y-m-d H:i:s') . "', '') ON DUPLICATE KEY UPDATE customer_name='" . $nameq . "', customer_email='" . $email . "', token='" . $tokencustomerid . "'";
$success = $conn->query($query);
if (!$success) {
error_log("Couldn't enter data: ".$conn->error);
}
if (isset($response->TransactionStatus) && $response->TransactionStatus) {
$transactionid = $response->TransactionID;
$AuthorisationCode = $response->AuthorisationCode;
//$tokencustomerid = $response->Customer->TokenCustomerID;
$query = "SELECT * FROM customer_tokens WHERE access_token_value='".$tokencustomerid."'";
$result = $conn->query($query);
if(!$result) {
error_log("Token error: ".$conn->error);
} else {
if ($result->num_rows > 0)
{
$row = $result->fetch_assoc();
$tokencheck = $row['access_token_value'];
$query = "UPDATE customer_tokens SET modified = NOW() WHERE access_token_value = ".$tokencheck;
$result = $conn->query($query);
if(!$result) {
error_log("Token update error: ".$conn->error);
}
} else {
$query = "INSERT INTO customer_tokens (`id`, `cid`, `access_token_value`, `status`, `created`, `modified`) VALUES (NULL, '', ".$tokencustomerid.", 1, NOW(), NOW())";
$result = $conn->query($query);
if(!$result) {
error_log("Token insert error: ".$conn->error);
}
}
}
} else {
$error = true;
if ($response->getErrors()) {
foreach ($response->getErrors() as $error) {
$errormessage.= "Error: $error (".\Eway\Rapid::getMessage($error).")
\n";
}
} else {
$errormessage.= "Sorry, your payment was declined";
}
}
}
if($_POST['account']==1) {
$tokencustomerid = $_POST['token'];
$fullname = $_POST['name'];
$nameq = mysqli_real_escape_string($qcon, $fullname);
$query = "INSERT into customers (customer_name, customer_mobile, token, customer_email, date_added, welcomemess) VALUES ('" . $nameq . "','" . $intphone . "','" . $tokencustomerid . "','" . $email . "','" . date('Y-m-d H:i:s') . "', '') ON DUPLICATE KEY UPDATE customer_name='" . $nameq . "', customer_email='" . $email . "', token='" . $tokencustomerid . "'";
$success = $conn->query($query);
if (!$success) {
error_log("Couldn't enter data: ".$conn->error);
}
}
$jobCity = $_POST['job_city'];
if($jobCity == "") {
$jobCity = "perth";
}
if($jobCity == "sydney") {
$type = "SF";
date_default_timezone_set("Australia/Sydney");
} else if($jobCity == "melbourne") {
$type = "MF";
date_default_timezone_set("Australia/Melbourne");
} else if($jobCity == "queensland") {
$type = "BF";
date_default_timezone_set("Australia/Brisbane");
$distGC = getDistance($_POST['lat1_value'], $_POST['lng1_value'], "GC");
$distSC = getDistance($_POST['lat1_value'], $_POST['lng1_value'], "SC");
if($distGC <= 40) {
$goldCoast = true;
$type = "GC";
} else if($distSC <= 50) {
$sunshineCoast = true;
$type = "SC";
}
} else {
$type = "FC";
date_default_timezone_set("Australia/Perth");
}
$pickup= $_POST['pickup'];
$pickupencode = $_POST['pickupencode'];
$dropoff= $_POST['dropoff'];
$dropoffencode= $_POST['dropoffencode'];
$date= $_POST['date'];
$d = date_create_from_format("jS M, Y", $date);
$date24 = date_format($d, "Y-m-d");
error_log($date24);
$time= $_POST['time'];
$time24 = date("G:i", strtotime($time));
$timeUTC = date("c", strtotime("$date24 $time24"));
$timestamp = strtotime("$date24 $time24") * 1000;
$lat1= $_POST['lat1_value'];
$lng1= $_POST['lng1_value'];
$sql = "INSERT INTO `desid573_eway_codes`.`place_coords`(`id`, `name`, `lat`, `lon`, `date_added`) VALUES (NULL,'".$pickup."',".$lat1.",".$lng1.",NOW())";
$result = $conn->query($sql);
if(!$result) {
error_log($sql);
error_log("Error inserting coords ".$conn->error);
}
$lat2= $_POST['lat2_value'];
$lng2= $_POST['lng2_value'];
$sql = "INSERT INTO `desid573_eway_codes`.`place_coords`(`id`, `name`, `lat`, `lon`, `date_added`) VALUES (NULL,'".$dropoff."',".$lat2.",".$lng2.",NOW())";
$result = $conn->query($sql);
if(!$result) {
error_log($sql);
error_log("Error inserting coords ".$conn->error);
}
$onewayprice= $_POST['onewayPrice'];
$fnum1 = $_POST['flight_number'];
$ptime1 = $_POST['pickup_time'];
if($_POST['pickupType'] == "search1") {
$ptime1 = "";
}
$passNum = $_POST['passenger_count'];
$rfNum = $_POST['car_seat'];
$ffNum = $_POST['ff_count'];
$boostNum = $_POST['booster_count'];
$luggage = $_POST['luggage'];
$return_trip = $_POST['journeyType'];
if(isset($_POST['oneway'])) {
$return_trip = $_POST['oneway'];
}
$reference = $_POST['hidden_ref'];
if(!$error)
{
$paymentlink = shortenLink($reference, $type, "payment");
$flighttext = "$fnum1 + $ptime1 mins";
if($fnum1 == ""){
$flighttext = "";
}
$seats = "$passNum pax \\n$rfNum RF\\n$ffNum FF\\n$boostNum Boost";
$cityCheck = $jobCity;
if($goldCoast) {
$cityCheck = "goldcoast";
}
if($sunshineCoast) {
$cityCheck = "sunshinecoast";
}
$dispatchString = "";
// $sql = "SELECT * FROM `desid573_eway_codes`.`dispatcher` WHERE `city` = '".$cityCheck."'";
// $result = $conn->query($sql);
// if(!$result) {
// error_log("error fetching dispatcher ".$conn->error);
// } else {
// $row = $result->fetch_assoc();
// if($row["active"]) {
// $dispatchString = $row["string"];
// }
// }
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, 'https://api.vromo.io/v2/graph/role/jobs?access_token='.$vromo);
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curlObj, CURLOPT_HEADER, 0);
curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
curl_setopt($curlObj, CURLOPT_POST, 1);
curl_setopt($curlObj, CURLOPT_POSTFIELDS, '[{"name": "'.$type.' ' . $fullname . '",'.$dispatchString.' "campaign": {"id": 5623765662}, "contact": {"name": "' . $fullname . '","phone": "' . $intphone . '","email": "' . $email . '"},"tasks": [{"timeframe":{"by": '.$timestamp.'}, "zone": {"name": "' . $pickup . '","address": "' . $pickup . '","coords": {"lat": ' . $lat1 . ',"lon": ' . $lng1 . '},"radius": 100}},{"zone": {"name": "' . $dropoff . '","address": "' . $dropoff . '","coords": {"lat": ' . $lat2 . ',"lon": ' . $lng2 . '},"radius": 100}}],"attr": [{ "key": "Flight", "value": "' . $flighttext . '" },{ "key": "Seats", "value": "' . $seats . '" },{ "key": "Payment Link", "value": "' . $paymentlink . '" }]}]');
// ,
$response = curl_exec($curlObj);
error_log($response);
$json = json_decode($response, true);
curl_close($curlObj);
$spatulalink = $json['items'][0]['tracking'];
$spatulaid = $json['items'][0]['id'];
$km_est = $_POST['km_est'];
$time_est = $_POST['time_est'];
$luggageq = mysqli_real_escape_string($qcon, $luggage);
$pickupq = mysqli_real_escape_string($qcon, $pickup);
$dropoffq = mysqli_real_escape_string($qcon, $dropoff);
$query = "INSERT into jobs (id, reference, job_name, job_phone, job_email, job_city, job_pickup, flight_num, mins_post, job_dropoff, job_date, job_time, job_pax, job_rf, job_ff, job_boost, job_luggage, job_quote, token, quote_km, quote_time, promo_code, promo_value, date_added, spat_ref, spat_link, conf_sms_sent, xero_inv, payment_eway, driver) VALUES (NULL,'" . $reference . "','" . $nameq . "','" . $intphone . "','" . $email . "', '".$jobCity."', '" . $pickupq . "','" . $fnum1 . "','" . $ptime1 . "','" . $dropoffq . "','" . $date . "','" . $time . "','" . $passNum . "','" . $rfNum . "','" . $ffNum . "','" . $boostNum . "','" . $luggageq . "','" . $onewayprice . "', '".$tokencustomerid."', '".$km_est."', '".$time_est."', '', '','" . date('Y-m-d H:i:s') . "','" . $spatulaid . "','" . $spatulalink . "', '', '', '', '')";
$success = $conn->query($query);
if (!$success) {
error_log("Could not enter data: ".$conn->error);
}
$sql = "SELECT * FROM `desid573_eway_codes`.`ip_address` WHERE `ip` = '".$_SERVER["REMOTE_ADDR"]."'";
$ip = $conn->query($sql);
if($ip->num_rows > 0) {
$row = $ip->fetch_assoc();
$sql = "UPDATE `desid573_eway_codes`.`ip_address` SET booking_reference = '".$reference."', booking_date = NOW() WHERE `ip` = '".$_SERVER["REMOTE_ADDR"]."'";
$set = $conn->query($sql);
if(!$set) {
error_log("update ip error: ".$conn->error);
}
$slackmessage = "$type booking $nameq $$onewayprice was quoted ".$row["quote"]. " on ".$row["quote_date"];
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, 'https://hooks.slack.com/services/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');
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curlObj, CURLOPT_HEADER, 0);
curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
curl_setopt($curlObj, CURLOPT_POST, 1);
curl_setopt($curlObj, CURLOPT_POSTFIELDS, '{"text": "'.$slackmessage.'"}');
$response = curl_exec($curlObj);
curl_close($curlObj);
}
if($_POST['tollAmount'] != "0") {
$query = "INSERT into toll_estimates (id, reference, amount, description) VALUES (NULL, '".$reference."', '".$_POST['tollAmount']."', '".$_POST['tollDescription']."')";
$success = $conn->query($query);
if (!$success) {
error_log("Could not enter toll data: ".$conn->error);
}
}
echo "
Your booking has been successfully processed ";
echo "
You will receive an SMS confirmation from the dispatch team within 30 mins (unless you have submitted after hours) ";
$message= "Type FC
Date $date $time24
Transaction ID $transactionid
Token Customer ID $tokencustomerid
Name $fullname
Phone $intphone
Pick Up $pickup
Flight Number $fnum1
Mins post flight $ptime1
TO
Drop Off $dropoff
Quoted $onewayprice
Credit Card Authorised
Number of Passengers $passNum
Number of RF Seats $rfNum
Number of FF Seats $ffNum
Number of Boosters $boostNum
Luggage $luggage
Lat1 $lat1
Long1 $lng1
Lat2 $lat2
Long2 $lng2
Booking Type $return_trip 1st Leg
Reference $reference
Email $email
";
$message_sql = "Type: $type
Ref: $spatulaid
";
send_mail('lewis@perthdesignateddrivers.com.au','info@familycab.com.au','New Order From '.$email ,$message);
echo "
When your driver is en route you will receive an SMS with a tracking link and driver contact details. If you do not receive this SMS atleast 10 mins before your booking time please contact us on +61466062355 ";
echo "
Trip Details ";
echo "
Name $fullname
Phone $phone
Email $email
Pick Up $pickup
Drop Off $dropoff
Date/Time $date $time
Passengers $passNum pax, $rfNum RF, $ffNum FF, $boostNum Boosters
Quoted $onewayprice
";
if($return_trip == 'return') {
$return_date= $_POST['return_date'];
$d = date_create_from_format("jS M, Y", $return_date);
$date24 = date_format($d, "Y-m-d");
$return_time= $_POST['return_time'];
$time24 = date("G:i", strtotime($return_time));
$timeUTC = date("c", strtotime("$date24 $time24"));
$timestamp = strtotime("$date24 $time24") * 1000;
$return_time24 = date("G:i", strtotime($return_time));
$lat3= $_POST['lat3_value'];
$lng3= $_POST['lng3_value'];
$lat4= $_POST['lat4_value'];
$lng4= $_POST['lng4_value'];
$returnprice= $_POST['returnPrice'];
$return_pickup = $_POST['return_pickup'];
$sql = "INSERT INTO `desid573_eway_codes`.`place_coords`(`id`, `name`, `lat`, `lon`, `date_added`) VALUES (NULL,'".$return_pickup."',".$lat3.",".$lng3.",NOW())";
$result = $conn->query($sql);
if(!$result) {
error_log($sql);
error_log("Error inserting coords ".$conn->error);
}
$return_dropoff = $_POST['return_dropoff'];
$sql = "INSERT INTO `desid573_eway_codes`.`place_coords`(`id`, `name`, `lat`, `lon`, `date_added`) VALUES (NULL,'".$return_dropoff."',".$lat4.",".$lng4.",NOW())";
$result = $conn->query($sql);
if(!$result) {
error_log($sql);
error_log("Error inserting coords ".$conn->error);
}
$return_fnum1 = $_POST['return_flight_number'];
$return_ptime1 = $_POST['return_pickup_time'];
if($_POST['returnPickupType'] == "search3") {
$return_ptime1 = "";
}
$r_reference = $_POST['hidden_ref'];
$return_reference = floatval($r_reference)+1;
$paymentlink = shortenLink($return_reference, $type, "payment");
$flighttext = "$return_fnum1 + $return_ptime1 mins";
if($return_fnum1 == ""){
$flighttext = "";
}
if(strpos($return_dropoff, "airport") !== false) {
$destinationtext = "Airport";
} else {
$destinationtext = "Destination";
}
$seats = "$passNum pax \\n$rfNum RF\\n$ffNum FF\\n$boostNum Boost";
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, 'https://api.vromo.io/v2/graph/role/jobs?access_token='.$vromo);
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curlObj, CURLOPT_HEADER, 0);
curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
curl_setopt($curlObj, CURLOPT_POST, 1);
curl_setopt($curlObj, CURLOPT_POSTFIELDS, '[{"name": "'.$type.' ' . $fullname . '","contact": {"name": "' . $fullname . '","phone": "' . $intphone . '","email": "' . $email . '"},"tasks": [{"timeframe":{"by": '.$timestamp.'}, "zone": {"name": "' . $return_pickup . '","address": "' . $return_pickup . '","coords": {"lat": ' . $lat3 . ',"lon": ' . $lng3 . '},"radius": 100}},{"zone": {"name": "' . $return_dropoff . '","address": "' . $return_dropoff . '","coords": {"lat": ' . $lat4 . ',"lon": ' . $lng4 . '},"radius": 100}}],"attr": [{ "key": "Flight", "value": "' . $flighttext . '" },{ "key": "Seats", "value": "' . $seats . '" },{ "key": "Payment Link", "value": "' . $paymentlink . '" }]}]');
// ,
$response = curl_exec($curlObj);
error_log($response);
$json = json_decode($response, true);
curl_close($curlObj);
$spatulalink = $json['items'][0]['tracking'];
$spatulaid = $json['items'][0]['id'];
$return_message = "Type FC
Date $return_date $return_time24
Transaction ID $transactionid
Token Customer ID $tokencustomerid
Name $fullname
Phone $intphone
Pick Up $return_pickup
Flight Number $return_fnum1
Mins post flight $return_ptime1
TO
Drop Off $return_dropoff
Quoted $returnprice
Credit Card Authorised
Number of Passengers $passNum
Number of RF Seats $rfNum
Number of FF Seats $ffNum
Number of Boosters $boostNum
Luggage $luggage
Lat1 $lat3
Long1 $lng3
Lat2 $lat4
Long2 $lng4
Booking Type Return 2nd Leg
Reference $return_reference
Email $email
";
$return_km_est = $_POST['return_km_est'];
$return_time_est = $_POST['return_time_est'];
$returnpickupq = mysqli_real_escape_string($qcon, $return_pickup);
$returndropoffq = mysqli_real_escape_string($qcon, $return_dropoff);
$query = "INSERT into jobs (id, reference, job_name, job_phone, job_email, job_city, job_pickup, flight_num, mins_post, job_dropoff, job_date, job_time, job_pax, job_rf, job_ff, job_boost, job_luggage, job_quote, token, quote_km, quote_time, promo_code, promo_value, date_added, spat_ref, spat_link, conf_sms_sent, xero_inv, payment_eway, driver) VALUES (NULL,'" . $return_reference . "','" . $nameq . "','" . $intphone . "','" . $email . "', '".$jobCity."', '" . $returnpickupq . "','" . $return_fnum1 . "','" . $return_ptime1 . "','" . $returndropoffq . "','" . $return_date . "','" . $return_time . "','" . $passNum . "','" . $rfNum . "','" . $ffNum . "','" . $boostNum . "','" . $luggageq . "','" . $returnprice . "', '".$tokencustomerid."', '".$return_km_est."', '".$return_time_est."', '', '', '" . date('Y-m-d H:i:s') . "','" . $spatulaid . "','" . $spatulalink . "', '', '', '', '')";
$success = $conn->query($query);
if (!$success) {
die("Couldn't enter data: ".$conn->error);
}
if($_POST['returnTollAmount'] != "0") {
$query = "INSERT into toll_estimates (id, reference, amount, description) VALUES (NULL, '".$return_reference."', '".$_POST['returnTollAmount']."', '".$_POST['returnTollDescription']."')";
$success = $conn->query($query);
if (!$success) {
error_log("Could not enter toll data: ".$conn->error);
}
}
$message_sql = "Type: $type
Ref: $spatulaid
";
send_mail('lewis@perthdesignateddrivers.com.au','info@familycab.com.au','New Order From '.$email ,$return_message);
$url = "https://www.bookings.perthdesignateddrivers.com.au/newJob.php?type=$type&ref=$return_reference";
echo "
Return Trip Details ";
echo "
Pick Up $return_pickup
Drop Off $return_dropoff
Date/Time $return_date $return_time
Passengers $passNum pax, $rfNum RF, $ffNum FF, $boostNum Boosters
Quoted $returnprice
";
}
if($_POST['admin'] == "1") {
$result = $conn->query("SELECT id, driver FROM desid573_eway_codes.drivers");
echo "Dispatch to:  
";
while ($row = $result->fetch_assoc()) {
unset($id, $name);
$id = $row['id'];
$name = $row['driver'];
echo ''.$name.' ';
}
echo '
Status
';
}
?>