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