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 \*=====================================================================*/
29 require_once('ISSO/PrinterElement.php');
30 require_once('ISSO/PrinterBaseElement.php');
31 require_once('ISSO/PrinterLabelElement.php');
32 require_once('ISSO/PrinterRootElement.php');
33 require_once('ISSO/PrinterRootElementPage.php');
34 require_once('ISSO/PrinterRootElementTable.php');
35 require_once('ISSO/PrinterTableElement.php');
40 * This framework generates standard HTML through various functions. The purpose
41 * is generally so that things like the admin system can be created without templates.
44 * ISSO_PRINTER_DONE_HEADER - An internal constant that is used to check to see
45 * if the page header has already been printed
46 * ISSO_PRINTER_HIDE_SETUP - Will stop the page footer data (copyright and debug
47 * box) from being printed
48 * ISSO_PRINTER_NO_NAVIGATION - Do not show the navigation frame from ISSO.Printer.Navigation
51 * @copyright Copyright ©2002 - [#]year[#], Blue Static
59 * Framework registry object
62 private $registry = null
;
65 * Realm that we are operating in (displayed in the <title>)
68 private $realm = '[UNDEFINED REALM]';
71 * CSS to place in the page
86 private $page_start_hook = ':=NO METHOD=:';
89 * Language information array: ('langcode' =>, 'direction' =>, 'charset' =>)
92 private $language = array('langcode' => 'en_US', 'direction' => 'ltr', 'charset' => 'utf-8');
94 // ###################################################################
96 * Sets the realm (or title) of the printed output
98 * @param string Title/realm
100 public function setRealm($realm)
102 $this->realm
= $realm;
105 // ###################################################################
107 * Sets the language array information
109 * @param array Language array
111 public function setLanguageInformation($lang)
113 $this->language
= $lang;
116 // ###################################################################
118 * Creates a redirect to another page; constructs the header and footer
119 * (therefore execution stops)
121 * @param string Location to redirect to
122 * @param string Redirect message to be shown
123 * @param array An aray of POST variables to send through on the redirect
125 public function redirect($location, $message = null
, $postvars = array())
128 <script type="text/javascript">
134 setTimeout("redirect()", timeout);
143 ' . ($postvars ?
'document.forms.postvars.submit();' : 'window.location = "' . $location . '";') . '
149 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
151 define('ISSO_PRINTER_NO_NAVIGATION', 1);
154 $this->page_start(_('Redirect'));
158 $this->form_start($location, null
, false
, 'postvars');
160 foreach ($postvars AS $key => $value)
162 $this->form_hidden_field($key, $value);
168 $redir = sprintf(_('Please wait to be redirected. If you are not redirected in a few seconds, click <a href="%1$s">here</a>.'), $location);
170 if ($message == null
)
172 $showmessage = $redir;
176 $showmessage = '<blockquote>' . $message . '</blockquote>';
177 $showmessage .= "\n<p>" . $redir . "</p>";
181 $this->page_message(_('Redirect'), $showmessage, $override);
183 $this->page_code($js);
188 // ###################################################################
190 * Produces an entire page layout that asks the user whether or not
191 * they want to perform X action and provides a link to the YES and NO
194 * @param string Message that asks if they want to do X
195 * @param string Location to go for YES
196 * @param string DO action to pass
197 * @param array Hidden parameters to pass to the next page
199 public function confirm($message, $location, $action, $params)
201 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
203 define('ISSO_PRINTER_NO_NAVIGATION', 1);
206 $this->page_start(_('Confirm'));
208 $this->form_start($location, $action);
209 foreach ($params AS $key => $value)
211 $this->form_hidden_field($key, $value);
214 $this->table_start(true
, '75%');
215 $this->table_head(_('Confirm'), 1);
216 $this->row_span("<blockquote>$message</blockquote>", ':swap:', 'left', 1);
217 $this->row_submit('<input type="button" class="button" name="no" value=" ' . _('No') . ' " onclick="history.back(1); return false;" />', _('Yes'), '');
225 // ###################################################################
227 * Throws a fatal error; constructs the header and footer
229 * @param string Error messsage text
231 public function error($message)
233 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
235 define('ISSO_PRINTER_NO_NAVIGATION', 1);
238 $this->page_start(_('Error'));
239 $this->page_message(_('Error'), $message);
245 // ###################################################################
247 * Links CSS to the page from a given relative path
249 * @param string Relative path to the CSS file
251 public function css_link($path)
253 $this->css
.= "\n\t<link rel=\"stylesheet\" href=\"$path\" />";
256 // ###################################################################
258 * Imbeds actual CSS information into the page in <style> tags
260 * @param string Path of the CSS file to be imbeded
262 public function css_imbed($path)
264 $data = require_once($path);
265 $css = preg_replace('#/\*(.*?)\*/(\r|\n)*#s', '', $css);
267 $this->css
.= "\n\t<style type=\"text/css\">\n\t<!--\n" . $css . "\n\t//-->\n\t</style>";
270 // ###################################################################
272 * Places raw HTML code directly into the documet at the current
275 * @param string HTML code
277 public function page_code($code)
279 if (defined('ISSO_PRINTER_DONE_HEADER'))
281 echo "\n\n$code\n\n";
285 $this->code
.= "\n\n$code\n\n";
289 // ###################################################################
291 * A block function that produces a table with a message in it. This
292 * does not print the header and footer.
294 * @param string The title of the message (appears at the top of the block)
295 * @param string Content of the message
296 * @param bool Override the message: control the entire output (no <blockquote>)?
298 public function page_message($title, $message, $overridemessage = false
)
300 $this->table_start(true
, '75%');
301 $this->table_head($title, 1);
302 $this->row_span(($overridemessage ?
$message : "<blockquote>$message</blockquote>"), ':swap:', 'left', 1);
306 // ###################################################################
308 * Closes the HTML document structure an adds the copyright; this also
309 * stops execution of the page
311 public function page_end()
313 if (BSRegister
::GetDebug() AND isset($_GET['query']))
318 if (is_array($this->registry
->modules
[ISSO_DB_LAYER
]->history
))
320 foreach ($this->registry
->modules
[ISSO_DB_LAYER
]->history
AS $query)
322 echo $this->registry
->modules
[ISSO_DB_LAYER
]->construct_query_debug($query);
328 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
)))
330 echo $this->registry
->modules
['printer_navigation']->generate_footer_html();
333 $copyright = "\n<br />\n<p align=\"center\" class=\"copyright\">\n\t<a href=\"http://www.bluestatic.org\" target=\"_blank\">" . BSRegister
::GetApplication() . ' ' . BSRegister
::GetAppVersion() . ", ©2002 - " . date('Y') . " Blue Static</a>\n</p>";
335 if (!defined('ISSO_PRINTER_HIDE_SETUP'))
338 echo $this->registry
->construct_debug_block(false
);
341 echo "\n\n</body>\n</html>";
346 // -------------------------------------------------------------------
348 // ###################################################################
350 * Opens a <table> tag with styling
352 * @param bool Whether to add a <br /> before the table
353 * @param string Value of the width attribute
355 public function table_start($break = true
, $width = '90%')
362 echo "\n<table cellpadding=\"4\" cellspacing=\"1\" border=\"0\" align=\"center\" width=\"$width\" class=\"tborder\">\n";
365 // ###################################################################
367 * Adds a table row that is sued to head the entire table
369 * @param string Title string
370 * @param integer Colspan attribute value
372 public function table_head($title, $colspan = 2)
374 echo "<tr>\n\t<td class=\"tcat\" align=\"center\" colspan=\"$colspan\">$title</td>\n</tr>\n";
377 // ###################################################################
379 * Creates column headings; useful for a grid-style page. This uses a
380 * different styling than table_head() and is usually used directly
381 * after a table header.
383 * @param array Array of titles to print
385 public function table_column_head($columnarray)
387 if (is_array($columnarray))
389 $render = "<tr valign=\"top\" align=\"center\">\n";
391 foreach ($columnarray AS $header)
393 $render .= "\t<td class=\"thead\" align=\"center\">$header</td>\n";
396 $render .= "</tr>\n";
402 // ###################################################################
404 * Closes a <table> tag
406 public function table_end()
411 // -------------------------------------------------------------------
413 // ###################################################################
415 * Starts a <form> tag and adds the DO hidden input field
417 * @param string Action/name of the file to action to
418 * @param string Value of the DO parameter; used to do-branch
419 * @param bool Enctype attribute; used for mime/multi-part
420 * @param string Name of the form; this only matters for DOM access
421 * @param string Method to action as; POST or GET (default is POST)
423 public function form_start($action, $do, $enctype = false
, $name = 'inputform', $submitmethod = 'post')
425 echo "\n<!-- input form -->\n<form name=\"$name\" action=\"$action\"" . ($enctype ?
" enctype=\"$enctype\"" : '') . " method=\"$submitmethod\">\n";
429 $this->form_hidden_field('do', $do);
433 // ###################################################################
435 * Adds a hidden field at the current location
437 * @param string Name of the field
438 * @param string Value of the field
440 public function form_hidden_field($name, $value)
442 echo "<input type=\"hidden\" name=\"$name\" value=\"$value\" />\n";
445 // ###################################################################
447 * Closes a <form> tag
449 public function form_end()
451 echo "</form>\n<!-- / input form -->\n";
454 // -------------------------------------------------------------------
456 // ###################################################################
458 * Creates a table row that has more than two columns; this is used in
459 * conjunction with table_column_head() usually; it takes an array of
462 * @param array Array of values in form value => alignment key (c for center, l for left, and r for right)
464 public function row_multi_item($row_array)
466 BSFunctions
::SwapCssClasses();
468 foreach ($row_array AS $item => $align)
470 $row_data["$align"][] = $item;
473 echo "<tr valign=\"top\">";
475 foreach ($row_data AS $align_key => $item_array)
477 if ($align_key == 'c')
481 else if ($align_key == 'l')
485 else if ($align_key == 'r')
490 foreach ($item_array AS $value)
492 echo "\n\t<td class=\"" . BSFunctions
::$cssClass . "\" align=\"$align\">$value</td>";
499 // ###################################################################
501 * Generic row creation function that has two columns: label and value;
502 * this is used for many other form functions, but can also be used for
503 * non-editable fields
505 * @param string Label text
506 * @param string HTML or text to place in the value column
507 * @param string Vertical align (valign attribute) for the row
508 * @param integer Colspan attribute
509 * @param string Class to style the row with; default is to alternate
511 public function row_text($label, $value = ' ', $valign = 'top', $colspan = 2, $class = -1)
519 BSFunctions
::SwapCssClasses();
520 $row_class = BSFunctions
::$cssClass;
532 echo "<tr valign=\"$valign\">";
533 echo "\n\t<td class=\"$row_class\">$label</td>";
534 echo "\n\t<td class=\"$row_class\" colspan=\"" . ($colspan - 1) . "\">$value</td>";
539 // ###################################################################
541 * Creates a table row with a <textarea> as the value column
543 * @param string Label text
544 * @param string Name of the <textarea>
545 * @param string Value of the <textarea>
546 * @param integer Colspan attribute
547 * @param integer Number of rows in the <textarea>
548 * @param integer Number of colums in the <textarea>
549 * @param bool Whether or not to use monospacing font
550 * @param string Extra style attributes to apply to the <textarea>
552 public function row_textarea($label, $name, $value = '', $colspan = 2, $rows = 7, $cols = 50, $code = false
, $style = '')
554 $this->row_text($label, "<textarea name=\"$name\" class=\"" . ($code ?
'code' : 'input') . "\" rows=\"$rows\" cols=\"$cols\"" . ($style ?
' style="' . $style . '"' : '') . ">$value</textarea>", 'top', $colspan);
557 // ###################################################################
559 * Creates an upload row; you need to specify some other paramaters in
560 * form_start() for this to work
562 * @param string Label text
563 * @param string Upload name
564 * @param integer Colspan attribute
566 public function row_upload($label, $name, $colspan = 2)
568 $this->row_text($label, "<input type=\"file\" class=\"button\" name=\"$name\" size=\"35\" />", 'top', $colspan);
571 // ###################################################################
573 * Adds a name-value pair to an array that is constructed into a
576 * @param string Text displayed for the option
577 * @param string Value of the option
578 * @param bool Whether or not to select this particluar option
580 public function list_item($name, $value, $selected = false
)
584 $listitem["$value"] = array('name' => $name, 'selected' => $selected);
587 // ###################################################################
589 * Assembles a <select> table row from list_item() items
591 * @param string Label text
592 * @param string Name of the <select>
593 * @param bool Automatically submit the form on a change?
594 * @param integer Colspan attribute
596 public function row_list($label, $name, $is_jump = false
, $colspan = 2)
600 foreach ($listitem AS $value => $option)
602 $optionlist .= "\n\t<option value=\"$value\"" . ($option['selected'] == true ?
' selected="selected"' : '') . ">$option[name]</option>";
607 $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=\" " . _('Go') . " \" accesskey=\"g\" />" : '') . "\n", $colspan);
610 // ###################################################################
612 * Assembles a list of checkboxes from list_item() items
614 * @param string Label text
615 * @param string Name of the <input>s
616 * @param integer Colspan attribute
618 public function row_checkbox($label, $name, $colspan = 2)
622 foreach ($listitem AS $value => $box)
624 $optionlist[] = "\n\t<input type=\"checkbox\" class=\"button\" name=\"{$name}[]\" value=\"$value\"" . ($box['selected'] == true ?
' checked="checked"' : '') . " /> $box[name]";
629 $this->row_text($label, "\n" . implode('<br />', $optionlist) . "\n", $colspan);
632 // ###################################################################
634 * Creates a row with two radio buttons: yes and now
636 * @param string Label text
637 * @param string Name of the BOOL flag
638 * @param bool TRUE to select the YES by default; FALSE for NO
639 * @param integer Colspan attribute
641 public function row_yesno($label, $name, $value, $colspan = 2)
643 $this->row_text($label, "<input type=\"radio\" name=\"$name\" value=\"1\"" . ($value ?
' checked="checked"' : '') . " /> " . _('Yes') . " <input type=\"radio\" name=\"$name\" value=\"0\"" . (!$value ?
' checked="checked"' : '') . " /> " . _('No'), $colspan);
647 /*=====================================================================*\
648 || ###################################################################
651 || ###################################################################
652 \*=====================================================================*/