<?php
session_start();
if (!isset($_SESSION['username']) || $_SESSION['role'] !== 'admin') {
	header("Location: login.html");
	exit();
}
include 'db_connect.php';

if (isset($_GET['id'])) {
	$id = $_GET['id'];

	//prevent deleting self
	if ($_SESSION['user_id'] == $id) {
		header("Location: manage_users.php?error=Cannot delete yourself");
		exit();
	}
	$stmt = $conn->prepare("DELETE FROM users WHERE id = ?");
	$stmt->bind_param("i", $id);
	$stmt->execute();
}
header("Location: manage_users.php?success=User deleted");
exit();
?>