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
58 * @param string Page title
60 function __construct($title)
62 $this->title
= $title;
66 * Makes a new instance of the object in a static fashion
70 public static function make()
72 $obj = new ReflectionClass(__CLASS__
);
73 $args = func_get_args();
74 return $obj->newInstanceArgs($args);
78 * Sets the navigation object
80 * @param BSPrinterNavigation Navigator
82 * @return fluent interface
84 public function setNavigator(BSPrinterNavigation
$nav)
86 $this->navigator
= $nav;
91 * Returns the printer navigation object
93 * @return BSPrinterNavigation Navigation object
95 public function getNavigatior()
97 return $this->navigatior
;
101 * Creates a redirect to another page; constructs the header and footer
102 * (therefore execution stops)
104 * @param string Location
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($location, $message = null
, $postvars = array())
110 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
112 define('ISSO_PRINTER_NO_NAVIGATION', 1);
115 $page = new BSPrinterRootPage(_('Redirect'));
117 $page->addChild(new BSPrinterElementLabel('
118 <script type="text/javascript">
124 setTimeout("redirect()", timeout);
133 ' . ($postvars ?
'document.forms.postvars.submit();' : 'window.location = "' . $location . '";') . '
141 $vars = new BSPrinterRootForm($location, $postvars['do'], 'postvars');
142 unset($postvars['do']);
144 foreach ($postvars as $key => $value)
146 $vars->addChild(new BSPrinterElement('hidden', $key, $value));
149 $page->addChild($vars);
152 $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>";
163 $page->addChild(BSPrinterRootPage
::message(_('Redirect'), $showmessage));
170 * Prints a complete table message
172 * @param string Message title
173 * @param string Message text
175 * @return BSPrinterRootTable A table
177 public static function message($title, $message)
179 $table = new BSPrinterRootTable();
181 $head = new BSPrinterElementTable();
182 $head->setCssClass('tcat');
183 $head->addChild(new BSPrinterElementLabel($title));
184 $table->addHeadingChild($head);
186 $msg = new BSPrinterElementTable();
187 $msg->addChild(new BSPrinterElementLabel((strpos($message, '<blockquote') === false ?
"<blockquote>$message</blockquote>" : $message)));
188 $table->addChild($msg);
194 * Produces an entire page layout that asks the user whether or not
195 * they want to perform X action and provides a link to the YES and NO
198 * @param string Message that asks if they want to do X
199 * @param string Location to go to if the user confirms
200 * @param string Form 'do' value
201 * @param array Hidden parameters to pass to the next page
203 public static function confirm($message, $action, $do, $params)
205 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
207 define('ISSO_PRINTER_NO_NAVIGATION', 1);
210 $page = new BSPrinterRootPage(_('Confirm'));
212 $form = new BSPrinterRootForm($action, $do);
213 foreach ($params as $key => $value)
215 $form->addChild(new BSPrinterElement('hidden', $key, $value));
217 $page->addChild($form);
219 $table = new BSPrinterRootTable();
220 $table->setWidth('75%');
222 $head = new BSPrinterElementTable();
223 $head->addChild(new BSPrinterElementLabel(_('Confirm')));
224 $head->setCssClass('tcat');
225 $table->addChild($head);
227 $table->addChild(new BSPrinterElementTable(new BSPrinterElementLabel("<blockquote>$message</blockquote>")));
228 $no = new BSPrinterElement('button', '__no__', _('No'));
229 $no->setOnClick('history.back(1); return false;');
230 $table->addChild(BSPrinterElementTable
::row_submit(array($no), _('Yes'), null
));
232 $form->addChild($table);
239 * Throws a fatal error message
241 * @param string Error string
243 public static function error($message)
245 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
247 define('ISSO_PRINTER_NO_NAVIGATION', 1);
250 $page = new BSPrinterRootPage(_('Error'));
251 $page->addChild(BSPrinterRootPage
::message(_('Error'), $message));
258 * Returns the HTML for all printed children elements
260 * @return string Printed HTML
262 protected function _paintChildren()
266 foreach ($this->children
as $child)
268 $builder .= "\n" . $child->paint() . "\n";
275 * Tells the element to paint itself (and any children)
277 public function paint()
279 $language = BSPrinter
::get_language_information();
281 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
282 echo "<html xml:lang=\"" . $language['langcode'] . "\" lang=\"" . $language['langcode'] . "\" dir=\"" . $language['direction'] . "\">\n<head>";
283 echo "\n\t<title>" . BSPrinter
::get_realm() . " - " . $this->title
. "</title>";
284 echo "\n\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" . $language['charset'] . "\" />";
285 echo "\n\t<link rel=\"stylesheet\" href=\"" . BSPrinter
::get_stylesheet() . "\" />";
286 echo "\n</head>\n<body>\n";
288 if ($this->navigator
&& (!defined('ISSO_PRINTER_NO_NAVIGATION') ||
!constant('ISSO_PRINTER_NO_NAVIGATION')))
290 echo $this->navigator
->constructHeaderHtml();
293 echo $this->_paintChildren();
295 if ($this->navigator
&& (!defined('ISSO_PRINTER_NO_NAVIGATION') ||
!constant('ISSO_PRINTER_NO_NAVIGATION')))
297 echo $this->navigator
->constructFooterHtml();
300 $copyright = "\n<br />\n<p align=\"center\" class=\"copyright\">\n\t" . BSPrinter
::get_copyright() . "\n</p>";
302 if (!defined('ISSO_PRINTER_HIDE_SETUP'))
308 if (BSApp
::get_debug())
310 if (defined('SVN') && preg_match('#^\$Id:?#', constant('SVN')))
312 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'));
315 if (defined('ISSO_MT_START'))
317 echo "\n<div align=\"center\">Executed in " . round(BSFunctions
::fetch_microtime_diff(ISSO_MT_START
), 10) . ' seconds</div>';
320 echo "\n<br /><div align=\"center\">" . BSApp
::get_debug_list() . "</div>\n";
324 $queries = BSApp
::$db->getHistory();
326 $table = new BSPrinterRootTable();
327 $head = new BSPrinterElementTable();
328 $head->addChild(new BSPrinterElementLabel('Query Debug'));
329 $head->setCssClass('thead');
330 $table->addHeadingChild($head);
332 foreach ($queries as $query)
334 $tr = new BSPrinterElementTable();
335 $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"));
336 $table->addChild($tr);
339 $table->setWidth('30%');
341 echo $table->paint();
346 echo "\n\n</body>\n</html>";