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

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

$id = $_GET['id'];

// Prevent admin delete himself
if($id == $_SESSION['user_id']){
    header("Location: ../settings.php");
    exit();
}

$stmt = mysqli_prepare($conn, "DELETE FROM users WHERE id=?");
mysqli_stmt_bind_param($stmt, "i", $id);
mysqli_stmt_execute($stmt);

header("Location: ../settings.php");
exit();