<?php
include 'auth.php';
require_permission('bookings_delete');
include '../includes/db.php';
if (isset($_GET['id']) && isset($_GET['type'])) {
$id = $_GET['id'];
$type = $_GET['type'];
$table_name = '';
if ($type === 'visit') {
$table_name = 'visit_reservations';
} elseif ($type === 'maintenance') {
$table_name = 'maintenance_reservations';
} else {
header("Location: bookings.php?error=نوع الحجز غير صالح");
exit();
}
$stmt = $conn->prepare("DELETE FROM {$table_name} WHERE id = ?");
$stmt->bind_param("i", $id);
if ($stmt->execute()) {
header("Location: bookings.php?success=تم حذف الحجز بنجاح");
} else {
header("Location: bookings.php?error=حدث خطأ أثناء الحذف");
}
$stmt->close();
$conn->close();
} else {
header("Location: bookings.php");
exit();
}
?>