time()], 'Session refreshed'); break; case 'dashboard-overview': $analyticsPeriod = $_GET['analytics_period'] ?? 'days'; $analyticsCount = isset($_GET['analytics_count']) ? (int)$_GET['analytics_count'] : 30; if (!in_array($analyticsPeriod, ['days', 'months', 'years'], true)) { $analyticsPeriod = 'days'; } if ($analyticsPeriod === 'months' && $analyticsCount <= 0) { $analyticsCount = 12; } elseif ($analyticsPeriod === 'years' && $analyticsCount < 0) { $analyticsCount = 0; } elseif ($analyticsPeriod === 'days' && $analyticsCount <= 0) { $analyticsCount = 30; } $pagesPath = defined('CONTENT_PATH') ? CONTENT_PATH : dirname(RAIJU_ADMIN_DIR) . '/content/pages/'; $newsPath = dirname(RAIJU_ADMIN_DIR) . '/content/news/'; $pageCount = count(glob($pagesPath . '[a-z][a-z]_*.json') ?: []); $newsCount = is_dir($newsPath) ? count(glob($newsPath . '*.json') ?: []) : 0; $response = [ 'pages' => $pageCount, 'news' => $newsCount, 'status' => dashboardStatusOverview($pagesPath, $newsPath), 'analytics' => raijuAnalyticsSummary($analyticsPeriod, $analyticsCount), ]; $settings = is_file(SETTINGS_PATH) ? json_decode(file_get_contents(SETTINGS_PATH), true) : []; $response['analytics']['state'] = ($response['analytics']['state'] ?? '') === 'error' ? 'error' : (!raijuAnalyticsEnabled() ? 'disabled' : (empty($response['analytics']['periodViews']) ? 'empty' : 'ready')); if (dashboardAiModuleEnabled()) { $aiSettings = raijuAiLoadSettings(true); // Same shape as load-ai-settings, so the form rendered from the overview is complete if (isAdmin() && function_exists('raijuAgentStatusForAdmin')) $aiSettings['agentStatus'] = raijuAgentStatusForAdmin(); $response['ai'] = [ 'settings' => $aiSettings, 'usage' => raijuAiUsageSummary() ]; } jsonResponse(true, $response); break; // ============================================================ // CONTENT MANAGEMENT // ============================================================ }