<?php
session_start();

if (!isset($_SESSION['clinic_logged_in']) || $_SESSION['clinic_logged_in'] !== true) {
    header('Location: index.php');
    exit;
}

// Optional: access admin ID like this
$admin_id = $_SESSION['clinic_id'];

require 'dbconn.php'; // Include your DB connection

// Check if ID is provided
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
    echo "<script>alert('Invalid ID.'); window.history.back();</script>";
    exit;
}

$id = intval($_GET['id']); // sanitize

// Prepare and execute delete query
$stmt = $mysqli->prepare("DELETE FROM site_facilities WHERE id = ?");
$stmt->bind_param("i", $id);

if ($stmt->execute()) {
    echo "<script>alert('Record deleted successfully.'); window.location.href = 'site_facility.php';</script>";
} else {
    echo "<script>alert('Error deleting record: " . $stmt->error . "'); window.history.back();</script>";
}

$stmt->close();
$mysqli->close();
?>
