1: <?php
2: /**
3: * Copyright 2011-2014 Horde LLC (http://www.horde.org/)
4: *
5: * See the enclosed file COPYING for license information (GPL). If you
6: * did not receive this file, see http://www.horde.org/licenses/gpl.
7: *
8: * @category Horde
9: * @copyright 2011-2014 Horde LLC
10: * @license http://www.horde.org/licenses/gpl GPL
11: * @package IMP
12: */
13:
14: /**
15: * Provides the object that contains the status data to output when viewing
16: * MIME parts in IMP.
17: *
18: * @author Michael Slusarz <slusarz@horde.org>
19: * @category Horde
20: * @copyright 2011-2014 Horde LLC
21: * @license http://www.horde.org/licenses/gpl GPL
22: * @package IMP
23: */
24: class IMP_Mime_Status
25: {
26: /* Action constants. */
27: const ERROR = 1;
28: const SUCCESS = 2;
29: const WARNING = 3;
30:
31: /**
32: * Views to display this status in.
33: *
34: * @var array
35: */
36: public $views = array(
37: Horde_Registry::VIEW_BASIC,
38: Horde_Registry::VIEW_DYNAMIC,
39: Horde_Registry::VIEW_MINIMAL
40: );
41:
42: /**
43: * DOM ID to use for the status block.
44: *
45: * @var string
46: */
47: protected $_domid;
48:
49: /**
50: * Icon image HTML.
51: *
52: * @var string
53: */
54: protected $_icon;
55:
56: /**
57: * List of text to output. Each entry will be output on a newline.
58: *
59: * @var array
60: */
61: protected $_text = array();
62:
63: /**
64: * Constructor.
65: *
66: * @param mixed $text See addText().
67: */
68: public function __construct($text = null)
69: {
70: if (!is_null($text)) {
71: $this->addText($text);
72: }
73: }
74:
75: /**
76: * Pre-defined actions.
77: *
78: * @param integer $type The action type.
79: */
80: public function action($type)
81: {
82: switch ($type) {
83: case self::ERROR:
84: $this->icon('alerts/error.png', _("Error"));
85: break;
86:
87: case self::SUCCESS:
88: $this->icon('alerts/success.png', _("Success"));
89: break;
90:
91: case self::WARNING:
92: $this->icon('alerts/warning.png', _("Warning"));
93: break;
94: }
95: }
96:
97: /**
98: * Adds text line(s) to the output.
99: *
100: * @param mixed $text Either a line of text or an array of lines to add.
101: */
102: public function addText($text)
103: {
104: if (!is_array($text)) {
105: $text = array($text);
106: }
107:
108: $this->_text = array_merge($this->_text, $text);
109: }
110:
111: /**
112: * Set the icon to use for the status block (Default: no icon).
113: *
114: * @param string $img The image file.
115: * @param string $alt ALT text to use.
116: */
117: public function icon($img, $alt = null)
118: {
119: $this->_icon = Horde_Themes_Image::tag($img, array('alt' => $alt));
120: }
121:
122: /**
123: * Set a DOM ID for the status block.
124: *
125: * @param string $id The DOM ID to use.
126: */
127: public function domid($id = null)
128: {
129: $this->_domid = $id;
130: }
131:
132: /**
133: * Output status block HTML.
134: *
135: * @return string The formatted status message HTML.
136: */
137: public function __toString()
138: {
139: global $registry;
140:
141: $out = '';
142:
143: switch ($registry->getView()) {
144: case $registry::VIEW_SMARTMOBILE:
145: foreach ($this->_text as $val) {
146: $out .= '<div>' . $val . '</div>';
147: }
148: break;
149:
150: default:
151: $out = '<div><table class="mimeStatusMessageTable"' .
152: (isset($this->_domid) ? (' id="' . $this->_domid . '" ') : '')
153: . '>';
154:
155: /* If no image, simply print out the message. */
156: if (empty($this->_icon)) {
157: foreach ($this->_text as $val) {
158: $out .= '<tr><td>' . $val . '</td></tr>';
159: }
160: } else {
161: $out .= '<tr><td class="mimeStatusIcon">' . $this->_icon . '</td><td><table>';
162: foreach ($this->_text as $val) {
163: $out .= '<tr><td>' . $val . '</td></tr>';
164: }
165: $out .= '</table></td></tr>';
166: }
167:
168: $out .= '</table></div>';
169: break;
170: }
171:
172: return '<div class="mimeStatusMessage">' . $out . '</div>';
173: }
174:
175: }
176: