da058baef71f0cf554517f3424b39ef32eaea42d
[ssproject1617.git] / testcms-final-anon / system / classes / notifications.php
1 <?php defined('IN_CMS') or die('No direct access allowed.');
2
3 /*
4 Handle error, notice and success messages in the admin
5 */
6 class Notifications {
7
8 public static function set($type, $message) {
9 $data = Session::get('notifications', array());
10
11 if(!isset($data[$type])) {
12 $data[$type] = array();
13 }
14
15 if(!is_array($message)) {
16 $message = array($message);
17 }
18
19 $data[$type] = array_merge($data[$type], $message);
20
21 Session::set('notifications', $data);
22 }
23
24 public static function read() {
25 $data = Session::get('notifications', array());
26 $html = '';
27
28 foreach($data as $type => $messages) {
29 $html .= '<p class="notification ' . $type . '">' . implode('<br>', $messages) . '</p>';
30 }
31
32 Session::forget('notifications');
33
34 return $html;
35 }
36
37 }