. */ require_once ROOT . '/php/session.php'; require_once ROOT . '/php/database.php'; require_once ROOT . '/php/render.php'; const USER_STATUSES = ['none', 'member', 'mod', 'admin']; function find_user(string $username): ?array { $sql = "SELECT id, username, status FROM users WHERE username = :username"; return fetch_row($sql, ['username' => $username]); } function current_user(): ?array { $user_id = get_user_id(); if ($user_id === null) { return null; } $sql = "SELECT id, username, status FROM users WHERE id = :id"; return fetch_row($sql, ['id' => $user_id]); } function is_admin(): bool { $user = current_user(); return $user !== null && $user['status'] === 'admin'; } function require_admin(): void { if (is_admin()) { return; } if (get_user_id() === null) { http_response_code(401); } else { http_response_code(403); } exit; } ?>