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