From aa3ee32638d4b41ca1e3a5e621adaad2f07ee59b Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 22 Oct 2005 22:31:20 +0000 Subject: [PATCH] Documented nearly all of the functions --- printer.php | 252 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 204 insertions(+), 48 deletions(-) diff --git a/printer.php b/printer.php index 93c089e..743f1fa 100644 --- a/printer.php +++ b/printer.php @@ -40,10 +40,22 @@ */ class Printer { + /** + * Framework registry object + * @var object + */ + var $registry = null; + + /** + * Constructor + */ + function Printer(&$registry) + { + $this->registry =& $registry; + } + function redirect($location, $timeout = 10) { - global $bugsys; - $timeout = $timeout * 200; $js = @@ -69,37 +81,44 @@ class Printer EOD; - $this->page_start($bugsys->lang->string('Redirect'), ':default:', 15, $js); + $this->page_start($this->registry->modules['localize']->string('Redirect'), ':default:', 15, $js); - $this->page_message($bugsys->lang->string('Redirect'), sprintf($bugsys->lang->string('Please wait to be redirected. If you are not redirected in a few seconds, click here.'), $location)); + $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 here.'), $location)); $this->page_end(); } function error($message) { - global $bugsys; - - $this->page_start($bugsys->lang->string('Error')); - $this->page_message($bugsys->lang->string('Error'), $message); + $this->page_start($this->registry->modules['localize']->string('Error')); + $this->page_message($this->registry->modules['localize']->string('Error'), $message); $this->page_end(); exit; } // ################################################################### - // ########################### PAGE CONTROL ########################## - // ################################################################### + /** + * Outputs the header of the page: doctype, , , , <body> + * and imbeds the style information + * + * @param string Title of the page + * @param string Class of the page to be applied to the body + * @param integer Margin of the <div> that all content is placed in + * @param string Extra HTML to imbed in the <head> tag + * @param string <body> onLoad action to imbed + * @param integer Margin of the actual <body > tag + * @param string Relative path where the CSS data is stored + * @param bool Will force re-print the header if it has already been printed + */ function page_start($actiontitle, $pageclass = ':default:', $pagemargin = 15, $extra = '', $onload = false, $margin = 0, $dotpath = '.', $override = false) { - global $bugsys; - if (constant('DONE_HEADER') AND !$override) { return; } - $title = sprintf($bugsys->lang->string('BugStrike - Administration - %1$s'), $actiontitle); + $title = sprintf($this->registry->modules['localize']->string('BugStrike - Administration - %1$s'), $actiontitle); echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>"; @@ -108,7 +127,7 @@ EOD; echo "\n\t<link rel=\"stylesheet\" href=\"$dotpath/admin.css\" />" . (($extra) ? "\n$extra" : ''); echo "\n</head>\n<body style=\"margin: {$margin}px;\"" . (($pageclass !== ':default:') ? " class=\"$pageclass\"" : '') . (($onload) ? " onload=\"$onload\"" : '') . ">\n"; - if (!defined('HIDE_SETUP') AND $bugsys->userinfo['adminsession']) + if (!defined('HIDE_SETUP') AND $this->registry->userinfo['adminsession']) { global $globalnav; @@ -118,8 +137,8 @@ EOD; echo "<div class=\"tcat\" style=\"padding: 5px; border-bottom: 4px outset\">\n"; echo "\n\t<form action=\"jump.php\" method=\"post\" title=\"navigation\" style=\"display: inline\">"; - echo "\n\t<span style=\"float: right\"><a href=\"../\">" . $bugsys->lang->string('Tracker Home') . "</a></span>"; - echo "\n\t\t" . $bugsys->lang->string('Navigation') . ": <select name=\"jumplocation\" onchange=\"this.form.submit()\">"; + echo "\n\t<span style=\"float: right\"><a href=\"../\">" . $this->registry->modules['localize']->string('Tracker Home') . "</a></span>"; + echo "\n\t\t" . $this->registry->modules['localize']->string('Navigation') . ": <select name=\"jumplocation\" onchange=\"this.form.submit()\">"; foreach ($globalnav AS $grouptitle => $links) { echo "\n\t\t<optgroup label=\"$grouptitle\">"; @@ -131,7 +150,7 @@ EOD; echo "\n\t\t</optgroup>"; } echo "\n\t\t</select>"; - echo "\n\t\t<input type=\"submit\" name=\"go\" value=\" " . $bugsys->lang->string('Go') . " \" />"; + echo "\n\t\t<input type=\"submit\" name=\"go\" value=\" " . $this->registry->modules['localize']->string('Go') . " \" />"; echo "\n\t</form>"; echo "\n</div>"; } @@ -144,11 +163,22 @@ EOD; } } + /** + * Places raw HTML code directly into the documet at the current position + * + * @param string HTML code + */ function page_code($code) { echo "\n\n$code\n\n"; } + /** + * A block function that produces a table with a message in it. This does not print the header and footer + * + * @param string The title of the message (appears at the top of the block) + * @param string Content of the message + */ function page_message($title, $message) { $this->table_start(true, '75%'); @@ -157,22 +187,28 @@ EOD; $this->table_end(); } + /** + * Produces an entire page layout that asks the user whether or not they want to perform X action and provides + * a link to the YES action + * + * @param string Message that asks if they want to do X + * @param string Location to go for YES + */ function page_confirm($message, $location) { - global $bugsys; - - $this->page_start($bugsys->lang->string('Confirm')); + $this->page_start($this->registry->modules['localize']->string('Confirm')); - $this->page_message($bugsys->lang->string('Confirm'), $message . '<p><input type="button" name="confirm" value=" ' . $bugsys->lang->string('Yes') . ' " onclick="window.location = \'' . $location . '\';" />'); + $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 . '\';" />'); $this->page_end(); } + /** + * Closes the HTML document structure an adds the copyright; this also stops execution of the page + */ function page_end() { - global $bugsys; - - $copyright = "\n<br />\n<p align=\"center\" class=\"copyright\">\n\t<a href=\"http://www.iris-studios.com\" target=\"_blank\">BugStrike " . $bugsys->options['trackerversion'] . ", © 2002 - " . date('Y') . " Iris Studios, Inc.</a>\n</p>"; + $copyright = "\n<br />\n<p align=\"center\" class=\"copyright\">\n\t<a href=\"http://www.iris-studios.com\" target=\"_blank\">BugStrike " . $this->registry->options['trackerversion'] . ", © 2002 - " . date('Y') . " Iris Studios, Inc.</a>\n</p>"; if (!defined('HIDE_SETUP')) { @@ -187,10 +223,14 @@ EOD; exit; } - - // ################################################################### - // ##################### TABLE SKELETON RENDERING #################### + // ################################################################### + /** + * Opens a <table> tag with styling + * + * @param bool Whether to add a <br /> before the table + * @param string Value of the width attribute + */ function table_start($break = true, $width = '90%') { if ($break) @@ -201,11 +241,24 @@ EOD; echo "\n<table cellpadding=\"4\" cellspacing=\"0\" border=\"0\" align=\"center\" width=\"$width\" class=\"tborder\">\n"; } + /** + * Adds a table row that is sued to head the entire table + * + * @param string Title string + * @param integer Colspan attribute value + * @param bool Whether to bold the title + */ function table_head($title, $colspan = 2, $strong = true) { echo "<tr>\n\t<td class=\"tcat\" align=\"center\" colspan=\"$colspan\">" . (($strong) ? "<strong>$title</strong>" : $title) . "</td>\n</tr>\n"; } + /** + * Creates column headings; useful for a grid-style page. This uses a different styling than table_head() + * and is usually used directly after a table header + * + * @param array Array of titles to print + */ function table_column_head($columnarray) { if (is_array($columnarray)) @@ -223,40 +276,64 @@ EOD; } } + /** + * Closes a <table> tag + */ function table_end() { echo "\n</table>\n"; } // ################################################################### - // ########################## FORM CREATION ########################## - // ################################################################### + /** + * Starts a <form> tag and adds the DO hidden input field + * + * @param string Action/name of the file to action to + * @param string Value of the DO parameter; used to do-branch + * @param bool Enctype attribute; used for mime/multi-part + * @param string Name of the form; this only matters for DOM access + * @param string Method to action as; POST or GET (default is POST) + */ function form_start($action, $do, $enctype = false, $name = 'inputform', $submitmethod = 'post') { echo "\n<!-- input form -->\n<form name=\"$name\" action=\"$action\"" . (($enctype) ? " enctype=\"$enctype\"" : '') . " method=\"$submitmethod\">\n"; $this->form_hidden_field('do', $do); } + /** + * Adds a hidden field at the current location + * + * @param string Name of the field + * @param string Value of the field + */ function form_hidden_field($name, $value) { echo "<input type=\"hidden\" name=\"$name\" value=\"$value\" />\n"; } + /** + * Closes a <form> tag + */ function form_end() { echo "</form>\n<!-- / input form -->\n"; } // ################################################################### - // ####################### TABLE ROW RENDERING ####################### - // ################################################################### + /** + * Creates a table row that spans an entire row; this is used to divide sections, usually + * + * @param string Text to place in the row + * @param string Class name to style with; by default it alternates between alt1 and alt2 (use :swap: to do that) + * @param string Alignment of the text in the row + * @param integer Colspan attribute + */ function row_span($text, $class = ':swap:', $align = 'left', $colspan = 2) { - global $bugsys; if ($class === ':swap:') { - $bugsys->funct->exec_swap_bg(); - $row_class = $bugsys->funct->bgcolour; + $this->registry->modules['functions']->exec_swap_bg(); + $row_class = $this->registry->modules['functions']->bgcolour; $is_style_element = false; } else @@ -276,10 +353,15 @@ EOD; echo "<tr>\n\t<td ". (($is_style_element) ? "style=\"$style\"" : "class=\"$row_class\"") . " colspan=\"$colspan\" align=\"$align\">$text</td>\n</tr>"; } + /** + * Creates a table row that has more than two columns; this is used in conjunction with table_column_head() + * usually; it takes an array of values + * + * @param array Array of values in form value => alignment key (c for center, l for left, and r for right) + */ function row_multi_item($row_array) { - global $bugsys; - $bugsys->funct->exec_swap_bg(); + $this->registry->modules['functions']->exec_swap_bg(); foreach ($row_array AS $item => $align) { @@ -305,23 +387,33 @@ EOD; foreach ($item_array AS $value) { - echo "\n\t<td class=\"{$bugsys->funct->bgcolour}\" align=\"$align\">$value</td>"; + echo "\n\t<td class=\"{$this->registry->modules['functions']->bgcolour}\" align=\"$align\">$value</td>"; } } echo "\n</tr>\n"; } + /** + * Generic row creation function that has two columns: label and value; this is used for many + * other form functions, but can also be used for non-editable fields + * + * @param string Label text + * @param string HTML or text to place in the value column + * @param string Vertical align (valign attribute) for the row + * @param integer Colspan attribute + * @param string Class to style the row with; default is to alternate + */ function row_text($label, $value = ' ', $valign = 'top', $colspan = 2, $class = -1) { - global $bugsys, $IS_SETTINGS; + global $IS_SETTINGS; if ($class == -1) { if (!$IS_SETTINGS) { - $bugsys->funct->exec_swap_bg(); - $row_class = $bugsys->funct->bgcolour; + $this->registry->modules['functions']->exec_swap_bg(); + $row_class = $this->registry->modules['functions']->bgcolour; } else { @@ -345,28 +437,64 @@ EOD; echo "\n</tr>\n"; } + /** + * Creates a table row with an <input> text field as the value column + * + * @param string Label text + * @param string Name of the <input> field + * @param string Value of the field + * @param integer Colspan attribute + * @param integer Size of the <input> field + * @param integer Length attribute; use FALSE for no length to be specified + * @param bool Whether to make this a password field + * @param string Vertical align (valign attribute) + */ function row_input($label, $name, $value = '', $colspan = 2, $size = 35, $length = false, $password = false, $lalign = 'top') { $this->row_text($label, "<input type=\"" . (($password) ? 'password' : 'text') . "\" class=\"input\" name=\"$name\" value=\"$value\" size=\"$size\" " . (($length) ? "maxlength=\"$length\" " : '') . "/>", $lalign, $colspan); } + /** + * Creates a table row with a <textarea> as the value column + * + * @param string Label text + * @param string Name of the <textarea> + * @param string Value of the <textarea> + * @param integer Colspan attribute + * @param integer Number of rows in the <textarea> + * @param integer Number of colums in the <textarea> + * @param bool Whether or not to use monospacing font + * @param string Extra style attributes to apply to the <textarea> + */ function row_textarea($label, $name, $value = '', $colspan = 2, $rows = 7, $cols = 50, $code = false, $style = '') { $this->row_text($label, "<textarea name=\"$name\" class=\"" . (($code) ? 'code' : 'input') . "\" rows=\"$rows\" cols=\"$cols\"" . (($style) ? ' style="' . $style . '"' : '') . ">$value</textarea>", 'top', $colspan); } + /** + * Creates a table row with the tfoot class + * + * @param string Extra text or HTML to insert into the row + * @param integer Colspan attribute + */ function row_tfoot($data, $colspan = 2) { echo $this->row_span($data, 'tfoot', 'center'); } + /** + * Creates a tfoot table row with submit buttons + * + * @param string Extra HTML to imbed in the row after the buttons + * @param string Submit button text (by default it uses pre-translated "Submit" from :save:) + * @param string Reset button text (default it uses pre-translated "Reset" from :reset:) + * @param integer Colspan attribute + */ function row_submit($extra = false, $submit = ':save:', $reset = ':reset:', $colspan = 2) { - global $bugsys; - if ($submit === ':save:') { - $submit = " " . $bugsys->lang->string('Submit') . " "; + $submit = " " . $this->registry->modules['localize']->string('Submit') . " "; } else { @@ -375,7 +503,7 @@ EOD; if ($reset === ':reset:') { - $reset = " " . $bugsys->lang->string('Reset') . " "; + $reset = " " . $this->registry->modules['localize']->string('Reset') . " "; } else { @@ -387,11 +515,25 @@ EOD; $this->row_tfoot($output); } + /** + * Creates an upload row; you need to specify some other paramaters in form_start() for this to work + * + * @param string Label text + * @param string Upload name + * @param integer Colspan attribute + */ function row_upload($label, $name, $colspan = 2) { $this->row_text($label, "<input type=\"file\" class=\"button\" name=\"$name\" size=\"35\" />", 'top', $colspan); } + /** + * Adds a name-value pair to an array that is constructed into a <select> list + * + * @param string Text displayed for the option + * @param string Value of the option + * @param bool Whether or not to select this particluar option + */ function list_item($name, $value, $selected = false) { global $listitem; @@ -399,6 +541,14 @@ EOD; $listitem[] = "\n\t<option value=\"$value\"" . (($selected == true) ? ' selected="selected"' : '') . ">$name</option>"; } + /** + * Assembles a <select> table row from list_item() items + * + * @param string Label text + * @param string Name of the <select> + * @param bool Automatically submit the form on a change? + * @param integer Colspan attribute + */ function row_list($label, $name, $is_jump = false, $colspan = 2) { global $listitem; @@ -410,14 +560,20 @@ EOD; $listitem = ''; - $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=\" " . $bugsys->lang->string('Go') . " \" accesskey=\"g\" />" : '') . "\n", $colspan); + $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); } + /** + * Creates a row with two radio buttons: yes and now + * + * @param string Label text + * @param string Name of the BOOL flag + * @param bool TRUE to select the YES by default; FALSE for NO + * @param integer Colspan attribute + */ function row_yesno($label, $name, $value, $colspan = 2) { - global $bugsys; - - $this->row_text($label, "<input type=\"radio\" name=\"$name\" value=\"1\"" . (($value) ? ' checked="checked"' : '') . " /> " . $bugsys->lang->string('Yes') . " <input type=\"radio\" name=\"$name\" value=\"0\"" . ((!$value) ? ' checked="checked"' : '') . " /> " . $bugsys->lang->string('No'), $colspan); + $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); } } -- 2.43.5