Fix DB_MySQL_PDO::escape_binary().
[bugdar.git] / includes / class_message_reporter.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2002-2007 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 global $bugsys;
86 global $doctype, $header, $headinclude, $footer, $focus, $show, $stylevar;
87
88 if ($error == null)
89 {
90 $error = $this->errorBox;
91 }
92
93 eval('$bugsys->template->flush("' . $bugsys->template->fetch('std_error') . '");');
94 exit;
95 }
96
97 // ###################################################################
98 /**
99 * Throws a common no-permission error
100 */
101 function errorPermission()
102 {
103 $this->error(T('You do not have permission to access this page. If you think that this is an error, please contact an administrator.'));
104 }
105
106 // ###################################################################
107 /**
108 * Performs a front-end redirect by either header or <meta>
109 *
110 * @param string Redirect message text
111 * @param string URL to take the user
112 */
113 function redirect($message, $url)
114 {
115 global $bugsys;
116 global $doctype, $header, $headinclude, $footer, $focus, $show, $stylevar;
117
118 if ($bugsys->options['redirectheaders'])
119 {
120 header("Location: $url");
121 exit;
122 }
123
124 eval('$bugsys->template->flush("' . $bugsys->template->fetch('std_redirect') . '");');
125 exit;
126 }
127
128 // ###################################################################
129 /**
130 * Displays a fatal warning/notice that is usually not an error
131 *
132 * @param string Warning text
133 */
134 function message($message)
135 {
136 global $bugsys;
137 global $doctype, $header, $headinclude, $footer, $focus, $show, $stylevar;
138
139 eval('$bugsys->template->flush("' . $bugsys->template->fetch('std_message') . '");');
140 exit;
141 }
142
143 // ###################################################################
144 /**
145 * Displays a standard message template with extra confirm data on it
146 *
147 * @access public
148 *
149 * @param string Message to confirm to
150 * @param string Form action
151 * @param string Do branch
152 * @param string Button text
153 * @param string Cancel action
154 * @param array Extra hidden information
155 */
156 function confirm($message, $action, $do, $button, $cancel, $arrextra)
157 {
158 global $bugsys;
159 global $doctype, $header, $headinclude, $footer, $focus, $show, $stylevar;
160
161 $show['confirm'] = true;
162
163 foreach ($arrextra AS $name => $value)
164 {
165 $extra .= '<input type="hidden" name="' . $name . '" value="' . $value . '" />' . "\n";
166 }
167
168 eval('$bugsys->template->flush("' . $bugsys->template->fetch('std_message') . '");');
169 exit;
170 }
171 }
172