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

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

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

    $request_id = intval($_POST['request_id']);

    $stmt = mysqli_prepare($conn,
        "UPDATE maintenance_request 
         SET status='Rejected' 
         WHERE id=?"
    );
    mysqli_stmt_bind_param($stmt, "i", $request_id);
    mysqli_stmt_execute($stmt);

    header("Location: maintenance_details.php?id=" . $request_id);
    exit();
}
