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