2 /*=====================================================================*\
3 || ###################################################################
4 || # Iris Studios Shared Object Framework [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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.
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
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 \*=====================================================================*/
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.
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
41 * @author Iris Studios, Inc.
42 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
50 * Framework registry object
56 * Realm that we are operating in (displayed in the <title>)
59 var $realm = '[UNDEFINED REALM]';
62 * CSS to place in the page
67 // ###################################################################
71 function __construct(&$registry)
73 $this->registry
=& $registry;
76 // ###################################################################
80 function Printer(&$registry)
82 $this->__construct($registry);
85 // ###################################################################
87 * Creates a redirect to another page; constructs the header and footer
88 * (therefore execution stops)
92 * @param string Location to redirect to
93 * @param integer Time to wait before the redirect
94 * @param array An aray of POST variables to send through on the redirect
96 function redirect($location, $timeout = 10, $postvars = array())
98 $timeout = $timeout * 200;
103 <script type
="text/javascript">
105 var timeout
= $timeout;
109 setTimeout("redirect()", $timeout);
118 document
.forms
.postvars
.submit();
128 <script type
="text/javascript">
130 var timeout
= $timeout;
134 setTimeout("redirect()", $timeout);
143 window
.location
= "$location";
150 $this->page_start($this->registry
->modules
['localize']->string('Redirect'));
154 $this->form_start($location, null
, false
, 'postvars');
156 foreach ($postvars AS $key => $value)
158 $this->form_hidden_field($key, $value);
164 $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));
166 $this->page_code($js);
171 // ###################################################################
173 * Throws a fatal error; constructs the header and footer
177 * @param string Error messsage text
179 function error($message)
181 $this->page_start($this->registry
->modules
['localize']->string('Error'));
182 $this->page_message($this->registry
->modules
['localize']->string('Error'), $message);
188 // ###################################################################
190 * Outputs the header of the page: doctype, <html>, <head>, <title>,
191 * <body> and imbeds the style information
195 * @param string Title of the page
196 * @param string Class of the page to be applied to the body
197 * @param integer Margin of the <div> that all content is placed in
198 * @param string Extra HTML to imbed in the <head> tag
199 * @param string <body> onLoad action to imbed
200 * @param integer Margin of the actual <body > tag
201 * @param string Relative path where the CSS data is stored
202 * @param bool Will force re-print the header if it has already been printed
204 function page_start($actiontitle, $pageclass = ':default:', $pagemargin = 15, $extra = '', $onload = false
, $margin = 0, $dotpath = '.', $override = false
)
206 if ($this->registry
->debug
AND isset($_GET['query']))
211 if (defined('ISSO_PRINTER_DONE_HEADER') AND !$override)
213 if (constant('ISSO_PRINTER_DONE_HEADER') AND !$override)
219 $title = sprintf($this->registry
->modules
['localize']->string('%1$s - %2$s - %3$s'), $this->registry
->application
, $this->realm
, $actiontitle);
221 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
222 echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>";
223 echo "\n\t<title>$title</title>";
224 echo "\n\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
226 echo ($extra ?
"\n$extra" : '');
227 echo "\n</head>\n<body style=\"margin: {$margin}px;\"" . (($pageclass !== ':default:') ?
" class=\"$pageclass\"" : '') . (($onload) ?
" onload=\"$onload\"" : '') . ">\n";
229 if (!defined('ISSO_PRINTER_HIDE_SETUP') AND function_exists('_printer_page_start'))
231 _printer_page_start();
234 echo "<div style=\"margin: {$pagemargin}px;\">\n<!-- / page head -->\n\n";
236 if (!defined('ISSO_PRINTER_DONE_HEADER'))
238 define('ISSO_PRINTER_DONE_HEADER', 1);
242 // ###################################################################
244 * Links CSS to the page from a given relative path
248 * @param string Relative path to the CSS file
250 function css_link($path)
252 $this->css
.= "\n\t<link rel=\"stylesheet\" href=\"$path\" />";
255 // ###################################################################
257 * Imbeds actual CSS information into the page in <style> tags
261 * @param string Path of the CSS file to be imbeded
263 function css_imbed($path)
265 $data = require_once($path);
266 $css = preg_replace('#/\*(.*?)\*/(\r|\n)*#s', '', $css);
268 $this->css
.= "\n\t<style type=\"text/css\">\n\t<!--\n" . $css . "\n\t//-->\n\t</style>";
271 // ###################################################################
273 * Places raw HTML code directly into the documet at the current
278 * @param string HTML code
280 function page_code($code)
282 echo "\n\n$code\n\n";
285 // ###################################################################
287 * A block function that produces a table with a message in it. This
288 * does not print the header and footer.
292 * @param string The title of the message (appears at the top of the block)
293 * @param string Content of the message
295 function page_message($title, $message)
297 $this->table_start(true
, '75%');
298 $this->table_head($title, 1);
299 $this->row_span("<blockquote>$message</blockquote>", ':swap:', 'left', 1);
303 // ###################################################################
305 * Produces an entire page layout that asks the user whether or not
306 * they want to perform X action and provides a link to the YES and NO
311 * @param string Message that asks if they want to do X
312 * @param string Location to go for YES
313 * @param string DO action to pass
314 * @param array Hidden parameters to pass to the next page
316 function page_confirm($message, $location, $action, $params)
318 $this->page_start($this->registry
->modules
['localize']->string('Confirm'));
320 $this->form_start($location, $action);
321 foreach ($params AS $key => $value)
323 $this->form_hidden_field($key, $value);
326 $this->table_start(true
, '75%');
327 $this->table_head($this->registry
->modules
['localize']->string('Confirm'), 1);
328 $this->row_span("<blockquote>$message</blockquote>", ':swap:', 'left', 1);
329 $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'), '');
337 // ###################################################################
339 * Closes the HTML document structure an adds the copyright; this also
340 * stops execution of the page
346 if ($this->registry
->debug
AND isset($_GET['query']))
351 if (is_array($this->registry
->modules
[ISSO_DB_LAYER
]->history
))
354 foreach ($this->registry
->modules
[ISSO_DB_LAYER
]->history
AS $query)
356 echo $query . "\n\n<hr />\n\n";
363 $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
. ", © 2002 - " . date('Y') . " Iris Studios, Inc.</a>\n</p>";
365 if (!defined('ISSO_PRINTER_HIDE_SETUP'))
367 echo "\n<!-- page end -->\n</div>\n$copyright";
368 echo $this->registry
->construct_debug_block(false
);
372 echo "\n<!-- page end -->\n</div>";
375 echo "\n\n</body>\n</html>";
380 // -------------------------------------------------------------------
382 // ###################################################################
384 * Opens a <table> tag with styling
388 * @param bool Whether to add a <br /> before the table
389 * @param string Value of the width attribute
391 function table_start($break = true
, $width = '90%')
398 echo "\n<table cellpadding=\"4\" cellspacing=\"0\" border=\"0\" align=\"center\" width=\"$width\" class=\"tborder\">\n";
401 // ###################################################################
403 * Adds a table row that is sued to head the entire table
407 * @param string Title string
408 * @param integer Colspan attribute value
409 * @param bool Whether to bold the title
411 function table_head($title, $colspan = 2, $strong = true
)
413 echo "<tr>\n\t<td class=\"tcat\" align=\"center\" colspan=\"$colspan\">" . (($strong) ?
"<strong>$title</strong>" : $title) . "</td>\n</tr>\n";
416 // ###################################################################
418 * Creates column headings; useful for a grid-style page. This uses a
419 * different styling than table_head() and is usually used directly
420 * after a table header.
424 * @param array Array of titles to print
426 function table_column_head($columnarray)
428 if (is_array($columnarray))
430 $render = "<tr valign=\"top\" align=\"center\">\n";
432 foreach ($columnarray AS $header)
434 $render .= "\t<td class=\"thead\" align=\"center\">$header</td>\n";
437 $render .= "</tr>\n";
443 // ###################################################################
445 * Closes a <table> tag
454 // -------------------------------------------------------------------
456 // ###################################################################
458 * Starts a <form> tag and adds the DO hidden input field
462 * @param string Action/name of the file to action to
463 * @param string Value of the DO parameter; used to do-branch
464 * @param bool Enctype attribute; used for mime/multi-part
465 * @param string Name of the form; this only matters for DOM access
466 * @param string Method to action as; POST or GET (default is POST)
468 function form_start($action, $do, $enctype = false
, $name = 'inputform', $submitmethod = 'post')
470 echo "\n<!-- input form -->\n<form name=\"$name\" action=\"$action\"" . (($enctype) ?
" enctype=\"$enctype\"" : '') . " method=\"$submitmethod\">\n";
474 $this->form_hidden_field('do', $do);
478 // ###################################################################
480 * Adds a hidden field at the current location
484 * @param string Name of the field
485 * @param string Value of the field
487 function form_hidden_field($name, $value)
489 echo "<input type=\"hidden\" name=\"$name\" value=\"$value\" />\n";
492 // ###################################################################
494 * Closes a <form> tag
500 echo "</form>\n<!-- / input form -->\n";
503 // -------------------------------------------------------------------
505 // ###################################################################
507 * Creates a table row that spans an entire row; this is used to divide
512 * @param string Text to place in the row
513 * @param string Class name to style with; by default it alternates between alt1 and alt2 (use :swap: to do that)
514 * @param string Alignment of the text in the row
515 * @param integer Colspan attribute
517 function row_span($text, $class = ':swap:', $align = 'left', $colspan = 2)
519 if ($class === ':swap:')
521 $this->registry
->modules
['functions']->exec_swap_bg();
522 $row_class = $this->registry
->modules
['functions']->bgcolour
;
523 $is_style_element = false
;
527 if (preg_match('#:style:(.*?)#i', $class))
529 $is_style_element = true
;
530 $style = str_replace(':style:', '', $class);
535 $is_style_element = false
;
539 echo "\n<tr>\n\t<td ". (($is_style_element) ?
"style=\"$style\"" : "class=\"$row_class\"") . " colspan=\"$colspan\" align=\"$align\">$text</td>\n</tr>";
542 // ###################################################################
544 * Creates a table row that has more than two columns; this is used in
545 * conjunction with table_column_head() usually; it takes an array of
550 * @param array Array of values in form value => alignment key (c for center, l for left, and r for right)
552 function row_multi_item($row_array)
554 $this->registry
->modules
['functions']->exec_swap_bg();
556 foreach ($row_array AS $item => $align)
558 $row_data["$align"][] = $item;
561 echo "<tr valign=\"top\">";
563 foreach ($row_data AS $align_key => $item_array)
565 if ($align_key == 'c')
569 else if ($align_key == 'l')
573 else if ($align_key == 'r')
578 foreach ($item_array AS $value)
580 echo "\n\t<td class=\"{$this->registry->modules['functions']->bgcolour}\" align=\"$align\">$value</td>";
587 // ###################################################################
589 * Generic row creation function that has two columns: label and value;
590 * this is used for many other form functions, but can also be used for
591 * non-editable fields
595 * @param string Label text
596 * @param string HTML or text to place in the value column
597 * @param string Vertical align (valign attribute) for the row
598 * @param integer Colspan attribute
599 * @param string Class to style the row with; default is to alternate
601 function row_text($label, $value = ' ', $valign = 'top', $colspan = 2, $class = -1)
609 $this->registry
->modules
['functions']->exec_swap_bg();
610 $row_class = $this->registry
->modules
['functions']->bgcolour
;
622 echo "<tr valign=\"$valign\">";
623 echo "\n\t<td class=\"$row_class\">$label</td>";
624 echo "\n\t<td class=\"$row_class\">$value</td>";
628 echo "\n\t<td class=\"$row_class\" colspan=\"" . $colspan - 2 . "\"> </td>";
634 // ###################################################################
636 * Creates a table row with an <input> text field as the value column
640 * @param string Label text
641 * @param string Name of the <input> field
642 * @param string Value of the field
643 * @param integer Colspan attribute
644 * @param integer Size of the <input> field
645 * @param integer Length attribute; use FALSE for no length to be specified
646 * @param bool Whether to make this a password field
647 * @param string Vertical align (valign attribute)
649 function row_input($label, $name, $value = '', $colspan = 2, $size = 35, $length = false
, $password = false
, $lalign = 'top')
651 $this->row_text($label, "<input type=\"" . (($password) ?
'password' : 'text') . "\" class=\"input\" name=\"$name\" value=\"$value\" size=\"$size\" " . (($length) ?
"maxlength=\"$length\" " : '') . "/>", $lalign, $colspan);
654 // ###################################################################
656 * Creates a table row with a <textarea> as the value column
660 * @param string Label text
661 * @param string Name of the <textarea>
662 * @param string Value of the <textarea>
663 * @param integer Colspan attribute
664 * @param integer Number of rows in the <textarea>
665 * @param integer Number of colums in the <textarea>
666 * @param bool Whether or not to use monospacing font
667 * @param string Extra style attributes to apply to the <textarea>
669 function row_textarea($label, $name, $value = '', $colspan = 2, $rows = 7, $cols = 50, $code = false
, $style = '')
671 $this->row_text($label, "<textarea name=\"$name\" class=\"" . (($code) ?
'code' : 'input') . "\" rows=\"$rows\" cols=\"$cols\"" . (($style) ?
' style="' . $style . '"' : '') . ">$value</textarea>", 'top', $colspan);
674 // ###################################################################
676 * Creates a table row with the tfoot class
680 * @param string Extra text or HTML to insert into the row
681 * @param integer Colspan attribute
683 function row_tfoot($data, $colspan = 2)
685 echo $this->row_span($data, 'tfoot', 'center', $colspan);
688 // ###################################################################
690 * Creates a tfoot table row with submit buttons
694 * @param string Extra HTML to imbed in the row after the buttons
695 * @param string Submit button text (by default it uses pre-translated "Submit" from :save:)
696 * @param string Reset button text (default it uses pre-translated "Reset" from :reset:)
697 * @param integer Colspan attribute
699 function row_submit($extra = false
, $submit = ':save:', $reset = ':reset:', $colspan = 2)
701 if ($submit === ':save:')
703 $submit = " " . $this->registry
->modules
['localize']->string('Submit') . " ";
707 $submit = " $submit ";
710 if ($reset === ':reset:')
712 $reset = " " . $this->registry
->modules
['localize']->string('Reset') . " ";
716 $reset = (($reset) ?
" $reset " : '');
719 $output = "\n\t\t<input type=\"submit\" class=\"button\" name=\"__submit__\" value=\"$submit\" accesskey=\"s\" />";
720 $output .= ($reset ?
"\n\t\t<input type=\"reset\" class=\"button\" name=\"__reset__\" value=\"$reset\" accesskey=\"r\" />" : '');
721 $output .= ($extra ?
"\n\t\t$extra" : '');
723 $this->row_tfoot($output, $colspan);
726 // ###################################################################
728 * Creates an upload row; you need to specify some other paramaters in
729 * form_start() for this to work
733 * @param string Label text
734 * @param string Upload name
735 * @param integer Colspan attribute
737 function row_upload($label, $name, $colspan = 2)
739 $this->row_text($label, "<input type=\"file\" class=\"button\" name=\"$name\" size=\"35\" />", 'top', $colspan);
742 // ###################################################################
744 * Adds a name-value pair to an array that is constructed into a
749 * @param string Text displayed for the option
750 * @param string Value of the option
751 * @param bool Whether or not to select this particluar option
753 function list_item($name, $value, $selected = false
)
757 $listitem[] = "\n\t<option value=\"$value\"" . (($selected == true
) ?
' selected="selected"' : '') . ">$name</option>";
760 // ###################################################################
762 * Assembles a <select> table row from list_item() items
766 * @param string Label text
767 * @param string Name of the <select>
768 * @param bool Automatically submit the form on a change?
769 * @param integer Colspan attribute
771 function row_list($label, $name, $is_jump = false
, $colspan = 2)
775 foreach ($listitem AS $option)
777 $optionlist .= $option;
782 $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);
785 // ###################################################################
787 * Creates a row with two radio buttons: yes and now
791 * @param string Label text
792 * @param string Name of the BOOL flag
793 * @param bool TRUE to select the YES by default; FALSE for NO
794 * @param integer Colspan attribute
796 function row_yesno($label, $name, $value, $colspan = 2)
798 $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);
802 /*=====================================================================*\
803 || ###################################################################
806 || ###################################################################
807 \*=====================================================================*/