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