36766-vm/notifications.php
Flatlogic Bot 6c14b2436f 2.0
2025-12-18 09:40:37 +00:00

47 lines
1.7 KiB
PHP

<?php
require_once __DIR__ . '/includes/header.php';
require_once __DIR__ . '/db/config.php';
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
$user_id = $_SESSION['user_id'];
$pdo = db();
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['mark_all_read'])) {
$stmt = $pdo->prepare("UPDATE notifications SET is_read = 1 WHERE user_id = ?");
$stmt->execute([$user_id]);
header('Location: notifications.php');
exit;
}
$stmt = $pdo->prepare("SELECT * FROM notifications WHERE user_id = ? ORDER BY created_at DESC");
$stmt->execute([$user_id]);
$notifications = $stmt->fetchAll();
?>
<div class="container">
<h1 class="mt-5">Notifications</h1>
<form method="POST" class="mb-3">
<button type="submit" name="mark_all_read" class="btn btn-primary">Mark all as read</button>
</form>
<ul class="list-group">
<?php foreach ($notifications as $notification): ?>
<li class="list-group-item <?php echo $notification['is_read'] ? '' : 'list-group-item-secondary'; ?>">
<a href="service_request_details.php?id=<?php echo $notification['service_request_id']; ?>" class="text-decoration-none text-dark">
<p class="mb-1"><?php echo htmlspecialchars($notification['message']); ?></p>
<small class="text-muted"><?php echo date('F j, Y, g:i a', strtotime($notification['created_at'])); ?></small>
</a>
</li>
<?php endforeach; ?>
<?php if (empty($notifications)): ?>
<li class="list-group-item">You have no notifications.</li>
<?php endif; ?>
</ul>
</div>
<?php require_once __DIR__ . '/includes/footer.php'; ?>