2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework [#]issoversion[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
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
47 * @copyright Copyright ©2002 - [#]year[#], Blue Static
55 * Framework registry object
58 private $registry = null
;
61 * Realm that we are operating in (displayed in the <title>)
64 private $realm = '[UNDEFINED REALM]';
67 * CSS to place in the page
82 private $page_start_hook = ':=NO METHOD=:';
85 * Fields array that is used in this module
88 private $fields = array(
89 'realm' => array(REQ_YES
, null
, false
),
90 'page_start_hook' => array(REQ_NO
, null
, false
)
93 // ###################################################################
97 function __construct(&$registry)
99 $this->registry
=& $registry;
102 // ###################################################################
104 * (PHP 4) Constructor
106 function Printer(&$registry)
108 $this->__construct($registry);
111 // ###################################################################
117 * @param string Field name
118 * @param mixed Value of the field
120 function set($name, $value)
122 $this->registry
->do_set($name, $value, 'printer');
125 // ###################################################################
131 * @param string Field name
133 * @return mixed Value of the field
135 function get($fieldname)
137 return $this->registry
->do_get($fieldname, 'printer');
140 // ###################################################################
142 * Creates a redirect to another page; constructs the header and footer
143 * (therefore execution stops)
147 * @param string Location to redirect to
148 * @param string Redirect message to be shown
149 * @param array An aray of POST variables to send through on the redirect
151 function redirect($location, $message = null
, $postvars = array())
158 <script type
="text/javascript">
160 var timeout
= $timeout;
164 setTimeout("redirect()", $timeout);
173 document
.forms
.postvars
.submit();
183 <script type
="text/javascript">
185 var timeout
= $timeout;
189 setTimeout("redirect()", $timeout);
198 window
.location
= "$location";
205 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
207 define('ISSO_PRINTER_NO_NAVIGATION', 1);
210 $this->page_start($this->registry
->modules
['localize']->string('Redirect'));
214 $this->form_start($location, null
, false
, 'postvars');
216 foreach ($postvars AS $key => $value)
218 $this->form_hidden_field($key, $value);
224 $redir = sprintf($this->registry
->modules
['localize']->string('Please wait to be redirected. If you are not redirected in a few seconds, click <a href="%1$s">here</a>.'), $location);
226 if ($message == null
)
228 $showmessage = $redir;
232 $showmessage = '<blockquote>' . $message . '</blockquote>';
233 $showmessage .= "\n<p>" . $redir . "</p>";
237 $this->page_message($this->registry
->modules
['localize']->string('Redirect'), $showmessage, $override);
239 $this->page_code($js);
244 // ###################################################################
246 * Throws a fatal error; constructs the header and footer
250 * @param string Error messsage text
252 function error($message)
254 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
256 define('ISSO_PRINTER_NO_NAVIGATION', 1);
259 $this->page_start($this->registry
->modules
['localize']->string('Error'));
260 $this->page_message($this->registry
->modules
['localize']->string('Error'), $message);
266 // ###################################################################
268 * Outputs the header of the page: doctype, <html>, <head>, <title>,
269 * <body> and imbeds the style information
273 * @param string Title of the page
274 * @param string Class of the page to be applied to the body
275 * @param integer Margin of the <div> that all content is placed in
276 * @param string Extra HTML to imbed in the <head> tag
277 * @param string <body> onLoad action to imbed
278 * @param integer Margin of the actual <body > tag
279 * @param string Relative path where the CSS data is stored
280 * @param bool Will force re-print the header if it has already been printed
282 function page_start($actiontitle, $pageclass = ':default:', $pagemargin = 15, $extra = '', $onload = false
, $margin = 0, $dotpath = '.', $override = false
)
284 $this->registry
->check_isso_fields(get_class($this));
286 if ($this->registry
->debug
AND isset($_GET['query']))
291 if (defined('ISSO_PRINTER_DONE_HEADER') AND !$override)
293 if (constant('ISSO_PRINTER_DONE_HEADER') AND !$override)
299 $title = sprintf($this->registry
->modules
['localize']->string('%1$s - %2$s - %3$s'), $this->registry
->application
, $this->realm
, $actiontitle);
301 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
302 echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>";
303 echo "\n\t<title>$title</title>";
304 echo "\n\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
307 echo ($extra ?
"\n$extra" : '');
308 echo "\n</head>\n<body style=\"margin: {$margin}px;\"" . (($pageclass !== ':default:') ?
" class=\"$pageclass\"" : '') . (($onload) ?
" onload=\"$onload\"" : '') . ">\n";
310 if (is_callable($this->page_start_hook
))
312 call_user_func($this->page_start_hook
);
315 echo "<div style=\"margin: {$pagemargin}px;\">\n<!-- / page head -->\n\n";
317 if ($this->registry
->is_loaded('printer_navigation') AND (!defined('ISSO_PRINTER_NO_NAVIGATION') OR (defined('ISSO_PRINTER_NO_NAVIGATION') AND constant('ISSO_PRINTER_NO_NAVIGATION') != true
)))
319 echo $this->registry
->modules
['printer_navigation']->generate_header_html();
322 if (!defined('ISSO_PRINTER_DONE_HEADER'))
324 define('ISSO_PRINTER_DONE_HEADER', 1);
328 // ###################################################################
330 * Links CSS to the page from a given relative path
334 * @param string Relative path to the CSS file
336 function css_link($path)
338 $this->css
.= "\n\t<link rel=\"stylesheet\" href=\"$path\" />";
341 // ###################################################################
343 * Imbeds actual CSS information into the page in <style> tags
347 * @param string Path of the CSS file to be imbeded
349 function css_imbed($path)
351 $data = require_once($path);
352 $css = preg_replace('#/\*(.*?)\*/(\r|\n)*#s', '', $css);
354 $this->css
.= "\n\t<style type=\"text/css\">\n\t<!--\n" . $css . "\n\t//-->\n\t</style>";
357 // ###################################################################
359 * Places raw HTML code directly into the documet at the current
364 * @param string HTML code
366 function page_code($code)
368 if (defined('ISSO_PRINTER_DONE_HEADER'))
370 echo "\n\n$code\n\n";
374 $this->code
.= "\n\n$code\n\n";
378 // ###################################################################
380 * A block function that produces a table with a message in it. This
381 * does not print the header and footer.
385 * @param string The title of the message (appears at the top of the block)
386 * @param string Content of the message
387 * @param bool Override the message: control the entire output (no <blockquote>)?
389 function page_message($title, $message, $overridemessage = false
)
391 $this->table_start(true
, '75%');
392 $this->table_head($title, 1);
393 $this->row_span(($overridemessage ?
$message : "<blockquote>$message</blockquote>"), ':swap:', 'left', 1);
397 // ###################################################################
399 * Produces an entire page layout that asks the user whether or not
400 * they want to perform X action and provides a link to the YES and NO
405 * @param string Message that asks if they want to do X
406 * @param string Location to go for YES
407 * @param string DO action to pass
408 * @param array Hidden parameters to pass to the next page
410 function page_confirm($message, $location, $action, $params)
412 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
414 define('ISSO_PRINTER_NO_NAVIGATION', 1);
417 $this->page_start($this->registry
->modules
['localize']->string('Confirm'));
419 $this->form_start($location, $action);
420 foreach ($params AS $key => $value)
422 $this->form_hidden_field($key, $value);
425 $this->table_start(true
, '75%');
426 $this->table_head($this->registry
->modules
['localize']->string('Confirm'), 1);
427 $this->row_span("<blockquote>$message</blockquote>", ':swap:', 'left', 1);
428 $this->row_submit('<input type="button" class="button" name="no" value=" ' . $this->registry
->modules
['localize']->string('No') . ' " onclick="history.back(1); return false;" />', $this->registry
->modules
['localize']->string('Yes'), '');
436 // ###################################################################
438 * Closes the HTML document structure an adds the copyright; this also
439 * stops execution of the page
445 if ($this->registry
->debug
AND isset($_GET['query']))
450 if (is_array($this->registry
->modules
[ISSO_DB_LAYER
]->history
))
452 foreach ($this->registry
->modules
[ISSO_DB_LAYER
]->history
AS $query)
454 echo $this->registry
->modules
[ISSO_DB_LAYER
]->construct_query_debug($query);
460 if ($this->registry
->is_loaded('printer_navigation') AND (!defined('ISSO_PRINTER_NO_NAVIGATION') OR (defined('ISSO_PRINTER_NO_NAVIGATION') AND constant('ISSO_PRINTER_NO_NAVIGATION') != true
)))
462 echo $this->registry
->modules
['printer_navigation']->generate_footer_html();
465 $copyright = "\n<br />\n<p align=\"center\" class=\"copyright\">\n\t<a href=\"http://www.bluestatic.org\" target=\"_blank\">" . $this->registry
->get('application') . ' ' . $this->registry
->get('appversion') . ", ©2002 - " . date('Y') . " Blue Static</a>\n</p>";
467 if (!defined('ISSO_PRINTER_HIDE_SETUP'))
469 echo "\n<!-- page end -->\n</div>\n$copyright";
470 echo $this->registry
->construct_debug_block(false
);
474 echo "\n<!-- page end -->\n</div>";
477 echo "\n\n</body>\n</html>";
482 // -------------------------------------------------------------------
484 // ###################################################################
486 * Opens a <table> tag with styling
490 * @param bool Whether to add a <br /> before the table
491 * @param string Value of the width attribute
493 function table_start($break = true
, $width = '90%')
500 echo "\n<table cellpadding=\"4\" cellspacing=\"1\" border=\"0\" align=\"center\" width=\"$width\" class=\"tborder\">\n";
503 // ###################################################################
505 * Adds a table row that is sued to head the entire table
509 * @param string Title string
510 * @param integer Colspan attribute value
511 * @param bool Whether to bold the title
513 function table_head($title, $colspan = 2, $strong = true
)
515 echo "<tr>\n\t<td class=\"tcat\" align=\"center\" colspan=\"$colspan\">" . (($strong) ?
"<strong>$title</strong>" : $title) . "</td>\n</tr>\n";
518 // ###################################################################
520 * Creates column headings; useful for a grid-style page. This uses a
521 * different styling than table_head() and is usually used directly
522 * after a table header.
526 * @param array Array of titles to print
528 function table_column_head($columnarray)
530 if (is_array($columnarray))
532 $render = "<tr valign=\"top\" align=\"center\">\n";
534 foreach ($columnarray AS $header)
536 $render .= "\t<td class=\"thead\" align=\"center\">$header</td>\n";
539 $render .= "</tr>\n";
545 // ###################################################################
547 * Closes a <table> tag
556 // -------------------------------------------------------------------
558 // ###################################################################
560 * Starts a <form> tag and adds the DO hidden input field
564 * @param string Action/name of the file to action to
565 * @param string Value of the DO parameter; used to do-branch
566 * @param bool Enctype attribute; used for mime/multi-part
567 * @param string Name of the form; this only matters for DOM access
568 * @param string Method to action as; POST or GET (default is POST)
570 function form_start($action, $do, $enctype = false
, $name = 'inputform', $submitmethod = 'post')
572 echo "\n<!-- input form -->\n<form name=\"$name\" action=\"$action\"" . (($enctype) ?
" enctype=\"$enctype\"" : '') . " method=\"$submitmethod\">\n";
576 $this->form_hidden_field('do', $do);
580 // ###################################################################
582 * Adds a hidden field at the current location
586 * @param string Name of the field
587 * @param string Value of the field
589 function form_hidden_field($name, $value)
591 echo "<input type=\"hidden\" name=\"$name\" value=\"$value\" />\n";
594 // ###################################################################
596 * Closes a <form> tag
602 echo "</form>\n<!-- / input form -->\n";
605 // -------------------------------------------------------------------
607 // ###################################################################
609 * Creates a table row that spans an entire row; this is used to divide
614 * @param string Text to place in the row
615 * @param string Class name to style with; by default it alternates between alt1 and alt2 (use :swap: to do that)
616 * @param string Alignment of the text in the row
617 * @param integer Colspan attribute
619 function row_span($text, $class = ':swap:', $align = 'left', $colspan = 2)
621 if ($class === ':swap:')
623 $this->registry
->modules
['functions']->exec_swap_bg();
624 $row_class = $this->registry
->modules
['functions']->bgcolour
;
625 $is_style_element = false
;
629 if (preg_match('#:style:(.*?)#i', $class))
631 $is_style_element = true
;
632 $style = str_replace(':style:', '', $class);
637 $is_style_element = false
;
641 echo "\n<tr>\n\t<td ". (($is_style_element) ?
"style=\"$style\"" : "class=\"$row_class\"") . " colspan=\"$colspan\" align=\"$align\">$text</td>\n</tr>";
644 // ###################################################################
646 * Creates a table row that has more than two columns; this is used in
647 * conjunction with table_column_head() usually; it takes an array of
652 * @param array Array of values in form value => alignment key (c for center, l for left, and r for right)
654 function row_multi_item($row_array)
656 $this->registry
->modules
['functions']->exec_swap_bg();
658 foreach ($row_array AS $item => $align)
660 $row_data["$align"][] = $item;
663 echo "<tr valign=\"top\">";
665 foreach ($row_data AS $align_key => $item_array)
667 if ($align_key == 'c')
671 else if ($align_key == 'l')
675 else if ($align_key == 'r')
680 foreach ($item_array AS $value)
682 echo "\n\t<td class=\"{$this->registry->modules['functions']->bgcolour}\" align=\"$align\">$value</td>";
689 // ###################################################################
691 * Generic row creation function that has two columns: label and value;
692 * this is used for many other form functions, but can also be used for
693 * non-editable fields
697 * @param string Label text
698 * @param string HTML or text to place in the value column
699 * @param string Vertical align (valign attribute) for the row
700 * @param integer Colspan attribute
701 * @param string Class to style the row with; default is to alternate
703 function row_text($label, $value = ' ', $valign = 'top', $colspan = 2, $class = -1)
711 $this->registry
->modules
['functions']->exec_swap_bg();
712 $row_class = $this->registry
->modules
['functions']->bgcolour
;
724 echo "<tr valign=\"$valign\">";
725 echo "\n\t<td class=\"$row_class\">$label</td>";
726 echo "\n\t<td class=\"$row_class\" colspan=\"" . ($colspan - 1) . "\">$value</td>";
731 // ###################################################################
733 * Creates a table row with an <input> text field as the value column
737 * @param string Label text
738 * @param string Name of the <input> field
739 * @param string Value of the field
740 * @param integer Colspan attribute
741 * @param integer Size of the <input> field
742 * @param integer Length attribute; use FALSE for no length to be specified
743 * @param bool Whether to make this a password field
744 * @param string Vertical align (valign attribute)
746 function row_input($label, $name, $value = '', $colspan = 2, $size = 35, $length = false
, $password = false
, $lalign = 'top')
748 $this->row_text($label, "<input type=\"" . (($password) ?
'password' : 'text') . "\" class=\"input\" name=\"$name\" value=\"$value\" size=\"$size\" " . (($length) ?
"maxlength=\"$length\" " : '') . "/>", $lalign, $colspan);
751 // ###################################################################
753 * Creates a table row with a <textarea> as the value column
757 * @param string Label text
758 * @param string Name of the <textarea>
759 * @param string Value of the <textarea>
760 * @param integer Colspan attribute
761 * @param integer Number of rows in the <textarea>
762 * @param integer Number of colums in the <textarea>
763 * @param bool Whether or not to use monospacing font
764 * @param string Extra style attributes to apply to the <textarea>
766 function row_textarea($label, $name, $value = '', $colspan = 2, $rows = 7, $cols = 50, $code = false
, $style = '')
768 $this->row_text($label, "<textarea name=\"$name\" class=\"" . (($code) ?
'code' : 'input') . "\" rows=\"$rows\" cols=\"$cols\"" . (($style) ?
' style="' . $style . '"' : '') . ">$value</textarea>", 'top', $colspan);
771 // ###################################################################
773 * Creates a table row with the tfoot class
777 * @param string Extra text or HTML to insert into the row
778 * @param integer Colspan attribute
780 function row_tfoot($data, $colspan = 2)
782 echo $this->row_span($data, 'tfoot', 'center', $colspan);
785 // ###################################################################
787 * Creates a tfoot table row with submit buttons
791 * @param string Extra HTML to imbed in the row after the buttons
792 * @param string Submit button text (by default it uses pre-translated "Submit" from :save:)
793 * @param string Reset button text (default it uses pre-translated "Reset" from :reset:)
794 * @param integer Colspan attribute
796 function row_submit($extra = false
, $submit = ':save:', $reset = ':reset:', $colspan = 2)
798 if ($submit === ':save:')
800 $submit = " " . $this->registry
->modules
['localize']->string('Submit') . " ";
804 $submit = " $submit ";
807 if ($reset === ':reset:')
809 $reset = " " . $this->registry
->modules
['localize']->string('Reset') . " ";
813 $reset = (($reset) ?
" $reset " : '');
816 $output = "\n\t\t<input type=\"submit\" class=\"button\" name=\"__submit__\" value=\"$submit\" accesskey=\"s\" />";
817 $output .= ($reset ?
"\n\t\t<input type=\"reset\" class=\"button\" name=\"__reset__\" value=\"$reset\" accesskey=\"r\" />" : '');
818 $output .= ($extra ?
"\n\t\t$extra" : '');
820 $this->row_tfoot($output, $colspan);
823 // ###################################################################
825 * Creates an upload row; you need to specify some other paramaters in
826 * form_start() for this to work
830 * @param string Label text
831 * @param string Upload name
832 * @param integer Colspan attribute
834 function row_upload($label, $name, $colspan = 2)
836 $this->row_text($label, "<input type=\"file\" class=\"button\" name=\"$name\" size=\"35\" />", 'top', $colspan);
839 // ###################################################################
841 * Adds a name-value pair to an array that is constructed into a
846 * @param string Text displayed for the option
847 * @param string Value of the option
848 * @param bool Whether or not to select this particluar option
850 function list_item($name, $value, $selected = false
)
854 $listitem["$value"] = array('name' => $name, 'selected' => $selected);
857 // ###################################################################
859 * Assembles a <select> table row from list_item() items
863 * @param string Label text
864 * @param string Name of the <select>
865 * @param bool Automatically submit the form on a change?
866 * @param integer Colspan attribute
868 function row_list($label, $name, $is_jump = false
, $colspan = 2)
872 foreach ($listitem AS $value => $option)
874 $optionlist .= "\n\t<option value=\"$value\"" . ($option['selected'] == true ?
' selected="selected"' : '') . ">$option[name]</option>";
879 $this->row_text($label, "\n<select class=\"button\" name=\"$name\"" . (($is_jump) ?
" onchange=\"this.form.submit();\"" : '') . ">$optionlist\n</select>" . (($is_jump) ?
"\n<input type=\"submit\" class=\"button\" value=\" " . $this->registry
->modules
['localize']->string('Go') . " \" accesskey=\"g\" />" : '') . "\n", $colspan);
882 // ###################################################################
884 * Assembles a list of checkboxes from list_item() items
888 * @param string Label text
889 * @param string Name of the <input>s
890 * @param integer Colspan attribute
892 function row_checkbox($label, $name, $colspan = 2)
896 foreach ($listitem AS $value => $box)
898 $optionlist[] = "\n\t<input type=\"checkbox\" class=\"button\" name=\"{$name}[]\" value=\"$value\"" . ($box['selected'] == true ?
' checked="checked"' : '') . " /> $box[name]";
903 $this->row_text($label, "\n" . implode('<br />', $optionlist) . "\n", $colspan);
906 // ###################################################################
908 * Creates a row with two radio buttons: yes and now
912 * @param string Label text
913 * @param string Name of the BOOL flag
914 * @param bool TRUE to select the YES by default; FALSE for NO
915 * @param integer Colspan attribute
917 function row_yesno($label, $name, $value, $colspan = 2)
919 $this->row_text($label, "<input type=\"radio\" name=\"$name\" value=\"1\"" . (($value) ?
' checked="checked"' : '') . " /> " . $this->registry
->modules
['localize']->string('Yes') . " <input type=\"radio\" name=\"$name\" value=\"0\"" . ((!$value) ?
' checked="checked"' : '') . " /> " . $this->registry
->modules
['localize']->string('No'), $colspan);
923 /*=====================================================================*\
924 || ###################################################################
927 || ###################################################################
928 \*=====================================================================*/