49 lines
1.6 KiB
PHP
49 lines
1.6 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
require_once 'mail/MailService.php';
|
|
|
|
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'coach') {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
if (!isset($_GET['id'])) {
|
|
header('Location: dashboard.php');
|
|
exit;
|
|
}
|
|
|
|
$booking_id = $_GET['id'];
|
|
$coach_id = $_SESSION['user_id'];
|
|
|
|
// Verify the booking belongs to the coach
|
|
$stmt = db()->prepare("SELECT * FROM bookings WHERE id = ? AND coach_id = ?");
|
|
$stmt->execute([$booking_id, $coach_id]);
|
|
$booking = $stmt->fetch();
|
|
|
|
if ($booking) {
|
|
$stmt = db()->prepare("UPDATE bookings SET status = 'confirmed' WHERE id = ?");
|
|
$stmt->execute([$booking_id]);
|
|
|
|
// Notify client
|
|
$stmt = db()->prepare("SELECT c.email, c.name as client_name, co.name as coach_name, b.booking_time FROM bookings b JOIN clients c ON b.client_id = c.id JOIN coaches co ON b.coach_id = co.id WHERE b.id = ?");
|
|
$stmt->execute([$booking_id]);
|
|
$booking_details = $stmt->fetch();
|
|
|
|
if ($booking_details) {
|
|
$to = $booking_details['email'];
|
|
$subject = 'Booking Confirmed';
|
|
$body = "<p>Hello " . htmlspecialchars($booking_details['client_name']) . ",</p>";
|
|
$body .= "<p>Your booking with " . htmlspecialchars($booking_details['coach_name']) . " on " . htmlspecialchars(date('F j, Y, g:i a', strtotime($booking_details['booking_time']))) . " has been confirmed.</p>";
|
|
$body .= "<p>Thank you for using CoachConnect.</p>";
|
|
|
|
MailService::sendMail($to, $subject, $body, strip_tags($body));
|
|
}
|
|
|
|
header('Location: dashboard.php?status=approved');
|
|
} else {
|
|
header('Location: dashboard.php?status=error');
|
|
}
|
|
|
|
exit;
|