- Update the copyright notices to use the correct year and not a non-ASCII symbol
[bugdar.git] / includes / class_message_reporter.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2004-2008 Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 class MessageReporter
23 {
24 /**
25 * Phrase array; null by default
26 * @var array
27 * @access private
28 */
29 var $errors = array();
30
31 /**
32 * The processed text for a compound error
33 * @var string
34 * @access private
35 */
36 var $errorBox = '';
37
38 // ###################################################################
39 /**
40 * Adds an error to the cumulative error list
41 *
42 * @access public
43 *
44 * @param string Error message
45 */
46 function addError($message)
47 {
48 $this->errors[] = $message;
49 }
50
51 // ###################################################################
52 /**
53 * Returns TRUE if there are any errors from addError(), and FALSE if
54 * there are not. This also processes all the errors into a message
55 * block that can then be used in error()
56 *
57 * @return bool Whether there are any errors present
58 */
59 function hasErrors()
60 {
61 if (sizeof($this->errors) < 1)
62 {
63 return false;
64 }
65
66 $this->errorBox = "\n\n<ol style=\"list-style-type: decimal\">";
67 foreach ($this->errors AS $err)
68 {
69 $this->errorBox .= "\n\t<li>" . $err . "</li>";
70 }
71 $this->errorBox .= "\n</ol>";
72
73 return true;
74 }
75
76 // ###################################################################
77 /**
78 * Throws an actual error. If an error text is passed, it takes
79 * precedence over any processed list errors
80 *
81 * @param string Error text
82 */
83 function error($error = null)
84 {
85 if ($error == null)
86 {
87 $error = $this->errorBox;
88 }
89
90 $tpl = new BSTemplate('std_error');
91 $tpl->vars = array('error' => $error);
92 $tpl->evaluate()->flush();
93 exit;
94 }
95
96 // ###################################################################
97 /**
98 * Throws a common no-permission error
99 */
100 function errorPermission()
101 {
102 $this->error(T('You do not have permission to access this page. If you think that this is an error, please contact an administrator.'));
103 }
104
105 // ###################################################################
106 /**
107 * Performs a front-end redirect by either header or <meta>
108 *
109 * @param string Redirect message text
110 * @param string URL to take the user
111 */
112 function redirect($message, $url)
113 {
114 if (bugdar::$options['redirectheaders'])
115 {
116 header("Location: $url");
117 exit;
118 }
119
120 $tpl = new BSTemplate('std_redirect');
121 $tpl->vars = array(
122 'message' => $message,
123 'url' => $url
124 );
125 $tpl->evaluate()->flush();
126 exit;
127 }
128
129 // ###################################################################
130 /**
131 * Displays a fatal warning/notice that is usually not an error
132 *
133 * @param string Warning text
134 */
135 function message($message)
136 {
137 $tpl = new BSTemplate('std_message');
138 $tpl->vars = array(
139 'message' => $message
140 );
141 $tpl->evaluate()->flush();
142 exit;
143 }
144
145 // ###################################################################
146 /**
147 * Displays a standard message template with extra confirm data on it
148 *
149 * @access public
150 *
151 * @param string Message to confirm to
152 * @param string Form action
153 * @param string Do branch
154 * @param string Button text
155 * @param string Cancel action
156 * @param array Extra hidden information
157 */
158 function confirm($message, $action, $do, $button, $cancel, $arrextra)
159 {
160 global $show;
161
162 $show['confirm'] = true;
163
164 foreach ($arrextra as $name => $value)
165 {
166 $extra .= '<input type="hidden" name="' . $name . '" value="' . $value . '" />' . "\n";
167 }
168
169 $tpl = new BSTemplate('std_message');
170 $tpl->vars = array(
171 'message' => $message,
172 'action' => $action,
173 'do' => $do,
174 'button' => $button,
175 'cancel' => $cancel,
176 'extra' => $extra
177 );
178 $tpl->evaluate()->flush();
179 exit;
180 }
181 }
182
183 ?>