2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
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 * @copyright Copyright ©2002 - [#]year[#], Blue Static
51 * Framework registry object
58 * Realm that we are operating in (displayed in the <title>)
62 var $realm = '[UNDEFINED REALM]';
65 * CSS to place in the page
83 var $page_start_hook = ':=NO METHOD=:';
86 * Language information array: ('langcode' =>, 'direction' =>, 'charset' =>)
90 var $language = array('langcode' => 'en_US', 'direction' => 'ltr', 'charset' => 'utf-8');
92 // ###################################################################
96 function __construct(&$registry)
98 $this->registry
=& $registry;
101 // ###################################################################
103 * (PHP 4) Constructor
105 function Printer(&$registry)
107 $this->__construct($registry);
110 // ###################################################################
116 * @param string Realm
118 function setRealm($realm)
120 $this->realm
= $realm;
123 // ###################################################################
129 * @return string Realm
136 // ###################################################################
138 * Gets the language array information
142 * @return array Language array
144 function getLanguageInformation()
146 return $this->language
;
149 // ###################################################################
151 * Sets the language array information
155 * @param array Language array
157 function setLanguageInformation($lang)
159 $this->language
= $lang;
162 // ###################################################################
164 * Creates a redirect to another page; constructs the header and footer
165 * (therefore execution stops)
169 * @param string Location to redirect to
170 * @param string Redirect message to be shown
171 * @param array An aray of POST variables to send through on the redirect
173 function redirect($location, $message = null
, $postvars = array())
180 <script type
="text/javascript">
182 var timeout
= $timeout;
186 setTimeout("redirect()", $timeout);
195 document
.forms
.postvars
.submit();
205 <script type
="text/javascript">
207 var timeout
= $timeout;
211 setTimeout("redirect()", $timeout);
220 window
.location
= "$location";
227 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
229 define('ISSO_PRINTER_NO_NAVIGATION', 1);
232 $this->page_start(T('Redirect'));
236 $this->form_start($location, null
, false
, 'postvars');
238 foreach ($postvars AS $key => $value)
240 $this->form_hidden_field($key, $value);
246 $redir = sprintf(T('Please wait to be redirected. If you are not redirected in a few seconds, click <a href="%1$s">here</a>.'), $location);
248 if ($message == null
)
250 $showmessage = $redir;
254 $showmessage = '<blockquote>' . $message . '</blockquote>';
255 $showmessage .= "\n<p>" . $redir . "</p>";
259 $this->page_message(T('Redirect'), $showmessage, $override);
261 $this->page_code($js);
266 // ###################################################################
268 * Throws a fatal error; constructs the header and footer
272 * @param string Error messsage text
274 function error($message)
276 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
278 define('ISSO_PRINTER_NO_NAVIGATION', 1);
281 $this->page_start(T('Error'));
282 $this->page_message(T('Error'), $message);
288 // ###################################################################
290 * Outputs the header of the page: doctype, <html>, <head>, <title>,
291 * <body> and imbeds the style information
295 * @param string Title of the page
296 * @param string Class of the page to be applied to the body
297 * @param string Extra HTML to imbed in the <head> tag
298 * @param string <body> onLoad action to imbed
300 function page_start($actiontitle, $pageclass = null
, $extra = '', $onload = false
)
302 if ($this->registry
->debug
AND isset($_GET['query']))
307 if (defined('ISSO_PRINTER_DONE_HEADER') AND constant('ISSO_PRINTER_DONE_HEADER'))
312 $title = sprintf(T('%1$s - %2$s - %3$s'), $this->registry
->getApplication(), $this->realm
, $actiontitle);
314 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
315 echo "<html xml:lang=\"" . $this->language
['langcode'] . "\" lang=\"" . $this->language
['langcode'] . "\" dir=\"" . $this->language
['direction'] . "\">\n<head>";
316 echo "\n\t<title>$title</title>";
317 echo "\n\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" . $this->language
['charset'] . "\" />";
320 echo ($extra ?
"\n$extra" : '');
321 echo "\n</head>\n<body" . ($pageclass != null ?
" class=\"$pageclass\"" : '') . ($onload ?
" onload=\"$onload\"" : '') . ">\n";
323 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
)))
325 echo $this->registry
->modules
['printer_navigation']->generate_header_html();
328 if (!defined('ISSO_PRINTER_DONE_HEADER'))
330 define('ISSO_PRINTER_DONE_HEADER', 1);
334 // ###################################################################
336 * Links CSS to the page from a given relative path
340 * @param string Relative path to the CSS file
342 function css_link($path)
344 $this->css
.= "\n\t<link rel=\"stylesheet\" href=\"$path\" />";
347 // ###################################################################
349 * Imbeds actual CSS information into the page in <style> tags
353 * @param string Path of the CSS file to be imbeded
355 function css_imbed($path)
357 $data = require_once($path);
358 $css = preg_replace('#/\*(.*?)\*/(\r|\n)*#s', '', $css);
360 $this->css
.= "\n\t<style type=\"text/css\">\n\t<!--\n" . $css . "\n\t//-->\n\t</style>";
363 // ###################################################################
365 * Places raw HTML code directly into the documet at the current
370 * @param string HTML code
372 function page_code($code)
374 if (defined('ISSO_PRINTER_DONE_HEADER'))
376 echo "\n\n$code\n\n";
380 $this->code
.= "\n\n$code\n\n";
384 // ###################################################################
386 * A block function that produces a table with a message in it. This
387 * does not print the header and footer.
391 * @param string The title of the message (appears at the top of the block)
392 * @param string Content of the message
393 * @param bool Override the message: control the entire output (no <blockquote>)?
395 function page_message($title, $message, $overridemessage = false
)
397 $this->table_start(true
, '75%');
398 $this->table_head($title, 1);
399 $this->row_span(($overridemessage ?
$message : "<blockquote>$message</blockquote>"), ':swap:', 'left', 1);
403 // ###################################################################
405 * Produces an entire page layout that asks the user whether or not
406 * they want to perform X action and provides a link to the YES and NO
411 * @param string Message that asks if they want to do X
412 * @param string Location to go for YES
413 * @param string DO action to pass
414 * @param array Hidden parameters to pass to the next page
416 function page_confirm($message, $location, $action, $params)
418 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
420 define('ISSO_PRINTER_NO_NAVIGATION', 1);
423 $this->page_start(T('Confirm'));
425 $this->form_start($location, $action);
426 foreach ($params AS $key => $value)
428 $this->form_hidden_field($key, $value);
431 $this->table_start(true
, '75%');
432 $this->table_head(T('Confirm'), 1);
433 $this->row_span("<blockquote>$message</blockquote>", ':swap:', 'left', 1);
434 $this->row_submit('<input type="button" class="button" name="no" value=" ' . T('No') . ' " onclick="history.back(1); return false;" />', T('Yes'), '');
442 // ###################################################################
444 * Closes the HTML document structure an adds the copyright; this also
445 * stops execution of the page
451 if ($this->registry
->debug
AND isset($_GET['query']))
456 if (is_array($this->registry
->modules
[ISSO_DB_LAYER
]->history
))
458 foreach ($this->registry
->modules
[ISSO_DB_LAYER
]->history
AS $query)
460 echo $this->registry
->modules
[ISSO_DB_LAYER
]->construct_query_debug($query);
466 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
)))
468 echo $this->registry
->modules
['printer_navigation']->generate_footer_html();
471 $copyright = "\n<br />\n<p align=\"center\" class=\"copyright\">\n\t<a href=\"http://www.bluestatic.org\" target=\"_blank\">" . $this->registry
->getApplication() . ' ' . $this->registry
->getAppVersion() . ", ©2002 - " . date('Y') . " Blue Static</a>\n</p>";
473 if (!defined('ISSO_PRINTER_HIDE_SETUP'))
476 echo $this->registry
->construct_debug_block(false
);
479 echo "\n\n</body>\n</html>";
484 // -------------------------------------------------------------------
486 // ###################################################################
488 * Opens a <table> tag with styling
492 * @param bool Whether to add a <br /> before the table
493 * @param string Value of the width attribute
495 function table_start($break = true
, $width = '90%')
502 echo "\n<table cellpadding=\"4\" cellspacing=\"1\" border=\"0\" align=\"center\" width=\"$width\" class=\"tborder\">\n";
505 // ###################################################################
507 * Adds a table row that is sued to head the entire table
511 * @param string Title string
512 * @param integer Colspan attribute value
513 * @param bool Whether to bold the title
515 function table_head($title, $colspan = 2, $strong = true
)
517 echo "<tr>\n\t<td class=\"tcat\" align=\"center\" colspan=\"$colspan\">" . (($strong) ?
"<strong>$title</strong>" : $title) . "</td>\n</tr>\n";
520 // ###################################################################
522 * Creates column headings; useful for a grid-style page. This uses a
523 * different styling than table_head() and is usually used directly
524 * after a table header.
528 * @param array Array of titles to print
530 function table_column_head($columnarray)
532 if (is_array($columnarray))
534 $render = "<tr valign=\"top\" align=\"center\">\n";
536 foreach ($columnarray AS $header)
538 $render .= "\t<td class=\"thead\" align=\"center\">$header</td>\n";
541 $render .= "</tr>\n";
547 // ###################################################################
549 * Closes a <table> tag
558 // -------------------------------------------------------------------
560 // ###################################################################
562 * Starts a <form> tag and adds the DO hidden input field
566 * @param string Action/name of the file to action to
567 * @param string Value of the DO parameter; used to do-branch
568 * @param bool Enctype attribute; used for mime/multi-part
569 * @param string Name of the form; this only matters for DOM access
570 * @param string Method to action as; POST or GET (default is POST)
572 function form_start($action, $do, $enctype = false
, $name = 'inputform', $submitmethod = 'post')
574 echo "\n<!-- input form -->\n<form name=\"$name\" action=\"$action\"" . (($enctype) ?
" enctype=\"$enctype\"" : '') . " method=\"$submitmethod\">\n";
578 $this->form_hidden_field('do', $do);
582 // ###################################################################
584 * Adds a hidden field at the current location
588 * @param string Name of the field
589 * @param string Value of the field
591 function form_hidden_field($name, $value)
593 echo "<input type=\"hidden\" name=\"$name\" value=\"$value\" />\n";
596 // ###################################################################
598 * Closes a <form> tag
604 echo "</form>\n<!-- / input form -->\n";
607 // -------------------------------------------------------------------
609 // ###################################################################
611 * Creates a table row that spans an entire row; this is used to divide
616 * @param string Text to place in the row
617 * @param string Class name to style with; by default it alternates between alt1 and alt2 (use :swap: to do that)
618 * @param string Alignment of the text in the row
619 * @param integer Colspan attribute
621 function row_span($text, $class = ':swap:', $align = 'left', $colspan = 2)
623 if ($class === ':swap:')
625 $this->registry
->modules
['functions']->exec_swap_bg();
626 $row_class = $this->registry
->modules
['functions']->bgcolour
;
627 $is_style_element = false
;
631 if (preg_match('#:style:(.*?)#i', $class))
633 $is_style_element = true
;
634 $style = str_replace(':style:', '', $class);
639 $is_style_element = false
;
643 echo "\n<tr>\n\t<td ". (($is_style_element) ?
"style=\"$style\"" : "class=\"$row_class\"") . " colspan=\"$colspan\" align=\"$align\">$text</td>\n</tr>";
646 // ###################################################################
648 * Creates a table row that has more than two columns; this is used in
649 * conjunction with table_column_head() usually; it takes an array of
654 * @param array Array of values in form value => alignment key (c for center, l for left, and r for right)
656 function row_multi_item($row_array)
658 $this->registry
->modules
['functions']->exec_swap_bg();
660 foreach ($row_array AS $item => $align)
662 $row_data["$align"][] = $item;
665 echo "<tr valign=\"top\">";
667 foreach ($row_data AS $align_key => $item_array)
669 if ($align_key == 'c')
673 else if ($align_key == 'l')
677 else if ($align_key == 'r')
682 foreach ($item_array AS $value)
684 echo "\n\t<td class=\"{$this->registry->modules['functions']->bgcolour}\" align=\"$align\">$value</td>";
691 // ###################################################################
693 * Generic row creation function that has two columns: label and value;
694 * this is used for many other form functions, but can also be used for
695 * non-editable fields
699 * @param string Label text
700 * @param string HTML or text to place in the value column
701 * @param string Vertical align (valign attribute) for the row
702 * @param integer Colspan attribute
703 * @param string Class to style the row with; default is to alternate
705 function row_text($label, $value = ' ', $valign = 'top', $colspan = 2, $class = -1)
713 $this->registry
->modules
['functions']->exec_swap_bg();
714 $row_class = $this->registry
->modules
['functions']->bgcolour
;
726 echo "<tr valign=\"$valign\">";
727 echo "\n\t<td class=\"$row_class\">$label</td>";
728 echo "\n\t<td class=\"$row_class\" colspan=\"" . ($colspan - 1) . "\">$value</td>";
733 // ###################################################################
735 * Creates a table row with an <input> text field as the value column
739 * @param string Label text
740 * @param string Name of the <input> field
741 * @param string Value of the field
742 * @param integer Colspan attribute
743 * @param integer Size of the <input> field
744 * @param integer Length attribute; use FALSE for no length to be specified
745 * @param bool Whether to make this a password field
746 * @param string Vertical align (valign attribute)
748 function row_input($label, $name, $value = '', $colspan = 2, $size = 35, $length = false
, $password = false
, $lalign = 'top')
750 $this->row_text($label, "<input type=\"" . (($password) ?
'password' : 'text') . "\" class=\"input\" name=\"$name\" value=\"$value\" size=\"$size\" " . (($length) ?
"maxlength=\"$length\" " : '') . "/>", $lalign, $colspan);
753 // ###################################################################
755 * Creates a table row with a <textarea> as the value column
759 * @param string Label text
760 * @param string Name of the <textarea>
761 * @param string Value of the <textarea>
762 * @param integer Colspan attribute
763 * @param integer Number of rows in the <textarea>
764 * @param integer Number of colums in the <textarea>
765 * @param bool Whether or not to use monospacing font
766 * @param string Extra style attributes to apply to the <textarea>
768 function row_textarea($label, $name, $value = '', $colspan = 2, $rows = 7, $cols = 50, $code = false
, $style = '')
770 $this->row_text($label, "<textarea name=\"$name\" class=\"" . (($code) ?
'code' : 'input') . "\" rows=\"$rows\" cols=\"$cols\"" . (($style) ?
' style="' . $style . '"' : '') . ">$value</textarea>", 'top', $colspan);
773 // ###################################################################
775 * Creates a table row with the tfoot class
779 * @param string Extra text or HTML to insert into the row
780 * @param integer Colspan attribute
782 function row_tfoot($data, $colspan = 2)
784 echo $this->row_span($data, 'tfoot', 'center', $colspan);
787 // ###################################################################
789 * Creates a tfoot table row with submit buttons
793 * @param string Extra HTML to imbed in the row after the buttons
794 * @param string Submit button text (by default it uses pre-translated "Submit" from :save:)
795 * @param string Reset button text (default it uses pre-translated "Reset" from :reset:)
796 * @param integer Colspan attribute
798 function row_submit($extra = false
, $submit = ':save:', $reset = ':reset:', $colspan = 2)
800 if ($submit === ':save:')
802 $submit = " " . T('Submit') . " ";
806 $submit = " $submit ";
809 if ($reset === ':reset:')
811 $reset = " " . T('Reset') . " ";
815 $reset = (($reset) ?
" $reset " : '');
818 $output = "\n\t\t<input type=\"submit\" class=\"button\" name=\"__submit__\" value=\"$submit\" accesskey=\"s\" />";
819 $output .= ($reset ?
"\n\t\t<input type=\"reset\" class=\"button\" name=\"__reset__\" value=\"$reset\" accesskey=\"r\" />" : '');
820 $output .= ($extra ?
"\n\t\t$extra" : '');
822 $this->row_tfoot($output, $colspan);
825 // ###################################################################
827 * Creates an upload row; you need to specify some other paramaters in
828 * form_start() for this to work
832 * @param string Label text
833 * @param string Upload name
834 * @param integer Colspan attribute
836 function row_upload($label, $name, $colspan = 2)
838 $this->row_text($label, "<input type=\"file\" class=\"button\" name=\"$name\" size=\"35\" />", 'top', $colspan);
841 // ###################################################################
843 * Adds a name-value pair to an array that is constructed into a
848 * @param string Text displayed for the option
849 * @param string Value of the option
850 * @param bool Whether or not to select this particluar option
852 function list_item($name, $value, $selected = false
)
856 $listitem["$value"] = array('name' => $name, 'selected' => $selected);
859 // ###################################################################
861 * Assembles a <select> table row from list_item() items
865 * @param string Label text
866 * @param string Name of the <select>
867 * @param bool Automatically submit the form on a change?
868 * @param integer Colspan attribute
870 function row_list($label, $name, $is_jump = false
, $colspan = 2)
874 foreach ($listitem AS $value => $option)
876 $optionlist .= "\n\t<option value=\"$value\"" . ($option['selected'] == true ?
' selected="selected"' : '') . ">$option[name]</option>";
881 $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=\" " . T('Go') . " \" accesskey=\"g\" />" : '') . "\n", $colspan);
884 // ###################################################################
886 * Assembles a list of checkboxes from list_item() items
890 * @param string Label text
891 * @param string Name of the <input>s
892 * @param integer Colspan attribute
894 function row_checkbox($label, $name, $colspan = 2)
898 foreach ($listitem AS $value => $box)
900 $optionlist[] = "\n\t<input type=\"checkbox\" class=\"button\" name=\"{$name}[]\" value=\"$value\"" . ($box['selected'] == true ?
' checked="checked"' : '') . " /> $box[name]";
905 $this->row_text($label, "\n" . implode('<br />', $optionlist) . "\n", $colspan);
908 // ###################################################################
910 * Creates a row with two radio buttons: yes and now
914 * @param string Label text
915 * @param string Name of the BOOL flag
916 * @param bool TRUE to select the YES by default; FALSE for NO
917 * @param integer Colspan attribute
919 function row_yesno($label, $name, $value, $colspan = 2)
921 $this->row_text($label, "<input type=\"radio\" name=\"$name\" value=\"1\"" . (($value) ?
' checked="checked"' : '') . " /> " . T('Yes') . " <input type=\"radio\" name=\"$name\" value=\"0\"" . ((!$value) ?
' checked="checked"' : '') . " /> " . T('No'), $colspan);
925 /*=====================================================================*\
926 || ###################################################################
929 || ###################################################################
930 \*=====================================================================*/