/home/desid573/public_html/fc_api
Edit: /home/desid573/public_html/fc_api/booking_edit_request.php (10196B)
query($sql);
if($result) {
$sql = "SELECT * FROM `booking` where id = '".$_REQUEST['bid']."'";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
while($row_details = $result->fetch_assoc())
{
$current_detail = $row_details;
}
}
if($current_detail["type"] == "SA") {
date_default_timezone_set("Australia/Sydney");
$slackurl = "https://hooks.slack.com/services/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";
} else if ($current_detail["type"] == "MA") {
date_default_timezone_set("Australia/Melbourne");
$slackurl = "https://hooks.slack.com/services/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";
} else if ($current_detail["type"] == "BA") {
date_default_timezone_set("Australia/Brisbane");
$slackurl = "https://hooks.slack.com/services/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";
} else if($current_detail["type"] == "GA") {
$slackurl = "https://hooks.slack.com/services/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";
date_default_timezone_set("Australia/Brisbane");
} else if($current_detail["type"] == "YA") {
$slackurl = "https://hooks.slack.com/services/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";
date_default_timezone_set("Australia/Brisbane");
} else {
$slackurl = "https://hooks.slack.com/services/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";
date_default_timezone_set("Australia/Perth");
}
$sql = "SELECT * FROM `customers` where email = '".$current_detail["email"]."'";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
while($row_detail = $result->fetch_assoc())
{
$cust_details = $row_detail;
}
}
$message = $cust_details["name"]." ".$current_detail["booking_date"]." ".$current_detail["booking_time"]."\n";
$date = $_REQUEST["date"];
if($date != $current_detail["booking_date"]) {
$date = str_replace("/","-",$date);
$format = 'd-m-Y';
$datetime = DateTime::createFromFormat($format, $date);
$bookingdate = $datetime->format('Y-m-d');
error_log($bookingdate." != ".$current_detail["booking_date"]);
if($bookingdate != $current_detail["booking_date"]) {
$message = $message."Date to ".$date."\n";
} else {
$date = NULL;
}
} else {
$date = NULL;
}
$time = date("G:i", strtotime($_REQUEST['time']));
error_log($_REQUEST['time']." != ".$current_detail["booking_time"]);
if($_REQUEST['time'] != $current_detail["booking_time"]) {
$message = $message."Time from ".$current_detail["booking_time"]." to ".$time."\n";
} else {
$time = "";
}
$pickup = "";
$pick_lat = "";
$pick_lon = "";
if(isset($_REQUEST["pickup"]) && $_REQUEST["pickup"] != $current_detail["pickup_addr"]) {
$pickup = $_REQUEST["pickup"];
$pick_lat = $_REQUEST["pick_lat"];
$pick_lon = $_REQUEST["pick_lon"];
$message = $message."Pickup from ".$current_detail["pickup_addr"]." to ".$pickup."\n";
}
$dropoff = "";
$drop_lat = "";
$drop_lon = "";
if(isset($_REQUEST["dropoff"]) && $_REQUEST["dropoff"] != $current_detail["pickoff_addr"]) {
$dropoff = $_REQUEST["dropoff"];
$drop_lat = $_REQUEST["drop_lat"];
$drop_lon = $_REQUEST["drop_lon"];
$message = $message."Dropoff from ".$current_detail["pickoff_addr"]." to ".$dropoff."\n";
}
$flight_num = "";
if($_REQUEST['flight_num'] != $current_detail["flight_num"]) {
$flight_num = $_REQUEST['flight_num'];
$message = $message."Flight# from .".$current_detail["flight_num"]." to ".$flight_num."\n";
}
$mins_to = "";
if(isset($_REQUEST["mins_to"]) && $_REQUEST["mins_to"] != $current_detail["mins_to"]) {
$mins_to = $_REQUEST["mins_to"];
$message = $message."Mins to flight from ".$current_detail["mins_to"]." now ".$mins_to."\n";
}
$book_pax = "";
if($_REQUEST["book_pax"] != $current_detail["book_pax"]) {
$book_pax = $_REQUEST["book_pax"];
$message = $message."Total Pax from ".$current_detail["book_pax"]." now ".$book_pax."\n";
}
$book_rf = "";
if($_REQUEST["book_rf"] != $current_detail["book_rf"]) {
$book_rf = $_REQUEST["book_rf"];
$message = $message."Rear Facings from ".$current_detail["book_rf"]." now ".$book_rf."\n";
}
$book_ff = "";
if($_REQUEST["book_ff"] != $current_detail["book_ff"]) {
$book_ff = $_REQUEST["book_ff"];
$message = $message."Forward Facings from ".$current_detail["book_ff"]." now ".$book_ff."\n";
}
$book_b = "";
if($_REQUEST["book_b"] != $current_detail["book_b"]) {
$book_b = $_REQUEST["book_b"];
$message = $message."Boosters from ".$current_detail["book_b"]. " now ".$book_b."\n";
}
$luggage = "";
if($_REQUEST["luggage"] != $current_detail["luggage"]) {
$luggage = $_REQUEST["luggage"];
$message = $message."Luggage now ".$luggage."\n";
}
$quote = "";
if($_REQUEST["quote"] != $current_detail["quote"] AND $_REQUEST["quote"] != "") {
$quote = $_REQUEST["quote"];
$message = $message."Quote was $".$current_detail["quote"]." now $".$quote."\n";
}
$sql = "INSERT INTO `booking_edit_request`(`id`, `bid`, `date`, `time`, `pickup`, `pick_lat`, `pick_lon`, `dropoff`, `drop_lat`, `drop_lon`, `book_pax`, `book_rf`, `book_ff`, `book_b`, `new_quote`, `new_quote_km`, `new_quote_time`, `flight_num`, `mins`, `luggage`, `toll_quote`, `toll_description`, `date_requested`, `date_approved`, `approved`) VALUES (NULL,'".$_REQUEST['bid']."','".$bookingdate."','".$time."','".$pickup."','".$pick_lat."','".$pick_lon."','".$dropoff."','".$drop_lat."','".$drop_lon."','".$book_pax."', '".$book_rf."', '".$book_ff."', '".$book_b."', '".$quote."', '".$_REQUEST["quote_km"]."', '".$_REQUEST["quote_time"]."', '".$flight_num."', '".$mins_to."', '".$luggage."', '".$_REQUEST["tollQuote"]."', '".$_REQUEST["tollDescription"]."', NOW(), '', 0)";
$request = $conn->query($sql);
if(!$request) {
error_log("Request add error ".$conn->error);
$Res["status"] = "error";
$Res["message"] = "Cannot Create Request";
} else {
$request_id = $conn->insert_id;
$sql = "UPDATE booking SET status = 'change' WHERE id = ".$_REQUEST['bid'];
$r = $conn->query($sql);
if(!$r) {
error_log("update error ".$conn->error);
}
$message = "
\n".$message;
error_log($message);
$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": "'.$message.'"}');
$response = curl_exec($curlObj);
error_log($response);
curl_close($curlObj);
$Res["status"] = "OK";
$Res["message"] = "Request Sent";
}
} else {
$Res["status"] = "error";
$Res["message"] = "cannot find booking";
}
echo json_encode($Res, true);