]>
src.bluestatic.org Git - isso.git/blob - printer.php
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
61 // ###################################################################
65 function __construct (& $registry )
67 $this- > registry
=& $registry ;
70 // ###################################################################
74 function Printer (& $registry )
76 $this- > __construct ( $registry );
79 // ###################################################################
81 * Creates a redirect to another page; constructs the header and footer
82 * (therefore execution stops)
86 * @param string Location to redirect to
87 * @param integer Time to wait before the redirect
88 * @param array An aray of POST variables to send through on the redirect
90 function redirect ( $location , $timeout = 10 , $postvars = array ())
92 $timeout = $timeout * 200 ;
97 <script type="text/javascript">
99 var timeout = $timeout ;
103 setTimeout("redirect()", $timeout );
112 document.forms.postvars.submit();
122 <script type="text/javascript">
124 var timeout = $timeout ;
128 setTimeout("redirect()", $timeout );
137 window.location = " $location" ;
144 $this- > page_start ( $this- > registry
-> modules
[ 'localize' ]-> string ( 'Redirect' ));
148 $this- > form_start ( $location , null , false , 'postvars' );
150 foreach ( $postvars AS $key => $value )
152 $this- > form_hidden_field ( $key , $value );
158 $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 ));
160 $this- > page_code ( $js );
165 // ###################################################################
167 * Throws a fatal error; constructs the header and footer
171 * @param string Error messsage text
173 function error ( $message )
175 $this- > page_start ( $this- > registry
-> modules
[ 'localize' ]-> string ( 'Error' ));
176 $this- > page_message ( $this- > registry
-> modules
[ 'localize' ]-> string ( 'Error' ), $message );
182 // ###################################################################
184 * Outputs the header of the page: doctype, <html>, <head>, <title>,
185 * <body> and imbeds the style information
189 * @param string Title of the page
190 * @param string Class of the page to be applied to the body
191 * @param integer Margin of the <div> that all content is placed in
192 * @param string Extra HTML to imbed in the <head> tag
193 * @param string <body> onLoad action to imbed
194 * @param integer Margin of the actual <body > tag
195 * @param string Relative path where the CSS data is stored
196 * @param bool Will force re-print the header if it has already been printed
198 function page_start ( $actiontitle , $pageclass = ':default:' , $pagemargin = 15 , $extra = '' , $onload = false , $margin = 0 , $dotpath = '.' , $override = false )
200 if ( $this- > registry
-> debug
AND isset ( $_GET [ 'query' ]))
205 if ( defined ( 'DONE_HEADER' ) AND ! $override )
207 if ( constant ( 'DONE_HEADER' ) AND ! $override )
213 $title = sprintf ( $this- > registry
-> modules
[ 'localize' ]-> string ( '%1 $s - %2 $s - %3 $s' ), $this- >registry->application, $this- >realm, $actiontitle );
215 echo "<!DOCTYPE html PUBLIC \" -//W3C//DTD XHTML 1.0 Transitional//EN \" \" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd \" > \n ";
216 echo "<html xmlns= \" http://www.w3.org/1999/xhtml \" > \n <head>";
217 echo " \n\t <title> $title </title>";
218 echo " \n\t <meta http-equiv= \" Content-Type \" content= \" text/html; charset=utf-8 \" />";
220 echo ( $extra ? " \n $extra" : ' ');
221 echo " \n </head> \n <body style= \" margin: {$margin} px; \" " . (( $pageclass !== ' : default : ') ? " class= \" $pageclass\" " : ' ') . (( $onload ) ? " onload= \" $onload\" " : ' ') . "> \n ";
223 if (!defined(' HIDE_SETUP
') AND function_exists(' _printer_page_start
'))
225 _printer_page_start();
228 echo "<div style= \" margin: {$pagemargin} px; \" > \n <!-- / page head --> \n\n ";
230 if (!defined(' DONE_HEADER
'))
232 define(' DONE_HEADER
', 1);
236 // ###################################################################
238 * Links CSS to the page from a given relative path
242 * @param string Relative path to the CSS file
244 function css_link( $path )
246 $this- >css .= " \n\t <link rel= \" stylesheet \" href= \" $path\" />";
249 // ###################################################################
251 * Imbeds actual CSS information into the page in <style> tags
255 * @param string Path of the CSS file to be imbeded
257 function css_imbed( $path )
259 $data = require_once( $path );
260 $css = preg_replace(' #/\*(.*?)\*/(\r|\n)*#s', '', $css);
262 $this- > css
.= " \n\t <style type= \" text/css \" > \n\t <!-- \n " . $css . " \n\t //--> \n\t </style>" ;
265 // ###################################################################
267 * Places raw HTML code directly into the documet at the current
272 * @param string HTML code
274 function page_code ( $code )
276 echo " \n\n $code\n\n " ;
279 // ###################################################################
281 * A block function that produces a table with a message in it. This
282 * does not print the header and footer.
286 * @param string The title of the message (appears at the top of the block)
287 * @param string Content of the message
289 function page_message ( $title , $message )
291 $this- > table_start ( true , '75%' );
292 $this- > table_head ( $title , 1 );
293 $this- > row_span ( "<blockquote> $message </blockquote>" , ':swap:' , 'left' , 1 );
297 // ###################################################################
299 * Produces an entire page layout that asks the user whether or not
300 * they want to perform X action and provides a link to the YES and NO
305 * @param string Message that asks if they want to do X
306 * @param string Location to go for YES
307 * @param string DO action to pass
308 * @param array Hidden parameters to pass to the next page
310 function page_confirm ( $message , $location , $action , $params )
312 $this- > page_start ( $this- > registry
-> modules
[ 'localize' ]-> string ( 'Confirm' ));
314 $this- > form_start ( $location , $action );
315 foreach ( $params AS $key => $value )
317 $this- > form_hidden_field ( $key , $value );
320 $this- > table_start ( true , '75%' );
321 $this- > table_head ( $this- > registry
-> modules
[ 'localize' ]-> string ( 'Confirm' ), 1 );
322 $this- > row_span ( "<blockquote> $message </blockquote>" , ':swap:' , 'left' , 1 );
323 $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' ), '' );
331 // ###################################################################
333 * Closes the HTML document structure an adds the copyright; this also
334 * stops execution of the page
340 if ( $this- > registry
-> debug
AND isset ( $_GET [ 'query' ]))
345 if ( is_array ( $this- > registry
-> modules
[ ISSO_DB_LAYER
]-> history
))
348 foreach ( $this- > registry
-> modules
[ ISSO_DB_LAYER
]-> history
AS $query )
350 echo $query . " \n\n <hr /> \n\n " ;
357 $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>" ;
359 if (! defined ( 'HIDE_SETUP' ))
361 echo " \n <!-- page end --> \n </div> \n $copyright" ;
362 echo $this- >registry->construct_debug_block(false);
366 echo " \n
<!-- page end
-->\n</ div
> ";
369 echo " \n\n
</ body
>\n</ html
> ";
374 // -------------------------------------------------------------------
376 // ###################################################################
378 * Opens a <table> tag with styling
382 * @param bool Whether to add a <br /> before the table
383 * @param string Value of the width attribute
385 function table_start( $break = true, $width = '90%')
392 echo " \n
< table cellpadding
=\" 4\" cellspacing
=\" 0\" border
=\" 0\" align
=\" center\" width
=\" $width\" class =\" tborder\"
>\n ";
395 // ###################################################################
397 * Adds a table row that is sued to head the entire table
401 * @param string Title string
402 * @param integer Colspan attribute value
403 * @param bool Whether to bold the title
405 function table_head( $title , $colspan = 2, $strong = true)
407 echo " < tr
>\n\t< td
class =\" tcat\" align
=\" center\" colspan
=\" $colspan\" > " . (( $strong ) ? " < strong
> $title </ strong
> " : $title ) . " </ td
>\n</ tr
>\n ";
410 // ###################################################################
412 * Creates column headings; useful for a grid-style page. This uses a
413 * different styling than table_head() and is usually used directly
414 * after a table header.
418 * @param array Array of titles to print
420 function table_column_head( $columnarray )
422 if (is_array( $columnarray ))
424 $render = " < tr valign
=\" top\" align
=\" center\"
>\n ";
426 foreach ( $columnarray AS $header )
428 $render .= " \t
< td
class =\" thead\" align
=\" center\"
> $header </ td
>\n ";
431 $render .= " </ tr
>\n ";
437 // ###################################################################
439 * Closes a <table> tag
448 // -------------------------------------------------------------------
450 // ###################################################################
452 * Starts a <form> tag and adds the DO hidden input field
456 * @param string Action/name of the file to action to
457 * @param string Value of the DO parameter; used to do-branch
458 * @param bool Enctype attribute; used for mime/multi-part
459 * @param string Name of the form; this only matters for DOM access
460 * @param string Method to action as; POST or GET (default is POST)
462 function form_start( $action , $do , $enctype = false, $name = 'inputform', $submitmethod = 'post')
464 echo " \n
<!-- input form
-->\n< form name
=\" $name\" action
=\" $action\" " . (( $enctype ) ? " enctype
=\" $enctype\" " : '') . " method
=\" $submitmethod\" >\n ";
468 $this- >form_hidden_field('do', $do );
472 // ###################################################################
474 * Adds a hidden field at the current location
478 * @param string Name of the field
479 * @param string Value of the field
481 function form_hidden_field( $name , $value )
483 echo " < input type
=\" hidden\" name
=\" $name\" value
=\" $value\" />\n ";
486 // ###################################################################
488 * Closes a <form> tag
494 echo " </ form
>\n<!-- / input form
-->\n ";
497 // -------------------------------------------------------------------
499 // ###################################################################
501 * Creates a table row that spans an entire row; this is used to divide
506 * @param string Text to place in the row
507 * @param string Class name to style with; by default it alternates between alt1 and alt2 (use :swap: to do that)
508 * @param string Alignment of the text in the row
509 * @param integer Colspan attribute
511 function row_span( $text , $class = ':swap:', $align = 'left', $colspan = 2)
513 if ( $class === ':swap:')
515 $this- >registry->modules['functions']->exec_swap_bg();
516 $row_class = $this- >registry->modules['functions']->bgcolour;
517 $is_style_element = false;
521 if (preg_match('#:style:(.*?)#i', $class ))
523 $is_style_element = true;
524 $style = str_replace(':style:', '', $class );
529 $is_style_element = false;
533 echo " \n
< tr
>\n\t< td
". (( $is_style_element ) ? " style
=\" $style\" " : " class =\" $row_class\" ") . " colspan
=\" $colspan\" align
=\" $align\" > $text </ td
>\n</ tr
> ";
536 // ###################################################################
538 * Creates a table row that has more than two columns; this is used in
539 * conjunction with table_column_head() usually; it takes an array of
544 * @param array Array of values in form value => alignment key (c for center, l for left, and r for right)
546 function row_multi_item( $row_array )
548 $this- >registry->modules['functions']->exec_swap_bg();
550 foreach ( $row_array AS $item => $align )
552 $row_data [" $align" ][] = $item ;
555 echo "<tr valign= \" top \" >" ;
557 foreach ( $row_data AS $align_key => $item_array )
559 if ( $align_key == 'c' )
563 else if ( $align_key == 'l' )
567 else if ( $align_key == 'r' )
572 foreach ( $item_array AS $value )
574 echo " \n\t <td class= \"{ $this->registry->modules['functions']->bgcolour} \" align= \" $align\" > $value </td>" ;
581 // ###################################################################
583 * Generic row creation function that has two columns: label and value;
584 * this is used for many other form functions, but can also be used for
585 * non-editable fields
589 * @param string Label text
590 * @param string HTML or text to place in the value column
591 * @param string Vertical align (valign attribute) for the row
592 * @param integer Colspan attribute
593 * @param string Class to style the row with; default is to alternate
595 function row_text ( $label , $value = ' ' , $valign = 'top' , $colspan = 2 , $class = - 1 )
603 $this- > registry
-> modules
[ 'functions' ]-> exec_swap_bg ();
604 $row_class = $this- > registry
-> modules
[ 'functions' ]-> bgcolour
;
616 echo "<tr valign= \" $valign\" >" ;
617 echo " \n\t <td class= \" $row_class\" > $label </td>" ;
618 echo " \n\t <td class= \" $row_class\" > $value </td>" ;
622 echo " \n\t <td class= \" $row_class\" colspan= \" " . $colspan - 2 . " \" > </td>" ;
628 // ###################################################################
630 * Creates a table row with an <input> text field as the value column
634 * @param string Label text
635 * @param string Name of the <input> field
636 * @param string Value of the field
637 * @param integer Colspan attribute
638 * @param integer Size of the <input> field
639 * @param integer Length attribute; use FALSE for no length to be specified
640 * @param bool Whether to make this a password field
641 * @param string Vertical align (valign attribute)
643 function row_input ( $label , $name , $value = '' , $colspan = 2 , $size = 35 , $length = false , $password = false , $lalign = 'top' )
645 $this- > row_text ( $label , "<input type= \" " . (( $password ) ? 'password' : 'text' ) . " \" class= \" input \" name= \" $name\" value= \" $value\" size= \" $size\" " . (( $length ) ? "maxlength= \" $length\" " : '' ) . "/>" , $lalign , $colspan );
648 // ###################################################################
650 * Creates a table row with a <textarea> as the value column
654 * @param string Label text
655 * @param string Name of the <textarea>
656 * @param string Value of the <textarea>
657 * @param integer Colspan attribute
658 * @param integer Number of rows in the <textarea>
659 * @param integer Number of colums in the <textarea>
660 * @param bool Whether or not to use monospacing font
661 * @param string Extra style attributes to apply to the <textarea>
663 function row_textarea ( $label , $name , $value = '' , $colspan = 2 , $rows = 7 , $cols = 50 , $code = false , $style = '' )
665 $this- > row_text ( $label , "<textarea name= \" $name\" class= \" " . (( $code ) ? 'code' : 'input' ) . " \" rows= \" $rows\" cols= \" $cols\" " . (( $style ) ? ' style="' . $style . '"' : '' ) . "> $value </textarea>" , 'top' , $colspan );
668 // ###################################################################
670 * Creates a table row with the tfoot class
674 * @param string Extra text or HTML to insert into the row
675 * @param integer Colspan attribute
677 function row_tfoot ( $data , $colspan = 2 )
679 echo $this- > row_span ( $data , 'tfoot' , 'center' , $colspan );
682 // ###################################################################
684 * Creates a tfoot table row with submit buttons
688 * @param string Extra HTML to imbed in the row after the buttons
689 * @param string Submit button text (by default it uses pre-translated "Submit" from :save:)
690 * @param string Reset button text (default it uses pre-translated "Reset" from :reset:)
691 * @param integer Colspan attribute
693 function row_submit ( $extra = false , $submit = ':save:' , $reset = ':reset:' , $colspan = 2 )
695 if ( $submit === ':save:' )
697 $submit = " " . $this- > registry
-> modules
[ 'localize' ]-> string ( 'Submit' ) . " " ;
701 $submit = " $submit " ;
704 if ( $reset === ':reset:' )
706 $reset = " " . $this- > registry
-> modules
[ 'localize' ]-> string ( 'Reset' ) . " " ;
710 $reset = (( $reset ) ? " $reset " : '' );
713 $output = " \n\t\t <input type= \" submit \" class= \" button \" name= \" __submit__ \" value= \" $submit\" accesskey= \" s \" />" ;
714 $output .= ( $reset ? " \n\t\t <input type= \" reset \" class= \" button \" name= \" __reset__ \" value= \" $reset\" accesskey= \" r \" />" : '' );
715 $output .= ( $extra ? " \n\t\t $extra" : '');
717 $this- >row_tfoot( $output , $colspan );
720 // ###################################################################
722 * Creates an upload row; you need to specify some other paramaters in
723 * form_start() for this to work
727 * @param string Label text
728 * @param string Upload name
729 * @param integer Colspan attribute
731 function row_upload( $label , $name , $colspan = 2)
733 $this- >row_text( $label , " < input type
=\" file\"
class =\" button\" name
=\" $name\" size
=\" 35\" /> ", 'top', $colspan );
736 // ###################################################################
738 * Adds a name-value pair to an array that is constructed into a
743 * @param string Text displayed for the option
744 * @param string Value of the option
745 * @param bool Whether or not to select this particluar option
747 function list_item( $name , $value , $selected = false)
751 $listitem [] = " \n\t
< option value
=\" $value\" " . (( $selected == true) ? ' selected=" selected
"' : '') . " > $name </ option
> ";
754 // ###################################################################
756 * Assembles a <select> table row from list_item() items
760 * @param string Label text
761 * @param string Name of the <select>
762 * @param bool Automatically submit the form on a change?
763 * @param integer Colspan attribute
765 function row_list( $label , $name , $is_jump = false, $colspan = 2)
769 foreach ( $listitem AS $option )
771 $optionlist .= $option ;
776 $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 );
779 // ###################################################################
781 * Creates a row with two radio buttons: yes and now
785 * @param string Label text
786 * @param string Name of the BOOL flag
787 * @param bool TRUE to select the YES by default; FALSE for NO
788 * @param integer Colspan attribute
790 function row_yesno( $label , $name , $value , $colspan = 2)
792 $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 );
796 /*=====================================================================*\
797 || ###################################################################
800 || ###################################################################
801 \*=====================================================================*/