<?php
session_start();
require_once "db.php";

$isAdmin = $_SESSION['is_admin'] ?? 0;
if (!$isAdmin) {
    header("Location: index.php");
    exit();
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $id = intval($_POST['id'] ?? 0);
    if ($id > 0) {
        $stmt = $conn->prepare("DELETE FROM contact_messages WHERE id = :id");
        $stmt->execute([':id' => $id]);
    }
}

header("Location: messages.php");
exit();
