2 /*=====================================================================*\
3 || ###################################################################
4 || # Iris Studios Shared Object Framework [#]version[#]
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.
35 * @author Iris Studios, Inc.
36 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
44 * Framework registry object
50 * Realm that we are operating in (displayed in the <title>)
53 var $realm = '[UNDEFINED REALM]';
56 * CSS to place in the page
64 function Printer(&$registry)
66 $this->registry
=& $registry;
70 * Creates a redirect to another page; constructs the header and footer (therefore execution stops)
72 * @param string Location to redirect to
73 * @param integer Time to wait before the redirect
75 function redirect($location, $timeout = 10)
77 $timeout = $timeout * 200;
81 <script type
="text/javascript">
83 var timeout
= $timeout;
87 setTimeout("redirect()", $timeout);
96 window
.location
= "$location";
102 $this->page_start($this->registry
->modules
['localize']->string('Redirect'), ':default:', 15, $js);
104 $this->page_message($this->registry
->modules
['localize']->string('Redirect'), 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));
110 * Throws a fatal error; constructs the header and footer
112 * @param string Error messsage text
114 function error($message)
116 $this->page_start($this->registry
->modules
['localize']->string('Error'));
117 $this->page_message($this->registry
->modules
['localize']->string('Error'), $message);
123 // ###################################################################
125 * Outputs the header of the page: doctype, <html>, <head>, <title>, <body>
126 * and imbeds the style information
128 * @param string Title of the page
129 * @param string Class of the page to be applied to the body
130 * @param integer Margin of the <div> that all content is placed in
131 * @param string Extra HTML to imbed in the <head> tag
132 * @param string <body> onLoad action to imbed
133 * @param integer Margin of the actual <body > tag
134 * @param string Relative path where the CSS data is stored
135 * @param bool Will force re-print the header if it has already been printed
137 function page_start($actiontitle, $pageclass = ':default:', $pagemargin = 15, $extra = '', $onload = false
, $margin = 0, $dotpath = '.', $override = false
)
139 if (constant('DONE_HEADER') AND !$override)
144 $title = sprintf($this->registry
->modules
['localize']->string('%1$s - %2$s - %3$s'), $this->registry
->application
, $this->realm
, $actiontitle);
146 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
147 echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>";
148 echo "\n\t<title>$title</title>";
149 echo "\n\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />";
151 echo ($extra ?
"\n$extra" : '');
152 echo "\n</head>\n<body style=\"margin: {$margin}px;\"" . (($pageclass !== ':default:') ?
" class=\"$pageclass\"" : '') . (($onload) ?
" onload=\"$onload\"" : '') . ">\n";
154 if (!defined('HIDE_SETUP') AND function_exists('_printer_page_start'))
156 _printer_page_start();
159 echo "<div style=\"margin: {$pagemargin}px;\">\n<!-- / page head -->\n\n";
161 if (!defined('DONE_HEADER'))
163 define('DONE_HEADER', 1);
168 * Links CSS to the page from a given relative path
170 * @param string Relative path to the CSS file
172 function css_link($path)
174 $this->css
.= "\n\t<link rel=\"stylesheet\" href=\"$path\" />";
178 * Imbeds actual CSS information into the page in <style> tags
180 * @param string Path of the CSS file to be imbeded
182 function css_imbed($path)
184 $data = file_get_contents($path);
185 $data = preg_replace('#/\*(.*?)\*/(\r|\n)*#s', '', $data);
187 $this->css
.= "\n\t<style type=\"text/css\">\n\t<!--\n" . $data . "\n\t//-->\n\t</style>";
191 * Places raw HTML code directly into the documet at the current position
193 * @param string HTML code
195 function page_code($code)
197 echo "\n\n$code\n\n";
201 * A block function that produces a table with a message in it. This does not print the header and footer
203 * @param string The title of the message (appears at the top of the block)
204 * @param string Content of the message
206 function page_message($title, $message)
208 $this->table_start(true
, '75%');
209 $this->table_head($title, 1);
210 $this->row_span("<blockquote>$message</blockquote>", ':swap:', 'left', 1);
215 * Produces an entire page layout that asks the user whether or not they want to perform X action and provides
216 * a link to the YES action
218 * @param string Message that asks if they want to do X
219 * @param string Location to go for YES
221 function page_confirm($message, $location)
223 $this->page_start($this->registry
->modules
['localize']->string('Confirm'));
225 $this->page_message($this->registry
->modules
['localize']->string('Confirm'), $message . '<p><input type="button" name="confirm" value=" ' . $this->registry
->modules
['localize']->string('Yes') . ' " onclick="window.location = \'' . $location . '\';" />');
231 * Closes the HTML document structure an adds the copyright; this also stops execution of the page
235 $copyright = "\n<br />\n<p align=\"center\" class=\"copyright\">\n\t<a href=\"http://www.iris-studios.com\" target=\"_blank\">" . $this->registry
->application
. ' ' . $this->registry
->appversion
. ", © 2002 - " . date('Y') . " Iris Studios, Inc.</a>\n</p>";
237 if (!defined('HIDE_SETUP'))
239 echo "\n<!-- page end -->\n</div>\n$copyright";
243 echo "\n<!-- page end -->\n</div>";
246 echo "\n\n</body>\n</html>";
251 // ###################################################################
253 * Opens a <table> tag with styling
255 * @param bool Whether to add a <br /> before the table
256 * @param string Value of the width attribute
258 function table_start($break = true
, $width = '90%')
265 echo "\n<table cellpadding=\"4\" cellspacing=\"0\" border=\"0\" align=\"center\" width=\"$width\" class=\"tborder\">\n";
269 * Adds a table row that is sued to head the entire table
271 * @param string Title string
272 * @param integer Colspan attribute value
273 * @param bool Whether to bold the title
275 function table_head($title, $colspan = 2, $strong = true
)
277 echo "<tr>\n\t<td class=\"tcat\" align=\"center\" colspan=\"$colspan\">" . (($strong) ?
"<strong>$title</strong>" : $title) . "</td>\n</tr>\n";
281 * Creates column headings; useful for a grid-style page. This uses a different styling than table_head()
282 * and is usually used directly after a table header
284 * @param array Array of titles to print
286 function table_column_head($columnarray)
288 if (is_array($columnarray))
290 $render = "<tr valign=\"top\" align=\"center\">\n";
292 foreach ($columnarray AS $header)
294 $render .= "\t<td class=\"thead\" align=\"center\">$header</td>\n";
297 $render .= "</tr>\n";
304 * Closes a <table> tag
311 // ###################################################################
313 * Starts a <form> tag and adds the DO hidden input field
315 * @param string Action/name of the file to action to
316 * @param string Value of the DO parameter; used to do-branch
317 * @param bool Enctype attribute; used for mime/multi-part
318 * @param string Name of the form; this only matters for DOM access
319 * @param string Method to action as; POST or GET (default is POST)
321 function form_start($action, $do, $enctype = false
, $name = 'inputform', $submitmethod = 'post')
323 echo "\n<!-- input form -->\n<form name=\"$name\" action=\"$action\"" . (($enctype) ?
" enctype=\"$enctype\"" : '') . " method=\"$submitmethod\">\n";
324 $this->form_hidden_field('do', $do);
328 * Adds a hidden field at the current location
330 * @param string Name of the field
331 * @param string Value of the field
333 function form_hidden_field($name, $value)
335 echo "<input type=\"hidden\" name=\"$name\" value=\"$value\" />\n";
339 * Closes a <form> tag
343 echo "</form>\n<!-- / input form -->\n";
346 // ###################################################################
348 * Creates a table row that spans an entire row; this is used to divide sections, usually
350 * @param string Text to place in the row
351 * @param string Class name to style with; by default it alternates between alt1 and alt2 (use :swap: to do that)
352 * @param string Alignment of the text in the row
353 * @param integer Colspan attribute
355 function row_span($text, $class = ':swap:', $align = 'left', $colspan = 2)
357 if ($class === ':swap:')
359 $this->registry
->modules
['functions']->exec_swap_bg();
360 $row_class = $this->registry
->modules
['functions']->bgcolour
;
361 $is_style_element = false
;
365 if (preg_match('#:style:(.*?)#i', $class))
367 $is_style_element = true
;
368 $style = str_replace(':style:', '', $class);
373 $is_style_element = false
;
377 echo "<tr>\n\t<td ". (($is_style_element) ?
"style=\"$style\"" : "class=\"$row_class\"") . " colspan=\"$colspan\" align=\"$align\">$text</td>\n</tr>";
381 * Creates a table row that has more than two columns; this is used in conjunction with table_column_head()
382 * usually; it takes an array of values
384 * @param array Array of values in form value => alignment key (c for center, l for left, and r for right)
386 function row_multi_item($row_array)
388 $this->registry
->modules
['functions']->exec_swap_bg();
390 foreach ($row_array AS $item => $align)
392 $row_data["$align"][] = $item;
395 echo "<tr valign=\"top\">";
397 foreach ($row_data AS $align_key => $item_array)
399 if ($align_key == 'c')
403 else if ($align_key == 'l')
407 else if ($align_key == 'r')
412 foreach ($item_array AS $value)
414 echo "\n\t<td class=\"{$this->registry->modules['functions']->bgcolour}\" align=\"$align\">$value</td>";
422 * Generic row creation function that has two columns: label and value; this is used for many
423 * other form functions, but can also be used for non-editable fields
425 * @param string Label text
426 * @param string HTML or text to place in the value column
427 * @param string Vertical align (valign attribute) for the row
428 * @param integer Colspan attribute
429 * @param string Class to style the row with; default is to alternate
431 function row_text($label, $value = ' ', $valign = 'top', $colspan = 2, $class = -1)
439 $this->registry
->modules
['functions']->exec_swap_bg();
440 $row_class = $this->registry
->modules
['functions']->bgcolour
;
452 echo "<tr valign=\"$valign\">";
453 echo "\n\t<td class=\"$row_class\">$label</td>";
454 echo "\n\t<td class=\"$row_class\">$value</td>";
458 echo "\n\t<td class=\"$row_class\" colspan=\"" . $colspan - 2 . "\"> </td>";
465 * Creates a table row with an <input> text field as the value column
467 * @param string Label text
468 * @param string Name of the <input> field
469 * @param string Value of the field
470 * @param integer Colspan attribute
471 * @param integer Size of the <input> field
472 * @param integer Length attribute; use FALSE for no length to be specified
473 * @param bool Whether to make this a password field
474 * @param string Vertical align (valign attribute)
476 function row_input($label, $name, $value = '', $colspan = 2, $size = 35, $length = false
, $password = false
, $lalign = 'top')
478 $this->row_text($label, "<input type=\"" . (($password) ?
'password' : 'text') . "\" class=\"input\" name=\"$name\" value=\"$value\" size=\"$size\" " . (($length) ?
"maxlength=\"$length\" " : '') . "/>", $lalign, $colspan);
482 * Creates a table row with a <textarea> as the value column
484 * @param string Label text
485 * @param string Name of the <textarea>
486 * @param string Value of the <textarea>
487 * @param integer Colspan attribute
488 * @param integer Number of rows in the <textarea>
489 * @param integer Number of colums in the <textarea>
490 * @param bool Whether or not to use monospacing font
491 * @param string Extra style attributes to apply to the <textarea>
493 function row_textarea($label, $name, $value = '', $colspan = 2, $rows = 7, $cols = 50, $code = false
, $style = '')
495 $this->row_text($label, "<textarea name=\"$name\" class=\"" . (($code) ?
'code' : 'input') . "\" rows=\"$rows\" cols=\"$cols\"" . (($style) ?
' style="' . $style . '"' : '') . ">$value</textarea>", 'top', $colspan);
499 * Creates a table row with the tfoot class
501 * @param string Extra text or HTML to insert into the row
502 * @param integer Colspan attribute
504 function row_tfoot($data, $colspan = 2)
506 echo $this->row_span($data, 'tfoot', 'center');
510 * Creates a tfoot table row with submit buttons
512 * @param string Extra HTML to imbed in the row after the buttons
513 * @param string Submit button text (by default it uses pre-translated "Submit" from :save:)
514 * @param string Reset button text (default it uses pre-translated "Reset" from :reset:)
515 * @param integer Colspan attribute
517 function row_submit($extra = false
, $submit = ':save:', $reset = ':reset:', $colspan = 2)
519 if ($submit === ':save:')
521 $submit = " " . $this->registry
->modules
['localize']->string('Submit') . " ";
525 $submit = " $submit ";
528 if ($reset === ':reset:')
530 $reset = " " . $this->registry
->modules
['localize']->string('Reset') . " ";
534 $reset = (($reset) ?
" $reset " : '');
537 $output = "\n\t\t<input type=\"submit\" class=\"button\" value=\"$submit\" accesskey=\"s\" />";
538 $output .= (($reset) ?
"\n\t\t<input type=\"reset\" class=\"button\" value=\"$reset\" accesskey=\"r\" /> $extra\n\t" : '');
539 $this->row_tfoot($output);
543 * Creates an upload row; you need to specify some other paramaters in form_start() for this to work
545 * @param string Label text
546 * @param string Upload name
547 * @param integer Colspan attribute
549 function row_upload($label, $name, $colspan = 2)
551 $this->row_text($label, "<input type=\"file\" class=\"button\" name=\"$name\" size=\"35\" />", 'top', $colspan);
555 * Adds a name-value pair to an array that is constructed into a <select> list
557 * @param string Text displayed for the option
558 * @param string Value of the option
559 * @param bool Whether or not to select this particluar option
561 function list_item($name, $value, $selected = false
)
565 $listitem[] = "\n\t<option value=\"$value\"" . (($selected == true
) ?
' selected="selected"' : '') . ">$name</option>";
569 * Assembles a <select> table row from list_item() items
571 * @param string Label text
572 * @param string Name of the <select>
573 * @param bool Automatically submit the form on a change?
574 * @param integer Colspan attribute
576 function row_list($label, $name, $is_jump = false
, $colspan = 2)
580 foreach ($listitem AS $option)
582 $optionlist .= $option;
587 $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);
591 * Creates a row with two radio buttons: yes and now
593 * @param string Label text
594 * @param string Name of the BOOL flag
595 * @param bool TRUE to select the YES by default; FALSE for NO
596 * @param integer Colspan attribute
598 function row_yesno($label, $name, $value, $colspan = 2)
600 $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);
604 /*=====================================================================*\
605 || ###################################################################
608 || ###################################################################
609 \*=====================================================================*/