0) { ob_end_clean(); } header('Location: '.$server_url.'login/index.php'); exit; } require 'preset.php'; // ── 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 ────────────────────────────────────────────────────────────── require_once __DIR__ . '/assets/utils/app_registry.php'; $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. // '/asset_dashboard/' and '/ac_dashboard/' do not match '/dashboard/' (no slash before "dashboard"). $_app_paths = [ 'wms' => ['/dashboard/', '/ics/', '/order/', '/po/', '/reports/'], 'accounting' => ['/ac_dashboard/', '/revenue/', '/expense/', '/finance/', '/journal/'], 'asset' => ['/asset_dashboard/', '/asset/'], ]; $topbar_current_app = null; // null = neutral page (master data / setting) foreach ($_app_paths as $_app_key => $_paths) { foreach ($_paths as $_p) { if (str_contains($_SERVER['PHP_SELF'], $_p)) { $topbar_current_app = $_app_key; break 2; } } } // Asset Management pages are only for users given that app. if ($topbar_current_app === 'asset' && !app_can_access($topbar_app_access, 'asset')) { while (ob_get_level() > 0) { ob_end_clean(); } header('Location: ' . $server_url . app_home_path($app_registry, app_default_for_access($app_registry, $topbar_app_access))); exit; } // 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'] = app_default_for_access($app_registry, $topbar_app_access); } $topbar_show_wms = app_can_access($topbar_app_access, 'wms'); $topbar_show_accounting = app_can_access($topbar_app_access, 'accounting'); $topbar_switch_apps = array_filter( $app_registry, fn($key) => app_can_access($topbar_app_access, $key), ARRAY_FILTER_USE_KEY ); // Per-app colour. WMS keeps the compiled orange theme (#E66239); the others override it. $_app_themes = [ 'accounting' => ['main' => '#0284c7', 'rgb' => '2, 132, 199', 'dark' => '#0369a1', 'subtle' => '#e0f2fe', 'border' => '#bae6fd'], 'asset' => ['main' => '#16a34a', 'rgb' => '22, 163, 74', 'dark' => '#15803d', 'subtle' => '#dcfce7', 'border' => '#bbf7d0'], ]; $_theme_app = $_SESSION['login_current_app'] ?? 'wms'; $_theme = $_app_themes[$_theme_app] ?? null; $_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; ?>