[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: save_admin_booking.php
<?php session_start(); include("../admin/db/db.php"); header('Content-Type: application/json'); ini_set('display_errors', 0); ini_set('log_errors', 1); ob_start(); // Check if admin is logged in if(!isset($_SESSION['username_Xw211qAAsq4'])) { echo json_encode(['success' => false, 'message' => 'Unauthorized access - Admin not logged in']); 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_phone'])) { echo json_encode(['success' => false, 'message' => 'Customer first name, last name and phone 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; } if (empty($data['employee_id'])) { echo json_encode(['success' => false, 'message' => 'Staff selection is 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 = isset($data['customer_email']) ? $data['customer_email'] : ''; $mynumber = $data['customer_phone']; // Check if client exists $check_client = $con->prepare("SELECT * FROM clients WHERE (client_email = ? OR phone_number = ?) AND business_name = ?"); $check_client->execute([$myemail, $mynumber, $shop]); if($check_client->rowCount() > 0){ $client_row = $check_client->fetch(PDO::FETCH_ASSOC); $customer_id = $client_row['client_id']; // Update existing client information $update_stmt = $con->prepare("UPDATE clients SET first_name = ?, last_name = ?, phone_number = ?, client_email = ? WHERE client_id = ?"); $update_stmt->execute([ $data['customer_first'], $data['customer_last'], $data['customer_phone'], $myemail, $customer_id ]); } else { // Insert new client $stmt = $con->prepare("INSERT INTO clients (first_name, last_name, phone_number, client_email, date, gender, business_name) VALUES (?, ?, ?, ?, ?, ?, ?)"); $stmt->execute([ $data['customer_first'], $data['customer_last'], $data['customer_phone'], $myemail, $date, $gender, $data['shopname'] ]); $customer_id = $con->lastInsertId(); } // Insert booking - Use 'online' status for ADMIN bookings (so they show in appointment page) $status = 'online'; // ADMIN bookings are 'online' to show in appointment page $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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->execute([ $date_created, $created, $customer_id, $data['employee_id'], $data['booking_date'], $data['booking_time'], $active, $status, $payment_mode, $data['shopname'], $discount, $comRate ]); $booking_id = $con->lastInsertId(); // Insert services $stmt = $con->prepare("INSERT INTO true_price (appointment_id, service_id, price) VALUES (?, ?, ?)"); foreach ($data['services'] as $service) { $stmt->execute([ $booking_id, $service['service_id'], $service['price'] ]); } $con->commit(); // ✅ SEND SMS NOTIFICATION TO CUSTOMER AFTER SUCCESSFUL BOOKING if (!empty($data['customer_phone'])) { $senderID = "VITEGH"; // Format the date for better readability $booking_date = date('l, F j, Y', strtotime($data['booking_date'])); $booking_time = date('g:i A', strtotime($data['booking_time'])); $sms_message = "Dear {$data['customer_first']}, your appointment has been scheduled on {$booking_date} at {$booking_time} with {$shop}. Thank you for choosing us!"; $smsdata = json_encode([ 'username' => "vitelogistics", 'password' => "vitelogis@2025", 'source' => $senderID, 'destination' => $data['customer_phone'], 'message' => $sms_message, '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); // Optional: Log SMS sending result error_log("SMS sent to {$data['customer_phone']}: " . ($sms_err ? "Failed - $sms_err" : "Success")); } echo json_encode([ 'success' => true, 'booking_id' => $booking_id, 'message' => 'Admin appointment booked successfully and SMS sent to customer' ]); } catch (PDOException $e) { $con->rollBack(); error_log("Admin 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.76 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