]>
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.
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
42 * _printer_page_start() - Define function to echo() data after the page header
45 * @author Iris Studios, Inc.
46 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
54 * Framework registry object
61 * Realm that we are operating in (displayed in the <title>)
65 var $realm = '[UNDEFINED REALM]' ;
68 * CSS to place in the page
75 * Fields array that is used in this module
80 'realm' => array ( REQ_YES
, null , false )
83 // ###################################################################
87 function __construct (& $registry )
89 $this- > registry
=& $registry ;
92 // ###################################################################
96 function Printer (& $registry )
98 $this- > __construct ( $registry );
101 // ###################################################################
107 * @param string Field name
108 * @param mixed Value of the field
110 function set ( $name , $value )
112 $this- > registry
-> do_set ( $name , $value , 'printer' );
115 // ###################################################################
117 * Creates a redirect to another page; constructs the header and footer
118 * (therefore execution stops)
122 * @param string Location to redirect to
123 * @param integer Time to wait before the redirect
124 * @param array An aray of POST variables to send through on the redirect
126 function redirect ( $location , $timeout = 10 , $postvars = array ())
128 $timeout = $timeout * 200 ;
133 <script type="text/javascript">
135 var timeout = $timeout ;
139 setTimeout("redirect()", $timeout );
148 document.forms.postvars.submit();
158 <script type="text/javascript">
160 var timeout = $timeout ;
164 setTimeout("redirect()", $timeout );
173 window.location = " $location" ;
180 $this- > page_start ( $this- > registry
-> modules
[ 'localize' ]-> string ( 'Redirect' ));
184 $this- > form_start ( $location , null , false , 'postvars' );
186 foreach ( $postvars AS $key => $value )
188 $this- > form_hidden_field ( $key , $value );
194 $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 ));
196 $this- > page_code ( $js );
201 // ###################################################################
203 * Throws a fatal error; constructs the header and footer
207 * @param string Error messsage text
209 function error ( $message )
211 $this- > page_start ( $this- > registry
-> modules
[ 'localize' ]-> string ( 'Error' ));
212 $this- > page_message ( $this- > registry
-> modules
[ 'localize' ]-> string ( 'Error' ), $message );
218 // ###################################################################
220 * Outputs the header of the page: doctype, <html>, <head>, <title>,
221 * <body> and imbeds the style information
225 * @param string Title of the page
226 * @param string Class of the page to be applied to the body
227 * @param integer Margin of the <div> that all content is placed in
228 * @param string Extra HTML to imbed in the <head> tag
229 * @param string <body> onLoad action to imbed
230 * @param integer Margin of the actual <body > tag
231 * @param string Relative path where the CSS data is stored
232 * @param bool Will force re-print the header if it has already been printed
234 function page_start ( $actiontitle , $pageclass = ':default:' , $pagemargin = 15 , $extra = '' , $onload = false , $margin = 0 , $dotpath = '.' , $override = false )
236 if ( $this- > registry
-> debug
AND isset ( $_GET [ 'query' ]))
241 if ( defined ( 'ISSO_PRINTER_DONE_HEADER' ) AND ! $override )
243 if ( constant ( 'ISSO_PRINTER_DONE_HEADER' ) AND ! $override )
249 $title = sprintf ( $this- > registry
-> modules
[ 'localize' ]-> string ( '%1 $s - %2 $s - %3 $s' ), $this- >registry->application, $this- >realm, $actiontitle );
251 echo "<!DOCTYPE html PUBLIC \" -//W3C//DTD XHTML 1.0 Transitional//EN \" \" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd \" > \n ";
252 echo "<html xmlns= \" http://www.w3.org/1999/xhtml \" > \n <head>";
253 echo " \n\t <title> $title </title>";
254 echo " \n\t <meta http-equiv= \" Content-Type \" content= \" text/html; charset=utf-8 \" />";
256 echo ( $extra ? " \n $extra" : ' ');
257 echo " \n </head> \n <body style= \" margin: {$margin} px; \" " . (( $pageclass !== ' : default : ') ? " class= \" $pageclass\" " : ' ') . (( $onload ) ? " onload= \" $onload\" " : ' ') . "> \n ";
259 if (!defined(' ISSO_PRINTER_HIDE_SETUP
') AND function_exists(' _printer_page_start
'))
261 _printer_page_start();
264 echo "<div style= \" margin: {$pagemargin} px; \" > \n <!-- / page head --> \n\n ";
266 if (!defined(' ISSO_PRINTER_DONE_HEADER
'))
268 define(' ISSO_PRINTER_DONE_HEADER
', 1);
272 // ###################################################################
274 * Links CSS to the page from a given relative path
278 * @param string Relative path to the CSS file
280 function css_link( $path )
282 $this- >css .= " \n\t <link rel= \" stylesheet \" href= \" $path\" />";
285 // ###################################################################
287 * Imbeds actual CSS information into the page in <style> tags
291 * @param string Path of the CSS file to be imbeded
293 function css_imbed( $path )
295 $data = require_once( $path );
296 $css = preg_replace(' #/\*(.*?)\*/(\r|\n)*#s', '', $css);
298 $this- > css
.= " \n\t <style type= \" text/css \" > \n\t <!-- \n " . $css . " \n\t //--> \n\t </style>" ;
301 // ###################################################################
303 * Places raw HTML code directly into the documet at the current
308 * @param string HTML code
310 function page_code ( $code )
312 echo " \n\n $code\n\n " ;
315 // ###################################################################
317 * A block function that produces a table with a message in it. This
318 * does not print the header and footer.
322 * @param string The title of the message (appears at the top of the block)
323 * @param string Content of the message
325 function page_message ( $title , $message )
327 $this- > table_start ( true , '75%' );
328 $this- > table_head ( $title , 1 );
329 $this- > row_span ( "<blockquote> $message </blockquote>" , ':swap:' , 'left' , 1 );
333 // ###################################################################
335 * Produces an entire page layout that asks the user whether or not
336 * they want to perform X action and provides a link to the YES and NO
341 * @param string Message that asks if they want to do X
342 * @param string Location to go for YES
343 * @param string DO action to pass
344 * @param array Hidden parameters to pass to the next page
346 function page_confirm ( $message , $location , $action , $params )
348 $this- > page_start ( $this- > registry
-> modules
[ 'localize' ]-> string ( 'Confirm' ));
350 $this- > form_start ( $location , $action );
351 foreach ( $params AS $key => $value )
353 $this- > form_hidden_field ( $key , $value );
356 $this- > table_start ( true , '75%' );
357 $this- > table_head ( $this- > registry
-> modules
[ 'localize' ]-> string ( 'Confirm' ), 1 );
358 $this- > row_span ( "<blockquote> $message </blockquote>" , ':swap:' , 'left' , 1 );
359 $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' ), '' );
367 // ###################################################################
369 * Closes the HTML document structure an adds the copyright; this also
370 * stops execution of the page
376 if ( $this- > registry
-> debug
AND isset ( $_GET [ 'query' ]))
381 if ( is_array ( $this- > registry
-> modules
[ ISSO_DB_LAYER
]-> history
))
384 foreach ( $this- > registry
-> modules
[ ISSO_DB_LAYER
]-> history
AS $query )
386 echo $query . " \n\n <hr /> \n\n " ;
393 $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>" ;
395 if (! defined ( 'ISSO_PRINTER_HIDE_SETUP' ))
397 echo " \n <!-- page end --> \n </div> \n $copyright" ;
398 echo $this- >registry->construct_debug_block(false);
402 echo " \n
<!-- page end
-->\n</ div
> ";
405 echo " \n\n
</ body
>\n</ html
> ";
410 // -------------------------------------------------------------------
412 // ###################################################################
414 * Opens a <table> tag with styling
418 * @param bool Whether to add a <br /> before the table
419 * @param string Value of the width attribute
421 function table_start( $break = true, $width = '90%')
428 echo " \n
< table cellpadding
=\" 4\" cellspacing
=\" 0\" border
=\" 0\" align
=\" center\" width
=\" $width\" class =\" tborder\"
>\n ";
431 // ###################################################################
433 * Adds a table row that is sued to head the entire table
437 * @param string Title string
438 * @param integer Colspan attribute value
439 * @param bool Whether to bold the title
441 function table_head( $title , $colspan = 2, $strong = true)
443 echo " < tr
>\n\t< td
class =\" tcat\" align
=\" center\" colspan
=\" $colspan\" > " . (( $strong ) ? " < strong
> $title </ strong
> " : $title ) . " </ td
>\n</ tr
>\n ";
446 // ###################################################################
448 * Creates column headings; useful for a grid-style page. This uses a
449 * different styling than table_head() and is usually used directly
450 * after a table header.
454 * @param array Array of titles to print
456 function table_column_head( $columnarray )
458 if (is_array( $columnarray ))
460 $render = " < tr valign
=\" top\" align
=\" center\"
>\n ";
462 foreach ( $columnarray AS $header )
464 $render .= " \t
< td
class =\" thead\" align
=\" center\"
> $header </ td
>\n ";
467 $render .= " </ tr
>\n ";
473 // ###################################################################
475 * Closes a <table> tag
484 // -------------------------------------------------------------------
486 // ###################################################################
488 * Starts a <form> tag and adds the DO hidden input field
492 * @param string Action/name of the file to action to
493 * @param string Value of the DO parameter; used to do-branch
494 * @param bool Enctype attribute; used for mime/multi-part
495 * @param string Name of the form; this only matters for DOM access
496 * @param string Method to action as; POST or GET (default is POST)
498 function form_start( $action , $do , $enctype = false, $name = 'inputform', $submitmethod = 'post')
500 echo " \n
<!-- input form
-->\n< form name
=\" $name\" action
=\" $action\" " . (( $enctype ) ? " enctype
=\" $enctype\" " : '') . " method
=\" $submitmethod\" >\n ";
504 $this- >form_hidden_field('do', $do );
508 // ###################################################################
510 * Adds a hidden field at the current location
514 * @param string Name of the field
515 * @param string Value of the field
517 function form_hidden_field( $name , $value )
519 echo " < input type
=\" hidden\" name
=\" $name\" value
=\" $value\" />\n ";
522 // ###################################################################
524 * Closes a <form> tag
530 echo " </ form
>\n<!-- / input form
-->\n ";
533 // -------------------------------------------------------------------
535 // ###################################################################
537 * Creates a table row that spans an entire row; this is used to divide
542 * @param string Text to place in the row
543 * @param string Class name to style with; by default it alternates between alt1 and alt2 (use :swap: to do that)
544 * @param string Alignment of the text in the row
545 * @param integer Colspan attribute
547 function row_span( $text , $class = ':swap:', $align = 'left', $colspan = 2)
549 if ( $class === ':swap:')
551 $this- >registry->modules['functions']->exec_swap_bg();
552 $row_class = $this- >registry->modules['functions']->bgcolour;
553 $is_style_element = false;
557 if (preg_match('#:style:(.*?)#i', $class ))
559 $is_style_element = true;
560 $style = str_replace(':style:', '', $class );
565 $is_style_element = false;
569 echo " \n
< tr
>\n\t< td
". (( $is_style_element ) ? " style
=\" $style\" " : " class =\" $row_class\" ") . " colspan
=\" $colspan\" align
=\" $align\" > $text </ td
>\n</ tr
> ";
572 // ###################################################################
574 * Creates a table row that has more than two columns; this is used in
575 * conjunction with table_column_head() usually; it takes an array of
580 * @param array Array of values in form value => alignment key (c for center, l for left, and r for right)
582 function row_multi_item( $row_array )
584 $this- >registry->modules['functions']->exec_swap_bg();
586 foreach ( $row_array AS $item => $align )
588 $row_data [" $align" ][] = $item ;
591 echo "<tr valign= \" top \" >" ;
593 foreach ( $row_data AS $align_key => $item_array )
595 if ( $align_key == 'c' )
599 else if ( $align_key == 'l' )
603 else if ( $align_key == 'r' )
608 foreach ( $item_array AS $value )
610 echo " \n\t <td class= \"{ $this->registry->modules['functions']->bgcolour} \" align= \" $align\" > $value </td>" ;
617 // ###################################################################
619 * Generic row creation function that has two columns: label and value;
620 * this is used for many other form functions, but can also be used for
621 * non-editable fields
625 * @param string Label text
626 * @param string HTML or text to place in the value column
627 * @param string Vertical align (valign attribute) for the row
628 * @param integer Colspan attribute
629 * @param string Class to style the row with; default is to alternate
631 function row_text ( $label , $value = ' ' , $valign = 'top' , $colspan = 2 , $class = - 1 )
639 $this- > registry
-> modules
[ 'functions' ]-> exec_swap_bg ();
640 $row_class = $this- > registry
-> modules
[ 'functions' ]-> bgcolour
;
652 echo "<tr valign= \" $valign\" >" ;
653 echo " \n\t <td class= \" $row_class\" > $label </td>" ;
654 echo " \n\t <td class= \" $row_class\" > $value </td>" ;
658 echo " \n\t <td class= \" $row_class\" colspan= \" " . $colspan - 2 . " \" > </td>" ;
664 // ###################################################################
666 * Creates a table row with an <input> text field as the value column
670 * @param string Label text
671 * @param string Name of the <input> field
672 * @param string Value of the field
673 * @param integer Colspan attribute
674 * @param integer Size of the <input> field
675 * @param integer Length attribute; use FALSE for no length to be specified
676 * @param bool Whether to make this a password field
677 * @param string Vertical align (valign attribute)
679 function row_input ( $label , $name , $value = '' , $colspan = 2 , $size = 35 , $length = false , $password = false , $lalign = 'top' )
681 $this- > row_text ( $label , "<input type= \" " . (( $password ) ? 'password' : 'text' ) . " \" class= \" input \" name= \" $name\" value= \" $value\" size= \" $size\" " . (( $length ) ? "maxlength= \" $length\" " : '' ) . "/>" , $lalign , $colspan );
684 // ###################################################################
686 * Creates a table row with a <textarea> as the value column
690 * @param string Label text
691 * @param string Name of the <textarea>
692 * @param string Value of the <textarea>
693 * @param integer Colspan attribute
694 * @param integer Number of rows in the <textarea>
695 * @param integer Number of colums in the <textarea>
696 * @param bool Whether or not to use monospacing font
697 * @param string Extra style attributes to apply to the <textarea>
699 function row_textarea ( $label , $name , $value = '' , $colspan = 2 , $rows = 7 , $cols = 50 , $code = false , $style = '' )
701 $this- > row_text ( $label , "<textarea name= \" $name\" class= \" " . (( $code ) ? 'code' : 'input' ) . " \" rows= \" $rows\" cols= \" $cols\" " . (( $style ) ? ' style="' . $style . '"' : '' ) . "> $value </textarea>" , 'top' , $colspan );
704 // ###################################################################
706 * Creates a table row with the tfoot class
710 * @param string Extra text or HTML to insert into the row
711 * @param integer Colspan attribute
713 function row_tfoot ( $data , $colspan = 2 )
715 echo $this- > row_span ( $data , 'tfoot' , 'center' , $colspan );
718 // ###################################################################
720 * Creates a tfoot table row with submit buttons
724 * @param string Extra HTML to imbed in the row after the buttons
725 * @param string Submit button text (by default it uses pre-translated "Submit" from :save:)
726 * @param string Reset button text (default it uses pre-translated "Reset" from :reset:)
727 * @param integer Colspan attribute
729 function row_submit ( $extra = false , $submit = ':save:' , $reset = ':reset:' , $colspan = 2 )
731 if ( $submit === ':save:' )
733 $submit = " " . $this- > registry
-> modules
[ 'localize' ]-> string ( 'Submit' ) . " " ;
737 $submit = " $submit " ;
740 if ( $reset === ':reset:' )
742 $reset = " " . $this- > registry
-> modules
[ 'localize' ]-> string ( 'Reset' ) . " " ;
746 $reset = (( $reset ) ? " $reset " : '' );
749 $output = " \n\t\t <input type= \" submit \" class= \" button \" name= \" __submit__ \" value= \" $submit\" accesskey= \" s \" />" ;
750 $output .= ( $reset ? " \n\t\t <input type= \" reset \" class= \" button \" name= \" __reset__ \" value= \" $reset\" accesskey= \" r \" />" : '' );
751 $output .= ( $extra ? " \n\t\t $extra" : '');
753 $this- >row_tfoot( $output , $colspan );
756 // ###################################################################
758 * Creates an upload row; you need to specify some other paramaters in
759 * form_start() for this to work
763 * @param string Label text
764 * @param string Upload name
765 * @param integer Colspan attribute
767 function row_upload( $label , $name , $colspan = 2)
769 $this- >row_text( $label , " < input type
=\" file\"
class =\" button\" name
=\" $name\" size
=\" 35\" /> ", 'top', $colspan );
772 // ###################################################################
774 * Adds a name-value pair to an array that is constructed into a
779 * @param string Text displayed for the option
780 * @param string Value of the option
781 * @param bool Whether or not to select this particluar option
783 function list_item( $name , $value , $selected = false)
787 $listitem [] = " \n\t
< option value
=\" $value\" " . (( $selected == true) ? ' selected=" selected
"' : '') . " > $name </ option
> ";
790 // ###################################################################
792 * Assembles a <select> table row from list_item() items
796 * @param string Label text
797 * @param string Name of the <select>
798 * @param bool Automatically submit the form on a change?
799 * @param integer Colspan attribute
801 function row_list( $label , $name , $is_jump = false, $colspan = 2)
805 foreach ( $listitem AS $option )
807 $optionlist .= $option ;
812 $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 );
815 // ###################################################################
817 * Creates a row with two radio buttons: yes and now
821 * @param string Label text
822 * @param string Name of the BOOL flag
823 * @param bool TRUE to select the YES by default; FALSE for NO
824 * @param integer Colspan attribute
826 function row_yesno( $label , $name , $value , $colspan = 2)
828 $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 );
832 /*=====================================================================*\
833 || ###################################################################
836 || ###################################################################
837 \*=====================================================================*/