application not appname
[isso.git] / printer.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Iris Studios Shared Object Framework [#]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 /**
23 * Printer
24 * printer.php
25 *
26 * @package ISSO
27 */
28
29 /**
30 * Printer
31 *
32 * This framework generates standard HTML through various functions. The purpose
33 * is generally so that things like the admin system can be created without templates.
34 *
35 * @author Iris Studios, Inc.
36 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
37 * @version $Revision$
38 * @package ISSO
39 *
40 */
41 class Printer
42 {
43 /**
44 * Framework registry object
45 * @var object
46 */
47 var $registry = null;
48
49 /**
50 * Realm that we are operating in (displayed in the <title>)
51 * @var string
52 */
53 var $realm = '[UNDEFINED REALM]';
54
55 /**
56 * Constructor
57 */
58 function Printer(&$registry)
59 {
60 $this->registry =& $registry;
61 }
62
63 /**
64 * Creates a redirect to another page; constructs the header and footer (therefore execution stops)
65 *
66 * @param string Location to redirect to
67 * @param integer Time to wait before the redirect
68 */
69 function redirect($location, $timeout = 10)
70 {
71 $timeout = $timeout * 200;
72
73 $js =
74 <<<EOD
75 <script type="text/javascript">
76 <!--
77 var timeout = $timeout;
78
79 if (timeout > 0)
80 {
81 setTimeout("redirect()", $timeout);
82 }
83 else
84 {
85 redirect();
86 }
87
88 function redirect()
89 {
90 window.location = "$location";
91 }
92 -->
93 </script>
94 EOD;
95
96 $this->page_start($this->registry->modules['localize']->string('Redirect'), ':default:', 15, $js);
97
98 $this->page_message($this->registry->modules['localize']->string('Redirect'), sprintf($this->registry->modules['localize']->string('Please wait to be redirected. If you are not redirected in a few seconds, click <a href="%1$s">here</a>.'), $location));
99
100 $this->page_end();
101 }
102
103 /**
104 * Throws a fatal error; constructs the header and footer
105 *
106 * @param string Error messsage text
107 */
108 function error($message)
109 {
110 $this->page_start($this->registry->modules['localize']->string('Error'));
111 $this->page_message($this->registry->modules['localize']->string('Error'), $message);
112 $this->page_end();
113
114 exit;
115 }
116
117 // ###################################################################
118 /**
119 * Outputs the header of the page: doctype, <html>, <head>, <title>, <body>
120 * and imbeds the style information
121 *
122 * @param string Title of the page
123 * @param string Class of the page to be applied to the body
124 * @param integer Margin of the <div> that all content is placed in
125 * @param string Extra HTML to imbed in the <head> tag
126 * @param string <body> onLoad action to imbed
127 * @param integer Margin of the actual <body > tag
128 * @param string Relative path where the CSS data is stored
129 * @param bool Will force re-print the header if it has already been printed
130 */
131 function page_start($actiontitle, $pageclass = ':default:', $pagemargin = 15, $extra = '', $onload = false, $margin = 0, $dotpath = '.', $override = false)
132 {
133 if (constant('DONE_HEADER') AND !$override)
134 {
135 return;
136 }
137
138 $title = sprintf($this->registry->modules['localize']->string('%1$s - %2$s - %3$s'), $this->registry->application, $this->realm, $actiontitle);
139
140 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
141 echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>";
142 echo "\n\t<title>$title</title>";
143 echo "\n\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />";
144 echo "\n\t<link rel=\"stylesheet\" href=\"$dotpath/admin.css\" />" . (($extra) ? "\n$extra" : '');
145 echo "\n</head>\n<body style=\"margin: {$margin}px;\"" . (($pageclass !== ':default:') ? " class=\"$pageclass\"" : '') . (($onload) ? " onload=\"$onload\"" : '') . ">\n";
146
147 if (!defined('HIDE_SETUP') AND function_exists('_printer_page_start'))
148 {
149 _printer_page_start();
150 }
151
152 echo "<div style=\"margin: {$pagemargin}px;\">\n<!-- / page head -->\n\n";
153
154 if (!defined('DONE_HEADER'))
155 {
156 define('DONE_HEADER', 1);
157 }
158 }
159
160 /**
161 * Places raw HTML code directly into the documet at the current position
162 *
163 * @param string HTML code
164 */
165 function page_code($code)
166 {
167 echo "\n\n$code\n\n";
168 }
169
170 /**
171 * A block function that produces a table with a message in it. This does not print the header and footer
172 *
173 * @param string The title of the message (appears at the top of the block)
174 * @param string Content of the message
175 */
176 function page_message($title, $message)
177 {
178 $this->table_start(true, '75%');
179 $this->table_head($title, 1);
180 $this->row_span("<blockquote>$message</blockquote>", ':swap:', 'left', 1);
181 $this->table_end();
182 }
183
184 /**
185 * Produces an entire page layout that asks the user whether or not they want to perform X action and provides
186 * a link to the YES action
187 *
188 * @param string Message that asks if they want to do X
189 * @param string Location to go for YES
190 */
191 function page_confirm($message, $location)
192 {
193 $this->page_start($this->registry->modules['localize']->string('Confirm'));
194
195 $this->page_message($this->registry->modules['localize']->string('Confirm'), $message . '<p><input type="button" name="confirm" value=" ' . $this->registry->modules['localize']->string('Yes') . ' " onclick="window.location = \'' . $location . '\';" />');
196
197 $this->page_end();
198 }
199
200 /**
201 * Closes the HTML document structure an adds the copyright; this also stops execution of the page
202 */
203 function page_end()
204 {
205 $copyright = "\n<br />\n<p align=\"center\" class=\"copyright\">\n\t<a href=\"http://www.iris-studios.com\" target=\"_blank\">" . $this->registry->application . ' ' . $this->registry->appversion . ", &copy; 2002 - " . date('Y') . " Iris Studios, Inc.</a>\n</p>";
206
207 if (!defined('HIDE_SETUP'))
208 {
209 echo "\n<!-- page end -->\n</div>\n$copyright";
210 }
211 else
212 {
213 echo "\n<!-- page end -->\n</div>";
214 }
215
216 echo "\n\n</body>\n</html>";
217
218 exit;
219 }
220
221 // ###################################################################
222 /**
223 * Opens a <table> tag with styling
224 *
225 * @param bool Whether to add a <br /> before the table
226 * @param string Value of the width attribute
227 */
228 function table_start($break = true, $width = '90%')
229 {
230 if ($break)
231 {
232 echo '<br />';
233 }
234
235 echo "\n<table cellpadding=\"4\" cellspacing=\"0\" border=\"0\" align=\"center\" width=\"$width\" class=\"tborder\">\n";
236 }
237
238 /**
239 * Adds a table row that is sued to head the entire table
240 *
241 * @param string Title string
242 * @param integer Colspan attribute value
243 * @param bool Whether to bold the title
244 */
245 function table_head($title, $colspan = 2, $strong = true)
246 {
247 echo "<tr>\n\t<td class=\"tcat\" align=\"center\" colspan=\"$colspan\">" . (($strong) ? "<strong>$title</strong>" : $title) . "</td>\n</tr>\n";
248 }
249
250 /**
251 * Creates column headings; useful for a grid-style page. This uses a different styling than table_head()
252 * and is usually used directly after a table header
253 *
254 * @param array Array of titles to print
255 */
256 function table_column_head($columnarray)
257 {
258 if (is_array($columnarray))
259 {
260 $render = "<tr valign=\"top\" align=\"center\">\n";
261
262 foreach ($columnarray AS $header)
263 {
264 $render .= "\t<td class=\"thead\" align=\"center\">$header</td>\n";
265 }
266
267 $render .= "</tr>\n";
268
269 echo $render;
270 }
271 }
272
273 /**
274 * Closes a <table> tag
275 */
276 function table_end()
277 {
278 echo "\n</table>\n";
279 }
280
281 // ###################################################################
282 /**
283 * Starts a <form> tag and adds the DO hidden input field
284 *
285 * @param string Action/name of the file to action to
286 * @param string Value of the DO parameter; used to do-branch
287 * @param bool Enctype attribute; used for mime/multi-part
288 * @param string Name of the form; this only matters for DOM access
289 * @param string Method to action as; POST or GET (default is POST)
290 */
291 function form_start($action, $do, $enctype = false, $name = 'inputform', $submitmethod = 'post')
292 {
293 echo "\n<!-- input form -->\n<form name=\"$name\" action=\"$action\"" . (($enctype) ? " enctype=\"$enctype\"" : '') . " method=\"$submitmethod\">\n";
294 $this->form_hidden_field('do', $do);
295 }
296
297 /**
298 * Adds a hidden field at the current location
299 *
300 * @param string Name of the field
301 * @param string Value of the field
302 */
303 function form_hidden_field($name, $value)
304 {
305 echo "<input type=\"hidden\" name=\"$name\" value=\"$value\" />\n";
306 }
307
308 /**
309 * Closes a <form> tag
310 */
311 function form_end()
312 {
313 echo "</form>\n<!-- / input form -->\n";
314 }
315
316 // ###################################################################
317 /**
318 * Creates a table row that spans an entire row; this is used to divide sections, usually
319 *
320 * @param string Text to place in the row
321 * @param string Class name to style with; by default it alternates between alt1 and alt2 (use :swap: to do that)
322 * @param string Alignment of the text in the row
323 * @param integer Colspan attribute
324 */
325 function row_span($text, $class = ':swap:', $align = 'left', $colspan = 2)
326 {
327 if ($class === ':swap:')
328 {
329 $this->registry->modules['functions']->exec_swap_bg();
330 $row_class = $this->registry->modules['functions']->bgcolour;
331 $is_style_element = false;
332 }
333 else
334 {
335 if (preg_match('#:style:(.*?)#i', $class))
336 {
337 $is_style_element = true;
338 $style = str_replace(':style:', '', $class);
339 }
340 else
341 {
342 $row_class = $class;
343 $is_style_element = false;
344 }
345 }
346
347 echo "<tr>\n\t<td ". (($is_style_element) ? "style=\"$style\"" : "class=\"$row_class\"") . " colspan=\"$colspan\" align=\"$align\">$text</td>\n</tr>";
348 }
349
350 /**
351 * Creates a table row that has more than two columns; this is used in conjunction with table_column_head()
352 * usually; it takes an array of values
353 *
354 * @param array Array of values in form value => alignment key (c for center, l for left, and r for right)
355 */
356 function row_multi_item($row_array)
357 {
358 $this->registry->modules['functions']->exec_swap_bg();
359
360 foreach ($row_array AS $item => $align)
361 {
362 $row_data["$align"][] = $item;
363 }
364
365 echo "<tr valign=\"top\">";
366
367 foreach ($row_data AS $align_key => $item_array)
368 {
369 if ($align_key == 'c')
370 {
371 $align = 'center';
372 }
373 else if ($align_key == 'l')
374 {
375 $align = 'left';
376 }
377 else if ($align_key == 'r')
378 {
379 $align = 'right';
380 }
381
382 foreach ($item_array AS $value)
383 {
384 echo "\n\t<td class=\"{$this->registry->modules['functions']->bgcolour}\" align=\"$align\">$value</td>";
385 }
386 }
387
388 echo "\n</tr>\n";
389 }
390
391 /**
392 * Generic row creation function that has two columns: label and value; this is used for many
393 * other form functions, but can also be used for non-editable fields
394 *
395 * @param string Label text
396 * @param string HTML or text to place in the value column
397 * @param string Vertical align (valign attribute) for the row
398 * @param integer Colspan attribute
399 * @param string Class to style the row with; default is to alternate
400 */
401 function row_text($label, $value = '&nbsp;', $valign = 'top', $colspan = 2, $class = -1)
402 {
403 global $IS_SETTINGS;
404
405 if ($class == -1)
406 {
407 if (!$IS_SETTINGS)
408 {
409 $this->registry->modules['functions']->exec_swap_bg();
410 $row_class = $this->registry->modules['functions']->bgcolour;
411 }
412 else
413 {
414 $row_class = 'alt2';
415 }
416 }
417 else
418 {
419 $row_class = $class;
420 }
421
422 echo "<tr valign=\"$valign\">";
423 echo "\n\t<td class=\"$row_class\">$label</td>";
424 echo "\n\t<td class=\"$row_class\">$value</td>";
425
426 if ($colspan > 2)
427 {
428 echo "\n\t<td class=\"$row_class\" colspan=\"" . $colspan - 2 . "\">&nbsp;</td>";
429 }
430
431 echo "\n</tr>\n";
432 }
433
434 /**
435 * Creates a table row with an <input> text field as the value column
436 *
437 * @param string Label text
438 * @param string Name of the <input> field
439 * @param string Value of the field
440 * @param integer Colspan attribute
441 * @param integer Size of the <input> field
442 * @param integer Length attribute; use FALSE for no length to be specified
443 * @param bool Whether to make this a password field
444 * @param string Vertical align (valign attribute)
445 */
446 function row_input($label, $name, $value = '', $colspan = 2, $size = 35, $length = false, $password = false, $lalign = 'top')
447 {
448 $this->row_text($label, "<input type=\"" . (($password) ? 'password' : 'text') . "\" class=\"input\" name=\"$name\" value=\"$value\" size=\"$size\" " . (($length) ? "maxlength=\"$length\" " : '') . "/>", $lalign, $colspan);
449 }
450
451 /**
452 * Creates a table row with a <textarea> as the value column
453 *
454 * @param string Label text
455 * @param string Name of the <textarea>
456 * @param string Value of the <textarea>
457 * @param integer Colspan attribute
458 * @param integer Number of rows in the <textarea>
459 * @param integer Number of colums in the <textarea>
460 * @param bool Whether or not to use monospacing font
461 * @param string Extra style attributes to apply to the <textarea>
462 */
463 function row_textarea($label, $name, $value = '', $colspan = 2, $rows = 7, $cols = 50, $code = false, $style = '')
464 {
465 $this->row_text($label, "<textarea name=\"$name\" class=\"" . (($code) ? 'code' : 'input') . "\" rows=\"$rows\" cols=\"$cols\"" . (($style) ? ' style="' . $style . '"' : '') . ">$value</textarea>", 'top', $colspan);
466 }
467
468 /**
469 * Creates a table row with the tfoot class
470 *
471 * @param string Extra text or HTML to insert into the row
472 * @param integer Colspan attribute
473 */
474 function row_tfoot($data, $colspan = 2)
475 {
476 echo $this->row_span($data, 'tfoot', 'center');
477 }
478
479 /**
480 * Creates a tfoot table row with submit buttons
481 *
482 * @param string Extra HTML to imbed in the row after the buttons
483 * @param string Submit button text (by default it uses pre-translated "Submit" from :save:)
484 * @param string Reset button text (default it uses pre-translated "Reset" from :reset:)
485 * @param integer Colspan attribute
486 */
487 function row_submit($extra = false, $submit = ':save:', $reset = ':reset:', $colspan = 2)
488 {
489 if ($submit === ':save:')
490 {
491 $submit = " " . $this->registry->modules['localize']->string('Submit') . " ";
492 }
493 else
494 {
495 $submit = " $submit ";
496 }
497
498 if ($reset === ':reset:')
499 {
500 $reset = " " . $this->registry->modules['localize']->string('Reset') . " ";
501 }
502 else
503 {
504 $reset = (($reset) ? " $reset " : '');
505 }
506
507 $output = "\n\t\t<input type=\"submit\" class=\"button\" value=\"$submit\" accesskey=\"s\" />";
508 $output .= (($reset) ? "\n\t\t<input type=\"reset\" class=\"button\" value=\"$reset\" accesskey=\"r\" /> $extra\n\t" : '');
509 $this->row_tfoot($output);
510 }
511
512 /**
513 * Creates an upload row; you need to specify some other paramaters in form_start() for this to work
514 *
515 * @param string Label text
516 * @param string Upload name
517 * @param integer Colspan attribute
518 */
519 function row_upload($label, $name, $colspan = 2)
520 {
521 $this->row_text($label, "<input type=\"file\" class=\"button\" name=\"$name\" size=\"35\" />", 'top', $colspan);
522 }
523
524 /**
525 * Adds a name-value pair to an array that is constructed into a <select> list
526 *
527 * @param string Text displayed for the option
528 * @param string Value of the option
529 * @param bool Whether or not to select this particluar option
530 */
531 function list_item($name, $value, $selected = false)
532 {
533 global $listitem;
534
535 $listitem[] = "\n\t<option value=\"$value\"" . (($selected == true) ? ' selected="selected"' : '') . ">$name</option>";
536 }
537
538 /**
539 * Assembles a <select> table row from list_item() items
540 *
541 * @param string Label text
542 * @param string Name of the <select>
543 * @param bool Automatically submit the form on a change?
544 * @param integer Colspan attribute
545 */
546 function row_list($label, $name, $is_jump = false, $colspan = 2)
547 {
548 global $listitem;
549
550 foreach ($listitem AS $option)
551 {
552 $optionlist .= $option;
553 }
554
555 $listitem = '';
556
557 $this->row_text($label, "\n<select class=\"button\" name=\"$name\"" . (($is_jump) ? " onchange=\"this.form.submit();\"" : '') . ">$optionlist\n</select>" . (($is_jump) ? "\n<input type=\"submit\" class=\"button\" value=\" " . $this->registry->modules['localize']->string('Go') . " \" accesskey=\"g\" />" : '') . "\n", $colspan);
558 }
559
560 /**
561 * Creates a row with two radio buttons: yes and now
562 *
563 * @param string Label text
564 * @param string Name of the BOOL flag
565 * @param bool TRUE to select the YES by default; FALSE for NO
566 * @param integer Colspan attribute
567 */
568 function row_yesno($label, $name, $value, $colspan = 2)
569 {
570 $this->row_text($label, "<input type=\"radio\" name=\"$name\" value=\"1\"" . (($value) ? ' checked="checked"' : '') . " /> " . $this->registry->modules['localize']->string('Yes') . " <input type=\"radio\" name=\"$name\" value=\"0\"" . ((!$value) ? ' checked="checked"' : '') . " /> " . $this->registry->modules['localize']->string('No'), $colspan);
571 }
572 }
573
574 /*=====================================================================*\
575 || ###################################################################
576 || # $HeadURL$
577 || # $Id$
578 || ###################################################################
579 \*=====================================================================*/
580 ?>