<?php
session_start();
if (!isset($_SESSION['role_id']) || $_SESSION['role_id'] != 4) {
    header("Location: ../../index.php");
    exit();
}

include('../../includes/config.php');

$journal_id = isset($_GET['id']) ? intval($_GET['id']) : 0;

if ($journal_id <= 0) {
    header("Location: journal_entries.php?msg=Invalid+journal+entry");
    exit();
}

// Delete the journal entry
$stmt = $conn->prepare("DELETE FROM journal_entries WHERE id = ?");
$stmt->bind_param("i", $journal_id);

if ($stmt->execute()) {
    header("Location: journal_entries.php?msg=Journal+entry+deleted+successfully");
} else {
    header("Location: journal_entries.php?msg=Failed+to+delete+entry");
}
$stmt->close();
exit();
?>
