2 /*=====================================================================*\
3 || ###################################################################
4 || # Iris Studios Shared Object Framework [#]issoversion[#]
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
40 * ISSO_PRINTER_NO_NAVIGATION - Do not show the navigation frame from ISSO.Printer.Navigation
43 * $this->page_start_hook - Define function to echo() data after the page header
46 * @author Iris Studios, Inc.
47 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
55 * Framework registry object
62 * Realm that we are operating in (displayed in the <title>)
66 var $realm = '[UNDEFINED REALM]';
69 * CSS to place in the page
87 var $page_start_hook = ':=NO METHOD=:';
90 * Fields array that is used in this module
95 'realm' => array(REQ_YES
, null
, false
),
96 'page_start_hook' => array(REQ_NO
, null
, false
)
99 // ###################################################################
103 function __construct(&$registry)
105 $this->registry
=& $registry;
108 // ###################################################################
110 * (PHP 4) Constructor
112 function Printer(&$registry)
114 $this->__construct($registry);
117 // ###################################################################
123 * @param string Field name
124 * @param mixed Value of the field
126 function set($name, $value)
128 $this->registry
->do_set($name, $value, 'printer');
131 // ###################################################################
137 * @param string Field name
139 * @return mixed Value of the field
141 function get($fieldname)
143 return $this->registry
->do_get($fieldname, 'printer');
146 // ###################################################################
148 * Creates a redirect to another page; constructs the header and footer
149 * (therefore execution stops)
153 * @param string Location to redirect to
154 * @param string Redirect message to be shown
155 * @param array An aray of POST variables to send through on the redirect
157 function redirect($location, $message = null
, $postvars = array())
164 <script type
="text/javascript">
166 var timeout
= $timeout;
170 setTimeout("redirect()", $timeout);
179 document
.forms
.postvars
.submit();
189 <script type
="text/javascript">
191 var timeout
= $timeout;
195 setTimeout("redirect()", $timeout);
204 window
.location
= "$location";
211 $this->page_start($this->registry
->modules
['localize']->string('Redirect'));
215 $this->form_start($location, null
, false
, 'postvars');
217 foreach ($postvars AS $key => $value)
219 $this->form_hidden_field($key, $value);
225 $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);
227 if ($message == null
)
229 $showmessage = $redir;
233 $showmessage = '<blockquote>' . $message . '</blockquote>';
234 $showmessage .= "\n<p>" . $redir . "</p>";
238 $this->page_message($this->registry
->modules
['localize']->string('Redirect'), $showmessage, $override);
240 $this->page_code($js);
245 // ###################################################################
247 * Throws a fatal error; constructs the header and footer
251 * @param string Error messsage text
253 function error($message)
255 $this->page_start($this->registry
->modules
['localize']->string('Error'));
256 $this->page_message($this->registry
->modules
['localize']->string('Error'), $message);
262 // ###################################################################
264 * Outputs the header of the page: doctype, <html>, <head>, <title>,
265 * <body> and imbeds the style information
269 * @param string Title of the page
270 * @param string Class of the page to be applied to the body
271 * @param integer Margin of the <div> that all content is placed in
272 * @param string Extra HTML to imbed in the <head> tag
273 * @param string <body> onLoad action to imbed
274 * @param integer Margin of the actual <body > tag
275 * @param string Relative path where the CSS data is stored
276 * @param bool Will force re-print the header if it has already been printed
278 function page_start($actiontitle, $pageclass = ':default:', $pagemargin = 15, $extra = '', $onload = false
, $margin = 0, $dotpath = '.', $override = false
)
280 $this->registry
->check_isso_fields(get_class($this));
282 if ($this->registry
->debug
AND isset($_GET['query']))
287 if (defined('ISSO_PRINTER_DONE_HEADER') AND !$override)
289 if (constant('ISSO_PRINTER_DONE_HEADER') AND !$override)
295 $title = sprintf($this->registry
->modules
['localize']->string('%1$s - %2$s - %3$s'), $this->registry
->application
, $this->realm
, $actiontitle);
297 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
298 echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>";
299 echo "\n\t<title>$title</title>";
300 echo "\n\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
303 echo ($extra ?
"\n$extra" : '');
304 echo "\n</head>\n<body style=\"margin: {$margin}px;\"" . (($pageclass !== ':default:') ?
" class=\"$pageclass\"" : '') . (($onload) ?
" onload=\"$onload\"" : '') . ">\n";
306 if (is_callable($this->page_start_hook
))
308 call_user_func($this->page_start_hook
);
311 echo "<div style=\"margin: {$pagemargin}px;\">\n<!-- / page head -->\n\n";
313 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
)))
315 echo $this->registry
->modules
['printer_navigation']->generate_header_html();
318 if (!defined('ISSO_PRINTER_DONE_HEADER'))
320 define('ISSO_PRINTER_DONE_HEADER', 1);
324 // ###################################################################
326 * Links CSS to the page from a given relative path
330 * @param string Relative path to the CSS file
332 function css_link($path)
334 $this->css
.= "\n\t<link rel=\"stylesheet\" href=\"$path\" />";
337 // ###################################################################
339 * Imbeds actual CSS information into the page in <style> tags
343 * @param string Path of the CSS file to be imbeded
345 function css_imbed($path)
347 $data = require_once($path);
348 $css = preg_replace('#/\*(.*?)\*/(\r|\n)*#s', '', $css);
350 $this->css
.= "\n\t<style type=\"text/css\">\n\t<!--\n" . $css . "\n\t//-->\n\t</style>";
353 // ###################################################################
355 * Places raw HTML code directly into the documet at the current
360 * @param string HTML code
362 function page_code($code)
364 if (defined('ISSO_PRINTER_DONE_HEADER'))
366 echo "\n\n$code\n\n";
370 $this->code
.= "\n\n$code\n\n";
374 // ###################################################################
376 * A block function that produces a table with a message in it. This
377 * does not print the header and footer.
381 * @param string The title of the message (appears at the top of the block)
382 * @param string Content of the message
383 * @param bool Override the message: control the entire output (no <blockquote>)?
385 function page_message($title, $message, $overridemessage = false
)
387 $this->table_start(true
, '75%');
388 $this->table_head($title, 1);
389 $this->row_span(($overridemessage ?
$message : "<blockquote>$message</blockquote>"), ':swap:', 'left', 1);
393 // ###################################################################
395 * Produces an entire page layout that asks the user whether or not
396 * they want to perform X action and provides a link to the YES and NO
401 * @param string Message that asks if they want to do X
402 * @param string Location to go for YES
403 * @param string DO action to pass
404 * @param array Hidden parameters to pass to the next page
406 function page_confirm($message, $location, $action, $params)
408 $this->page_start($this->registry
->modules
['localize']->string('Confirm'));
410 $this->form_start($location, $action);
411 foreach ($params AS $key => $value)
413 $this->form_hidden_field($key, $value);
416 $this->table_start(true
, '75%');
417 $this->table_head($this->registry
->modules
['localize']->string('Confirm'), 1);
418 $this->row_span("<blockquote>$message</blockquote>", ':swap:', 'left', 1);
419 $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'), '');
427 // ###################################################################
429 * Closes the HTML document structure an adds the copyright; this also
430 * stops execution of the page
436 if ($this->registry
->debug
AND isset($_GET['query']))
441 if (is_array($this->registry
->modules
[ISSO_DB_LAYER
]->history
))
443 foreach ($this->registry
->modules
[ISSO_DB_LAYER
]->history
AS $query)
445 echo $this->registry
->modules
[ISSO_DB_LAYER
]->construct_query_debug($query);
451 $copyright = "\n<br />\n<p align=\"center\" class=\"copyright\">\n\t<a href=\"http://www.iris-studios.com\" target=\"_blank\">" . $this->registry
->get('application') . ' ' . $this->registry
->get('appversion') . ", ©2002 - " . date('Y') . " Iris Studios, Inc.</a>\n</p>";
453 if (!defined('ISSO_PRINTER_HIDE_SETUP'))
455 echo "\n<!-- page end -->\n</div>\n$copyright";
456 echo $this->registry
->construct_debug_block(false
);
460 echo "\n<!-- page end -->\n</div>";
463 echo "\n\n</body>\n</html>";
468 // -------------------------------------------------------------------
470 // ###################################################################
472 * Opens a <table> tag with styling
476 * @param bool Whether to add a <br /> before the table
477 * @param string Value of the width attribute
479 function table_start($break = true
, $width = '90%')
486 echo "\n<table cellpadding=\"4\" cellspacing=\"0\" border=\"0\" align=\"center\" width=\"$width\" class=\"tborder\">\n";
489 // ###################################################################
491 * Adds a table row that is sued to head the entire table
495 * @param string Title string
496 * @param integer Colspan attribute value
497 * @param bool Whether to bold the title
499 function table_head($title, $colspan = 2, $strong = true
)
501 echo "<tr>\n\t<td class=\"tcat\" align=\"center\" colspan=\"$colspan\">" . (($strong) ?
"<strong>$title</strong>" : $title) . "</td>\n</tr>\n";
504 // ###################################################################
506 * Creates column headings; useful for a grid-style page. This uses a
507 * different styling than table_head() and is usually used directly
508 * after a table header.
512 * @param array Array of titles to print
514 function table_column_head($columnarray)
516 if (is_array($columnarray))
518 $render = "<tr valign=\"top\" align=\"center\">\n";
520 foreach ($columnarray AS $header)
522 $render .= "\t<td class=\"thead\" align=\"center\">$header</td>\n";
525 $render .= "</tr>\n";
531 // ###################################################################
533 * Closes a <table> tag
542 // -------------------------------------------------------------------
544 // ###################################################################
546 * Starts a <form> tag and adds the DO hidden input field
550 * @param string Action/name of the file to action to
551 * @param string Value of the DO parameter; used to do-branch
552 * @param bool Enctype attribute; used for mime/multi-part
553 * @param string Name of the form; this only matters for DOM access
554 * @param string Method to action as; POST or GET (default is POST)
556 function form_start($action, $do, $enctype = false
, $name = 'inputform', $submitmethod = 'post')
558 echo "\n<!-- input form -->\n<form name=\"$name\" action=\"$action\"" . (($enctype) ?
" enctype=\"$enctype\"" : '') . " method=\"$submitmethod\">\n";
562 $this->form_hidden_field('do', $do);
566 // ###################################################################
568 * Adds a hidden field at the current location
572 * @param string Name of the field
573 * @param string Value of the field
575 function form_hidden_field($name, $value)
577 echo "<input type=\"hidden\" name=\"$name\" value=\"$value\" />\n";
580 // ###################################################################
582 * Closes a <form> tag
588 echo "</form>\n<!-- / input form -->\n";
591 // -------------------------------------------------------------------
593 // ###################################################################
595 * Creates a table row that spans an entire row; this is used to divide
600 * @param string Text to place in the row
601 * @param string Class name to style with; by default it alternates between alt1 and alt2 (use :swap: to do that)
602 * @param string Alignment of the text in the row
603 * @param integer Colspan attribute
605 function row_span($text, $class = ':swap:', $align = 'left', $colspan = 2)
607 if ($class === ':swap:')
609 $this->registry
->modules
['functions']->exec_swap_bg();
610 $row_class = $this->registry
->modules
['functions']->bgcolour
;
611 $is_style_element = false
;
615 if (preg_match('#:style:(.*?)#i', $class))
617 $is_style_element = true
;
618 $style = str_replace(':style:', '', $class);
623 $is_style_element = false
;
627 echo "\n<tr>\n\t<td ". (($is_style_element) ?
"style=\"$style\"" : "class=\"$row_class\"") . " colspan=\"$colspan\" align=\"$align\">$text</td>\n</tr>";
630 // ###################################################################
632 * Creates a table row that has more than two columns; this is used in
633 * conjunction with table_column_head() usually; it takes an array of
638 * @param array Array of values in form value => alignment key (c for center, l for left, and r for right)
640 function row_multi_item($row_array)
642 $this->registry
->modules
['functions']->exec_swap_bg();
644 foreach ($row_array AS $item => $align)
646 $row_data["$align"][] = $item;
649 echo "<tr valign=\"top\">";
651 foreach ($row_data AS $align_key => $item_array)
653 if ($align_key == 'c')
657 else if ($align_key == 'l')
661 else if ($align_key == 'r')
666 foreach ($item_array AS $value)
668 echo "\n\t<td class=\"{$this->registry->modules['functions']->bgcolour}\" align=\"$align\">$value</td>";
675 // ###################################################################
677 * Generic row creation function that has two columns: label and value;
678 * this is used for many other form functions, but can also be used for
679 * non-editable fields
683 * @param string Label text
684 * @param string HTML or text to place in the value column
685 * @param string Vertical align (valign attribute) for the row
686 * @param integer Colspan attribute
687 * @param string Class to style the row with; default is to alternate
689 function row_text($label, $value = ' ', $valign = 'top', $colspan = 2, $class = -1)
697 $this->registry
->modules
['functions']->exec_swap_bg();
698 $row_class = $this->registry
->modules
['functions']->bgcolour
;
710 echo "<tr valign=\"$valign\">";
711 echo "\n\t<td class=\"$row_class\">$label</td>";
712 echo "\n\t<td class=\"$row_class\">$value</td>";
716 echo "\n\t<td class=\"$row_class\" colspan=\"" . $colspan - 2 . "\"> </td>";
722 // ###################################################################
724 * Creates a table row with an <input> text field as the value column
728 * @param string Label text
729 * @param string Name of the <input> field
730 * @param string Value of the field
731 * @param integer Colspan attribute
732 * @param integer Size of the <input> field
733 * @param integer Length attribute; use FALSE for no length to be specified
734 * @param bool Whether to make this a password field
735 * @param string Vertical align (valign attribute)
737 function row_input($label, $name, $value = '', $colspan = 2, $size = 35, $length = false
, $password = false
, $lalign = 'top')
739 $this->row_text($label, "<input type=\"" . (($password) ?
'password' : 'text') . "\" class=\"input\" name=\"$name\" value=\"$value\" size=\"$size\" " . (($length) ?
"maxlength=\"$length\" " : '') . "/>", $lalign, $colspan);
742 // ###################################################################
744 * Creates a table row with a <textarea> as the value column
748 * @param string Label text
749 * @param string Name of the <textarea>
750 * @param string Value of the <textarea>
751 * @param integer Colspan attribute
752 * @param integer Number of rows in the <textarea>
753 * @param integer Number of colums in the <textarea>
754 * @param bool Whether or not to use monospacing font
755 * @param string Extra style attributes to apply to the <textarea>
757 function row_textarea($label, $name, $value = '', $colspan = 2, $rows = 7, $cols = 50, $code = false
, $style = '')
759 $this->row_text($label, "<textarea name=\"$name\" class=\"" . (($code) ?
'code' : 'input') . "\" rows=\"$rows\" cols=\"$cols\"" . (($style) ?
' style="' . $style . '"' : '') . ">$value</textarea>", 'top', $colspan);
762 // ###################################################################
764 * Creates a table row with the tfoot class
768 * @param string Extra text or HTML to insert into the row
769 * @param integer Colspan attribute
771 function row_tfoot($data, $colspan = 2)
773 echo $this->row_span($data, 'tfoot', 'center', $colspan);
776 // ###################################################################
778 * Creates a tfoot table row with submit buttons
782 * @param string Extra HTML to imbed in the row after the buttons
783 * @param string Submit button text (by default it uses pre-translated "Submit" from :save:)
784 * @param string Reset button text (default it uses pre-translated "Reset" from :reset:)
785 * @param integer Colspan attribute
787 function row_submit($extra = false
, $submit = ':save:', $reset = ':reset:', $colspan = 2)
789 if ($submit === ':save:')
791 $submit = " " . $this->registry
->modules
['localize']->string('Submit') . " ";
795 $submit = " $submit ";
798 if ($reset === ':reset:')
800 $reset = " " . $this->registry
->modules
['localize']->string('Reset') . " ";
804 $reset = (($reset) ?
" $reset " : '');
807 $output = "\n\t\t<input type=\"submit\" class=\"button\" name=\"__submit__\" value=\"$submit\" accesskey=\"s\" />";
808 $output .= ($reset ?
"\n\t\t<input type=\"reset\" class=\"button\" name=\"__reset__\" value=\"$reset\" accesskey=\"r\" />" : '');
809 $output .= ($extra ?
"\n\t\t$extra" : '');
811 $this->row_tfoot($output, $colspan);
814 // ###################################################################
816 * Creates an upload row; you need to specify some other paramaters in
817 * form_start() for this to work
821 * @param string Label text
822 * @param string Upload name
823 * @param integer Colspan attribute
825 function row_upload($label, $name, $colspan = 2)
827 $this->row_text($label, "<input type=\"file\" class=\"button\" name=\"$name\" size=\"35\" />", 'top', $colspan);
830 // ###################################################################
832 * Adds a name-value pair to an array that is constructed into a
837 * @param string Text displayed for the option
838 * @param string Value of the option
839 * @param bool Whether or not to select this particluar option
841 function list_item($name, $value, $selected = false
)
845 $listitem["$value"] = array('name' => $name, 'selected' => $selected);
848 // ###################################################################
850 * Assembles a <select> table row from list_item() items
854 * @param string Label text
855 * @param string Name of the <select>
856 * @param bool Automatically submit the form on a change?
857 * @param integer Colspan attribute
859 function row_list($label, $name, $is_jump = false
, $colspan = 2)
863 foreach ($listitem AS $value => $option)
865 $optionlist .= "\n\t<option value=\"$value\"" . ($option['selected'] == true ?
' selected="selected"' : '') . ">$option[name]</option>";
870 $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);
873 // ###################################################################
875 * Assembles a list of checkboxes from list_item() items
879 * @param string Label text
880 * @param string Name of the <input>s
881 * @param integer Colspan attribute
883 function row_checkbox($label, $name, $colspan = 2)
887 foreach ($listitem AS $value => $box)
889 $optionlist[] = "\n\t<input type=\"checkbox\" class=\"button\" name=\"{$name}[]\" value=\"$value\"" . ($box['selected'] == true ?
' checked="checked"' : '') . " /> $box[name]";
894 $this->row_text($label, "\n" . implode('<br />', $optionlist) . "\n", $colspan);
897 // ###################################################################
899 * Creates a row with two radio buttons: yes and now
903 * @param string Label text
904 * @param string Name of the BOOL flag
905 * @param bool TRUE to select the YES by default; FALSE for NO
906 * @param integer Colspan attribute
908 function row_yesno($label, $name, $value, $colspan = 2)
910 $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);
914 /*=====================================================================*\
915 || ###################################################################
918 || ###################################################################
919 \*=====================================================================*/