Notifications
You have unread notifications
No notifications yet.
- For:
```php getConnection(); $userId = isAdmin() ? null : $_SESSION['user_id']; // Get notifications if (isAdmin()) { $query = "SELECT n.*, u.name as userName FROM notifications n LEFT JOIN users u ON n.userId = u.userId ORDER BY n.createdAt DESC"; $stmt = $connection->prepare($query); } else { $query = "SELECT * FROM notifications WHERE userId = :userId ORDER BY createdAt DESC"; $stmt = $connection->prepare($query); $stmt->bindParam(':userId', $userId); } $stmt->execute(); $notifications = $stmt->fetchAll(PDO::FETCH_ASSOC); // Mark notifications as read if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['mark_read'])) { if (isAdmin()) { $updateQuery = "UPDATE notifications SET readFlag = 1"; $updateStmt = $connection->prepare($updateQuery); } else { $updateQuery = "UPDATE notifications SET readFlag = 1 WHERE userId = :userId"; $updateStmt = $connection->prepare($updateQuery); $updateStmt->bindParam(':userId', $userId); } $updateStmt->execute(); header("Location: notifications.php"); exit(); } // Get unread count if (isAdmin()) { $countQuery = "SELECT COUNT(*) as count FROM notifications WHERE readFlag = 0"; $countStmt = $connection->prepare($countQuery); } else { $countQuery = "SELECT COUNT(*) as count FROM notifications WHERE userId = :userId AND readFlag = 0"; $countStmt = $connection->prepare($countQuery); $countStmt->bindParam(':userId', $userId); } $countStmt->execute(); $unreadCount = $countStmt->fetch(PDO::FETCH_ASSOC)['count']; ?>
You have unread notifications
No notifications yet.
- For: