0) { ob_end_clean(); } header('Location: '.$server_url.'login/index.php'); exit; } require 'preset.php'; require_once __DIR__ . '/assets/utils/app_access.php'; // Accounting pages require accounting app access; the menus below only hide the // links, this stops a WMS-only user who opens the URL directly. $_page_app = app_access_app_for($_SERVER['SCRIPT_NAME'] ?? ''); if ($_page_app !== null && !app_access_allows($_SESSION['login_app_access'] ?? 'wms', $_page_app)) { while (ob_get_level() > 0) { ob_end_clean(); } header('Location: '.$server_url.'dashboard/index.php'); exit; } // ── User display data from session ──────────────────────────────────────────── $topbar_name = htmlspecialchars(trim(($_SESSION['login_name'] ?? '') . ' ' . ($_SESSION['login_surname'] ?? '')), ENT_QUOTES, 'UTF-8'); $topbar_username = htmlspecialchars($_SESSION['login_username'] ?? '', ENT_QUOTES, 'UTF-8'); $topbar_picture = $_SESSION['login_profile_picture'] ?? ''; $topbar_avatar_src = $topbar_picture ? htmlspecialchars($server_url . 'uploads/profile/' . $topbar_picture, ENT_QUOTES, 'UTF-8') : htmlspecialchars($server_url . 'assets/images/avatar-1.jpg', ENT_QUOTES, 'UTF-8'); // ── App switcher ────────────────────────────────────────────────────────────── $topbar_app_access = $_SESSION['login_app_access'] ?? 'wms'; // Detect which app this page belongs to. // Master-data pages (/accounting/, /inventory/, /contact/, /setting/) are neutral — don't change the session. $_wms_paths = ['/dashboard/', '/ics/', '/order/', '/po/', '/reports/']; $_ac_paths = ['/ac_dashboard/', '/revenue/', '/expense/', '/finance/', '/journal/']; $topbar_current_app = null; // null = neutral page (master data / setting) foreach ($_wms_paths as $_p) { if (str_contains($_SERVER['PHP_SELF'], $_p)) { $topbar_current_app = 'wms'; break; } } if (!$topbar_current_app) { foreach ($_ac_paths as $_p) { if (str_contains($_SERVER['PHP_SELF'], $_p)) { $topbar_current_app = 'accounting'; break; } } } // Only persist to session when on a definitive app page if ($topbar_current_app) { $_SESSION['login_current_app'] = $topbar_current_app; } // Default session on first visit or neutral pages if (empty($_SESSION['login_current_app'])) { $_SESSION['login_current_app'] = ($topbar_app_access === 'accounting') ? 'accounting' : 'wms'; } $topbar_show_wms = in_array($topbar_app_access, ['all', 'wms']); $topbar_show_accounting = in_array($topbar_app_access, ['all', 'accounting']); $_usage = (new UsageGuard($pdo1, (int)$_SESSION['login_company_id'], $packages))->getStatus(); $_usage_max_pct = max($_usage['daily_pct'], $_usage['weekly_pct']); $_usage_warn = $_usage_max_pct >= 80 && $_usage_max_pct < 100; $_usage_full = $_usage_max_pct >= 100; ?>