From 9d8c23db65454f08a6dda76bf621c40546f4067f Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 25 Dec 2006 22:43:44 +0000 Subject: [PATCH] - BSPrinterTableElement::RowSubmit() now will ignore buttons if they're null - Implemented BSPrinterRootElementPage:: Redirect(), ::Message(), ::Confirm, ::Error - Added onClick properties to BSPrinterBaseElement --- PrinterBaseElement.php | 25 ++++- PrinterRootElementPage.php | 165 +++++++++++++++++++++++++++- PrinterTableElement.php | 14 ++- printer.php | 213 +------------------------------------ 4 files changed, 198 insertions(+), 219 deletions(-) diff --git a/PrinterBaseElement.php b/PrinterBaseElement.php index 023254b..ce68dc9 100644 --- a/PrinterBaseElement.php +++ b/PrinterBaseElement.php @@ -66,6 +66,12 @@ class BSPrinterBaseElement extends BSPrinterElement */ private $active; + /** + * The JavaScript onClick attribute + * @var string + */ + private $onClick; + /** * Constructor */ @@ -93,6 +99,17 @@ class BSPrinterBaseElement extends BSPrinterElement $this->active = $active; } + // ################################################################### + /** + * Sets the JavaScript onclick action + * + * @param string onClick attribute value + */ + public function setOnClick($onClick) + { + $this->onClick = $onClick; + } + // ################################################################### /** * Returns the type @@ -136,6 +153,10 @@ class BSPrinterBaseElement extends BSPrinterElement { $name = ' name="' . $this->name . '"'; $value = ' value="' . $this->value . '"'; + $onclick = ($this->onClick ? ' onclick="' . $this->onClick . '"' : ''); + + $attrs = $name . $value . $onclick; + switch ($this->type) { case 'text': @@ -143,7 +164,7 @@ class BSPrinterBaseElement extends BSPrinterElement case 'button': case 'submit': case 'reset': - return 'type == 'text' OR $this->type == 'password') ? ' size="35" maxlength="255"' : ''). $this->_prepareStyle() . ' />'; + return 'type == 'text' OR $this->type == 'password') ? ' size="35" maxlength="255"' : ''). $this->_prepareStyle() . ' />'; break; case 'hidden': @@ -152,7 +173,7 @@ class BSPrinterBaseElement extends BSPrinterElement case 'checkbox': case 'radio': - return 'active ? ' checked="checked"' : '') . $this->_prepareStyle() . ' />'; + return 'active ? ' checked="checked"' : '') . $this->_prepareStyle() . ' />'; break; case 'upload': diff --git a/PrinterRootElementPage.php b/PrinterRootElementPage.php index a3c85a8..c4e65e2 100644 --- a/PrinterRootElementPage.php +++ b/PrinterRootElementPage.php @@ -70,6 +70,169 @@ class BSPrinterRootElementPage extends BSPrinterRootElement $this->title = $title; } + // ################################################################### + /** + * Creates a redirect to another page; constructs the header and footer + * (therefore execution stops) + * + * @param string Controller + * @param string Action + * @param string Redirect message to be shown + * @param array An aray of POST variables to send through on the redirect + */ + public static function Redirect($controller, $action, $message = null, $postvars = array()) + { + if (!defined('ISSO_PRINTER_NO_NAVIGATION')) + { + define('ISSO_PRINTER_NO_NAVIGATION', 1); + } + + $page = new BSPrinterRootElementPage(_('Redirect')); + + $page->addChild(new BSPrinterLabelElement(' + ')); + + if ($postvars) + { + $vars = new BSPrinterRootElementForm($controller, $action, 'postvars'); + + foreach ($postvars AS $key => $value) + { + $vars->addChild(new BSPrinterBaseElement('hidden', $key, $value)); + } + + $page->addChild($vars); + } + + $redir = _('Please wait to be redirected. This page will load in a few seconds.'); + $override = false; + if ($message == null) + { + $showmessage = $redir; + } + else + { + $showmessage = '
' . $message . '
'; + $showmessage .= "\n

" . $redir . "

"; + $override = true; + } + + $page->addChild(BSPrinterRootElementPage::Message(_('Redirect'), $showmessage)); + + $page->paint(); + exit; + } + + // ################################################################### + /** + * Prints a complete table message + * + * @param string Message title + * @param string Message text + * + * @return BSPrinterRootElementTable A table + */ + public static function Message($title, $message) + { + $table = new BSPrinterRootElementTable(); + + $head = new BSPrinterTableElement(); + $head->setCssClass('tcat'); + $head->addChild(new BSPrinterLabelElement($title)); + $table->addHeadingChild($head); + + $msg = new BSPrinterTableElement(); + $msg->addChild(new BSPrinterLabelElement((strpos($message, '$message" : $message))); + $table->addChild($msg); + + return $table; + } + + // ################################################################### + /** + * 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 and NO + * action + * + * @param string Message that asks if they want to do X + * @param string Controller to go for YES + * @param string Action to pass + * @param array Hidden parameters to pass to the next page + */ + public static function Confirm($message, $controller, $action, $params) + { + if (!defined('ISSO_PRINTER_NO_NAVIGATION')) + { + define('ISSO_PRINTER_NO_NAVIGATION', 1); + } + + $page = new BSPrinterRootElementPage(_('Confirm')); + + $form = new BSPrinterRootElementForm($controller, $action); + foreach ($params AS $key => $value) + { + $form->addChild(new BSPrinterBaseElement('hidden', $key, $value)); + } + $page->addChild($form); + + $table = new BSPrinterRootElementTable(); + $table->setWidth('75%'); + + $head = new BSPrinterTableElement(); + $head->addChild(new BSPrinterLabelElement(_('Confirm'))); + $head->setCssClass('tcat'); + $table->addChild($head); + + $table->addChild(new BSPrinterTableElement(new BSPrinterLabelElement("
$message
"))); + $no = new BSPrinterBaseElement('button', '__no__', _('No')); + $no->setOnClick('history.back(1); return false;'); + $table->addChild(BSPrinterTableElement::RowSubmit(array($no), _('Yes'), null)); + + $form->addChild($table); + + $page->paint(); + exit; + } + + // ################################################################### + /** + * Throws a fatal error message + * + * @param string Error string + */ + public static function Error($message) + { + if (!defined('ISSO_PRINTER_NO_NAVIGATION')) + { + define('ISSO_PRINTER_NO_NAVIGATION', 1); + } + + $page = new BSPrinterRootElementPage(_('Error')); + $page->addChild(BSPrinterRootElementPage::Message(_('Error'), $message)); + $page->paint(); + + exit; + } + // ################################################################### /** * Sets the language array information @@ -181,7 +344,7 @@ class BSPrinterRootElementPage extends BSPrinterRootElement } } - echo("\n\n\n"); + echo "\n\n\n"; } } diff --git a/PrinterTableElement.php b/PrinterTableElement.php index 6bf70c4..f3e7d9c 100644 --- a/PrinterTableElement.php +++ b/PrinterTableElement.php @@ -133,11 +133,17 @@ class BSPrinterTableElement extends BSPrinterElement $save = ($save == ':submit:' ? _('Submit') : $save); $reset = ($reset == ':reset:' ? _('Reset') : $reset); - $elm = new BSPrinterBaseElement('submit', '__submit__', " $save "); - $build .= "\n\t\t\t" . $elm->paint(); + if (!is_null($save)) + { + $elm = new BSPrinterBaseElement('submit', '__submit__', " $save "); + $build .= "\n\t\t\t" . $elm->paint(); + } - $elm = new BSPrinterBaseElement('reset', '__reset__', " $reset "); - $build .= "\n\t\t\t" . $elm->paint() . "\n\t\t"; + if (!is_null($reset)) + { + $elm = new BSPrinterBaseElement('reset', '__reset__', " $reset "); + $build .= "\n\t\t\t" . $elm->paint() . "\n\t\t"; + } $tr = new BSPrinterTableElement(); $tr->addChild(new BSPrinterLabelElement($build)); diff --git a/printer.php b/printer.php index 4da94fd..b0be961 100644 --- a/printer.php +++ b/printer.php @@ -55,158 +55,7 @@ require_once('ISSO/PrinterTableElement.php'); * */ class Printer -{ - /* Page-start hooko - * @var string - */ - private $page_start_hook = ':=NO METHOD=:'; - - // ################################################################### - /** - * Creates a redirect to another page; constructs the header and footer - * (therefore execution stops) - * - * @param string Location to redirect to - * @param string Redirect message to be shown - * @param array An aray of POST variables to send through on the redirect - */ - public function redirect($location, $message = null, $postvars = array()) - { - $js = ' - '; - - if (!defined('ISSO_PRINTER_NO_NAVIGATION')) - { - define('ISSO_PRINTER_NO_NAVIGATION', 1); - } - - $this->page_start(_('Redirect')); - - if ($postvars) - { - $this->form_start($location, null, false, 'postvars'); - - foreach ($postvars AS $key => $value) - { - $this->form_hidden_field($key, $value); - } - - $this->form_end(); - } - - $redir = sprintf(_('Please wait to be redirected. If you are not redirected in a few seconds, click here.'), $location); - $override = false; - if ($message == null) - { - $showmessage = $redir; - } - else - { - $showmessage = '
' . $message . '
'; - $showmessage .= "\n

" . $redir . "

"; - $override = true; - } - - $this->page_message(_('Redirect'), $showmessage, $override); - - $this->page_code($js); - - $this->page_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 and NO - * action - * - * @param string Message that asks if they want to do X - * @param string Location to go for YES - * @param string DO action to pass - * @param array Hidden parameters to pass to the next page - */ - public function confirm($message, $location, $action, $params) - { - if (!defined('ISSO_PRINTER_NO_NAVIGATION')) - { - define('ISSO_PRINTER_NO_NAVIGATION', 1); - } - - $this->page_start(_('Confirm')); - - $this->form_start($location, $action); - foreach ($params AS $key => $value) - { - $this->form_hidden_field($key, $value); - } - - $this->table_start(true, '75%'); - $this->table_head(_('Confirm'), 1); - $this->row_span("
$message
", ':swap:', 'left', 1); - $this->row_submit('', _('Yes'), ''); - $this->table_end(); - - $this->form_end(); - - $this->page_end(); - } - - // ################################################################### - /** - * Throws a fatal error; constructs the header and footer - * - * @param string Error messsage text - */ - public function error($message) - { - if (!defined('ISSO_PRINTER_NO_NAVIGATION')) - { - define('ISSO_PRINTER_NO_NAVIGATION', 1); - } - - $this->page_start(_('Error')); - $this->page_message(_('Error'), $message); - $this->page_end(); - - exit; - } - - // ################################################################### - /** - * 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 - * @param bool Override the message: control the entire output (no
)? - */ - public function page_message($title, $message, $overridemessage = false) - { - $this->table_start(true, '75%'); - $this->table_head($title, 1); - $this->row_span(($overridemessage ? $message : "
$message
"), ':swap:', 'left', 1); - $this->table_end(); - } - +{ // ################################################################### /** * Creates a table row with a ", 'top', $colspan); } - - // ################################################################### - /** - * Adds a name-value pair to an array that is constructed into a - * table row from list_item() items - * - * @param string Label text - * @param string Name of the $optionlist\n\n", $colspan); - } - - // ################################################################### - /** - * Assembles a list of checkboxes from list_item() items - * - * @param string Label text - * @param string Name of the s - * @param integer Colspan attribute - */ - public function row_checkbox($label, $name, $colspan = 2) - { - global $listitem; - - foreach ($listitem AS $value => $box) - { - $optionlist[] = "\n\t $box[name]"; - } - - $listitem = array(); - - $this->row_text($label, "\n" . implode('
', $optionlist) . "\n", $colspan); - } } /*=====================================================================*\ -- 2.22.5