📂 FileMgr
📍
/
home
/
u865173473
/
domains
/
yelagiri.co.in
/
public_html
/
admin
/
bookings
✏️ s/update_status.php
⬅ Kembali
<?php require_once '../includes/auth_session.php'; require_once '../../db.php'; require_once '../notifications/send_email.php'; require_once '../notifications/send_sms.php'; if ($_SERVER['REQUEST_METHOD'] !== 'POST') { header('Location: index.php'); exit; } $booking_id = isset($_POST['booking_id']) ? intval($_POST['booking_id']) : 0; $status = isset($_POST['status']) ? $_POST['status'] : ''; $allowed_statuses = ['confirmed', 'rejected', 'pending', 'cancelled']; if ($booking_id > 0 && in_array($status, $allowed_statuses)) { // 1. Get current status to check for transition $stmt_check = $conn->prepare('SELECT status FROM bookings WHERE id = ?'); $stmt_check->bind_param('i', $booking_id); $stmt_check->execute(); $check_res = $stmt_check->get_result(); $old_data = $check_res->fetch_assoc(); $old_status = $old_data ? $old_data['status'] : ''; $stmt = $conn->prepare('UPDATE bookings SET status = ? WHERE id = ?'); $stmt->bind_param('si', $status, $booking_id); if ($stmt->execute()) { error_log("UpdateStatus: DB updated for ID $booking_id to $status"); // 2. Trigger Notifications if status changed to confirmed if ($status === 'confirmed' && $old_status !== 'confirmed') { try { // Fetch full details (Join with rooms to get property name) $sql = 'SELECT b.*, r.title as room_name FROM bookings b JOIN rooms r ON b.room_id = r.id WHERE b.id = ?'; $stmt_details = $conn->prepare($sql); $stmt_details->bind_param('i', $booking_id); $stmt_details->execute(); $booking_data = $stmt_details->get_result()->fetch_assoc(); if ($booking_data) { // Always send email first (more reliable) $emailSent = sendBookingConfirmationEmail($booking_data); // Try to send SMS $smsResult = sendBookingConfirmationSMS( $booking_data['customer_phone'], $booking_id, $booking_data['customer_name'], $booking_data['check_in'], $booking_data['check_out'], $booking_data['room_name'], $booking_data['total_price'] ); // Handle SMS failure if (is_array($smsResult) && !$smsResult['success']) { if (isset($smsResult['balance_error']) && $smsResult['balance_error']) { // Critical: Wallet balance low error_log('⚠️⚠️⚠️ ADMIN ACTION REQUIRED: Fast2SMS wallet balance is low! Recharge at https://www.fast2sms.com/'); error_log("Booking #$booking_id: Email sent, SMS failed due to insufficient balance"); } else { error_log("Booking #$booking_id: Email sent, SMS failed - " . $smsResult['error']); } } else if ($smsResult['success']) { error_log("Booking #$booking_id: Both email and SMS sent successfully"); } } } catch (Exception $e) { error_log("Critical Notification Failure for Booking #$booking_id: " . $e->getMessage()); } } header('Location: index.php?msg=status_updated'); exit; } else { echo 'Error: ' . $conn->error; } } else { header('Location: index.php?error=invalid_request'); exit; } ?>
💾 Simpan
Batal
⬅ admin
2 item
Nama
Tipe
Ukuran
Diubah
Aksi
🐘
index.php
php
18.8 KB
2026-01-25 15:46
✏️
👁️
🔤
🗑
🐘
update_status.php
php
3.7 KB
2026-01-25 15:46
✏️
👁️
🔤
🗑
✏️ Rename
Nama Baru
Simpan
Batal