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
42 * _printer_page_start() - Define function to echo() data after the page header
45 * @author Iris Studios, Inc.
46 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
54 * Framework registry object
61 * Realm that we are operating in (displayed in the <title>)
65 var $realm = '[UNDEFINED REALM]';
68 * CSS to place in the page
74 // ###################################################################
78 function __construct(&$registry)
80 $this->registry
=& $registry;
83 // ###################################################################
87 function Printer(&$registry)
89 $this->__construct($registry);
92 // ###################################################################
94 * Creates a redirect to another page; constructs the header and footer
95 * (therefore execution stops)
99 * @param string Location to redirect to
100 * @param integer Time to wait before the redirect
101 * @param array An aray of POST variables to send through on the redirect
103 function redirect($location, $timeout = 10, $postvars = array())
105 $timeout = $timeout * 200;
110 <script type
="text/javascript">
112 var timeout
= $timeout;
116 setTimeout("redirect()", $timeout);
125 document
.forms
.postvars
.submit();
135 <script type
="text/javascript">
137 var timeout
= $timeout;
141 setTimeout("redirect()", $timeout);
150 window
.location
= "$location";
157 $this->page_start($this->registry
->modules
['localize']->string('Redirect'));
161 $this->form_start($location, null
, false
, 'postvars');
163 foreach ($postvars AS $key => $value)
165 $this->form_hidden_field($key, $value);
171 $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));
173 $this->page_code($js);
178 // ###################################################################
180 * Throws a fatal error; constructs the header and footer
184 * @param string Error messsage text
186 function error($message)
188 $this->page_start($this->registry
->modules
['localize']->string('Error'));
189 $this->page_message($this->registry
->modules
['localize']->string('Error'), $message);
195 // ###################################################################
197 * Outputs the header of the page: doctype, <html>, <head>, <title>,
198 * <body> and imbeds the style information
202 * @param string Title of the page
203 * @param string Class of the page to be applied to the body
204 * @param integer Margin of the <div> that all content is placed in
205 * @param string Extra HTML to imbed in the <head> tag
206 * @param string <body> onLoad action to imbed
207 * @param integer Margin of the actual <body > tag
208 * @param string Relative path where the CSS data is stored
209 * @param bool Will force re-print the header if it has already been printed
211 function page_start($actiontitle, $pageclass = ':default:', $pagemargin = 15, $extra = '', $onload = false
, $margin = 0, $dotpath = '.', $override = false
)
213 if ($this->registry
->debug
AND isset($_GET['query']))
218 if (defined('ISSO_PRINTER_DONE_HEADER') AND !$override)
220 if (constant('ISSO_PRINTER_DONE_HEADER') AND !$override)
226 $title = sprintf($this->registry
->modules
['localize']->string('%1$s - %2$s - %3$s'), $this->registry
->application
, $this->realm
, $actiontitle);
228 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
229 echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>";
230 echo "\n\t<title>$title</title>";
231 echo "\n\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
233 echo ($extra ?
"\n$extra" : '');
234 echo "\n</head>\n<body style=\"margin: {$margin}px;\"" . (($pageclass !== ':default:') ?
" class=\"$pageclass\"" : '') . (($onload) ?
" onload=\"$onload\"" : '') . ">\n";
236 if (!defined('ISSO_PRINTER_HIDE_SETUP') AND function_exists('_printer_page_start'))
238 _printer_page_start();
241 echo "<div style=\"margin: {$pagemargin}px;\">\n<!-- / page head -->\n\n";
243 if (!defined('ISSO_PRINTER_DONE_HEADER'))
245 define('ISSO_PRINTER_DONE_HEADER', 1);
249 // ###################################################################
251 * Links CSS to the page from a given relative path
255 * @param string Relative path to the CSS file
257 function css_link($path)
259 $this->css
.= "\n\t<link rel=\"stylesheet\" href=\"$path\" />";
262 // ###################################################################
264 * Imbeds actual CSS information into the page in <style> tags
268 * @param string Path of the CSS file to be imbeded
270 function css_imbed($path)
272 $data = require_once($path);
273 $css = preg_replace('#/\*(.*?)\*/(\r|\n)*#s', '', $css);
275 $this->css
.= "\n\t<style type=\"text/css\">\n\t<!--\n" . $css . "\n\t//-->\n\t</style>";
278 // ###################################################################
280 * Places raw HTML code directly into the documet at the current
285 * @param string HTML code
287 function page_code($code)
289 echo "\n\n$code\n\n";
292 // ###################################################################
294 * A block function that produces a table with a message in it. This
295 * does not print the header and footer.
299 * @param string The title of the message (appears at the top of the block)
300 * @param string Content of the message
302 function page_message($title, $message)
304 $this->table_start(true
, '75%');
305 $this->table_head($title, 1);
306 $this->row_span("<blockquote>$message</blockquote>", ':swap:', 'left', 1);
310 // ###################################################################
312 * Produces an entire page layout that asks the user whether or not
313 * they want to perform X action and provides a link to the YES and NO
318 * @param string Message that asks if they want to do X
319 * @param string Location to go for YES
320 * @param string DO action to pass
321 * @param array Hidden parameters to pass to the next page
323 function page_confirm($message, $location, $action, $params)
325 $this->page_start($this->registry
->modules
['localize']->string('Confirm'));
327 $this->form_start($location, $action);
328 foreach ($params AS $key => $value)
330 $this->form_hidden_field($key, $value);
333 $this->table_start(true
, '75%');
334 $this->table_head($this->registry
->modules
['localize']->string('Confirm'), 1);
335 $this->row_span("<blockquote>$message</blockquote>", ':swap:', 'left', 1);
336 $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'), '');
344 // ###################################################################
346 * Closes the HTML document structure an adds the copyright; this also
347 * stops execution of the page
353 if ($this->registry
->debug
AND isset($_GET['query']))
358 if (is_array($this->registry
->modules
[ISSO_DB_LAYER
]->history
))
361 foreach ($this->registry
->modules
[ISSO_DB_LAYER
]->history
AS $query)
363 echo $query . "\n\n<hr />\n\n";
370 $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>";
372 if (!defined('ISSO_PRINTER_HIDE_SETUP'))
374 echo "\n<!-- page end -->\n</div>\n$copyright";
375 echo $this->registry
->construct_debug_block(false
);
379 echo "\n<!-- page end -->\n</div>";
382 echo "\n\n</body>\n</html>";
387 // -------------------------------------------------------------------
389 // ###################################################################
391 * Opens a <table> tag with styling
395 * @param bool Whether to add a <br /> before the table
396 * @param string Value of the width attribute
398 function table_start($break = true
, $width = '90%')
405 echo "\n<table cellpadding=\"4\" cellspacing=\"0\" border=\"0\" align=\"center\" width=\"$width\" class=\"tborder\">\n";
408 // ###################################################################
410 * Adds a table row that is sued to head the entire table
414 * @param string Title string
415 * @param integer Colspan attribute value
416 * @param bool Whether to bold the title
418 function table_head($title, $colspan = 2, $strong = true
)
420 echo "<tr>\n\t<td class=\"tcat\" align=\"center\" colspan=\"$colspan\">" . (($strong) ?
"<strong>$title</strong>" : $title) . "</td>\n</tr>\n";
423 // ###################################################################
425 * Creates column headings; useful for a grid-style page. This uses a
426 * different styling than table_head() and is usually used directly
427 * after a table header.
431 * @param array Array of titles to print
433 function table_column_head($columnarray)
435 if (is_array($columnarray))
437 $render = "<tr valign=\"top\" align=\"center\">\n";
439 foreach ($columnarray AS $header)
441 $render .= "\t<td class=\"thead\" align=\"center\">$header</td>\n";
444 $render .= "</tr>\n";
450 // ###################################################################
452 * Closes a <table> tag
461 // -------------------------------------------------------------------
463 // ###################################################################
465 * Starts a <form> tag and adds the DO hidden input field
469 * @param string Action/name of the file to action to
470 * @param string Value of the DO parameter; used to do-branch
471 * @param bool Enctype attribute; used for mime/multi-part
472 * @param string Name of the form; this only matters for DOM access
473 * @param string Method to action as; POST or GET (default is POST)
475 function form_start($action, $do, $enctype = false
, $name = 'inputform', $submitmethod = 'post')
477 echo "\n<!-- input form -->\n<form name=\"$name\" action=\"$action\"" . (($enctype) ?
" enctype=\"$enctype\"" : '') . " method=\"$submitmethod\">\n";
481 $this->form_hidden_field('do', $do);
485 // ###################################################################
487 * Adds a hidden field at the current location
491 * @param string Name of the field
492 * @param string Value of the field
494 function form_hidden_field($name, $value)
496 echo "<input type=\"hidden\" name=\"$name\" value=\"$value\" />\n";
499 // ###################################################################
501 * Closes a <form> tag
507 echo "</form>\n<!-- / input form -->\n";
510 // -------------------------------------------------------------------
512 // ###################################################################
514 * Creates a table row that spans an entire row; this is used to divide
519 * @param string Text to place in the row
520 * @param string Class name to style with; by default it alternates between alt1 and alt2 (use :swap: to do that)
521 * @param string Alignment of the text in the row
522 * @param integer Colspan attribute
524 function row_span($text, $class = ':swap:', $align = 'left', $colspan = 2)
526 if ($class === ':swap:')
528 $this->registry
->modules
['functions']->exec_swap_bg();
529 $row_class = $this->registry
->modules
['functions']->bgcolour
;
530 $is_style_element = false
;
534 if (preg_match('#:style:(.*?)#i', $class))
536 $is_style_element = true
;
537 $style = str_replace(':style:', '', $class);
542 $is_style_element = false
;
546 echo "\n<tr>\n\t<td ". (($is_style_element) ?
"style=\"$style\"" : "class=\"$row_class\"") . " colspan=\"$colspan\" align=\"$align\">$text</td>\n</tr>";
549 // ###################################################################
551 * Creates a table row that has more than two columns; this is used in
552 * conjunction with table_column_head() usually; it takes an array of
557 * @param array Array of values in form value => alignment key (c for center, l for left, and r for right)
559 function row_multi_item($row_array)
561 $this->registry
->modules
['functions']->exec_swap_bg();
563 foreach ($row_array AS $item => $align)
565 $row_data["$align"][] = $item;
568 echo "<tr valign=\"top\">";
570 foreach ($row_data AS $align_key => $item_array)
572 if ($align_key == 'c')
576 else if ($align_key == 'l')
580 else if ($align_key == 'r')
585 foreach ($item_array AS $value)
587 echo "\n\t<td class=\"{$this->registry->modules['functions']->bgcolour}\" align=\"$align\">$value</td>";
594 // ###################################################################
596 * Generic row creation function that has two columns: label and value;
597 * this is used for many other form functions, but can also be used for
598 * non-editable fields
602 * @param string Label text
603 * @param string HTML or text to place in the value column
604 * @param string Vertical align (valign attribute) for the row
605 * @param integer Colspan attribute
606 * @param string Class to style the row with; default is to alternate
608 function row_text($label, $value = ' ', $valign = 'top', $colspan = 2, $class = -1)
616 $this->registry
->modules
['functions']->exec_swap_bg();
617 $row_class = $this->registry
->modules
['functions']->bgcolour
;
629 echo "<tr valign=\"$valign\">";
630 echo "\n\t<td class=\"$row_class\">$label</td>";
631 echo "\n\t<td class=\"$row_class\">$value</td>";
635 echo "\n\t<td class=\"$row_class\" colspan=\"" . $colspan - 2 . "\"> </td>";
641 // ###################################################################
643 * Creates a table row with an <input> text field as the value column
647 * @param string Label text
648 * @param string Name of the <input> field
649 * @param string Value of the field
650 * @param integer Colspan attribute
651 * @param integer Size of the <input> field
652 * @param integer Length attribute; use FALSE for no length to be specified
653 * @param bool Whether to make this a password field
654 * @param string Vertical align (valign attribute)
656 function row_input($label, $name, $value = '', $colspan = 2, $size = 35, $length = false
, $password = false
, $lalign = 'top')
658 $this->row_text($label, "<input type=\"" . (($password) ?
'password' : 'text') . "\" class=\"input\" name=\"$name\" value=\"$value\" size=\"$size\" " . (($length) ?
"maxlength=\"$length\" " : '') . "/>", $lalign, $colspan);
661 // ###################################################################
663 * Creates a table row with a <textarea> as the value column
667 * @param string Label text
668 * @param string Name of the <textarea>
669 * @param string Value of the <textarea>
670 * @param integer Colspan attribute
671 * @param integer Number of rows in the <textarea>
672 * @param integer Number of colums in the <textarea>
673 * @param bool Whether or not to use monospacing font
674 * @param string Extra style attributes to apply to the <textarea>
676 function row_textarea($label, $name, $value = '', $colspan = 2, $rows = 7, $cols = 50, $code = false
, $style = '')
678 $this->row_text($label, "<textarea name=\"$name\" class=\"" . (($code) ?
'code' : 'input') . "\" rows=\"$rows\" cols=\"$cols\"" . (($style) ?
' style="' . $style . '"' : '') . ">$value</textarea>", 'top', $colspan);
681 // ###################################################################
683 * Creates a table row with the tfoot class
687 * @param string Extra text or HTML to insert into the row
688 * @param integer Colspan attribute
690 function row_tfoot($data, $colspan = 2)
692 echo $this->row_span($data, 'tfoot', 'center', $colspan);
695 // ###################################################################
697 * Creates a tfoot table row with submit buttons
701 * @param string Extra HTML to imbed in the row after the buttons
702 * @param string Submit button text (by default it uses pre-translated "Submit" from :save:)
703 * @param string Reset button text (default it uses pre-translated "Reset" from :reset:)
704 * @param integer Colspan attribute
706 function row_submit($extra = false
, $submit = ':save:', $reset = ':reset:', $colspan = 2)
708 if ($submit === ':save:')
710 $submit = " " . $this->registry
->modules
['localize']->string('Submit') . " ";
714 $submit = " $submit ";
717 if ($reset === ':reset:')
719 $reset = " " . $this->registry
->modules
['localize']->string('Reset') . " ";
723 $reset = (($reset) ?
" $reset " : '');
726 $output = "\n\t\t<input type=\"submit\" class=\"button\" name=\"__submit__\" value=\"$submit\" accesskey=\"s\" />";
727 $output .= ($reset ?
"\n\t\t<input type=\"reset\" class=\"button\" name=\"__reset__\" value=\"$reset\" accesskey=\"r\" />" : '');
728 $output .= ($extra ?
"\n\t\t$extra" : '');
730 $this->row_tfoot($output, $colspan);
733 // ###################################################################
735 * Creates an upload row; you need to specify some other paramaters in
736 * form_start() for this to work
740 * @param string Label text
741 * @param string Upload name
742 * @param integer Colspan attribute
744 function row_upload($label, $name, $colspan = 2)
746 $this->row_text($label, "<input type=\"file\" class=\"button\" name=\"$name\" size=\"35\" />", 'top', $colspan);
749 // ###################################################################
751 * Adds a name-value pair to an array that is constructed into a
756 * @param string Text displayed for the option
757 * @param string Value of the option
758 * @param bool Whether or not to select this particluar option
760 function list_item($name, $value, $selected = false
)
764 $listitem[] = "\n\t<option value=\"$value\"" . (($selected == true
) ?
' selected="selected"' : '') . ">$name</option>";
767 // ###################################################################
769 * Assembles a <select> table row from list_item() items
773 * @param string Label text
774 * @param string Name of the <select>
775 * @param bool Automatically submit the form on a change?
776 * @param integer Colspan attribute
778 function row_list($label, $name, $is_jump = false
, $colspan = 2)
782 foreach ($listitem AS $option)
784 $optionlist .= $option;
789 $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);
792 // ###################################################################
794 * Creates a row with two radio buttons: yes and now
798 * @param string Label text
799 * @param string Name of the BOOL flag
800 * @param bool TRUE to select the YES by default; FALSE for NO
801 * @param integer Colspan attribute
803 function row_yesno($label, $name, $value, $colspan = 2)
805 $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);
809 /*=====================================================================*\
810 || ###################################################################
813 || ###################################################################
814 \*=====================================================================*/