<?php

session_start();
require_once __DIR__ . "/../config/db.php";

if (
    !isset($_SESSION['user_id']) ||
    $_SESSION['role'] !== 'hod'
){
    header("Location: ../login.php");
    exit;
}

$request_id = intval($_GET['id'] ?? 0);
$hod_id = $_SESSION['user_id'];

$stmt = mysqli_prepare(
    $conn,
    "
    UPDATE maintenance_request
    SET
        status='Rejected',
        reviewed_by=?,
        reviewed_at=NOW()
    WHERE id=?
    "
);

mysqli_stmt_bind_param(
    $stmt,
    "ii",
    $hod_id,
    $request_id
);

mysqli_stmt_execute($stmt);

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