]>
src.bluestatic.org Git - isso.git/blob - PrinterRootPage.php
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 (PrinterRootPage.php)
28 require_once(ISSO
. '/PrinterRootAbstract.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 BSPrinterRootPage
extends BSPrinterRootAbstract
51 * @var BSPrinterNavigation
56 * The header code for the page
64 * @param string Page title
66 function __construct($title)
68 $this->title
= $title;
72 * Makes a new instance of the object in a static fashion
76 public static function make()
78 $obj = new ReflectionClass(__CLASS__
);
79 $args = func_get_args();
80 return $obj->newInstanceArgs($args);
84 * Sets the navigation object
86 * @param BSPrinterNavigation Navigator
88 * @return fluent interface
90 public function setNavigator(BSPrinterNavigation
$nav)
92 $this->navigator
= $nav;
97 * Returns the printer navigation object
99 * @return BSPrinterNavigation Navigation object
101 public function getNavigatior()
103 return $this->navigatior
;
107 * Sets the code to inject into the <head> element of the page
111 public function setHeaderCode($code)
113 $this->headerCode
= $code;
117 * Creates a redirect to another page; constructs the header and footer
118 * (therefore execution stops)
120 * @param string Location
121 * @param string Redirect message to be shown
122 * @param array An aray of POST variables to send through on the redirect
124 public static function redirect($location, $message = null, $postvars = array())
126 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
128 define('ISSO_PRINTER_NO_NAVIGATION', 1);
131 $page = new BSPrinterRootPage(_('Redirect'));
133 $page->addChild(new BSPrinterElementLabel('
134 <script type="text/javascript">
140 setTimeout("redirect()", timeout);
149 ' . ($postvars ? 'document.forms.postvars.submit();' : 'window.location = "' . $location . '";') . '
157 $vars = new BSPrinterRootForm($location, $postvars['do'], 'postvars');
158 unset($postvars['do']);
160 foreach ($postvars as $key => $value)
162 $vars->addChild(new BSPrinterElement('hidden', $key, $value));
165 $page->addChild($vars);
168 $redir = _('Please wait to be redirected. This page will load in a few seconds.');
169 if ($message == null)
171 $showmessage = $redir;
175 $showmessage = '<blockquote>' . $message . '</blockquote>';
176 $showmessage .= "\n<p>" . $redir . "</p>";
179 $page->addChild(BSPrinterRootPage
::message(_('Redirect'), $showmessage));
186 * Prints a complete table message
188 * @param string Message title
189 * @param string Message text
191 * @return BSPrinterRootTable A table
193 public static function message($title, $message)
195 $table = new BSPrinterRootTable();
197 $head = new BSPrinterElementTable();
198 $head->setCssClass('tcat');
199 $head->addChild(new BSPrinterElementLabel($title));
200 $table->addHeadingChild($head);
202 $msg = new BSPrinterElementTable();
203 $msg->addChild(new BSPrinterElementLabel((strpos($message, '<blockquote') === false ? "<blockquote>$message</blockquote>" : $message)));
204 $table->addChild($msg);
210 * Produces an entire page layout that asks the user whether or not
211 * they want to perform X action and provides a link to the YES and NO
214 * @param string Message that asks if they want to do X
215 * @param string Location to go to if the user confirms
216 * @param string Form 'do' value
217 * @param array Hidden parameters to pass to the next page
219 public static function confirm($message, $action, $do, $params)
221 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
223 define('ISSO_PRINTER_NO_NAVIGATION', 1);
226 $page = new BSPrinterRootPage(_('Confirm'));
228 $form = new BSPrinterRootForm($action, $do);
229 foreach ($params as $key => $value)
231 $form->addChild(new BSPrinterElement('hidden', $key, $value));
233 $page->addChild($form);
235 $table = new BSPrinterRootTable();
236 $table->setWidth('75%');
238 $head = new BSPrinterElementTable();
239 $head->addChild(new BSPrinterElementLabel(_('Confirm')));
240 $head->setCssClass('tcat');
241 $table->addChild($head);
243 $table->addChild(new BSPrinterElementTable(new BSPrinterElementLabel("<blockquote>$message</blockquote>")));
244 $no = new BSPrinterElement('button', '__no__', _('No'));
245 $no->setOnClick('history.back(1); return false;');
246 $table->addChild(BSPrinterElementTable
::row_submit(array($no), _('Yes'), null));
248 $form->addChild($table);
255 * Throws a fatal error message
257 * @param string Error string
259 public static function error($message)
261 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
263 define('ISSO_PRINTER_NO_NAVIGATION', 1);
266 $page = new BSPrinterRootPage(_('Error'));
267 $page->addChild(BSPrinterRootPage
::message(_('Error'), $message));
274 * Returns the HTML for all printed children elements
276 * @return string Printed HTML
278 protected function _paintChildren()
282 foreach ($this->children
as $child)
284 $builder .= "\n" . $child->paint() . "\n";
291 * Tells the element to paint itself (and any children)
293 public function paint()
295 $language = BSPrinter
::get_language_information();
297 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
298 echo "<html xml:lang=\"" . $language['langcode'] . "\" lang=\"" . $language['langcode'] . "\" dir=\"" . $language['direction'] . "\">\n<head>";
299 echo "\n\t<title>" . BSPrinter
::get_realm() . " - " . $this->title
. "</title>";
300 echo "\n\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" . $language['charset'] . "\" />";
301 echo "\n\t<link rel=\"stylesheet\" href=\"" . BSPrinter
::get_stylesheet() . "\" />";
302 echo "\n" . $this->headerCode
;
303 echo "\n</head>\n<body>\n";
305 if ($this->navigator
&& (!defined('ISSO_PRINTER_NO_NAVIGATION') || !constant('ISSO_PRINTER_NO_NAVIGATION')))
307 echo $this->navigator
->constructHeaderHtml();
310 echo $this->_paintChildren();
312 if ($this->navigator
&& (!defined('ISSO_PRINTER_NO_NAVIGATION') || !constant('ISSO_PRINTER_NO_NAVIGATION')))
314 echo $this->navigator
->constructFooterHtml();
317 $copyright = "\n<br />\n<p align=\"center\" class=\"copyright\">\n\t" . BSPrinter
::get_copyright() . "\n</p>";
319 if (!defined('ISSO_PRINTER_HIDE_SETUP'))
325 if (BSApp::get_debug())
327 if (defined('SVN') && preg_match('#^\$Id:?#', constant('SVN')))
329 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'));
332 if (defined('ISSO_MT_START'))
334 require_once ISSO . '/Functions.php';
335 echo "\n
<div align
=\"center\"
>Executed in
" . round(BSFunctions::fetch_microtime_diff(ISSO_MT_START), 10) . ' seconds</div>';
338 echo "\n
<br
/><div align
=\"center\"
>" . BSApp::get_debug_list() . "</div
>\n";
342 $queries = BSApp::$db->getHistory();
344 $table = new BSPrinterRootTable();
345 $head = new BSPrinterElementTable();
346 $head->addChild(new BSPrinterElementLabel('Query Debug'));
347 $head->setCssClass('thead');
348 $table->addHeadingChild($head);
350 foreach ($queries as $query)
352 $tr = new BSPrinterElementTable();
353 $tr->addChild(new BSPrinterElementLabel("\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"));
354 $table->addChild($tr);
357 $table->setWidth('30%');
359 echo $table->paint();
364 echo "\n\n
</body
>\n</html
>";