diff --git a/app/Controllers/DashboardController.php b/app/Controllers/DashboardController.php index 624b52f..4f3a69b 100644 --- a/app/Controllers/DashboardController.php +++ b/app/Controllers/DashboardController.php @@ -27,13 +27,11 @@ class DashboardController extends Controller $settingModel = new \App\Models\Setting(); $isolationMode = $settingModel->getValue('user_isolation_mode', 'shared'); - // Get statistics based on isolation mode + // Get data based on isolation mode (stats are now handled in base.php) if ($isolationMode === 'isolated') { - $stats = $this->domainModel->getStatistics($userId); $recentDomains = $this->domainModel->getRecent(5, $userId); $groups = $this->groupModel->getAllWithChannelCount($userId); } else { - $stats = $this->domainModel->getStatistics(); $recentDomains = $this->domainModel->getRecent(5); $groups = $this->groupModel->getAllWithChannelCount(); } @@ -59,12 +57,7 @@ class DashboardController extends Controller $formattedRecentDomains = \App\Helpers\DomainHelper::formatMultiple($recentDomains); $formattedExpiringDomains = \App\Helpers\DomainHelper::formatMultiple($expiringThisMonth); - // Get global stats for dashboard cards - $globalStats = \App\Helpers\LayoutHelper::getGlobalStats($userId); - $this->view('dashboard/index', [ - 'stats' => $stats, - 'globalStats' => $globalStats, 'recentDomains' => $formattedRecentDomains, 'expiringThisMonth' => $formattedExpiringDomains, 'expiringCount' => count($allExpiringDomains), diff --git a/app/Controllers/ErrorLogController.php b/app/Controllers/ErrorLogController.php index 217e04c..0758f70 100644 --- a/app/Controllers/ErrorLogController.php +++ b/app/Controllers/ErrorLogController.php @@ -100,7 +100,7 @@ class ErrorLogController extends Controller $notes = $_POST['notes'] ?? null; // Mark error as resolved using model - $this->errorLogModel->markErrorResolved($errorId, $_SESSION['user_id'], $notes); + $this->errorLogModel->markErrorResolved($errorId, \Core\Auth::id(), $notes); $_SESSION['success'] = 'Error marked as resolved'; header('Location: /errors/' . urlencode($errorId)); diff --git a/app/Helpers/LayoutHelper.php b/app/Helpers/LayoutHelper.php index ca48333..12e67b5 100644 --- a/app/Helpers/LayoutHelper.php +++ b/app/Helpers/LayoutHelper.php @@ -34,73 +34,6 @@ class LayoutHelper } } - /** - * Get stats for sidebar (respects user isolation) - */ - public static function getGlobalStats(?int $userId = null): array - { - try { - $pdo = \Core\Database::getConnection(); - - // Check isolation mode - $settingModel = new Setting(); - $isolationMode = $settingModel->getValue('user_isolation_mode', 'shared'); - - // Build WHERE clause based on isolation mode - $whereClause = ''; - $params = []; - - if ($isolationMode === 'isolated' && $userId) { - $whereClause = ' WHERE user_id = ?'; - $params[] = $userId; - } - - // Get total domains - $totalSql = "SELECT COUNT(*) as count FROM domains" . $whereClause; - $totalStmt = $pdo->prepare($totalSql); - $totalStmt->execute($params); - $total = $totalStmt->fetch(\PDO::FETCH_ASSOC)['count'] ?? 0; - - // Get active domains - $activeSql = "SELECT COUNT(*) as count FROM domains WHERE is_active = 1" . $whereClause; - $activeStmt = $pdo->prepare($activeSql); - $activeStmt->execute($params); - $active = $activeStmt->fetch(\PDO::FETCH_ASSOC)['count'] ?? 0; - - // Get expiring soon - $notificationDays = $settingModel->getNotificationDays(); - $threshold = !empty($notificationDays) ? max($notificationDays) : 30; - - $expiringSql = "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()" . $whereClause; - - $expiringParams = [$threshold]; - if ($isolationMode === 'isolated' && $userId) { - $expiringParams[] = $userId; - } - - $expiringSoonStmt = $pdo->prepare($expiringSql); - $expiringSoonStmt->execute($expiringParams); - $expiringSoon = $expiringSoonStmt->fetch(\PDO::FETCH_ASSOC)['count'] ?? 0; - - return [ - 'total' => $total, - 'active' => $active, - 'expiring_soon' => $expiringSoon, - 'expiring_threshold' => $threshold - ]; - } catch (\Exception $e) { - return [ - 'total' => 0, - 'active' => 0, - 'expiring_soon' => 0, - 'expiring_threshold' => 30 - ]; - } - } /** * Convert timestamp to "time ago" format diff --git a/app/Models/Domain.php b/app/Models/Domain.php index 0061db7..d519087 100644 --- a/app/Models/Domain.php +++ b/app/Models/Domain.php @@ -164,6 +164,7 @@ class Domain extends Model 'expiring_soon' => 0, 'expired' => 0, 'inactive' => 0, + 'expiring_threshold' => 30, ]; // Build WHERE clause for user filtering @@ -204,6 +205,25 @@ class Domain extends Model // Add inactive count to total $stats['total'] += $stats['inactive']; + // Get expiring soon count + $settingModel = new \App\Models\Setting(); + $notificationDays = $settingModel->getNotificationDays(); + $threshold = !empty($notificationDays) ? max($notificationDays) : 30; + $stats['expiring_threshold'] = $threshold; + + $expiringWhereClause = "WHERE is_active = 1 AND expiration_date IS NOT NULL AND expiration_date <= DATE_ADD(NOW(), INTERVAL ? DAY) AND expiration_date >= NOW()"; + $expiringParams = [$threshold]; + + if ($userId) { + $expiringWhereClause .= " AND user_id = ?"; + $expiringParams[] = $userId; + } + + $expiringStmt = $this->db->prepare("SELECT COUNT(*) as count FROM domains $expiringWhereClause"); + $expiringStmt->execute($expiringParams); + $expiringResult = $expiringStmt->fetch(); + $stats['expiring_soon'] = $expiringResult['count'] ?? 0; + return $stats; } diff --git a/app/Views/dashboard/index.php b/app/Views/dashboard/index.php index cced667..a1f5ed5 100644 --- a/app/Views/dashboard/index.php +++ b/app/Views/dashboard/index.php @@ -39,8 +39,8 @@ ob_start();
Expiring Soon
-= $globalStats['expiring_soon'] ?? 0 ?>
-within = $globalStats['expiring_threshold'] ?? 30 ?> days
+= $stats['expiring_soon'] ?? 0 ?>
+within = $stats['expiring_threshold'] ?? 30 ?> days
No domains expiring soon
-within = $globalStats['expiring_threshold'] ?? 30 ?> days
+within = $stats['expiring_threshold'] ?? 30 ?> days