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