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

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

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

if ($id <= 0) {
    die("Invalid equipment ID.");
}

/* ===============================
   UPDATE STATUS TO INACTIVE
=================================*/
$stmt = mysqli_prepare($conn, "
    UPDATE equipment 
    SET status = 'Inactive' 
    WHERE id = ?
");

mysqli_stmt_bind_param($stmt, "i", $id);

if (mysqli_stmt_execute($stmt)) {
    header("Location: " . BASE_URL . "equipment/equipment_details.php?id=" . $id . "&deactivated=1");
    exit();
} else {
    die("Failed to deactivate equipment.");
}