ISSO is no longer a product regularly released so we'll remove the issoversion tag...
[isso.git] / printer.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
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 /**
23 * Printer
24 * printer.php
25 *
26 * @package ISSO
27 */
28
29 require_once('ISSO/PrinterElement.php');
30 require_once('ISSO/PrinterBaseElement.php');
31 require_once('ISSO/PrinterLabelElement.php');
32 require_once('ISSO/PrinterRootElement.php');
33 require_once('ISSO/PrinterRootElementPage.php');
34 require_once('ISSO/PrinterRootElementTable.php');
35 require_once('ISSO/PrinterRootElementForm.php');
36 require_once('ISSO/PrinterTableElement.php');
37
38 /**
39 * Printer
40 *
41 * This framework generates standard HTML through various functions. The purpose
42 * is generally so that things like the admin system can be created without templates.
43 *
44 * Constants:
45 * ISSO_PRINTER_DONE_HEADER - An internal constant that is used to check to see
46 * if the page header has already been printed
47 * ISSO_PRINTER_HIDE_SETUP - Will stop the page footer data (copyright and debug
48 * box) from being printed
49 * ISSO_PRINTER_NO_NAVIGATION - Do not show the navigation frame from ISSO.Printer.Navigation
50 *
51 * @author Blue Static
52 * @copyright Copyright ©2002 - [#]year[#], Blue Static
53 * @version $Revision$
54 * @package ISSO
55 *
56 */
57 class Printer
58 {
59 * Page-start hooko
60 * @var string
61 */
62 private $page_start_hook = ':=NO METHOD=:';
63
64 // ###################################################################
65 /**
66 * Creates a redirect to another page; constructs the header and footer
67 * (therefore execution stops)
68 *
69 * @param string Location to redirect to
70 * @param string Redirect message to be shown
71 * @param array An aray of POST variables to send through on the redirect
72 */
73 public function redirect($location, $message = null, $postvars = array())
74 {
75 $js = '
76 <script type="text/javascript">
77 <!--
78 var timeout = 2000;
79
80 if (timeout > 0)
81 {
82 setTimeout("redirect()", timeout);
83 }
84 else
85 {
86 redirect();
87 }
88
89 function redirect()
90 {
91 ' . ($postvars ? 'document.forms.postvars.submit();' : 'window.location = "' . $location . '";') . '
92 }
93
94 //-->
95 </script>';
96
97 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
98 {
99 define('ISSO_PRINTER_NO_NAVIGATION', 1);
100 }
101
102 $this->page_start(_('Redirect'));
103
104 if ($postvars)
105 {
106 $this->form_start($location, null, false, 'postvars');
107
108 foreach ($postvars AS $key => $value)
109 {
110 $this->form_hidden_field($key, $value);
111 }
112
113 $this->form_end();
114 }
115
116 $redir = sprintf(_('Please wait to be redirected. If you are not redirected in a few seconds, click <a href="%1$s">here</a>.'), $location);
117 $override = false;
118 if ($message == null)
119 {
120 $showmessage = $redir;
121 }
122 else
123 {
124 $showmessage = '<blockquote>' . $message . '</blockquote>';
125 $showmessage .= "\n<p>" . $redir . "</p>";
126 $override = true;
127 }
128
129 $this->page_message(_('Redirect'), $showmessage, $override);
130
131 $this->page_code($js);
132
133 $this->page_end();
134 }
135
136 // ###################################################################
137 /**
138 * Produces an entire page layout that asks the user whether or not
139 * they want to perform X action and provides a link to the YES and NO
140 * action
141 *
142 * @param string Message that asks if they want to do X
143 * @param string Location to go for YES
144 * @param string DO action to pass
145 * @param array Hidden parameters to pass to the next page
146 */
147 public function confirm($message, $location, $action, $params)
148 {
149 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
150 {
151 define('ISSO_PRINTER_NO_NAVIGATION', 1);
152 }
153
154 $this->page_start(_('Confirm'));
155
156 $this->form_start($location, $action);
157 foreach ($params AS $key => $value)
158 {
159 $this->form_hidden_field($key, $value);
160 }
161
162 $this->table_start(true, '75%');
163 $this->table_head(_('Confirm'), 1);
164 $this->row_span("<blockquote>$message</blockquote>", ':swap:', 'left', 1);
165 $this->row_submit('<input type="button" class="button" name="no" value=" ' . _('No') . ' " onclick="history.back(1); return false;" />', _('Yes'), '');
166 $this->table_end();
167
168 $this->form_end();
169
170 $this->page_end();
171 }
172
173 // ###################################################################
174 /**
175 * Throws a fatal error; constructs the header and footer
176 *
177 * @param string Error messsage text
178 */
179 public function error($message)
180 {
181 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
182 {
183 define('ISSO_PRINTER_NO_NAVIGATION', 1);
184 }
185
186 $this->page_start(_('Error'));
187 $this->page_message(_('Error'), $message);
188 $this->page_end();
189
190 exit;
191 }
192
193 // ###################################################################
194 /**
195 * A block function that produces a table with a message in it. This
196 * does not print the header and footer.
197 *
198 * @param string The title of the message (appears at the top of the block)
199 * @param string Content of the message
200 * @param bool Override the message: control the entire output (no <blockquote>)?
201 */
202 public function page_message($title, $message, $overridemessage = false)
203 {
204 $this->table_start(true, '75%');
205 $this->table_head($title, 1);
206 $this->row_span(($overridemessage ? $message : "<blockquote>$message</blockquote>"), ':swap:', 'left', 1);
207 $this->table_end();
208 }
209
210 // ###################################################################
211 /**
212 * Creates a table row with a <textarea> as the value column
213 *
214 * @param string Label text
215 * @param string Name of the <textarea>
216 * @param string Value of the <textarea>
217 * @param integer Colspan attribute
218 * @param integer Number of rows in the <textarea>
219 * @param integer Number of colums in the <textarea>
220 * @param bool Whether or not to use monospacing font
221 * @param string Extra style attributes to apply to the <textarea>
222 */
223 public function row_textarea($label, $name, $value = '', $colspan = 2, $rows = 7, $cols = 50, $code = false, $style = '')
224 {
225 $this->row_text($label, "<textarea name=\"$name\" class=\"" . ($code ? 'code' : 'input') . "\" rows=\"$rows\" cols=\"$cols\"" . ($style ? ' style="' . $style . '"' : '') . ">$value</textarea>", 'top', $colspan);
226 }
227
228 // ###################################################################
229 /**
230 * Adds a name-value pair to an array that is constructed into a
231 * <select> list
232 *
233 * @param string Text displayed for the option
234 * @param string Value of the option
235 * @param bool Whether or not to select this particluar option
236 */
237 public function list_item($name, $value, $selected = false)
238 {
239 global $listitem;
240
241 $listitem["$value"] = array('name' => $name, 'selected' => $selected);
242 }
243
244 // ###################################################################
245 /**
246 * Assembles a <select> table row from list_item() items
247 *
248 * @param string Label text
249 * @param string Name of the <select>
250 * @param integer Colspan attribute
251 */
252 public function row_list($label, $name, $colspan = 2)
253 {
254 global $listitem;
255
256 foreach ($listitem AS $value => $option)
257 {
258 $optionlist .= "\n\t<option value=\"$value\"" . ($option['selected'] == true ? ' selected="selected"' : '') . ">$option[name]</option>";
259 }
260
261 $listitem = array();
262
263 $this->row_text($label, "\n<select class=\"button\" name=\"$name\">$optionlist\n</select>\n", $colspan);
264 }
265
266 // ###################################################################
267 /**
268 * Assembles a list of checkboxes from list_item() items
269 *
270 * @param string Label text
271 * @param string Name of the <input>s
272 * @param integer Colspan attribute
273 */
274 public function row_checkbox($label, $name, $colspan = 2)
275 {
276 global $listitem;
277
278 foreach ($listitem AS $value => $box)
279 {
280 $optionlist[] = "\n\t<input type=\"checkbox\" class=\"button\" name=\"{$name}[]\" value=\"$value\"" . ($box['selected'] == true ? ' checked="checked"' : '') . " /> $box[name]";
281 }
282
283 $listitem = array();
284
285 $this->row_text($label, "\n" . implode('<br />', $optionlist) . "\n", $colspan);
286 }
287 }
288
289 /*=====================================================================*\
290 || ###################################################################
291 || # $HeadURL$
292 || # $Id$
293 || ###################################################################
294 \*=====================================================================*/
295 ?>