<?php
session_start();

if (isset($_SESSION["security_Level"]) && $_SESSION["security_Level"] < 2) {
    require_once "../Config/session_check.php";
} else {
    header("location: ../index.php");
}
$_SESSION["last_Active"] = time();

$ID = "";
$status = '';

if (isset($_GET["ID"])) {
    $ID = $_GET["ID"];

} else {
    header("location: ../index.php");
}
if (isset($_GET["STATUS"])) {
    $status = $_GET["STATUS"];

} else {
    header("location: ../index.php");
}

require_once "../Config/config.php";

$SQL = "UPDATE users SET Locked = ? WHERE Staff_ID = ?;";
if ($status == '1') {
    $status = '0';
} else if ($status == '0') {
    $status = '1';
} else {
    echo "error occured";
    exit;
}

if ($stmt = mysqli_prepare($link, $SQL)) {

    mysqli_stmt_bind_param($stmt, "is", $status, $ID);
    // Attempt to execute the prepared statement
    if (mysqli_stmt_execute($stmt)) {
        // Close connection
        mysqli_close($link);
        header("location: ../Staff/DetailView.php?ID=" . $ID . "");
        exit;
    } else {
        echo "Something got in the way.";
    }
}


