| 123456789101112131415161718192021222324252627282930 |
- <?php
- class alert
- {
- private static $alerts = [];
- public static function addAlert($type, $message)
- {
- if (!isset($_SESSION['alerts'])) {
- $_SESSION['alerts'] = [];
- }
- $_SESSION['alerts'][] = ['type' => $type, 'message' => $message];
- }
- public static function displayAlerts()
- {
- if (!isset($_SESSION['alerts']) || empty($_SESSION['alerts'])) return;
- echo '<div class="alert-container">';
- foreach ($_SESSION['alerts'] as $alert) {
- $class = 'alert-' . $alert['type'];
- echo '<div class="alert ' . $class . '">' . htmlspecialchars($alert['message']) . '<span class="alert-close">×</span></div>';
- }
- echo '</div>';
- // Vider les alertes après affichage
- unset($_SESSION['alerts']);
- }
- }
|