1: <?php
2:
3: /**
4: * This file contains the notification GUI class.
5: *
6: * @package Core
7: * @subpackage GUI
8: * @version SVN Revision $Rev:$
9: *
10: * @author Timo Hummel
11: * @copyright four for business AG <www.4fb.de>
12: * @license http://www.contenido.org/license/LIZENZ.txt
13: * @link http://www.4fb.de
14: * @link http://www.contenido.org
15: */
16:
17: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
18:
19: /**
20: * Class for displaying notifications.
21: *
22: * Usage:
23: * <code>
24: * // render a error directly
25: * $oNotification = new cGuiNotification();
26: * $oNotification->displayNotification(
27: * cGuiNotification::LEVEL_ERROR, 'Foobar does not exists'
28: * );
29: *
30: * // assign a notification to a variable
31: * $oNotification = new cGuiNotification();
32: * $sNotification = $oNotification->displayNotification(
33: * cGuiNotification::LEVEL_NOTIFICATION, 'Hey dude, you did it!'
34: * );
35: * </code>
36: *
37: * @package Core
38: * @subpackage GUI
39: */
40: class cGuiNotification {
41:
42: /**
43: * Error message level
44: * @var string
45: */
46: const LEVEL_ERROR = 'error';
47:
48: /**
49: * Warning message level
50: * @var string
51: */
52: const LEVEL_WARNING = 'warning';
53:
54: /**
55: * Info message level
56: * @var string
57: */
58: const LEVEL_INFO = 'info';
59:
60: /**
61: * Ok message level
62: * @var string
63: */
64: const LEVEL_OK = 'ok';
65:
66: /**
67: * Notification message level
68: * @var string
69: */
70: const LEVEL_NOTIFICATION = 'notification';
71:
72: /**
73: * HTML path to images
74: * @var string
75: */
76: protected $_sPathImages;
77:
78: /**
79: * Constructor
80: */
81: public function __construct() {
82: global $cfg;
83: $this->_sPathImages = cRegistry::getBackendUrl() . $cfg['path']['images'];
84: }
85:
86: /**
87: * Generates message box and returns it back.
88: *
89: * @param string $sLevel
90: * Message level, one of cGuiNotification::LEVEL_* constants
91: * @param string $sMessage
92: * The message to display
93: * @param int $iStyle [optional]
94: * Flag tp use styles for display or not (feasible 1 or 0)
95: * @return string
96: */
97: public function returnMessageBox($sLevel, $sMessage, $iStyle = 1) {
98: switch ($sLevel) {
99: case self::LEVEL_ERROR:
100: $sHead = i18n('Error');
101: $sHeadClass = 'alertbox_error';
102: break;
103: case self::LEVEL_WARNING:
104: $sHead = i18n('Warning');
105: $sHeadClass = 'alertbox_warning';
106: break;
107: case self::LEVEL_INFO:
108: $sHead = i18n('Info');
109: $sHeadClass = 'alertbox_info';
110: $sMessage = '<span>' . $sMessage . '</span>';
111: break;
112: case self::LEVEL_OK:
113: $sHead = i18n('Ok');
114: $sHeadClass = 'alertbox_ok';
115: $sMessage = '<span>' . $sMessage . '</span>';
116: break;
117: default:
118: $sHead = i18n('Notification');
119: $sHeadClass = 'alertbox_notification';
120: $sMessage = '<span>' . $sMessage . '</span>';
121: break;
122: }
123:
124: if ($iStyle == 1) {
125: // Box on login page
126: $sMessageBox =
127: '<div class="alertbox ' . $sHeadClass . '_color" id="contenido_notification">' .
128: '<h1 class="alertbox_head ' . $sHeadClass . '">' . $sHead . '</h1>' .
129: '<div class="alertbox_message">' . $sMessage . '</div>' .
130: '</div>';
131: } else {
132: // Simple box
133: $sMessageBox =
134: '<div class="alertbox_line ' . $sHeadClass . '_color" id="contenido_notification">' .
135: '<h1 class=" alertbox_head ' . $sHeadClass . ' ' . $sHeadClass . '_color">' . $sHead . '</h1>' .
136: '<div class="alertbox_message ' . $sHeadClass . '_color">' . $sMessage . '</div>' .
137: '</div>';
138: }
139: return $sMessageBox;
140: }
141:
142: /**
143: * Generates message box and returns it back, uses markup with table.
144: *
145: * @param string $sLevel
146: * Message level, one of cGuiNotification::LEVEL_* constants
147: * @param string $sMessage
148: * The message to display
149: * @return string
150: */
151: public function returnNotification($sLevel, $sMessage) {
152:
153: $oNotifySpan = new cHTMLSpan($sMessage);
154:
155: switch ($sLevel) {
156: case self::LEVEL_ERROR:
157: $oNotifySpan->setClass('notify_general notify_error');
158: break;
159: case self::LEVEL_WARNING:
160: $oNotifySpan->setClass('notify_general notify_warning');
161: break;
162: case self::LEVEL_INFO:
163: $oNotifySpan->setClass('notify_general notify_info');
164: break;
165: case self::LEVEL_OK:
166: $oNotifySpan->setClass('notify_general notify_ok');
167: break;
168: default:
169: $oNotifySpan->setClass('notify_general notify_default');
170: break;
171: }
172:
173: $sNoti = '<div id="contenido_notification">';
174: $sNoti .= $oNotifySpan->toHTML();
175: $sNoti .= '</div>';
176:
177: return $sNoti;
178: }
179:
180: /**
181: * Displays small message box directly.
182: *
183: * @param string $sLevel
184: * Message level, one of cGuiNotification::LEVEL_* constants
185: * @param string $sMessage
186: * The message to display
187: */
188: public function displayNotification($sLevel, $sMessage) {
189: echo $this->returnNotification($sLevel, $sMessage) . '<br>';
190: }
191:
192: /**
193: * Displays large message box directly.
194: *
195: * @param string $sLevel
196: * Message level, one of cGuiNotification::LEVEL_* constants
197: * @param string $sMessage
198: * The message to display
199: * @param int $iStyle [optional]
200: * Flag tp use styles for display or not (feasible 1 or 0)
201: */
202: public function displayMessageBox($sLevel, $sMessage, $iStyle = 1) {
203: echo $this->returnMessageBox($sLevel, $sMessage, $iStyle) . '<br>';
204: }
205:
206: }
207: