<?php

session_start();

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

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

include 'dbconn.php';

if (isset($_GET['id'])) {
    $id = intval($_GET['id']);
    $sql = "DELETE FROM clinics WHERE id = $id";
    if ($mysqli->query($sql) === TRUE) {
        echo "<script>alert('Clinic deleted successfully!'); window.location.href='all_clinics.php';</script>";
    } else {
        echo "<script>alert('Error: " . $mysqli->error . "'); window.history.back();</script>";
    }
    $mysqli->close();
} else {
    echo "<script>alert('Invalid clinic ID.'); window.history.back();</script>";
}
?>