2 /*=====================================================================*
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2005-2008 Blue Static
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 2 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 \*=====================================================================*/
23 * Printer Root Element: Page (PrinterRootElementPage.php)
28 require_once(ISSO
. '/PrinterRootElement.php');
31 * Printer Root Element: Page
33 * This root element represents the entire page and is usually used for all
34 * printer applications
37 * @copyright Copyright (c)2005 - 2008, Blue Static
41 class BSPrinterRootElementPage
extends BSPrinterRootElement
51 * @var BSPrinterNavigation
55 // ###################################################################
59 * @param string Page title
61 function __construct($title)
63 $this->title
= $title;
67 * Makes a new instance of the object in a static fashion
71 public static function make()
73 $obj = new ReflectionClass(__CLASS__
);
74 $args = func_get_args();
75 return $obj->newInstanceArgs($args);
79 * Sets the navigation object
81 * @param BSPrinterNavigation Navigator
83 public function setNavigator(BSPrinterNavigation
$nav)
85 $this->navigator
= $nav;
89 * Returns the printer navigation object
91 * @return BSPrinterNavigation Navigation object
93 public function getNavigatior()
95 return $this->navigatior
;
98 // ###################################################################
100 * Creates a redirect to another page; constructs the header and footer
101 * (therefore execution stops)
103 * @param string Controller
104 * @param string Action
105 * @param string Redirect message to be shown
106 * @param array An aray of POST variables to send through on the redirect
108 public static function redirect($controller, $action, $message = null, $postvars = array())
110 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
112 define('ISSO_PRINTER_NO_NAVIGATION', 1);
115 $page = new BSPrinterRootElementPage(_('Redirect'));
117 $page->addChild(new BSPrinterLabelElement('
118 <script type="text/javascript">
124 setTimeout("redirect()", timeout);
133 ' . ($postvars ? 'document.forms.postvars.submit();' : 'window.location = "' . "$controller.php?action=$action" . '";') . '
141 $vars = new BSPrinterRootElementForm($controller, $action, 'postvars
');
143 foreach ($postvars AS $key => $value)
145 $vars->addChild(new BSPrinterBaseElement('hidden
', $key, $value));
148 $page->addChild($vars);
151 $redir = _('Please wait to be redirected
. This page will load in a few seconds
.');
153 if ($message == null)
155 $showmessage = $redir;
159 $showmessage = '<blockquote
>' . $message . '</blockquote
>';
160 $showmessage .= "\n<p>" . $redir . "</p>";
164 $page->addChild(BSPrinterRootElementPage::message(_('Redirect
'), $showmessage));
170 // ###################################################################
172 * Prints a complete table message
174 * @param string Message title
175 * @param string Message text
177 * @return BSPrinterRootElementTable A table
179 public static function message($title, $message)
181 $table = new BSPrinterRootElementTable();
183 $head = new BSPrinterTableElement();
184 $head->setCssClass('tcat
');
185 $head->addChild(new BSPrinterLabelElement($title));
186 $table->addHeadingChild($head);
188 $msg = new BSPrinterTableElement();
189 $msg->addChild(new BSPrinterLabelElement((strpos($message, '<blockquote
') === false ? "<blockquote>$message</blockquote>" : $message)));
190 $table->addChild($msg);
195 // ###################################################################
197 * Produces an entire page layout that asks the user whether or not
198 * they want to perform X action and provides a link to the YES and NO
201 * @param string Message that asks if they want to do X
202 * @param string Controller to go for YES
203 * @param string Action to pass
204 * @param array Hidden parameters to pass to the next page
206 public static function confirm($message, $controller, $action, $params)
208 if (!defined('ISSO_PRINTER_NO_NAVIGATION
'))
210 define('ISSO_PRINTER_NO_NAVIGATION
', 1);
213 $page = new BSPrinterRootElementPage(_('Confirm
'));
215 $form = new BSPrinterRootElementForm($controller, $action);
216 foreach ($params AS $key => $value)
218 $form->addChild(new BSPrinterBaseElement('hidden
', $key, $value));
220 $page->addChild($form);
222 $table = new BSPrinterRootElementTable();
223 $table->setWidth('75%
');
225 $head = new BSPrinterTableElement();
226 $head->addChild(new BSPrinterLabelElement(_('Confirm
')));
227 $head->setCssClass('tcat
');
228 $table->addChild($head);
230 $table->addChild(new BSPrinterTableElement(new BSPrinterLabelElement("<blockquote>$message</blockquote>")));
231 $no = new BSPrinterBaseElement('button
', '__no__
', _('No
'));
232 $no->setOnClick('history
.back(1); return false;');
233 $table->addChild(BSPrinterTableElement::row_submit(array($no), _('Yes
'), null));
235 $form->addChild($table);
241 // ###################################################################
243 * Throws a fatal error message
245 * @param string Error string
247 public static function error($message)
249 if (!defined('ISSO_PRINTER_NO_NAVIGATION
'))
251 define('ISSO_PRINTER_NO_NAVIGATION
', 1);
254 $page = new BSPrinterRootElementPage(_('Error
'));
255 $page->addChild(BSPrinterRootElementPage::message(_('Error
'), $message));
261 // ###################################################################
263 * Returns the HTML for all printed children elements
265 * @return string Printed HTML
267 protected function _paintChildren()
271 foreach ($this->children AS $child)
273 $this->builder .= "\n" . $child->paint() . "\n";
276 return $this->builder;
279 // ###################################################################
281 * Tells the element to paint itself (and any children)
283 public function paint()
285 $language = BSPrinter::get_language_information();
287 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
288 echo "<html xml:lang=\"" . $language['langcode
'] . "\" lang=\"" . $language['langcode
'] . "\" dir=\"" . $language['direction
'] . "\">\n<head>";
289 echo "\n\t<title>" . BSPrinter::get_realm() . " - " . $this->title . "</title>";
290 echo "\n\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" . $language['charset
'] . "\" />";
291 echo "\n\t<link rel=\"stylesheet\" href=\"" . BSPrinter::get_stylesheet() . "\" />";
292 echo "\n</head>\n<body>\n";
294 if ($this->navigator AND (!defined('ISSO_PRINTER_NO_NAVIGATION
') OR !constant('ISSO_PRINTER_NO_NAVIGATION
')))
296 echo $this->navigator->constructHeaderHtml();
299 echo $this->_paintChildren();
301 if ($this->navigator AND (!defined('ISSO_PRINTER_NO_NAVIGATION
') OR !constant('ISSO_PRINTER_NO_NAVIGATION
')))
303 echo $this->navigator->constructFooterHtml();
306 $copyright = "\n<br />\n<p align=\"center\" class=\"copyright\">\n\t" . BSPrinter::get_copyright() . "\n</p>";
308 if (!defined('ISSO_PRINTER_HIDE_SETUP
'))
314 if (BSApp::get_debug())
316 if (defined('SVN
') AND preg_match('#^\$Id:?#', constant('SVN')))
318 echo preg_replace('#\$' . 'Id: (.+?) ([0-9].+?) [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}(.+?) (.+?) \$#', "\n<br />\n" . '<div align="center"><strong>\1</strong> — r\2</div>', constant('SVN'));
321 if (defined('ISSO_MT_START'))
323 echo "\n<div align=\"center\">Executed in " . round(BSFunctions
::fetch_microtime_diff(ISSO_MT_START
), 10) . ' seconds</div>';
326 echo "\n<br /><div align=\"center\">" . BSApp
::get_debug_list() . "</div>\n";
328 if (BSApp
::GetType('Db'))
330 $queries = BSApp
::GetType('Db')->getHistory();
332 $table = new BSPrinterRootElementTable();
333 $head = new BSPrinterTableElement();
334 $head->addChild(new BSPrinterLabelElement('Query Debug'));
335 $head->setCssClass('thead');
336 $table->addHeadingChild($head);
338 foreach ($queries AS $query)
340 $tr = new BSPrinterTableElement();
341 $tr->addChild(new BSPrinterLabelElement("\n\t\t\t" . $query['query'] . "\n\n\t\t\t<div class=\"smallfont\">(" . $query['time'] . ")</div>\n<!--\n" . $query['trace'] . "\n-->\n\t\t"));
342 $table->addChild($tr);
345 $table->setWidth('30%');
347 echo $table->paint();
352 echo "\n\n</body>\n</html>";