prepare("SELECT id_account FROM account WHERE id_account = ?"); $stmt_check_user->execute([$_SESSION['user_id']]); if (!$stmt_check_user->fetch()) { session_destroy(); header("Location: login.php"); exit; } $id_account = isset($_SESSION['id_account']) ? (int) $_SESSION['id_account'] : (isset($_SESSION['user_id']) ? (int)$_SESSION['user_id'] : 1); try { $sidebarHistoryCount = $pdo->query("SELECT COUNT(*) FROM history WHERE is_read = 0 AND is_deleted = 0")->fetchColumn(); } catch (Exception $e) { $sidebarHistoryCount = 0; } try { $sidebarNotifCount = $pdo->query("SELECT COUNT(*) FROM notifications WHERE is_deleted = 0 AND is_read = 0")->fetchColumn(); } catch (Exception $e) { $sidebarNotifCount = 0; } try { $stmtChatCount = $pdo->prepare(" SELECT COUNT(c.id_chat) FROM chats c INNER JOIN occupant o ON c.id_occupant = o.id_occupant WHERE c.id_account = ? AND c.sender = 'occupant' AND c.is_read = 0 "); $stmtChatCount->execute([$id_account]); $sidebarChatCount = $stmtChatCount->fetchColumn(); } catch (Exception $e) { $sidebarChatCount = 0; } ?>