r765: Say hello to the GPL
[bugdar.git] / includes / class_message_reporter.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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 * Throws a fatal user-end error message
50 *
51 * @param string The text of a message
52 */
53 function error($text = '')
54 {
55 global $bugsys;
56 global $doctype, $header, $headinclude, $footer, $focus, $show, $stylevar;
57
58 if (count($this->items) > 0 AND empty($this->process))
59 {
60 trigger_error('Message_Reporter->items is an array so please use Message_Reporter->error_list_process() to prepare it', E_USER_ERROR);
61 }
62
63 $this->process = ($text ? $text : $this->process);
64
65 $this->check_process();
66
67 eval('$bugsys->template->flush("' . $bugsys->template->fetch('std_error') . '");');
68 exit;
69 }
70
71 /**
72 * Converts the phrase array into a list for use in error()
73 */
74 function error_list_process()
75 {
76 if (!is_array($this->items) OR count($this->items) < 1)
77 {
78 return;
79 }
80
81 $this->process = "\n\n<ol style=\"list-style-type: decimal\">";
82 foreach ($this->items AS $phrase)
83 {
84 $this->process .= "\n\t<li>" . $phrase . "</li>";
85 }
86 $this->process .= "\n</ol>";
87 }
88
89 /**
90 * Throws a common no-permission error
91 */
92 function error_permission()
93 {
94 global $bugsys;
95
96 $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.'));
97 }
98
99 /**
100 * Performs a front-end redirect by either header or <meta>
101 *
102 * @param string Redirect message text
103 * @param string URL to take the user
104 */
105 function redirect($text = '', $url = '')
106 {
107 global $bugsys;
108 global $doctype, $header, $headinclude, $footer, $focus, $show, $stylevar;
109
110 $this->process = ($text ? $text : $this->process);
111 $this->url = ($url ? $url : $this->url);
112
113 $this->check_process();
114
115 eval('$bugsys->template->flush("' . $bugsys->template->fetch('std_redirect') . '");');
116
117 if ($this->useheaders)
118 {
119 header("Location: {$this->url}");
120 }
121
122 exit;
123 }
124
125 /**
126 * Displays a fatal warning/notice that is usually not an error
127 *
128 * @param string Warning text
129 */
130 function message($text = '')
131 {
132 global $bugsys;
133 global $doctype, $header, $headinclude, $footer, $focus, $show, $stylevar;
134
135 $this->process = ($text ? $text : $this->process);
136
137 $this->check_process();
138
139 eval('$bugsys->template->flush("' . $bugsys->template->fetch('std_message') . '");');
140 exit;
141 }
142
143 /**
144 * Checks to make sure that there is some text in the processed variable
145 */
146 function check_process()
147 {
148 if (empty($this->process))
149 {
150 trigger_error('Message_Reporter requires some text to display a message', E_USER_ERROR);
151 }
152 }
153 }
154
155 /*=====================================================================*\
156 || ###################################################################
157 || # $HeadURL$
158 || # $Id$
159 || ###################################################################
160 \*=====================================================================*/
161 ?>