add cms, add todo
[ssproject1617.git] / testcms-final-anon / system / classes / notifications.php
diff --git a/testcms-final-anon/system/classes/notifications.php b/testcms-final-anon/system/classes/notifications.php
new file mode 100644 (file)
index 0000000..da058ba
--- /dev/null
@@ -0,0 +1,37 @@
+<?php defined('IN_CMS') or die('No direct access allowed.');\r
+\r
+/*\r
+       Handle error, notice and success messages in the admin\r
+*/\r
+class Notifications {\r
+\r
+       public static function set($type, $message) {\r
+               $data = Session::get('notifications', array());\r
+               \r
+               if(!isset($data[$type])) {\r
+                       $data[$type] = array();\r
+               }\r
+               \r
+               if(!is_array($message)) {\r
+                       $message = array($message);\r
+               }\r
+               \r
+               $data[$type] = array_merge($data[$type], $message);\r
+               \r
+               Session::set('notifications', $data);\r
+       }\r
+\r
+       public static function read() {\r
+               $data = Session::get('notifications', array());\r
+               $html = '';\r
+               \r
+               foreach($data as $type => $messages) {\r
+                       $html .= '<p class="notification ' . $type . '">' . implode('<br>', $messages) . '</p>';\r
+               }\r
+               \r
+               Session::forget('notifications');\r
+               \r
+               return $html;\r
+       }\r
+\r
+}\r