Removing the PHP4 constructors
[isso.git] / printer.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework [#]issoversion[#]
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 /**
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 * Constants:
36 * ISSO_PRINTER_DONE_HEADER - An internal constant that is used to check to see
37 * if the page header has already been printed
38 * ISSO_PRINTER_HIDE_SETUP - Will stop the page footer data (copyright and debug
39 * box) from being printed
40 * ISSO_PRINTER_NO_NAVIGATION - Do not show the navigation frame from ISSO.Printer.Navigation
41 *
42 * Hooks:
43 * $this->page_start_hook - Define function to echo() data after the page header
44 * has been outputted
45 *
46 * @author Blue Static
47 * @copyright Copyright ©2002 - [#]year[#], Blue Static
48 * @version $Revision$
49 * @package ISSO
50 *
51 */
52 class Printer
53 {
54 /**
55 * Framework registry object
56 * @var object
57 */
58 private $registry = null;
59
60 /**
61 * Realm that we are operating in (displayed in the <title>)
62 * @var string
63 */
64 private $realm = '[UNDEFINED REALM]';
65
66 /**
67 * CSS to place in the page
68 * @var string
69 */
70 private $css = '';
71
72 /**
73 * Extra code to place
74 * @var sring
75 */
76 private $code = '';
77
78 /**
79 * Page-start hooko
80 * @var string
81 */
82 private $page_start_hook = ':=NO METHOD=:';
83
84 /**
85 * Fields array that is used in this module
86 * @var array
87 */
88 private $fields = array(
89 'realm' => array(REQ_YES, null, false),
90 'page_start_hook' => array(REQ_NO, null, false)
91 );
92
93 // ###################################################################
94 /**
95 * Constructor
96 */
97 function __construct(&$registry)
98 {
99 $this->registry =& $registry;
100 }
101
102 // ###################################################################
103 /**
104 * Sets an ISSO field
105 *
106 * @access public
107 *
108 * @param string Field name
109 * @param mixed Value of the field
110 */
111 function set($name, $value)
112 {
113 $this->registry->do_set($name, $value, 'printer');
114 }
115
116 // ###################################################################
117 /**
118 * Gets an ISSO field
119 *
120 * @access public
121 *
122 * @param string Field name
123 *
124 * @return mixed Value of the field
125 */
126 function get($fieldname)
127 {
128 return $this->registry->do_get($fieldname, 'printer');
129 }
130
131 // ###################################################################
132 /**
133 * Creates a redirect to another page; constructs the header and footer
134 * (therefore execution stops)
135 *
136 * @access public
137 *
138 * @param string Location to redirect to
139 * @param string Redirect message to be shown
140 * @param array An aray of POST variables to send through on the redirect
141 */
142 function redirect($location, $message = null, $postvars = array())
143 {
144 $timeout = 10 * 200;
145
146 if ($postvars)
147 {
148 $js = <<<JS
149 <script type="text/javascript">
150 <!--
151 var timeout = $timeout;
152
153 if (timeout > 0)
154 {
155 setTimeout("redirect()", $timeout);
156 }
157 else
158 {
159 redirect();
160 }
161
162 function redirect()
163 {
164 document.forms.postvars.submit();
165 }
166
167 //-->
168 </script>
169 JS;
170 }
171 else
172 {
173 $js = <<<JS
174 <script type="text/javascript">
175 <!--
176 var timeout = $timeout;
177
178 if (timeout > 0)
179 {
180 setTimeout("redirect()", $timeout);
181 }
182 else
183 {
184 redirect();
185 }
186
187 function redirect()
188 {
189 window.location = "$location";
190 }
191 //-->
192 </script>
193 JS;
194 }
195
196 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
197 {
198 define('ISSO_PRINTER_NO_NAVIGATION', 1);
199 }
200
201 $this->page_start($this->registry->modules['localize']->string('Redirect'));
202
203 if ($postvars)
204 {
205 $this->form_start($location, null, false, 'postvars');
206
207 foreach ($postvars AS $key => $value)
208 {
209 $this->form_hidden_field($key, $value);
210 }
211
212 $this->form_end();
213 }
214
215 $redir = 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);
216 $override = false;
217 if ($message == null)
218 {
219 $showmessage = $redir;
220 }
221 else
222 {
223 $showmessage = '<blockquote>' . $message . '</blockquote>';
224 $showmessage .= "\n<p>" . $redir . "</p>";
225 $override = true;
226 }
227
228 $this->page_message($this->registry->modules['localize']->string('Redirect'), $showmessage, $override);
229
230 $this->page_code($js);
231
232 $this->page_end();
233 }
234
235 // ###################################################################
236 /**
237 * Throws a fatal error; constructs the header and footer
238 *
239 * @access public
240 *
241 * @param string Error messsage text
242 */
243 function error($message)
244 {
245 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
246 {
247 define('ISSO_PRINTER_NO_NAVIGATION', 1);
248 }
249
250 $this->page_start($this->registry->modules['localize']->string('Error'));
251 $this->page_message($this->registry->modules['localize']->string('Error'), $message);
252 $this->page_end();
253
254 exit;
255 }
256
257 // ###################################################################
258 /**
259 * Outputs the header of the page: doctype, <html>, <head>, <title>,
260 * <body> and imbeds the style information
261 *
262 * @access public
263 *
264 * @param string Title of the page
265 * @param string Class of the page to be applied to the body
266 * @param integer Margin of the <div> that all content is placed in
267 * @param string Extra HTML to imbed in the <head> tag
268 * @param string <body> onLoad action to imbed
269 * @param integer Margin of the actual <body > tag
270 * @param string Relative path where the CSS data is stored
271 * @param bool Will force re-print the header if it has already been printed
272 */
273 function page_start($actiontitle, $pageclass = ':default:', $pagemargin = 15, $extra = '', $onload = false, $margin = 0, $dotpath = '.', $override = false)
274 {
275 $this->registry->check_isso_fields(get_class($this));
276
277 if ($this->registry->debug AND isset($_GET['query']))
278 {
279 ob_start();
280 }
281
282 if (defined('ISSO_PRINTER_DONE_HEADER') AND !$override)
283 {
284 if (constant('ISSO_PRINTER_DONE_HEADER') AND !$override)
285 {
286 return;
287 }
288 }
289
290 $title = sprintf($this->registry->modules['localize']->string('%1$s - %2$s - %3$s'), $this->registry->application, $this->realm, $actiontitle);
291
292 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
293 echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>";
294 echo "\n\t<title>$title</title>";
295 echo "\n\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
296 echo $this->css;
297 echo $this->code;
298 echo ($extra ? "\n$extra" : '');
299 echo "\n</head>\n<body style=\"margin: {$margin}px;\"" . (($pageclass !== ':default:') ? " class=\"$pageclass\"" : '') . (($onload) ? " onload=\"$onload\"" : '') . ">\n";
300
301 if (is_callable($this->page_start_hook))
302 {
303 call_user_func($this->page_start_hook);
304 }
305
306 echo "<div style=\"margin: {$pagemargin}px;\">\n<!-- / page head -->\n\n";
307
308 if ($this->registry->is_loaded('printer_navigation') AND (!defined('ISSO_PRINTER_NO_NAVIGATION') OR (defined('ISSO_PRINTER_NO_NAVIGATION') AND constant('ISSO_PRINTER_NO_NAVIGATION') != true)))
309 {
310 echo $this->registry->modules['printer_navigation']->generate_header_html();
311 }
312
313 if (!defined('ISSO_PRINTER_DONE_HEADER'))
314 {
315 define('ISSO_PRINTER_DONE_HEADER', 1);
316 }
317 }
318
319 // ###################################################################
320 /**
321 * Links CSS to the page from a given relative path
322 *
323 * @access public
324 *
325 * @param string Relative path to the CSS file
326 */
327 function css_link($path)
328 {
329 $this->css .= "\n\t<link rel=\"stylesheet\" href=\"$path\" />";
330 }
331
332 // ###################################################################
333 /**
334 * Imbeds actual CSS information into the page in <style> tags
335 *
336 * @access public
337 *
338 * @param string Path of the CSS file to be imbeded
339 */
340 function css_imbed($path)
341 {
342 $data = require_once($path);
343 $css = preg_replace('#/\*(.*?)\*/(\r|\n)*#s', '', $css);
344 $css = trim($css);
345 $this->css .= "\n\t<style type=\"text/css\">\n\t<!--\n" . $css . "\n\t//-->\n\t</style>";
346 }
347
348 // ###################################################################
349 /**
350 * Places raw HTML code directly into the documet at the current
351 * position
352 *
353 * @access public
354 *
355 * @param string HTML code
356 */
357 function page_code($code)
358 {
359 if (defined('ISSO_PRINTER_DONE_HEADER'))
360 {
361 echo "\n\n$code\n\n";
362 }
363 else
364 {
365 $this->code .= "\n\n$code\n\n";
366 }
367 }
368
369 // ###################################################################
370 /**
371 * A block function that produces a table with a message in it. This
372 * does not print the header and footer.
373 *
374 * @access public
375 *
376 * @param string The title of the message (appears at the top of the block)
377 * @param string Content of the message
378 * @param bool Override the message: control the entire output (no <blockquote>)?
379 */
380 function page_message($title, $message, $overridemessage = false)
381 {
382 $this->table_start(true, '75%');
383 $this->table_head($title, 1);
384 $this->row_span(($overridemessage ? $message : "<blockquote>$message</blockquote>"), ':swap:', 'left', 1);
385 $this->table_end();
386 }
387
388 // ###################################################################
389 /**
390 * Produces an entire page layout that asks the user whether or not
391 * they want to perform X action and provides a link to the YES and NO
392 * action
393 *
394 * @access public
395 *
396 * @param string Message that asks if they want to do X
397 * @param string Location to go for YES
398 * @param string DO action to pass
399 * @param array Hidden parameters to pass to the next page
400 */
401 function page_confirm($message, $location, $action, $params)
402 {
403 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
404 {
405 define('ISSO_PRINTER_NO_NAVIGATION', 1);
406 }
407
408 $this->page_start($this->registry->modules['localize']->string('Confirm'));
409
410 $this->form_start($location, $action);
411 foreach ($params AS $key => $value)
412 {
413 $this->form_hidden_field($key, $value);
414 }
415
416 $this->table_start(true, '75%');
417 $this->table_head($this->registry->modules['localize']->string('Confirm'), 1);
418 $this->row_span("<blockquote>$message</blockquote>", ':swap:', 'left', 1);
419 $this->row_submit('<input type="button" class="button" name="no" value=" ' . $this->registry->modules['localize']->string('No') . ' " onclick="history.back(1); return false;" />', $this->registry->modules['localize']->string('Yes'), '');
420 $this->table_end();
421
422 $this->form_end();
423
424 $this->page_end();
425 }
426
427 // ###################################################################
428 /**
429 * Closes the HTML document structure an adds the copyright; this also
430 * stops execution of the page
431 *
432 * @access public
433 */
434 function page_end()
435 {
436 if ($this->registry->debug AND isset($_GET['query']))
437 {
438 ob_clean();
439 ob_end_clean();
440
441 if (is_array($this->registry->modules[ISSO_DB_LAYER]->history))
442 {
443 foreach ($this->registry->modules[ISSO_DB_LAYER]->history AS $query)
444 {
445 echo $this->registry->modules[ISSO_DB_LAYER]->construct_query_debug($query);
446 }
447 }
448 exit;
449 }
450
451 if ($this->registry->is_loaded('printer_navigation') AND (!defined('ISSO_PRINTER_NO_NAVIGATION') OR (defined('ISSO_PRINTER_NO_NAVIGATION') AND constant('ISSO_PRINTER_NO_NAVIGATION') != true)))
452 {
453 echo $this->registry->modules['printer_navigation']->generate_footer_html();
454 }
455
456 $copyright = "\n<br />\n<p align=\"center\" class=\"copyright\">\n\t<a href=\"http://www.bluestatic.org\" target=\"_blank\">" . $this->registry->get('application') . ' ' . $this->registry->get('appversion') . ", &copy;2002 - " . date('Y') . " Blue Static</a>\n</p>";
457
458 if (!defined('ISSO_PRINTER_HIDE_SETUP'))
459 {
460 echo "\n<!-- page end -->\n</div>\n$copyright";
461 echo $this->registry->construct_debug_block(false);
462 }
463 else
464 {
465 echo "\n<!-- page end -->\n</div>";
466 }
467
468 echo "\n\n</body>\n</html>";
469
470 exit;
471 }
472
473 // -------------------------------------------------------------------
474
475 // ###################################################################
476 /**
477 * Opens a <table> tag with styling
478 *
479 * @access public
480 *
481 * @param bool Whether to add a <br /> before the table
482 * @param string Value of the width attribute
483 */
484 function table_start($break = true, $width = '90%')
485 {
486 if ($break)
487 {
488 echo '<br />';
489 }
490
491 echo "\n<table cellpadding=\"4\" cellspacing=\"1\" border=\"0\" align=\"center\" width=\"$width\" class=\"tborder\">\n";
492 }
493
494 // ###################################################################
495 /**
496 * Adds a table row that is sued to head the entire table
497 *
498 * @access public
499 *
500 * @param string Title string
501 * @param integer Colspan attribute value
502 * @param bool Whether to bold the title
503 */
504 function table_head($title, $colspan = 2, $strong = true)
505 {
506 echo "<tr>\n\t<td class=\"tcat\" align=\"center\" colspan=\"$colspan\">" . (($strong) ? "<strong>$title</strong>" : $title) . "</td>\n</tr>\n";
507 }
508
509 // ###################################################################
510 /**
511 * Creates column headings; useful for a grid-style page. This uses a
512 * different styling than table_head() and is usually used directly
513 * after a table header.
514 *
515 * @access public
516 *
517 * @param array Array of titles to print
518 */
519 function table_column_head($columnarray)
520 {
521 if (is_array($columnarray))
522 {
523 $render = "<tr valign=\"top\" align=\"center\">\n";
524
525 foreach ($columnarray AS $header)
526 {
527 $render .= "\t<td class=\"thead\" align=\"center\">$header</td>\n";
528 }
529
530 $render .= "</tr>\n";
531
532 echo $render;
533 }
534 }
535
536 // ###################################################################
537 /**
538 * Closes a <table> tag
539 *
540 * @access public
541 */
542 function table_end()
543 {
544 echo "\n</table>\n";
545 }
546
547 // -------------------------------------------------------------------
548
549 // ###################################################################
550 /**
551 * Starts a <form> tag and adds the DO hidden input field
552 *
553 * @access public
554 *
555 * @param string Action/name of the file to action to
556 * @param string Value of the DO parameter; used to do-branch
557 * @param bool Enctype attribute; used for mime/multi-part
558 * @param string Name of the form; this only matters for DOM access
559 * @param string Method to action as; POST or GET (default is POST)
560 */
561 function form_start($action, $do, $enctype = false, $name = 'inputform', $submitmethod = 'post')
562 {
563 echo "\n<!-- input form -->\n<form name=\"$name\" action=\"$action\"" . (($enctype) ? " enctype=\"$enctype\"" : '') . " method=\"$submitmethod\">\n";
564
565 if ($do !== null)
566 {
567 $this->form_hidden_field('do', $do);
568 }
569 }
570
571 // ###################################################################
572 /**
573 * Adds a hidden field at the current location
574 *
575 * @access public
576 *
577 * @param string Name of the field
578 * @param string Value of the field
579 */
580 function form_hidden_field($name, $value)
581 {
582 echo "<input type=\"hidden\" name=\"$name\" value=\"$value\" />\n";
583 }
584
585 // ###################################################################
586 /**
587 * Closes a <form> tag
588 *
589 * @access public
590 */
591 function form_end()
592 {
593 echo "</form>\n<!-- / input form -->\n";
594 }
595
596 // -------------------------------------------------------------------
597
598 // ###################################################################
599 /**
600 * Creates a table row that spans an entire row; this is used to divide
601 * sections, usually
602 *
603 * @access public
604 *
605 * @param string Text to place in the row
606 * @param string Class name to style with; by default it alternates between alt1 and alt2 (use :swap: to do that)
607 * @param string Alignment of the text in the row
608 * @param integer Colspan attribute
609 */
610 function row_span($text, $class = ':swap:', $align = 'left', $colspan = 2)
611 {
612 if ($class === ':swap:')
613 {
614 $this->registry->modules['functions']->exec_swap_bg();
615 $row_class = $this->registry->modules['functions']->bgcolour;
616 $is_style_element = false;
617 }
618 else
619 {
620 if (preg_match('#:style:(.*?)#i', $class))
621 {
622 $is_style_element = true;
623 $style = str_replace(':style:', '', $class);
624 }
625 else
626 {
627 $row_class = $class;
628 $is_style_element = false;
629 }
630 }
631
632 echo "\n<tr>\n\t<td ". (($is_style_element) ? "style=\"$style\"" : "class=\"$row_class\"") . " colspan=\"$colspan\" align=\"$align\">$text</td>\n</tr>";
633 }
634
635 // ###################################################################
636 /**
637 * Creates a table row that has more than two columns; this is used in
638 * conjunction with table_column_head() usually; it takes an array of
639 * values
640 *
641 * @access public
642 *
643 * @param array Array of values in form value => alignment key (c for center, l for left, and r for right)
644 */
645 function row_multi_item($row_array)
646 {
647 $this->registry->modules['functions']->exec_swap_bg();
648
649 foreach ($row_array AS $item => $align)
650 {
651 $row_data["$align"][] = $item;
652 }
653
654 echo "<tr valign=\"top\">";
655
656 foreach ($row_data AS $align_key => $item_array)
657 {
658 if ($align_key == 'c')
659 {
660 $align = 'center';
661 }
662 else if ($align_key == 'l')
663 {
664 $align = 'left';
665 }
666 else if ($align_key == 'r')
667 {
668 $align = 'right';
669 }
670
671 foreach ($item_array AS $value)
672 {
673 echo "\n\t<td class=\"{$this->registry->modules['functions']->bgcolour}\" align=\"$align\">$value</td>";
674 }
675 }
676
677 echo "\n</tr>\n";
678 }
679
680 // ###################################################################
681 /**
682 * Generic row creation function that has two columns: label and value;
683 * this is used for many other form functions, but can also be used for
684 * non-editable fields
685 *
686 * @access public
687 *
688 * @param string Label text
689 * @param string HTML or text to place in the value column
690 * @param string Vertical align (valign attribute) for the row
691 * @param integer Colspan attribute
692 * @param string Class to style the row with; default is to alternate
693 */
694 function row_text($label, $value = '&nbsp;', $valign = 'top', $colspan = 2, $class = -1)
695 {
696 global $IS_SETTINGS;
697
698 if ($class == -1)
699 {
700 if (!$IS_SETTINGS)
701 {
702 $this->registry->modules['functions']->exec_swap_bg();
703 $row_class = $this->registry->modules['functions']->bgcolour;
704 }
705 else
706 {
707 $row_class = 'alt2';
708 }
709 }
710 else
711 {
712 $row_class = $class;
713 }
714
715 echo "<tr valign=\"$valign\">";
716 echo "\n\t<td class=\"$row_class\">$label</td>";
717 echo "\n\t<td class=\"$row_class\" colspan=\"" . ($colspan - 1) . "\">$value</td>";
718
719 echo "\n</tr>\n";
720 }
721
722 // ###################################################################
723 /**
724 * Creates a table row with an <input> text field as the value column
725 *
726 * @access public
727 *
728 * @param string Label text
729 * @param string Name of the <input> field
730 * @param string Value of the field
731 * @param integer Colspan attribute
732 * @param integer Size of the <input> field
733 * @param integer Length attribute; use FALSE for no length to be specified
734 * @param bool Whether to make this a password field
735 * @param string Vertical align (valign attribute)
736 */
737 function row_input($label, $name, $value = '', $colspan = 2, $size = 35, $length = false, $password = false, $lalign = 'top')
738 {
739 $this->row_text($label, "<input type=\"" . (($password) ? 'password' : 'text') . "\" class=\"input\" name=\"$name\" value=\"$value\" size=\"$size\" " . (($length) ? "maxlength=\"$length\" " : '') . "/>", $lalign, $colspan);
740 }
741
742 // ###################################################################
743 /**
744 * Creates a table row with a <textarea> as the value column
745 *
746 * @access public
747 *
748 * @param string Label text
749 * @param string Name of the <textarea>
750 * @param string Value of the <textarea>
751 * @param integer Colspan attribute
752 * @param integer Number of rows in the <textarea>
753 * @param integer Number of colums in the <textarea>
754 * @param bool Whether or not to use monospacing font
755 * @param string Extra style attributes to apply to the <textarea>
756 */
757 function row_textarea($label, $name, $value = '', $colspan = 2, $rows = 7, $cols = 50, $code = false, $style = '')
758 {
759 $this->row_text($label, "<textarea name=\"$name\" class=\"" . (($code) ? 'code' : 'input') . "\" rows=\"$rows\" cols=\"$cols\"" . (($style) ? ' style="' . $style . '"' : '') . ">$value</textarea>", 'top', $colspan);
760 }
761
762 // ###################################################################
763 /**
764 * Creates a table row with the tfoot class
765 *
766 * @access public
767 *
768 * @param string Extra text or HTML to insert into the row
769 * @param integer Colspan attribute
770 */
771 function row_tfoot($data, $colspan = 2)
772 {
773 echo $this->row_span($data, 'tfoot', 'center', $colspan);
774 }
775
776 // ###################################################################
777 /**
778 * Creates a tfoot table row with submit buttons
779 *
780 * @access public
781 *
782 * @param string Extra HTML to imbed in the row after the buttons
783 * @param string Submit button text (by default it uses pre-translated "Submit" from :save:)
784 * @param string Reset button text (default it uses pre-translated "Reset" from :reset:)
785 * @param integer Colspan attribute
786 */
787 function row_submit($extra = false, $submit = ':save:', $reset = ':reset:', $colspan = 2)
788 {
789 if ($submit === ':save:')
790 {
791 $submit = " " . $this->registry->modules['localize']->string('Submit') . " ";
792 }
793 else
794 {
795 $submit = " $submit ";
796 }
797
798 if ($reset === ':reset:')
799 {
800 $reset = " " . $this->registry->modules['localize']->string('Reset') . " ";
801 }
802 else
803 {
804 $reset = (($reset) ? " $reset " : '');
805 }
806
807 $output = "\n\t\t<input type=\"submit\" class=\"button\" name=\"__submit__\" value=\"$submit\" accesskey=\"s\" />";
808 $output .= ($reset ? "\n\t\t<input type=\"reset\" class=\"button\" name=\"__reset__\" value=\"$reset\" accesskey=\"r\" />" : '');
809 $output .= ($extra ? "\n\t\t$extra" : '');
810 $output .= "\n\t";
811 $this->row_tfoot($output, $colspan);
812 }
813
814 // ###################################################################
815 /**
816 * Creates an upload row; you need to specify some other paramaters in
817 * form_start() for this to work
818 *
819 * @access public
820 *
821 * @param string Label text
822 * @param string Upload name
823 * @param integer Colspan attribute
824 */
825 function row_upload($label, $name, $colspan = 2)
826 {
827 $this->row_text($label, "<input type=\"file\" class=\"button\" name=\"$name\" size=\"35\" />", 'top', $colspan);
828 }
829
830 // ###################################################################
831 /**
832 * Adds a name-value pair to an array that is constructed into a
833 * <select> list
834 *
835 * @access public
836 *
837 * @param string Text displayed for the option
838 * @param string Value of the option
839 * @param bool Whether or not to select this particluar option
840 */
841 function list_item($name, $value, $selected = false)
842 {
843 global $listitem;
844
845 $listitem["$value"] = array('name' => $name, 'selected' => $selected);
846 }
847
848 // ###################################################################
849 /**
850 * Assembles a <select> table row from list_item() items
851 *
852 * @access public
853 *
854 * @param string Label text
855 * @param string Name of the <select>
856 * @param bool Automatically submit the form on a change?
857 * @param integer Colspan attribute
858 */
859 function row_list($label, $name, $is_jump = false, $colspan = 2)
860 {
861 global $listitem;
862
863 foreach ($listitem AS $value => $option)
864 {
865 $optionlist .= "\n\t<option value=\"$value\"" . ($option['selected'] == true ? ' selected="selected"' : '') . ">$option[name]</option>";
866 }
867
868 $listitem = array();
869
870 $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);
871 }
872
873 // ###################################################################
874 /**
875 * Assembles a list of checkboxes from list_item() items
876 *
877 * @access public
878 *
879 * @param string Label text
880 * @param string Name of the <input>s
881 * @param integer Colspan attribute
882 */
883 function row_checkbox($label, $name, $colspan = 2)
884 {
885 global $listitem;
886
887 foreach ($listitem AS $value => $box)
888 {
889 $optionlist[] = "\n\t<input type=\"checkbox\" class=\"button\" name=\"{$name}[]\" value=\"$value\"" . ($box['selected'] == true ? ' checked="checked"' : '') . " /> $box[name]";
890 }
891
892 $listitem = array();
893
894 $this->row_text($label, "\n" . implode('<br />', $optionlist) . "\n", $colspan);
895 }
896
897 // ###################################################################
898 /**
899 * Creates a row with two radio buttons: yes and now
900 *
901 * @access public
902 *
903 * @param string Label text
904 * @param string Name of the BOOL flag
905 * @param bool TRUE to select the YES by default; FALSE for NO
906 * @param integer Colspan attribute
907 */
908 function row_yesno($label, $name, $value, $colspan = 2)
909 {
910 $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);
911 }
912 }
913
914 /*=====================================================================*\
915 || ###################################################################
916 || # $HeadURL$
917 || # $Id$
918 || ###################################################################
919 \*=====================================================================*/
920 ?>