connect_error);
$qcon=mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
$query1 = "SELECT token FROM inquiries WHERE inquiry_mobile='".$phone."' ORDER BY token DESC LIMIT 0,1";
$result = mysqli_query($conn, $query1);
$row = mysqli_fetch_assoc($result);
$tokencheck = $row['token'];
if( $tokencheck != ""){
$token = $tokencheck;
$updatetoken = 1;
}else{
$token = $_POST['token'];
$updatetoken = 0;
}
// Check if email has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Please enter a valid email address';
$error = true;
}
$error = false;
if(!$error)
{
echo "
Booking Submitted to Spatula ";
$fullnameencode = $_POST['nameencode'];
$email= $_POST['email'];
$name= $_POST['name'];
$pickup= $_POST['pickup'];
$pickupencode = $_POST['pickupencode'];
$dropoff= $_POST['dropoff'];
$dropoffencode= $_POST['dropoffencode'];
date_default_timezone_set("Australia/Perth");
$date=$_POST['date'];
$date24 = date("Y-m-d", strtotime($date));
$time=$_POST['time'];
$intphone = $_POST['intphone'];
$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);
}
$price=$_POST['onewayPrice'];
$reference=$_POST['hidden_ref'];
$time24 = date("G:i", strtotime($time));
$timeUTC = date("c", strtotime("$date24 $time24"));
$timestamp = strtotime("$date24 $time24") * 1000;
$paymentlink = shortenLink($reference, "DD", "payment");
$sql = "SELECT * FROM `desid573_eway_codes`.`dispatcher` WHERE `city` = 'perth'";
$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": "DD ' . $name . '",'.$dispatchString.' "campaign": {"id": 5622549795}, "contact": {"name": "' . $name . '","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": "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'];
$nameq = mysqli_real_escape_string($qcon, $name);
$pickupq = mysqli_real_escape_string($qcon, $pickup);
$dropoffq = mysqli_real_escape_string($qcon, $dropoff);
$query = "INSERT into inquiries (inquiry_name, inquiry_mobile, inquiry_dropoff, inquiry_email, token, inquiry_created, welcomemess) VALUES ('" . $nameq . "','" . $intphone . "','" . $dropoffq . "','" . $email . "','" . $token . "','" . date('Y-m-d H:i:s') . "', '') ON DUPLICATE KEY UPDATE inquiry_name='" . $nameq . "', inquiry_dropoff='" . $dropoffq . "', inquiry_email='" . $email . "', token='" . $token . "'";
$success = $conn->query($query);
if (!$success) {
die("Couldn't enter customer data: ".$conn->error);
}
$query = "INSERT into jobs (id, reference, job_name, job_phone, job_email, job_pickup, job_dropoff, job_date, job_time, job_quote, token, quote_km, quote_time, date_added, spat_ref, spat_link, xero_inv, conf_sms_sent, payment_eway, driver) VALUES (NULL,'" . $reference . "','" . $nameq . "','" . $intphone . "','" . $email . "','" . $pickupq . "','" . $dropoffq . "','" . $date . "','" . $time . "','" . $price . "', '".$_POST['token']."', '".$_POST['km_est']."', '".$_POST['time_est']."', '" . date('Y-m-d H:i:s') . "','" . $spatulaid . "','" . $spatulalink . "', '', '', '', '')";
$success = $conn->query($query);
if (!$success) {
die("Couldn't enter booking data: ".$conn->error);
}
$message= "Type DD
Date $date $time24
Name $name
Phone $phone
Token Customer ID $token
Pick Up $pickup
TO
Drop Off $dropoff
Quoted $price
Booking fee NOT PAID
Lat1 $lat1
Long1 $lng1
Lat2 $lat2
Long2 $lng2
Email $email
Reference $reference
";
$message_sql = "Type: DD
Ref: $spatulaid
";
send_mail('booking@perthdesignateddrivers.com.au','spatula@perthdesignateddrivers.com.au','New Order From
'.$email ,$message);
echo "
You will receive an SMS confirmation from the dispatch team within 30 mins (unless you have submitted after hours) 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 1300466365 ";
echo "
Name $name
Phone $phone
Email $email
Pick Up $pickup
Drop Off $dropoff
Date/Time $date $time
Quoted $price
";
}
else
{
echo "
Transaction has been declined ";
echo "
";
}
$result = $conn->query("SELECT id, driver FROM desid573_eway_codes.drivers WHERE city = 'perth'");
echo "Dispatch to:  
";
while ($row = $result->fetch_assoc()) {
unset($id, $name);
$id = $row['id'];
$name = $row['driver'];
echo ''.$name.' ';
}
echo " ";
// $size = ob_get_length();
//ob_end_flush();
//ob_flush();
//flush(); // yes, you need to call all 3 flushes!
//if (session_id()) session_write_close();
$url = "http://desidrivers.com.au/newJob.php?type=DD&ref=$reference";
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, "$url");
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_HTTPHEADER, array('Accept: application/json'));
//$response = curl_exec($curlObj);
curl_close($curlObj);
?>
Status