pdo = $connection->getPdo(); } public function index(Request $request, Response $response): string { $user = $request->routeParam('_authenticated_user'); $lang = $this->session->get('lang', 'en'); // Real stats from database $orgCount = (int)$this->pdo->query("SELECT COUNT(*) FROM organizations WHERE deleted_at IS NULL")->fetchColumn(); $vcCount = (int)$this->pdo->query("SELECT COUNT(*) FROM organizations WHERE type='vc' AND deleted_at IS NULL")->fetchColumn(); $acceleratorCount = (int)$this->pdo->query("SELECT COUNT(*) FROM organizations WHERE type='accelerator' AND deleted_at IS NULL")->fetchColumn(); $opportunityCount = (int)$this->pdo->query("SELECT COUNT(*) FROM opportunities WHERE deleted_at IS NULL AND status='active'")->fetchColumn(); $contactCount = (int)$this->pdo->query("SELECT COUNT(*) FROM contacts WHERE deleted_at IS NULL")->fetchColumn(); $sourceCount = (int)$this->pdo->query("SELECT COUNT(*) FROM sources WHERE status='active'")->fetchColumn(); $todayOpps = (int)$this->pdo->query("SELECT COUNT(*) FROM opportunities WHERE DATE(created_at) = CURDATE()")->fetchColumn(); // Recent opportunities $stmt = $this->pdo->query( "SELECT o.*, org.name as org_name FROM opportunities o LEFT JOIN organizations org ON org.id = o.organization_id WHERE o.deleted_at IS NULL ORDER BY o.created_at DESC LIMIT 10" ); $recentOpps = $stmt->fetchAll() ?: []; // Opportunities by type $byType = $this->pdo->query( "SELECT type, COUNT(*) as count FROM opportunities WHERE deleted_at IS NULL GROUP BY type" )->fetchAll(PDO::FETCH_KEY_PAIR) ?: []; // Recent activity $stmt = $this->pdo->query("SELECT * FROM activity_logs ORDER BY created_at DESC LIMIT 10"); $recentActivities = $stmt->fetchAll() ?: []; $langFile = __DIR__ . "/../../resources/lang/{$lang}.php"; $t = file_exists($langFile) ? require $langFile : []; return $this->render('admin/dashboard', [ 'user' => $user, 'title' => $t['dashboard'] ?? 'Dashboard', 't' => $t, 'lang' => $lang, 'stats' => [ 'organizations' => $orgCount, 'vc' => $vcCount, 'accelerators' => $acceleratorCount, 'opportunities' => $opportunityCount, 'contacts' => $contactCount, 'sources' => $sourceCount, 'today' => $todayOpps, ], 'recent_opportunities' => $recentOpps, 'opportunities_by_type' => $byType, 'recent_activities' => $recentActivities, ], 'admin'); } }