<?php

session_start();

require_once "../../config/koneksi.php";

// Cek login admin
if (!isset($_SESSION['user_id'])) {
    header("Location: ../login.php");
    exit;
}

// Cek ID
if (!isset($_GET['id']) || empty($_GET['id'])) {
    header("Location: index.php");
    exit;
}

$id = (int) $_GET['id'];

// Hapus data pengumuman
$query = mysqli_query(
    $koneksi,
    "DELETE FROM pengumuman WHERE id = $id"
);

// Jika berhasil
if ($query) {

    header("Location: index.php?status=hapus");
    exit;
} else {

    echo "Data gagal dihapus: " . mysqli_error($koneksi);
}
