query("SELECT COUNT(*) as count FROM domains"); $totalResult = $totalStmt->fetch(\PDO::FETCH_ASSOC); $total = $totalResult['count'] ?? 0; // Get active domains $activeStmt = $pdo->query("SELECT COUNT(*) as count FROM domains WHERE is_active = 1"); $activeResult = $activeStmt->fetch(\PDO::FETCH_ASSOC); $active = $activeResult['count'] ?? 0; // Get expiring soon - use the first notification threshold from settings $settingModel = new \App\Models\Setting(); $notificationDays = $settingModel->getNotificationDays(); $expiringThreshold = !empty($notificationDays) ? max($notificationDays) : 30; // Use the largest notification day $expiringSoonStmt = $pdo->prepare("SELECT COUNT(*) as count FROM domains WHERE is_active = 1 AND expiration_date IS NOT NULL AND expiration_date <= DATE_ADD(NOW(), INTERVAL ? DAY) AND expiration_date >= NOW()"); $expiringSoonStmt->execute([$expiringThreshold]); $expiringSoonResult = $expiringSoonStmt->fetch(\PDO::FETCH_ASSOC); $expiringSoon = $expiringSoonResult['count'] ?? 0; $globalStats = [ 'total' => $total, 'active' => $active, 'expiring_soon' => $expiringSoon, 'expiring_threshold' => $expiringThreshold ]; } catch (\Exception $e) { $globalStats = [ 'total' => 0, 'active' => 0, 'expiring_soon' => 0, 'expiring_threshold' => 30 ]; } } // Get application settings from database if (!isset($appName)) { try { $settingModel = new \App\Models\Setting(); $appSettings = $settingModel->getAppSettings(); $appName = $appSettings['app_name']; $appTimezone = $appSettings['app_timezone']; // Set PHP timezone date_default_timezone_set($appTimezone); } catch (\Exception $e) { $appName = 'Domain Monitor'; date_default_timezone_set('UTC'); } } ?>