r1389: Forgot to add the template diff
[bugdar.git] / includes / class_message_reporter.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] 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 [#]gpl[#] 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 Message_Reporter
23 {
24 /**
25 * The URL used for redirect
26 * @var string
27 */
28 var $url = '';
29
30 /**
31 * Phrase array; null by default
32 * @var array
33 */
34 var $items = null;
35
36 /**
37 * The processed text for a message
38 * @var string
39 */
40 var $process = '';
41
42 // ###################################################################
43 /**
44 * Adds an error to the cumulative error list
45 *
46 * @access public
47 *
48 * @param string Error message
49 */
50 function add_error($message)
51 {
52 $this->items[] = $message;
53 }
54
55 /**
56 * Throws a fatal user-end error message
57 *
58 * @param string The text of a message
59 */
60 function error($text = '')
61 {
62 global $bugsys;
63 global $doctype, $header, $headinclude, $footer, $focus, $show, $stylevar;
64
65 if (sizeof($this->items) > 0 AND empty($this->process))
66 {
67 trigger_error('Message_Reporter->items is an array so please use Message_Reporter->error_list_process() to prepare it', E_USER_ERROR);
68 }
69
70 $this->process = ($text ? $text : $this->process);
71
72 $this->check_process();
73
74 eval('$bugsys->template->flush("' . $bugsys->template->fetch('std_error') . '");');
75 exit;
76 }
77
78 /**
79 * Converts the phrase array into a list for use in error()
80 */
81 function error_list_process()
82 {
83 if (!is_array($this->items) OR sizeof($this->items) < 1)
84 {
85 return;
86 }
87
88 $this->process = "\n\n<ol style=\"list-style-type: decimal\">";
89 foreach ($this->items AS $phrase)
90 {
91 $this->process .= "\n\t<li>" . $phrase . "</li>";
92 }
93 $this->process .= "\n</ol>";
94 }
95
96 /**
97 * Throws a common no-permission error
98 */
99 function error_permission()
100 {
101 global $bugsys;
102
103 $this->error(_('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 * 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($text = '', $url = '')
113 {
114 global $bugsys;
115 global $doctype, $header, $headinclude, $footer, $focus, $show, $stylevar;
116
117 $this->process = ($text ? $text : $this->process);
118 $this->url = ($url ? $url : $this->url);
119
120 if ($bugsys->options['redirectheaders'])
121 {
122 header("Location: $url");
123 exit;
124 }
125
126 $this->check_process();
127
128 eval('$bugsys->template->flush("' . $bugsys->template->fetch('std_redirect') . '");');
129
130 exit;
131 }
132
133 /**
134 * Displays a fatal warning/notice that is usually not an error
135 *
136 * @param string Warning text
137 */
138 function message($text = '')
139 {
140 global $bugsys;
141 global $doctype, $header, $headinclude, $footer, $focus, $show, $stylevar;
142
143 $this->process = ($text ? $text : $this->process);
144
145 $this->check_process();
146
147 eval('$bugsys->template->flush("' . $bugsys->template->fetch('std_message') . '");');
148 exit;
149 }
150
151 // ###################################################################
152 /**
153 * Displays a standard message template with extra confirm data on it
154 *
155 * @access public
156 *
157 * @param string Message to confirm to
158 * @param string Form action
159 * @param string Do branch
160 * @param string Button text
161 * @param string Cancel action
162 * @param array Extra hidden information
163 */
164 function confirm($message, $action, $do, $button, $cancel, $arrextra)
165 {
166 global $bugsys;
167 global $doctype, $header, $headinclude, $footer, $focus, $show, $stylevar;
168
169 $show['confirm'] = true;
170
171 $this->process = $message;
172
173 foreach ($arrextra AS $name => $value)
174 {
175 $extra .= '<input type="hidden" name="' . $name . '" value="' . $value . '" />' . "\n";
176 }
177
178 eval('$bugsys->template->flush("' . $bugsys->template->fetch('std_message') . '");');
179 exit;
180 }
181
182 /**
183 * Checks to make sure that there is some text in the processed variable
184 */
185 function check_process()
186 {
187 if (empty($this->process))
188 {
189 trigger_error('Message_Reporter requires some text to display a message', E_USER_ERROR);
190 }
191 }
192 }
193
194 /*=====================================================================*\
195 || ###################################################################
196 || # $HeadURL$
197 || # $Id$
198 || ###################################################################
199 \*=====================================================================*/
200 ?>