37 lines
1.3 KiB
PHP
37 lines
1.3 KiB
PHP
|
|
<?php
|
|
if($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['mark_read'])) {
|
|
$stmt = $pdo->prepare("UPDATE notifications SET is_read = 1 WHERE user_id = ?");
|
|
$stmt->execute([$user_id]);
|
|
header("Location: ?action=notifications");
|
|
exit;
|
|
}
|
|
|
|
$stmt = $pdo->prepare("SELECT * FROM notifications WHERE user_id = ? ORDER BY created_at DESC");
|
|
$stmt->execute([$user_id]);
|
|
$notifications = $stmt->fetchAll();
|
|
?>
|
|
<div class="header">
|
|
<h1>Notifications</h1>
|
|
<?php if($unread_notifications > 0): ?>
|
|
<form method="POST">
|
|
<button type="submit" name="mark_read" class="btn">Mark All as Read</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<?php if(!$notifications): ?>
|
|
<p>No notifications yet.</p>
|
|
<?php else: ?>
|
|
<ul style="list-style:none;">
|
|
<?php foreach($notifications as $n): ?>
|
|
<li style="padding:1rem; border-bottom:1px solid var(--border); <?= !$n['is_read'] ? 'background:#EEF2FF; font-weight:600;' : '' ?>">
|
|
<?= htmlspecialchars($n['message']) ?>
|
|
<div style="font-size:0.75rem; color:var(--text-light); margin-top:0.25rem;"><?= $n['created_at'] ?></div>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?php endif; ?>
|
|
</div>
|