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