From 83cc76d7767b12caddfae86bd03b31e3b115cf94 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Tue, 19 Dec 2006 23:23:15 +0000 Subject: [PATCH] - Remove the functions that have already been created in the new Printer system from printer.php - Added an upload BaseElement - Added BSPrinterTableElement::RowUpload() and BSPrinterTableElement::RowYesNo() --- PrinterBaseElement.php | 6 +- PrinterTableElement.php | 48 ++++++ printer.php | 366 +--------------------------------------- 3 files changed, 57 insertions(+), 363 deletions(-) diff --git a/PrinterBaseElement.php b/PrinterBaseElement.php index 55996e6..258e06f 100644 --- a/PrinterBaseElement.php +++ b/PrinterBaseElement.php @@ -102,7 +102,7 @@ class BSPrinterBaseElement extends BSPrinterElement public function paint() { $name = ' name="' . $this->name . '"'; - $value = ($this->value ? ' value="' . $this->value . '"' : ''); + $value = ' value="' . $this->value . '"'; switch ($this->type) { case 'text': @@ -122,6 +122,10 @@ class BSPrinterBaseElement extends BSPrinterElement return 'active ? ' checked="checked"' : '') . $this->_prepareStyle() . ' />'; break; + case 'upload': + return '_prepareStyle() . ' />'; + break; + case 'option': return 'active ? ' selected="selected"' : '') . $this->_prepareStyle() . '>' . $this->name . ''; break; diff --git a/PrinterTableElement.php b/PrinterTableElement.php index bd8a673..8414470 100644 --- a/PrinterTableElement.php +++ b/PrinterTableElement.php @@ -155,6 +155,54 @@ class BSPrinterTableElement extends BSPrinterElement return $tr; } + // ################################################################### + /** + * Factory method to create an upload form element; requires that the + * form this is attached to have the upload flag set + * + * @param string Label for the element + * @param string Name of the + * + * @return BSPrinterTableElement Upload form + */ + public static function RowUpload($label, $name) + { + $tr = new BSPrinterTableElement(); + + $tr->addChild(new BSPrinterLabelElement($label)); + $tr->addChild(new BSPrinterBaseElement('upload', $name)); + + return $tr; + } + + // ################################################################### + /** + * Creates a row with a radio select option for yes/no + * + * @param string Row label + * @param string Name of the radio buttons + * @param bool Yes is selected? (if false, No is selected) + * + * @return BSPrinterTableElement Yes-No row + */ + public static function RowYesNo($label, $name, $yes) + { + $elm = new BSPrinterBaseElement('radio', $name, 1); + $elm->setActive($yes); + + $build = $elm->paint() . ' ' . _('Yes') . ' '; + + $elm = new BSPrinterBaseElement('radio', $name, 0); + $elm->setActive(!$yes); + + $build .= $elm->paint() . ' ' . _('No'); + + $tr = new BSPrinterTableElement(); + $tr->addChild(new BSPrinterLabelElement($label)); + $tr->addChild(new BSPrinterLabelElement($build)); + return $tr; + } + // ################################################################### /** * Returns the number of columns in this element diff --git a/printer.php b/printer.php index f789822..c975c77 100644 --- a/printer.php +++ b/printer.php @@ -32,6 +32,7 @@ require_once('ISSO/PrinterLabelElement.php'); require_once('ISSO/PrinterRootElement.php'); require_once('ISSO/PrinterRootElementPage.php'); require_once('ISSO/PrinterRootElementTable.php'); +require_once('ISSO/PrinterRootElementForm.php'); require_once('ISSO/PrinterTableElement.php'); /** @@ -55,64 +56,11 @@ require_once('ISSO/PrinterTableElement.php'); */ class Printer { - /** - * Framework registry object - * @var object - */ - private $registry = null; - - /** - * Realm that we are operating in (displayed in the ) - * @var string - */ - private $realm = '[UNDEFINED REALM]'; - - /** - * CSS to place in the page - * @var string - */ - private $css = ''; - - /** - * Extra code to place - * @var sring - */ - private $code = ''; - - /** * Page-start hooko * @var string */ private $page_start_hook = ':=NO METHOD=:'; - - /** - * Language information array: ('langcode' =>, 'direction' =>, 'charset' =>) - * @var array - */ - private $language = array('langcode' => 'en_US', 'direction' => 'ltr', 'charset' => 'utf-8'); - - // ################################################################### - /** - * Sets the realm (or title) of the printed output - * - * @param string Title/realm - */ - public function setRealm($realm) - { - $this->realm = $realm; - } - - // ################################################################### - /** - * Sets the language array information - * - * @param array Language array - */ - public function setLanguageInformation($lang) - { - $this->language = $lang; - } - + // ################################################################### /** * Creates a redirect to another page; constructs the header and footer @@ -242,50 +190,6 @@ class Printer exit; } - // ################################################################### - /** - * Links CSS to the page from a given relative path - * - * @param string Relative path to the CSS file - */ - public function css_link($path) - { - $this->css .= "\n\t<link rel=\"stylesheet\" href=\"$path\" />"; - } - - // ################################################################### - /** - * Imbeds actual CSS information into the page in <style> tags - * - * @param string Path of the CSS file to be imbeded - */ - public function css_imbed($path) - { - $data = require_once($path); - $css = preg_replace('#/\*(.*?)\*/(\r|\n)*#s', '', $css); - $css = trim($css); - $this->css .= "\n\t<style type=\"text/css\">\n\t<!--\n" . $css . "\n\t//-->\n\t</style>"; - } - - // ################################################################### - /** - * Places raw HTML code directly into the documet at the current - * position - * - * @param string HTML code - */ - public function page_code($code) - { - if (defined('ISSO_PRINTER_DONE_HEADER')) - { - echo "\n\n$code\n\n"; - } - else - { - $this->code .= "\n\n$code\n\n"; - } - } - // ################################################################### /** * A block function that produces a table with a message in it. This @@ -303,239 +207,6 @@ class Printer $this->table_end(); } - // ################################################################### - /** - * Closes the HTML document structure an adds the copyright; this also - * stops execution of the page - */ - public function page_end() - { - if (BSRegister::GetDebug() AND isset($_GET['query'])) - { - ob_clean(); - ob_end_clean(); - - if (is_array($this->registry->modules[ISSO_DB_LAYER]->history)) - { - foreach ($this->registry->modules[ISSO_DB_LAYER]->history AS $query) - { - echo $this->registry->modules[ISSO_DB_LAYER]->construct_query_debug($query); - } - } - exit; - } - - if ($this->registry->is_loaded('printer_navigation') AND (!defined('ISSO_PRINTER_NO_NAVIGATION') OR (defined('ISSO_PRINTER_NO_NAVIGATION') AND constant('ISSO_PRINTER_NO_NAVIGATION') != true))) - { - echo $this->registry->modules['printer_navigation']->generate_footer_html(); - } - - $copyright = "\n<br />\n<p align=\"center\" class=\"copyright\">\n\t<a href=\"http://www.bluestatic.org\" target=\"_blank\">" . BSRegister::GetApplication() . ' ' . BSRegister::GetAppVersion() . ", ©2002 - " . date('Y') . " Blue Static</a>\n</p>"; - - if (!defined('ISSO_PRINTER_HIDE_SETUP')) - { - echo "\n$copyright"; - echo $this->registry->construct_debug_block(false); - } - - echo "\n\n</body>\n</html>"; - - exit; - } - - // ------------------------------------------------------------------- - - // ################################################################### - /** - * Opens a <table> tag with styling - * - * @param bool Whether to add a <br /> before the table - * @param string Value of the width attribute - */ - public function table_start($break = true, $width = '90%') - { - if ($break) - { - echo '<br />'; - } - - echo "\n<table cellpadding=\"4\" cellspacing=\"1\" 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 - */ - public function table_head($title, $colspan = 2) - { - echo "<tr>\n\t<td class=\"tcat\" align=\"center\" colspan=\"$colspan\">$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 - */ - public function table_column_head($columnarray) - { - if (is_array($columnarray)) - { - $render = "<tr valign=\"top\" align=\"center\">\n"; - - foreach ($columnarray AS $header) - { - $render .= "\t<td class=\"thead\" align=\"center\">$header</td>\n"; - } - - $render .= "</tr>\n"; - - echo $render; - } - } - - // ################################################################### - /** - * Closes a <table> tag - */ - public function table_end() - { - echo "\n</table>\n"; - } - - // ------------------------------------------------------------------- - - // ################################################################### - /** - * 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) - */ - public 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"; - - if ($do !== null) - { - $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 - */ - public function form_hidden_field($name, $value) - { - echo "<input type=\"hidden\" name=\"$name\" value=\"$value\" />\n"; - } - - // ################################################################### - /** - * Closes a <form> tag - */ - public function form_end() - { - echo "</form>\n<!-- / input form -->\n"; - } - - // ------------------------------------------------------------------- - - // ################################################################### - /** - * 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) - */ - public function row_multi_item($row_array) - { - BSFunctions::SwapCssClasses(); - - foreach ($row_array AS $item => $align) - { - $row_data["$align"][] = $item; - } - - echo "<tr valign=\"top\">"; - - foreach ($row_data AS $align_key => $item_array) - { - if ($align_key == 'c') - { - $align = 'center'; - } - else if ($align_key == 'l') - { - $align = 'left'; - } - else if ($align_key == 'r') - { - $align = 'right'; - } - - foreach ($item_array AS $value) - { - echo "\n\t<td class=\"" . BSFunctions::$cssClass . "\" 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 - */ - public function row_text($label, $value = ' ', $valign = 'top', $colspan = 2, $class = -1) - { - global $IS_SETTINGS; - - if ($class == -1) - { - if (!$IS_SETTINGS) - { - BSFunctions::SwapCssClasses(); - $row_class = BSFunctions::$cssClass; - } - else - { - $row_class = 'alt2'; - } - } - else - { - $row_class = $class; - } - - echo "<tr valign=\"$valign\">"; - echo "\n\t<td class=\"$row_class\">$label</td>"; - echo "\n\t<td class=\"$row_class\" colspan=\"" . ($colspan - 1) . "\">$value</td>"; - - echo "\n</tr>\n"; - } - // ################################################################### /** * Creates a table row with a <textarea> as the value column @@ -554,20 +225,6 @@ class Printer $this->row_text($label, "<textarea name=\"$name\" class=\"" . ($code ? 'code' : 'input') . "\" rows=\"$rows\" cols=\"$cols\"" . ($style ? ' style="' . $style . '"' : '') . ">$value</textarea>", 'top', $colspan); } - // ################################################################### - /** - * 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 - */ - public 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 @@ -590,10 +247,9 @@ class Printer * * @param string Label text * @param string Name of the <select> - * @param bool Automatically submit the form on a change? * @param integer Colspan attribute */ - public function row_list($label, $name, $is_jump = false, $colspan = 2) + public function row_list($label, $name, $colspan = 2) { global $listitem; @@ -604,7 +260,7 @@ class Printer $listitem = array(); - $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=\" " . _('Go') . " \" accesskey=\"g\" />" : '') . "\n", $colspan); + $this->row_text($label, "\n<select class=\"button\" name=\"$name\">$optionlist\n</select>\n", $colspan); } // ################################################################### @@ -628,20 +284,6 @@ class Printer $this->row_text($label, "\n" . implode('<br />', $optionlist) . "\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 - */ - public function row_yesno($label, $name, $value, $colspan = 2) - { - $this->row_text($label, "<input type=\"radio\" name=\"$name\" value=\"1\"" . ($value ? ' checked="checked"' : '') . " /> " . _('Yes') . " <input type=\"radio\" name=\"$name\" value=\"0\"" . (!$value ? ' checked="checked"' : '') . " /> " . _('No'), $colspan); - } } /*=====================================================================*\ -- 2.22.5