0) { $nav_prefix = str_repeat('../', $depth); } } } } $nav_prefix = $nav_prefix ?: ''; // Check login status // Primary check uses website_user_id, but some remote deployments may only set website_username. // Treat presence of website_username as a fallback to consider the user logged in for UI purposes. $is_logged_in = (isset($_SESSION['website_user_id']) && !empty($_SESSION['website_user_id'])) || (isset($_SESSION['website_username']) && !empty($_SESSION['website_username'])); $username = ''; if (isset($_SESSION['website_username']) && !empty($_SESSION['website_username'])) { $username = htmlspecialchars($_SESSION['website_username']); } elseif (isset($_SESSION['website_user_id']) && !empty($_SESSION['website_user_id'])) { // fetch username lazily if only user_id is present $username = htmlspecialchars((string)($_SESSION['website_user_id'])); } // Determine if the logged-in user is an admin by checking the panel DB $is_admin = false; if ($is_logged_in) { // load DB credentials require_once(__DIR__ . '/config_loader.php'); // Variables from config.inc.php (helps IDEs understand scope) /** @var string $db_host Database host */ /** @var string $db_user Database user */ /** @var string $db_pass Database password */ /** @var string $db_name Database name */ /** @var string $table_prefix Table prefix for database tables */ // Prefer reusing an existing $db if present, otherwise open a local connection $menu_db = null; $menu_db_opened = false; // Only reuse $db if it is still an open (non-closed) connection. // mysqli_thread_id() returns 0 on a closed handle; no @ needed since instanceof // already guarantees $db is a mysqli object. if (isset($db) && $db instanceof mysqli && mysqli_thread_id($db)) { $menu_db = $db; } else { $menu_db_port = isset($db_port) ? (int)$db_port : null; $menu_db = @mysqli_connect($db_host, $db_user, $db_pass, $db_name, $menu_db_port); $menu_db_opened = true; } if ($menu_db) { $uid = null; if (isset($_SESSION['website_user_id']) && !empty($_SESSION['website_user_id'])) { $uid = intval($_SESSION['website_user_id']); } if (!empty($uid)) { $res = mysqli_query($menu_db, "SELECT users_role FROM {$table_prefix}users WHERE user_id = $uid LIMIT 1"); if ($res && mysqli_num_rows($res) === 1) { $row = mysqli_fetch_assoc($res); if (strtolower((string)($row['users_role'] ?? '')) === 'admin') $is_admin = true; } } if ($menu_db_opened) { if (function_exists('billing_maybe_close_db')) { billing_maybe_close_db($menu_db); } else { @mysqli_close($menu_db); } } } } ?>