]>
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
64 function __construct (& $registry )
66 $this- > registry
=& $registry ;
72 function Printer (& $registry )
74 $this- > __construct ( $registry );
78 * Creates a redirect to another page; constructs the header and footer (therefore execution stops)
80 * @param string Location to redirect to
81 * @param integer Time to wait before the redirect
83 function redirect ( $location , $timeout = 10 )
85 $timeout = $timeout * 200 ;
89 <script type="text/javascript">
91 var timeout = $timeout ;
95 setTimeout("redirect()", $timeout );
104 window.location = " $location" ;
110 $this- > page_start ( $this- > registry
-> modules
[ 'localize' ]-> string ( 'Redirect' ), ':default:' , 15 , $js );
112 $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 ));
118 * Throws a fatal error; constructs the header and footer
120 * @param string Error messsage text
122 function error ( $message )
124 $this- > page_start ( $this- > registry
-> modules
[ 'localize' ]-> string ( 'Error' ));
125 $this- > page_message ( $this- > registry
-> modules
[ 'localize' ]-> string ( 'Error' ), $message );
131 // ###################################################################
133 * Outputs the header of the page: doctype, <html>, <head>, <title>, <body>
134 * and imbeds the style information
136 * @param string Title of the page
137 * @param string Class of the page to be applied to the body
138 * @param integer Margin of the <div> that all content is placed in
139 * @param string Extra HTML to imbed in the <head> tag
140 * @param string <body> onLoad action to imbed
141 * @param integer Margin of the actual <body > tag
142 * @param string Relative path where the CSS data is stored
143 * @param bool Will force re-print the header if it has already been printed
145 function page_start ( $actiontitle , $pageclass = ':default:' , $pagemargin = 15 , $extra = '' , $onload = false , $margin = 0 , $dotpath = '.' , $override = false )
147 if ( $this- > registry
-> debug
AND isset ( $_GET [ 'query' ]))
152 if ( constant ( 'DONE_HEADER' ) AND ! $override )
157 $title = sprintf ( $this- > registry
-> modules
[ 'localize' ]-> string ( '%1 $s - %2 $s - %3 $s' ), $this- >registry->application, $this- >realm, $actiontitle );
159 echo "<!DOCTYPE html PUBLIC \" -//W3C//DTD XHTML 1.0 Transitional//EN \" \" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd \" > \n ";
160 echo "<html xmlns= \" http://www.w3.org/1999/xhtml \" > \n <head>";
161 echo " \n\t <title> $title </title>";
162 echo " \n\t <meta http-equiv= \" Content-Type \" content= \" text/html; charset=iso-8859-1 \" />";
164 echo ( $extra ? " \n $extra" : ' ');
165 echo " \n </head> \n <body style= \" margin: {$margin} px; \" " . (( $pageclass !== ' : default : ') ? " class= \" $pageclass\" " : ' ') . (( $onload ) ? " onload= \" $onload\" " : ' ') . "> \n ";
167 if (!defined(' HIDE_SETUP
') AND function_exists(' _printer_page_start
'))
169 _printer_page_start();
172 echo "<div style= \" margin: {$pagemargin} px; \" > \n <!-- / page head --> \n\n ";
174 if (!defined(' DONE_HEADER
'))
176 define(' DONE_HEADER
', 1);
181 * Links CSS to the page from a given relative path
183 * @param string Relative path to the CSS file
185 function css_link( $path )
187 $this- >css .= " \n\t <link rel= \" stylesheet \" href= \" $path\" />";
191 * Imbeds actual CSS information into the page in <style> tags
193 * @param string Path of the CSS file to be imbeded
195 function css_imbed( $path )
197 $data = require_once( $path );
198 $css = preg_replace(' #/\*(.*?)\*/(\r|\n)*#s', '', $css);
200 $this- > css
.= " \n\t <style type= \" text/css \" > \n\t <!-- \n " . $css . " \n\t //--> \n\t </style>" ;
204 * Places raw HTML code directly into the documet at the current position
206 * @param string HTML code
208 function page_code ( $code )
210 echo " \n\n $code\n\n " ;
214 * A block function that produces a table with a message in it. This does not print the header and footer
216 * @param string The title of the message (appears at the top of the block)
217 * @param string Content of the message
219 function page_message ( $title , $message )
221 $this- > table_start ( true , '75%' );
222 $this- > table_head ( $title , 1 );
223 $this- > row_span ( "<blockquote> $message </blockquote>" , ':swap:' , 'left' , 1 );
228 * Produces an entire page layout that asks the user whether or not they want to perform X action and provides
229 * a link to the YES and NO action
231 * @param string Message that asks if they want to do X
232 * @param string Location to go for YES
233 * @param string DO action to pass
234 * @param array Hidden parameters to pass to the next page
236 function page_confirm ( $message , $location , $action , $params )
238 $this- > page_start ( $this- > registry
-> modules
[ 'localize' ]-> string ( 'Confirm' ));
240 $this- > form_start ( $location , $action );
241 foreach ( $params AS $key => $value )
243 $this- > form_hidden_field ( $key , $value );
246 $this- > table_start ( true , '75%' );
247 $this- > table_head ( $this- > registry
-> modules
[ 'localize' ]-> string ( 'Confirm' ), 1 );
248 $this- > row_span ( "<blockquote> $message </blockquote>" , ':swap:' , 'left' , 1 );
249 $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' ), '' );
258 * Closes the HTML document structure an adds the copyright; this also stops execution of the page
262 if ( $this- > registry
-> debug
AND isset ( $_GET [ 'query' ]))
267 if ( is_array ( $this- > registry
-> modules
[ 'db_mysql' ]-> history
))
270 foreach ( $this- > registry
-> modules
[ 'db_mysql' ]-> history
AS $query )
272 echo $query . " \n\n <hr /> \n\n " ;
279 $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>" ;
281 if (! defined ( 'HIDE_SETUP' ))
283 echo " \n <!-- page end --> \n </div> \n $copyright" ;
287 echo " \n
<!-- page end
-->\n</ div
> ";
290 if ( $this- >registry->debug)
293 $scinfo = 'Not Under Source Control';
294 $possiblescms = array('cvs', 'svn', 'cvs_information', 'svn_information', 'scm', 'sc_information', 'scm_information');
295 foreach ( $possiblescms AS $scm )
297 if (defined(strtoupper( $scm )))
299 $scinfo = constant(strtoupper( $scm ));
303 if (strpos( $scinfo , 'RCSfile:') !== false)
307 else if (strpos( $scinfo , ',v ') !== false)
312 else if (strpos( $scinfo , 'URL:') !== false)
316 else if (strpos( $scinfo , 'https://') !== false OR strpos( $scinfo , 'http://') !== false)
320 // not found so just return it
321 // try a SVN ID tag as we can't really tell if we're using it
324 $test = preg_replace('# \$ ' . 'Id: (.+?) (.+?) [0-9] {4} -[0-9] {2} -[0-9] {2} [0-9] {2} :[0-9] {2} :[0-9] {2} (.+?) (.+?) \$ #', ' \\ 1 - SVN \\ 2', $scinfo );
325 if ( $test == ' $' . 'Id: $' )
327 $scinfo = 'Not Under Source Control';
338 $scinfo = preg_replace('# \$ ' . 'RCSfile: (.+?) \$ #', ' \\ 1', $scinfo );
339 $scinfo = preg_replace('# \$ ' . 'Revision: (.+?) \$ #', 'CVS \\ 1', $scinfo );
340 $scinfo = preg_replace('# \$ ' . 'Id: (.+?) (.+?) [0-9] {4} /[0-9] {2} /[0-9] {2} [0-9] {2} :[0-9] {2} :[0-9] {2} (.+?) (.+?) \$ #', ' \\ 1 - CVS \\ 2', $scinfo );
342 else if ( $type == 'svn')
344 $scinfo = preg_replace('# \$ ' . '(Head)?URL: (.+?) \$ #e', " end ( explode ( '/' , ' \\ 2' )) ", $scinfo );
345 $scinfo = preg_replace('# \$ ' . '(LastModified)?Revision: (.+?) \$ #', 'SVN \\ 2', $scinfo );
346 $scinfo = preg_replace('# \$ ' . 'Id: (.+?) ([0-9].+?) [0-9] {4} -[0-9] {2} -[0-9] {2} [0-9] {2} :[0-9] {2} :[0-9] {2} (.+?) (.+?) \$ #', ' \\ 1 - SVN \\ 2', $scinfo );
350 $scinfo = 'Not Under Source Control';
355 $scinfo = trim( $scinfo );
356 $debug .= " \n\t
< li
>< strong
> Source Control
:</ strong
> $scinfo </ li
> ";
359 if (is_object( $this- >registry->modules['db_mysql']))
361 $debug .= " \n\t
< li
>< strong
> Total Queries
:</ strong
> " . sizeof( $this- >registry->modules['db_mysql']->history) . " (< a href
=\" " . $this- >registry->sanitize( $_SERVER ['REQUEST_URI']) . ((strpos( $_SERVER ['REQUEST_URI'], '?') !== false) ? '&query=1' : '?query=1') . " \"
>?</ a
>)</ li
> ";
364 // total execution time
365 if (defined('ISSO_MT_START'))
367 $this- >registry->load('functions', 'functions');
368 $debug .= " \n\t
< li
>< strong
> Total Execution Time
:</ strong
> " . round( $this- >registry->modules['functions']->fetch_microtime_diff(ISSO_MT_START), 10) . " </ li
> ";
372 $debug .= " \n\t
< li
>\n\t\t< select
>\n\t\t\t< option
> Debug
Notices ( " . sizeof( $this- >registry->debuginfo) . " )</ option
> ";
373 foreach ((array) $this- >registry->debuginfo AS $msg )
375 $debug .= " \n\t\t\t
< option
>--- $msg </ option
> ";
377 $debug .= " \n\t\t
</ select
>\n\t</ li
> ";
380 $modules = $this- >registry->show_modules(true);
381 $debug .= " \n\t
< li
>\n\t\t< select
>\n\t\t\t< option
> Loaded
Modules ( " . sizeof( $modules ) . " )</ option
> ";
382 foreach ( $modules AS $mod )
384 $debug .= " \n\t\t\t
< option
>--- $mod </ option
> ";
386 $debug .= " \n\t\t
</ select
>\n\t</ li
> ";
391 $debug = " \n
< hr
/>\n " . $this- >registry->message('Debug Information', $debug , 1, true, false);
392 echo " \n\n
<!-- dev debug
-->\n< div align
=\" center\"
>\n $debug\n </ div
>\n<!-- / dev debug
-->\n\n ";
395 echo " \n\n
</ body
>\n</ html
> ";
400 // ###################################################################
402 * Opens a <table> tag with styling
404 * @param bool Whether to add a <br /> before the table
405 * @param string Value of the width attribute
407 function table_start( $break = true, $width = '90%')
414 echo " \n
< table cellpadding
=\" 4\" cellspacing
=\" 0\" border
=\" 0\" align
=\" center\" width
=\" $width\" class =\" tborder\"
>\n ";
418 * Adds a table row that is sued to head the entire table
420 * @param string Title string
421 * @param integer Colspan attribute value
422 * @param bool Whether to bold the title
424 function table_head( $title , $colspan = 2, $strong = true)
426 echo " < tr
>\n\t< td
class =\" tcat\" align
=\" center\" colspan
=\" $colspan\" > " . (( $strong ) ? " < strong
> $title </ strong
> " : $title ) . " </ td
>\n</ tr
>\n ";
430 * Creates column headings; useful for a grid-style page. This uses a different styling than table_head()
431 * and is usually used directly after a table header
433 * @param array Array of titles to print
435 function table_column_head( $columnarray )
437 if (is_array( $columnarray ))
439 $render = " < tr valign
=\" top\" align
=\" center\"
>\n ";
441 foreach ( $columnarray AS $header )
443 $render .= " \t
< td
class =\" thead\" align
=\" center\"
> $header </ td
>\n ";
446 $render .= " </ tr
>\n ";
453 * Closes a <table> tag
460 // ###################################################################
462 * Starts a <form> tag and adds the DO hidden input field
464 * @param string Action/name of the file to action to
465 * @param string Value of the DO parameter; used to do-branch
466 * @param bool Enctype attribute; used for mime/multi-part
467 * @param string Name of the form; this only matters for DOM access
468 * @param string Method to action as; POST or GET (default is POST)
470 function form_start( $action , $do , $enctype = false, $name = 'inputform', $submitmethod = 'post')
472 echo " \n
<!-- input form
-->\n< form name
=\" $name\" action
=\" $action\" " . (( $enctype ) ? " enctype
=\" $enctype\" " : '') . " method
=\" $submitmethod\" >\n ";
473 $this- >form_hidden_field('do', $do );
477 * Adds a hidden field at the current location
479 * @param string Name of the field
480 * @param string Value of the field
482 function form_hidden_field( $name , $value )
484 echo " < input type
=\" hidden\" name
=\" $name\" value
=\" $value\" />\n ";
488 * Closes a <form> tag
492 echo " </ form
>\n<!-- / input form
-->\n ";
495 // ###################################################################
497 * Creates a table row that spans an entire row; this is used to divide sections, usually
499 * @param string Text to place in the row
500 * @param string Class name to style with; by default it alternates between alt1 and alt2 (use :swap: to do that)
501 * @param string Alignment of the text in the row
502 * @param integer Colspan attribute
504 function row_span( $text , $class = ':swap:', $align = 'left', $colspan = 2)
506 if ( $class === ':swap:')
508 $this- >registry->modules['functions']->exec_swap_bg();
509 $row_class = $this- >registry->modules['functions']->bgcolour;
510 $is_style_element = false;
514 if (preg_match('#:style:(.*?)#i', $class ))
516 $is_style_element = true;
517 $style = str_replace(':style:', '', $class );
522 $is_style_element = false;
526 echo " \n
< tr
>\n\t< td
". (( $is_style_element ) ? " style
=\" $style\" " : " class =\" $row_class\" ") . " colspan
=\" $colspan\" align
=\" $align\" > $text </ td
>\n</ tr
> ";
530 * Creates a table row that has more than two columns; this is used in conjunction with table_column_head()
531 * usually; it takes an array of values
533 * @param array Array of values in form value => alignment key (c for center, l for left, and r for right)
535 function row_multi_item( $row_array )
537 $this- >registry->modules['functions']->exec_swap_bg();
539 foreach ( $row_array AS $item => $align )
541 $row_data [" $align" ][] = $item ;
544 echo "<tr valign= \" top \" >" ;
546 foreach ( $row_data AS $align_key => $item_array )
548 if ( $align_key == 'c' )
552 else if ( $align_key == 'l' )
556 else if ( $align_key == 'r' )
561 foreach ( $item_array AS $value )
563 echo " \n\t <td class= \"{ $this->registry->modules['functions']->bgcolour} \" align= \" $align\" > $value </td>" ;
571 * Generic row creation function that has two columns: label and value; this is used for many
572 * other form functions, but can also be used for non-editable fields
574 * @param string Label text
575 * @param string HTML or text to place in the value column
576 * @param string Vertical align (valign attribute) for the row
577 * @param integer Colspan attribute
578 * @param string Class to style the row with; default is to alternate
580 function row_text ( $label , $value = ' ' , $valign = 'top' , $colspan = 2 , $class = - 1 )
588 $this- > registry
-> modules
[ 'functions' ]-> exec_swap_bg ();
589 $row_class = $this- > registry
-> modules
[ 'functions' ]-> bgcolour
;
601 echo "<tr valign= \" $valign\" >" ;
602 echo " \n\t <td class= \" $row_class\" > $label </td>" ;
603 echo " \n\t <td class= \" $row_class\" > $value </td>" ;
607 echo " \n\t <td class= \" $row_class\" colspan= \" " . $colspan - 2 . " \" > </td>" ;
614 * Creates a table row with an <input> text field as the value column
616 * @param string Label text
617 * @param string Name of the <input> field
618 * @param string Value of the field
619 * @param integer Colspan attribute
620 * @param integer Size of the <input> field
621 * @param integer Length attribute; use FALSE for no length to be specified
622 * @param bool Whether to make this a password field
623 * @param string Vertical align (valign attribute)
625 function row_input ( $label , $name , $value = '' , $colspan = 2 , $size = 35 , $length = false , $password = false , $lalign = 'top' )
627 $this- > row_text ( $label , "<input type= \" " . (( $password ) ? 'password' : 'text' ) . " \" class= \" input \" name= \" $name\" value= \" $value\" size= \" $size\" " . (( $length ) ? "maxlength= \" $length\" " : '' ) . "/>" , $lalign , $colspan );
631 * Creates a table row with a <textarea> as the value column
633 * @param string Label text
634 * @param string Name of the <textarea>
635 * @param string Value of the <textarea>
636 * @param integer Colspan attribute
637 * @param integer Number of rows in the <textarea>
638 * @param integer Number of colums in the <textarea>
639 * @param bool Whether or not to use monospacing font
640 * @param string Extra style attributes to apply to the <textarea>
642 function row_textarea ( $label , $name , $value = '' , $colspan = 2 , $rows = 7 , $cols = 50 , $code = false , $style = '' )
644 $this- > row_text ( $label , "<textarea name= \" $name\" class= \" " . (( $code ) ? 'code' : 'input' ) . " \" rows= \" $rows\" cols= \" $cols\" " . (( $style ) ? ' style="' . $style . '"' : '' ) . "> $value </textarea>" , 'top' , $colspan );
648 * Creates a table row with the tfoot class
650 * @param string Extra text or HTML to insert into the row
651 * @param integer Colspan attribute
653 function row_tfoot ( $data , $colspan = 2 )
655 echo $this- > row_span ( $data , 'tfoot' , 'center' , $colspan );
659 * Creates a tfoot table row with submit buttons
661 * @param string Extra HTML to imbed in the row after the buttons
662 * @param string Submit button text (by default it uses pre-translated "Submit" from :save:)
663 * @param string Reset button text (default it uses pre-translated "Reset" from :reset:)
664 * @param integer Colspan attribute
666 function row_submit ( $extra = false , $submit = ':save:' , $reset = ':reset:' , $colspan = 2 )
668 if ( $submit === ':save:' )
670 $submit = " " . $this- > registry
-> modules
[ 'localize' ]-> string ( 'Submit' ) . " " ;
674 $submit = " $submit " ;
677 if ( $reset === ':reset:' )
679 $reset = " " . $this- > registry
-> modules
[ 'localize' ]-> string ( 'Reset' ) . " " ;
683 $reset = (( $reset ) ? " $reset " : '' );
686 $output = " \n\t\t <input type= \" submit \" class= \" button \" value= \" $submit\" accesskey= \" s \" />" ;
687 $output .= ( $reset ? " \n\t\t <input type= \" reset \" class= \" button \" value= \" $reset\" accesskey= \" r \" />" : '' );
688 $output .= ( $extra ? " \n\t\t $extra" : '');
690 $this- >row_tfoot( $output , $colspan );
694 * Creates an upload row; you need to specify some other paramaters in form_start() for this to work
696 * @param string Label text
697 * @param string Upload name
698 * @param integer Colspan attribute
700 function row_upload( $label , $name , $colspan = 2)
702 $this- >row_text( $label , " < input type
=\" file\"
class =\" button\" name
=\" $name\" size
=\" 35\" /> ", 'top', $colspan );
706 * Adds a name-value pair to an array that is constructed into a <select> list
708 * @param string Text displayed for the option
709 * @param string Value of the option
710 * @param bool Whether or not to select this particluar option
712 function list_item( $name , $value , $selected = false)
716 $listitem [] = " \n\t
< option value
=\" $value\" " . (( $selected == true) ? ' selected=" selected
"' : '') . " > $name </ option
> ";
720 * Assembles a <select> table row from list_item() items
722 * @param string Label text
723 * @param string Name of the <select>
724 * @param bool Automatically submit the form on a change?
725 * @param integer Colspan attribute
727 function row_list( $label , $name , $is_jump = false, $colspan = 2)
731 foreach ( $listitem AS $option )
733 $optionlist .= $option ;
738 $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 );
742 * Creates a row with two radio buttons: yes and now
744 * @param string Label text
745 * @param string Name of the BOOL flag
746 * @param bool TRUE to select the YES by default; FALSE for NO
747 * @param integer Colspan attribute
749 function row_yesno( $label , $name , $value , $colspan = 2)
751 $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 );
755 /*=====================================================================*\
756 || ###################################################################
759 || ###################################################################
760 \*=====================================================================*/