-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotifications.php
More file actions
61 lines (59 loc) · 2.07 KB
/
notifications.php
File metadata and controls
61 lines (59 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
require_once 'database/function.php';
session_start();
if (!isset($_SESSION['user'])) {
header('Location: connexion.php');
exit();
}
$user = $_SESSION['user'];
$notifications = [];
//marquer les notifications comme lues apres consultation
if (isset($_GET['mark_as_read']) && isset($_GET['notif_id'])) {
global $pdo;
$stmt = $pdo->prepare("UPDATE notifications SET lu = 1 WHERE id = ? AND id_utilisateur = ?");
$stmt->execute([$_GET['notif_id'], $user['id']]);
header('Location: notifications.php');
exit();
}
// Récupérer les notifications de l'utilisateur
if (isset($user['id'])) {
global $pdo;
$stmt = $pdo->prepare("SELECT * FROM notifications WHERE id_utilisateur = ? ORDER BY date_creation DESC");
$stmt->execute([$user['id']]);
$notifications = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
include "components/header.php";
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Tableau de bord</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.6/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="d-flex flex-column min-vh-100">
<div class="container mt-4">
<h2>Notifications</h2>
<?php if (empty($notifications)): ?>
<div class="alert alert-info">Aucune notification.</div>
<?php else: ?>
<ul class="list-group">
<?php foreach ($notifications as $notif): ?>
<li class="list-group-item d-flex justify-content-between align-items-center<?php if (!$notif['lu']) echo ' list-group-item-primary fw-bold'; ?>">
<div>
<span><?= htmlspecialchars($notif['message']) ?></span><br>
<small class="text-muted"><?= date('d/m/Y H:i', strtotime($notif['date_creation'])) ?></small>
</div>
<?php if (!$notif['lu']): ?>
<a href="?mark_as_read=1¬if_id=<?= $notif['id'] ?>" class="btn btn-sm btn-outline-success ms-2">Marquer comme lue</a>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
<div class="mt-auto">
<?php include "components/footer.php"; ?>
</div>
</body>
</html>