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 public function __construct(&$registry)
99 $this->registry
=& $registry;
102 // ###################################################################
106 * @param string Field name
107 * @param mixed Value of the field
109 public function set($name, $value)
111 $this->registry
->do_set($name, $value, 'printer');
114 // ###################################################################
118 * @param string Field name
120 * @return mixed Value of the field
122 public function get($fieldname)
124 return $this->registry
->do_get($fieldname, 'printer');
127 // ###################################################################
129 * Creates a redirect to another page; constructs the header and footer
130 * (therefore execution stops)
132 * @param string Location to redirect to
133 * @param string Redirect message to be shown
134 * @param array An aray of POST variables to send through on the redirect
136 public function redirect($location, $message = null, $postvars = array())
143 <script type="text/javascript">
145 var timeout = $timeout;
149 setTimeout("redirect()", $timeout);
158 document.forms.postvars.submit();
168 <script type="text/javascript">
170 var timeout = $timeout;
174 setTimeout("redirect()", $timeout);
183 window.location = "$location";
190 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
192 define('ISSO_PRINTER_NO_NAVIGATION', 1);
195 $this->page_start($this->registry
->modules
['localize']->string('Redirect'));
199 $this->form_start($location, null, false, 'postvars');
201 foreach ($postvars AS $key => $value)
203 $this->form_hidden_field($key, $value);
209 $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);
211 if ($message == null)
213 $showmessage = $redir;
217 $showmessage = '<blockquote>' . $message . '</blockquote>';
218 $showmessage .= "\n<p>" . $redir . "</p>";
222 $this->page_message($this->registry
->modules
['localize']->string('Redirect'), $showmessage, $override);
224 $this->page_code($js);
229 // ###################################################################
231 * Throws a fatal error; constructs the header and footer
233 * @param string Error messsage text
235 public function error($message)
237 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
239 define('ISSO_PRINTER_NO_NAVIGATION', 1);
242 $this->page_start($this->registry
->modules
['localize']->string('Error'));
243 $this->page_message($this->registry
->modules
['localize']->string('Error'), $message);
249 // ###################################################################
251 * Outputs the header of the page: doctype, <html>, <head>, <title>,
252 * <body> and imbeds the style information
254 * @param string Title of the page
255 * @param string Class of the page to be applied to the body
256 * @param integer Margin of the <div> that all content is placed in
257 * @param string Extra HTML to imbed in the <head> tag
258 * @param string <body> onLoad action to imbed
259 * @param integer Margin of the actual <body > tag
260 * @param string Relative path where the CSS data is stored
261 * @param bool Will force re-print the header if it has already been printed
263 public function page_start($actiontitle, $pageclass = ':default:', $pagemargin = 15, $extra = '', $onload = false, $margin = 0, $dotpath = '.', $override = false)
265 $this->registry
->check_isso_fields(get_class($this));
267 if ($this->registry
->debug
AND isset($_GET['query']))
272 if (defined('ISSO_PRINTER_DONE_HEADER') AND !$override)
274 if (constant('ISSO_PRINTER_DONE_HEADER') AND !$override)
280 $title = sprintf($this->registry
->modules
['localize']->string('%1$s - %2$s - %3$s'), $this->registry->application, $this->realm, $actiontitle);
282 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
283 echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>";
284 echo "\n\t<title>$title</title>";
285 echo "\n\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
288 echo ($extra ? "\n$extra" : '');
289 echo "\n</head>\n<body style=\"margin: {$margin}px;\"" . (($pageclass !== ':default:') ? " class=\"$pageclass\"" : '') . (($onload) ? " onload=\"$onload\"" : '') . ">\n";
291 if (is_callable($this->page_start_hook))
293 call_user_func($this->page_start_hook);
296 echo "<div style=\"margin: {$pagemargin}px;\">\n<!-- / page head -->\n\n";
298 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)))
300 echo $this->registry->modules['printer_navigation
']->generate_header_html();
303 if (!defined('ISSO_PRINTER_DONE_HEADER
'))
305 define('ISSO_PRINTER_DONE_HEADER
', 1);
309 // ###################################################################
311 * Links CSS to the page from a given relative path
313 * @param string Relative path to the CSS file
315 public function css_link($path)
317 $this->css .= "\n\t<link rel=\"stylesheet\" href=\"$path\" />";
320 // ###################################################################
322 * Imbeds actual CSS information into the page in <style> tags
324 * @param string Path of the CSS file to be imbeded
326 public function css_imbed($path)
328 $data = require_once($path);
329 $css = preg_replace('#/\*(.*?)\*/(\r|\n)*#s', '', $css);
331 $this->css
.= "\n\t<style type=\"text/css\">\n\t<!--\n" . $css . "\n\t//-->\n\t</style>";
334 // ###################################################################
336 * Places raw HTML code directly into the documet at the current
339 * @param string HTML code
341 public function page_code($code)
343 if (defined('ISSO_PRINTER_DONE_HEADER'))
345 echo "\n\n$code\n\n";
349 $this->code
.= "\n\n$code\n\n";
353 // ###################################################################
355 * A block function that produces a table with a message in it. This
356 * does not print the header and footer.
358 * @param string The title of the message (appears at the top of the block)
359 * @param string Content of the message
360 * @param bool Override the message: control the entire output (no <blockquote>)?
362 public function page_message($title, $message, $overridemessage = false)
364 $this->table_start(true, '75%');
365 $this->table_head($title, 1);
366 $this->row_span(($overridemessage ? $message : "<blockquote>$message</blockquote>"), ':swap:', 'left', 1);
370 // ###################################################################
372 * Produces an entire page layout that asks the user whether or not
373 * they want to perform X action and provides a link to the YES and NO
376 * @param string Message that asks if they want to do X
377 * @param string Location to go for YES
378 * @param string DO action to pass
379 * @param array Hidden parameters to pass to the next page
381 public function page_confirm($message, $location, $action, $params)
383 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
385 define('ISSO_PRINTER_NO_NAVIGATION', 1);
388 $this->page_start($this->registry
->modules
['localize']->string('Confirm'));
390 $this->form_start($location, $action);
391 foreach ($params AS $key => $value)
393 $this->form_hidden_field($key, $value);
396 $this->table_start(true, '75%');
397 $this->table_head($this->registry
->modules
['localize']->string('Confirm'), 1);
398 $this->row_span("<blockquote>$message</blockquote>", ':swap:', 'left', 1);
399 $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'), '');
407 // ###################################################################
409 * Closes the HTML document structure an adds the copyright; this also
410 * stops execution of the page
412 public function page_end()
414 if ($this->registry
->debug
AND isset($_GET['query']))
419 if (is_array($this->registry
->modules
[ISSO_DB_LAYER
]->history
))
421 foreach ($this->registry
->modules
[ISSO_DB_LAYER
]->history
AS $query)
423 echo $this->registry
->modules
[ISSO_DB_LAYER
]->construct_query_debug($query);
429 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)))
431 echo $this->registry
->modules
['printer_navigation']->generate_footer_html();
434 $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>";
436 if (!defined('ISSO_PRINTER_HIDE_SETUP'))
438 echo "\n<!-- page end -->\n</div>\n$copyright";
439 echo $this->registry->construct_debug_block(false);
443 echo "\n
<!-- page end
-->\n</div
>";
446 echo "\n\n
</body
>\n</html
>";
451 // -------------------------------------------------------------------
453 // ###################################################################
455 * Opens a <table> tag with styling
457 * @param bool Whether to add a <br /> before the table
458 * @param string Value of the width attribute
460 public function table_start($break = true, $width = '90%')
467 echo "\n
<table cellpadding
=\"4\" cellspacing
=\"1\" border
=\"0\" align
=\"center\" width
=\"$width\" class=\"tborder\"
>\n";
470 // ###################################################################
472 * Adds a table row that is sued to head the entire table
474 * @param string Title string
475 * @param integer Colspan attribute value
476 * @param bool Whether to bold the title
478 public function table_head($title, $colspan = 2, $strong = true)
480 echo "<tr
>\n\t<td
class=\"tcat\" align
=\"center\" colspan
=\"$colspan\">" . (($strong) ? "<strong
>$title</strong
>" : $title) . "</td
>\n</tr
>\n";
483 // ###################################################################
485 * Creates column headings; useful for a grid-style page. This uses a
486 * different styling than table_head() and is usually used directly
487 * after a table header.
489 * @param array Array of titles to print
491 public function table_column_head($columnarray)
493 if (is_array($columnarray))
495 $render = "<tr valign
=\"top\" align
=\"center\"
>\n";
497 foreach ($columnarray AS $header)
499 $render .= "\t
<td
class=\"thead\" align
=\"center\"
>$header</td
>\n";
502 $render .= "</tr
>\n";
508 // ###################################################################
510 * Closes a <table> tag
512 public function table_end()
517 // -------------------------------------------------------------------
519 // ###################################################################
521 * Starts a <form> tag and adds the DO hidden input field
523 * @param string Action/name of the file to action to
524 * @param string Value of the DO parameter; used to do-branch
525 * @param bool Enctype attribute; used for mime/multi-part
526 * @param string Name of the form; this only matters for DOM access
527 * @param string Method to action as; POST or GET (default is POST)
529 public function form_start($action, $do, $enctype = false, $name = 'inputform', $submitmethod = 'post')
531 echo "\n
<!-- input form
-->\n<form name
=\"$name\" action
=\"$action\"" . (($enctype) ? " enctype
=\"$enctype\"" : '') . " method
=\"$submitmethod\">\n";
535 $this->form_hidden_field('do', $do);
539 // ###################################################################
541 * Adds a hidden field at the current location
543 * @param string Name of the field
544 * @param string Value of the field
546 public function form_hidden_field($name, $value)
548 echo "<input type
=\"hidden\" name
=\"$name\" value
=\"$value\" />\n";
551 // ###################################################################
553 * Closes a <form> tag
555 public function form_end()
557 echo "</form
>\n<!-- / input form
-->\n";
560 // -------------------------------------------------------------------
562 // ###################################################################
564 * Creates a table row that spans an entire row; this is used to divide
567 * @param string Text to place in the row
568 * @param string Class name to style with; by default it alternates between alt1 and alt2 (use :swap: to do that)
569 * @param string Alignment of the text in the row
570 * @param integer Colspan attribute
572 public function row_span($text, $class = ':swap:', $align = 'left', $colspan = 2)
574 if ($class === ':swap:')
576 $this->registry->modules['functions']->exec_swap_bg();
577 $row_class = $this->registry->modules['functions']->bgcolour;
578 $is_style_element = false;
582 if (preg_match('#:style:(.*?)#i', $class))
584 $is_style_element = true;
585 $style = str_replace(':style:', '', $class);
590 $is_style_element = false;
594 echo "\n
<tr
>\n\t<td
". (($is_style_element) ? "style
=\"$style\"" : "class=\"$row_class\"") . " colspan
=\"$colspan\" align
=\"$align\">$text</td
>\n</tr
>";
597 // ###################################################################
599 * Creates a table row that has more than two columns; this is used in
600 * conjunction with table_column_head() usually; it takes an array of
603 * @param array Array of values in form value => alignment key (c for center, l for left, and r for right)
605 public function row_multi_item($row_array)
607 $this->registry->modules['functions']->exec_swap_bg();
609 foreach ($row_array AS $item => $align)
611 $row_data["$align"][] = $item;
614 echo "<tr valign=\"top\">";
616 foreach ($row_data AS $align_key => $item_array)
618 if ($align_key == 'c')
622 else if ($align_key == 'l')
626 else if ($align_key == 'r')
631 foreach ($item_array AS $value)
633 echo "\n\t<td class=\"{$this->registry->modules['functions']->bgcolour}\" align=\"$align\">$value</td>";
640 // ###################################################################
642 * Generic row creation function that has two columns: label and value;
643 * this is used for many other form functions, but can also be used for
644 * non-editable fields
646 * @param string Label text
647 * @param string HTML or text to place in the value column
648 * @param string Vertical align (valign attribute) for the row
649 * @param integer Colspan attribute
650 * @param string Class to style the row with; default is to alternate
652 public function row_text($label, $value = ' ', $valign = 'top', $colspan = 2, $class = -1)
660 $this->registry
->modules
['functions']->exec_swap_bg();
661 $row_class = $this->registry
->modules
['functions']->bgcolour
;
673 echo "<tr valign=\"$valign\">";
674 echo "\n\t<td class=\"$row_class\">$label</td>";
675 echo "\n\t<td class=\"$row_class\" colspan=\"" . ($colspan - 1) . "\">$value</td>";
680 // ###################################################################
682 * Creates a table row with an <input> text field as the value column
684 * @param string Label text
685 * @param string Name of the <input> field
686 * @param string Value of the field
687 * @param integer Colspan attribute
688 * @param integer Size of the <input> field
689 * @param integer Length attribute; use FALSE for no length to be specified
690 * @param bool Whether to make this a password field
691 * @param string Vertical align (valign attribute)
693 public function row_input($label, $name, $value = '', $colspan = 2, $size = 35, $length = false, $password = false, $lalign = 'top')
695 $this->row_text($label, "<input type=\"" . (($password) ? 'password' : 'text') . "\" class=\"input\" name=\"$name\" value=\"$value\" size=\"$size\" " . (($length) ? "maxlength=\"$length\" " : '') . "/>", $lalign, $colspan);
698 // ###################################################################
700 * Creates a table row with a <textarea> as the value column
702 * @param string Label text
703 * @param string Name of the <textarea>
704 * @param string Value of the <textarea>
705 * @param integer Colspan attribute
706 * @param integer Number of rows in the <textarea>
707 * @param integer Number of colums in the <textarea>
708 * @param bool Whether or not to use monospacing font
709 * @param string Extra style attributes to apply to the <textarea>
711 public function row_textarea($label, $name, $value = '', $colspan = 2, $rows = 7, $cols = 50, $code = false, $style = '')
713 $this->row_text($label, "<textarea name=\"$name\" class=\"" . (($code) ? 'code' : 'input') . "\" rows=\"$rows\" cols=\"$cols\"" . (($style) ? ' style="' . $style . '"' : '') . ">$value</textarea>", 'top', $colspan);
716 // ###################################################################
718 * Creates a table row with the tfoot class
720 * @param string Extra text or HTML to insert into the row
721 * @param integer Colspan attribute
723 public function row_tfoot($data, $colspan = 2)
725 echo $this->row_span($data, 'tfoot', 'center', $colspan);
728 // ###################################################################
730 * Creates a tfoot table row with submit buttons
732 * @param string Extra HTML to imbed in the row after the buttons
733 * @param string Submit button text (by default it uses pre-translated "Submit" from :save:)
734 * @param string Reset button text (default it uses pre-translated "Reset" from :reset:)
735 * @param integer Colspan attribute
737 public function row_submit($extra = false, $submit = ':save:', $reset = ':reset:', $colspan = 2)
739 if ($submit === ':save:')
741 $submit = " " . $this->registry
->modules
['localize']->string('Submit') . " ";
745 $submit = " $submit ";
748 if ($reset === ':reset:')
750 $reset = " " . $this->registry
->modules
['localize']->string('Reset') . " ";
754 $reset = (($reset) ? " $reset " : '');
757 $output = "\n\t\t<input type=\"submit\" class=\"button\" name=\"__submit__\" value=\"$submit\" accesskey=\"s\" />";
758 $output .= ($reset ? "\n\t\t<input type=\"reset\" class=\"button\" name=\"__reset__\" value=\"$reset\" accesskey=\"r\" />" : '');
759 $output .= ($extra ? "\n\t\t$extra" : '');
761 $this->row_tfoot($output, $colspan);
764 // ###################################################################
766 * Creates an upload row; you need to specify some other paramaters in
767 * form_start() for this to work
769 * @param string Label text
770 * @param string Upload name
771 * @param integer Colspan attribute
773 public function row_upload($label, $name, $colspan = 2)
775 $this->row_text($label, "<input type
=\"file\"
class=\"button\" name
=\"$name\" size
=\"35\" />", 'top', $colspan);
778 // ###################################################################
780 * Adds a name-value pair to an array that is constructed into a
783 * @param string Text displayed for the option
784 * @param string Value of the option
785 * @param bool Whether or not to select this particluar option
787 public function list_item($name, $value, $selected = false)
791 $listitem["$value"] = array('name' => $name, 'selected' => $selected);
794 // ###################################################################
796 * Assembles a <select> table row from list_item() items
798 * @param string Label text
799 * @param string Name of the <select>
800 * @param bool Automatically submit the form on a change?
801 * @param integer Colspan attribute
803 public function row_list($label, $name, $is_jump = false, $colspan = 2)
807 foreach ($listitem AS $value => $option)
809 $optionlist .= "\n\t<option value=\"$value\"" . ($option['selected'] == true ? ' selected="selected"' : '') . ">$option[name]</option>";
814 $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);
817 // ###################################################################
819 * Assembles a list of checkboxes from list_item() items
821 * @param string Label text
822 * @param string Name of the <input>s
823 * @param integer Colspan attribute
825 public function row_checkbox($label, $name, $colspan = 2)
829 foreach ($listitem AS $value => $box)
831 $optionlist[] = "\n\t<input type=\"checkbox\" class=\"button\" name=\"{$name}[]\" value=\"$value\"" . ($box['selected'] == true ? ' checked="checked"' : '') . " /> $box[name]";
836 $this->row_text($label, "\n" . implode('<br />', $optionlist) . "\n", $colspan);
839 // ###################################################################
841 * Creates a row with two radio buttons: yes and now
843 * @param string Label text
844 * @param string Name of the BOOL flag
845 * @param bool TRUE to select the YES by default; FALSE for NO
846 * @param integer Colspan attribute
848 public function row_yesno($label, $name, $value, $colspan = 2)
850 $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);
854 /*=====================================================================*\
855 || ###################################################################
858 || ###################################################################
859 \*=====================================================================*/