/home/desid573/public_html/app
Edit: /home/desid573/public_html/app/booking.php (9655B)
query($sql);
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
$customer[] = $row;
$sql = "SELECT * FROM `customer_details` where `cid` = '".$row["id"]."'";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
while($row_details = $result->fetch_assoc())
{
$cust_detail[] = $row_details;
}
}
$sql = "SELECT * FROM `customer_tokens` where `cid` = '".$row["id"]."'";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
while($row_token = $result->fetch_assoc())
{
$cust_token[] = $row_token;
}
}
}
$cus = $customer[0]["name"];
$mob = str_replace(" ", "", $customer[0]["mobile"]);
$cid = $customer[0]['id'];
date_default_timezone_set("US/Eastern");
$slackurl = "https://hooks.slack.com/services/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";
$date = $_REQUEST['booking_date'];
if($date == "") {
$bookingdate = date("Y-m-d");
$bookingtime = date("H:i:s");
} else {
$date = str_replace("/","-",$date);
$format = 'd-m-Y';
$datetime = DateTime::createFromFormat($format, $date);
$bookingdate = $datetime->format('Y-m-d');
$time=$_REQUEST['booking_time'];
$time24 = date("G:i", strtotime($time));
$bookingtime = $time24;
}
$timestamp = strtotime($bookingdate." ".$bookingtime) * 1000;
$timeUpper = date("H:i:s", strtotime($_REQUEST['booking_date']." ".$_REQUEST['booking_time']) + 900);
$timeLower = date("H:i:s", strtotime($_REQUEST['booking_date']." ".$_REQUEST['booking_time']) - 900);
$sql = "SELECT * FROM `booking` where `cid` = '".$cid."' and `status` != 'cancelled' and `booking_date` = '".$bookingdate."' and `booking_time` between '".$timeLower."' and '".$timeUpper."'";
$result = $conn->query($sql);
if (!$result) {
error_log($conn->error);
}
if ($result->num_rows > 0) {
error_log("found double");
$Res["message"] = "You already have a booking within 15 mins of this time, please check the Open Bookings tab";
$Res["status"] = "error";
} else {
function send_mail($to, $from, $title, $message)
{
$headers = "MIME-Version: 1.0 \r\n";
$headers .= "From: $from \n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html;charset=ISO-8859-1 \r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: smail-PHP " . phpversion() . "\r\n";
return mail($to, $title, $message, $headers);
}
;
$reference = time().rand(10,5000);
$price = $_REQUEST['quote'];
$price = str_replace("$","", "$price");
$tokencustomerid = $cust_token[0]["access_token_value"];
$type = $_REQUEST["vehicle"];
$longUrl = "";
$postData = array('longUrl' => $longUrl);
$jsonData = json_encode($postData);
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url?key=AIzaSyCq_JZBDbrE5qma5SgF06M2dVAqbiZBZ-o');
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, $jsonData);
//$response = curl_exec($curlObj);
// Change the response json string to object
//$json = json_decode($response);
curl_close($curlObj);
//$shortLink = get_object_vars($json);
//$paymentlink = $shortLink['id'];
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, 'https://api.fleeteng.com.au/v2/graph/role/jobs?access_token=KX53ZweKgbbVIhD0_411iNWI9cQurfxbygZH9vpfsyX7');
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.' ' . $cus . '",
"campaign": {"id": 6424425401},
"contact": {"name": "' . $cus . '","phone": "' .$mob . '"},
"tasks": [
{
"timeframe": {"by": '.$timestamp.'},
"zone": {
"name": "Pick Up","address": "' . $_REQUEST["pickup_addr"] . '",
"coords": {
"lat": ' . $_REQUEST["pickup_lat"] . ',
"lon": ' . $_REQUEST["pickup_long"] . '},
"radius": 100}
},{
"zone": {
"name": "Drop Off","address": "' . $_REQUEST["pickoff_addr"] . '",
"coords": {
"lat": ' . $_REQUEST["pickoff_lat"] . ',
"lon": ' . $_REQUEST["pickoff_long"] . '},
"radius": 100
}
}],
"attr":
[
{
"key" : "Vehicle Requested",
"value": "'.$row['vehicle'].'"
},{
"key" : "Color Requested",
"value": "'.$row['color'].'"
}
]
}]');
$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'];
$pickup = $conn->real_escape_string($_REQUEST['pickup_addr']);
$dropoff = $conn->real_escape_string($_REQUEST['pickoff_addr']);
$sql = "INSERT INTO `booking` (`id`, `cid`, `email`, `booking_date`, `booking_time`, `pickup_addr`, `pickup_lat`, `pickup_long`, `pickoff_addr`, `pickoff_lat`, `pickoff_long`, `spatula_id`,`spatula_link`, `reference`, `vehicle`, `color`, `quote`, `quote_km`, `quote_time`, `status`, `driver`) VALUES (NULL, '".$cid."', '".$_REQUEST["email"]."', '".$bookingdate."', '".$bookingtime."', '".$pickup."', '".$_REQUEST["pickup_lat"]."', '".$_REQUEST["pickup_long"]."', '".$dropoff."', '".$_REQUEST["pickoff_lat"]."', '".$_REQUEST["pickoff_long"]."', '".$spatulaid."', '".$spatulalink."', '".$reference."', '".$type."', '".$_REQUEST["color"]."', '".$price."', '".$_REQUEST['dist']."', '".$_REQUEST['time']."', '', '')";
if($conn->query($sql))
{
$bid = $conn->insert_id;
$slackmessage = "Confirm Booking for $cus \n$bookingdate $bookingtime\n$pickup\n$dropoff";
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, $slackurl);
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);
$message = '
Hi '.$cus.',
Thanks for your booking. Please check the details below for your booking and location :
Details:
| Date |
'.$_REQUEST["booking_date"]." ".$_REQUEST["booking_time"].' |
| Name |
'.$cus.' |
| Phone |
'.$mob.' |
| Pick Up |
'.$_REQUEST["pickup_addr"].' |
| To Drop |
'.$_REQUEST["pickoff_addr"].' |
| Pick up Long |
'.$_REQUEST["pickup_long"].' |
| Pick up Lat |
'.$_REQUEST["pickup_lat"].' |
| Drop of Long |
'.$_REQUEST["pickoff_long"].' |
| Drop of Lat |
'.$_REQUEST["pickoff_lat"].' |
';
$to = "lwscann@gmail.com";
$from = "booking@magicride.ng";
$title = "MagicRide Booking Details";
if(send_mail($to, $from, $title, $message))
{
$Res["message"] = "booking successfully done";
$Res["status"] = "ok";
$Res["bid"] = $bid;
$Res["spatula_link"] = "$spatulalink";
}
else
{
$Res["message"] = "booking successfully But email has some issue Not send";
$Res["status"] = "ok";
}
}
else
{
error_log($conn->error);
$Res["message"] = "booking Not done ".$conn->error;
$Res["status"] = "error";
}
}
}
else
{
$Res["message"] = "user is not found ";
$Res["status"] = "error";
}
}
echo json_encode(new ArrayObject($Res));
//echo "
";
//print_r($data);
//print_r($Res);
//echo "
";
$conn->close();
?>