Spaces:
Configuration error
Configuration error
Download notifications.php from brucelloyd1/lost-found-tracker-pro: direct link, hf CLI and curl.
- Browser
- Download file 5.63 kB
-
https://huggingface.co/spaces/brucelloyd1/lost-found-tracker-pro/resolve/main/notifications.php
- Command line
-
hf download hf://spaces/brucelloyd1/lost-found-tracker-pro/notifications.php
-
curl -L -o notifications.php https://huggingface.co/spaces/brucelloyd1/lost-found-tracker-pro/resolve/main/notifications.php
5.63 kB
| ```php | |
| include 'includes/auth.php'; | |
| redirectIfNotLoggedIn(); | |
| include 'config/database.php'; | |
| $db = new Database(); | |
| $connection = $db->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']; | |
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Notifications - Lost & Found</title> | |
| <link rel="stylesheet" href="style.css"> | |
| </head> | |
| <body> | |
| <header> | |
| <div class="container"> | |
| <nav> | |
| <div class="logo">Lost & Found Pro</div> | |
| <ul class="nav-links"> | |
| <li><a href="home.php">Home</a></li> | |
| <li><a href="items.php">Browse Items</a></li> | |
| <li><a href="dashboard.php">Dashboard</a></li> | |
| <?php if (isAdmin()): ?> | |
| <li><a href="admin.php">Admin</a></li> | |
| <li><a href="verifications.php">Verifications</a></li> | |
| <li><a href="storage.php">Storage</a></li> | |
| <?php endif; ?> | |
| <?php if (isFinder()): ?> | |
| <li><a href="report_item.php">Report Item</a></li> | |
| <?php endif; ?> | |
| <li><a href="notifications.php">Notifications</a></li> | |
| <li><a href="profile.php">Profile</a></li> | |
| <li><a href="logout.php">Logout</a></li> | |
| </ul> | |
| </nav> | |
| </div> | |
| </header> | |
| <main class="container"> | |
| <div class="card"> | |
| <div class="card-header d-flex justify-between align-center"> | |
| <div> | |
| <h1>Notifications</h1> | |
| <p>You have <?php echo $unreadCount; ?> unread notifications</p> | |
| </div> | |
| <?php if ($unreadCount > 0): ?> | |
| <form method="POST"> | |
| <button type="submit" name="mark_read" class="btn btn-primary">Mark All as Read</button> | |
| </form> | |
| <?php endif; ?> | |
| </div> | |
| <?php if (empty($notifications)): ?> | |
| <div class="text-center p-4"> | |
| <p>No notifications yet.</p> | |
| </div> | |
| <?php else: ?> | |
| <div class="notification-list"> | |
| <?php foreach ($notifications as $notification): ?> | |
| <div class="p-3 border-bottom <?php echo $notification['readFlag'] ? '' : 'bg-blue-50'; ?>"> | |
| <div class="d-flex justify-between align-center"> | |
| <div> | |
| <p class="<?php echo $notification['readFlag'] ? '' : 'font-semibold'; ?>"> | |
| <?php echo $notification['message']; ?> | |
| </p> | |
| <small class="text-gray-600"> | |
| <?php echo date('M j, Y g:i A', strtotime($notification['createdAt'])); ?> | |
| <?php if (isAdmin() && isset($notification['userName'])): ?> | |
| - For: <?php echo $notification['userName']; ?> | |
| <?php endif; ?> | |
| </small> | |
| </div> | |
| <?php if (!$notification['readFlag']): ?> | |
| <span class="badge badge-primary">New</span> | |
| <?php endif; ?> | |
| </div> | |
| </div> | |
| <?php endforeach; ?> | |
| </div> | |
| <?php endif; ?> | |
| </div> | |
| </main> | |
| <footer> | |
| <div class="container"> | |
| <div class="footer-content"> | |
| <div class="logo">Lost & Found Pro</div> | |
| <p>© 2024 Lost & Found Management System. All rights reserved.</p> | |
| </div> | |
| </div> | |
| </footer> | |
| </body> | |
| </html> | |
| ``` |