. */ define('ROOT', rtrim($_SERVER['DOCUMENT_ROOT'], '/') . '/'); require_once ROOT . '/php/user.php'; require_admin(); if ($_SERVER["REQUEST_METHOD"] != "POST") { header("Location: /admin/remove-user/"); exit; } $username = isset($_POST['username']) ? $_POST['username'] : ''; try { $user = find_user($username); if (!$user) { echo "User not found."; exit; } $me = current_user(); if ($me !== null && (int)$user['id'] === (int)$me['id']) { echo "You cannot remove yourself!"; exit; } if ($user['status'] === 'admin') { echo "You cannot remove an admin, lower their status first!"; exit; } $sql = "DELETE FROM users WHERE username = :username"; query($sql, ['username' => $username]); } catch (\PDOException $e) { echo "Error: " . $e->getMessage(); exit; } header("Location: /admin/"); ?>