36716-vm/delete-availability.php
2025-12-07 05:00:42 +00:00

40 lines
1.2 KiB
PHP

<?php
session_start();
require_once 'db/config.php';
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'coach') {
header('Location: login.php');
exit;
}
if (!isset($_GET['id'])) {
header('Location: dashboard.php?status=error&message=Invalid+request');
exit;
}
$availability_id = $_GET['id'];
$coach_id = $_SESSION['user_id'];
try {
// Verify the availability slot belongs to the coach
$stmt = db()->prepare("SELECT * FROM coach_availability WHERE id = ? AND coach_id = ?");
$stmt->execute([$availability_id, $coach_id]);
$availability = $stmt->fetch();
if (!$availability) {
header('Location: dashboard.php?status=error&message=Availability+not+found');
exit;
}
// Delete the availability slot
$delete_stmt = db()->prepare("DELETE FROM coach_availability WHERE id = ?");
$delete_stmt->execute([$availability_id]);
header('Location: dashboard.php?status=success&message=Availability+deleted+successfully');
exit;
} catch (PDOException $e) {
error_log('Error deleting availability: ' . $e->getMessage());
header('Location: dashboard.php?status=error&message=Could+not+delete+availability');
exit;
}