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
49 // ###################################################################
53 * @param string Page title
55 function __construct($title)
57 $this->title
= $title;
61 * Makes a new instance of the object in a static fashion
65 public static function make()
67 $obj = new ReflectionClass(__CLASS__
);
68 $args = func_get_args();
69 return $obj->newInstanceArgs($args);
72 // ###################################################################
74 * Creates a redirect to another page; constructs the header and footer
75 * (therefore execution stops)
77 * @param string Controller
78 * @param string Action
79 * @param string Redirect message to be shown
80 * @param array An aray of POST variables to send through on the redirect
82 public static function redirect($controller, $action, $message = null, $postvars = array())
84 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
86 define('ISSO_PRINTER_NO_NAVIGATION', 1);
89 $page = new BSPrinterRootElementPage(_('Redirect'));
91 $page->addChild(new BSPrinterLabelElement('
92 <script type="text/javascript">
98 setTimeout("redirect()", timeout);
107 ' . ($postvars ? 'document.forms.postvars.submit();' : 'window.location = "' . "$controller.php?action=$action" . '";') . '
115 $vars = new BSPrinterRootElementForm($controller, $action, 'postvars
');
117 foreach ($postvars AS $key => $value)
119 $vars->addChild(new BSPrinterBaseElement('hidden
', $key, $value));
122 $page->addChild($vars);
125 $redir = _('Please wait to be redirected
. This page will load in a few seconds
.');
127 if ($message == null)
129 $showmessage = $redir;
133 $showmessage = '<blockquote
>' . $message . '</blockquote
>';
134 $showmessage .= "\n<p>" . $redir . "</p>";
138 $page->addChild(BSPrinterRootElementPage::message(_('Redirect
'), $showmessage));
144 // ###################################################################
146 * Prints a complete table message
148 * @param string Message title
149 * @param string Message text
151 * @return BSPrinterRootElementTable A table
153 public static function message($title, $message)
155 $table = new BSPrinterRootElementTable();
157 $head = new BSPrinterTableElement();
158 $head->setCssClass('tcat
');
159 $head->addChild(new BSPrinterLabelElement($title));
160 $table->addHeadingChild($head);
162 $msg = new BSPrinterTableElement();
163 $msg->addChild(new BSPrinterLabelElement((strpos($message, '<blockquote
') === false ? "<blockquote>$message</blockquote>" : $message)));
164 $table->addChild($msg);
169 // ###################################################################
171 * Produces an entire page layout that asks the user whether or not
172 * they want to perform X action and provides a link to the YES and NO
175 * @param string Message that asks if they want to do X
176 * @param string Controller to go for YES
177 * @param string Action to pass
178 * @param array Hidden parameters to pass to the next page
180 public static function confirm($message, $controller, $action, $params)
182 if (!defined('ISSO_PRINTER_NO_NAVIGATION
'))
184 define('ISSO_PRINTER_NO_NAVIGATION
', 1);
187 $page = new BSPrinterRootElementPage(_('Confirm
'));
189 $form = new BSPrinterRootElementForm($controller, $action);
190 foreach ($params AS $key => $value)
192 $form->addChild(new BSPrinterBaseElement('hidden
', $key, $value));
194 $page->addChild($form);
196 $table = new BSPrinterRootElementTable();
197 $table->setWidth('75%
');
199 $head = new BSPrinterTableElement();
200 $head->addChild(new BSPrinterLabelElement(_('Confirm
')));
201 $head->setCssClass('tcat
');
202 $table->addChild($head);
204 $table->addChild(new BSPrinterTableElement(new BSPrinterLabelElement("<blockquote>$message</blockquote>")));
205 $no = new BSPrinterBaseElement('button
', '__no__
', _('No
'));
206 $no->setOnClick('history
.back(1); return false;');
207 $table->addChild(BSPrinterTableElement::row_submit(array($no), _('Yes
'), null));
209 $form->addChild($table);
215 // ###################################################################
217 * Throws a fatal error message
219 * @param string Error string
221 public static function error($message)
223 if (!defined('ISSO_PRINTER_NO_NAVIGATION
'))
225 define('ISSO_PRINTER_NO_NAVIGATION
', 1);
228 $page = new BSPrinterRootElementPage(_('Error
'));
229 $page->addChild(BSPrinterRootElementPage::message(_('Error
'), $message));
235 // ###################################################################
237 * Returns the HTML for all printed children elements
239 * @return string Printed HTML
241 protected function _paintChildren()
245 foreach ($this->children AS $child)
247 $this->builder .= "\n" . $child->paint() . "\n";
250 return $this->builder;
253 // ###################################################################
255 * Tells the element to paint itself (and any children)
257 public function paint()
259 $language = BSPrinter::get_language_information();
261 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
262 echo "<html xml:lang=\"" . $language['langcode
'] . "\" lang=\"" . $language['langcode
'] . "\" dir=\"" . $language['direction
'] . "\">\n<head>";
263 echo "\n\t<title>" . sprintf(_('%
1$s - %
2$s - %
3$s'), BSApp
::get_application(), BSPrinter
::get_realm(), $this->title
) . "</title>";
264 echo "\n\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" . $language['charset'] . "\" />";
265 echo "\n\t<link rel=\"stylesheet\" href=\"" . BSPrinter
::get_stylesheet() . "\" />";
266 echo "\n</head>\n<body>\n";
268 if (BSApp
::GetType('PrinterNavigation') AND (!defined('ISSO_PRINTER_NO_NAVIGATION') OR !constant('ISSO_PRINTER_NO_NAVIGATION')))
270 echo BSApp
::GetType('PrinterNavigation')->constructHeaderHtml();
273 echo $this->_paintChildren();
275 if (BSApp
::GetType('PrinterNavigation') AND (!defined('ISSO_PRINTER_NO_NAVIGATION') OR !constant('ISSO_PRINTER_NO_NAVIGATION')))
277 echo BSApp
::GetType('PrinterNavigation')->constructFooterHtml();
280 $copyright = "\n<br />\n<p align=\"center\" class=\"copyright\">\n\t<a href=\"http://www.bluestatic.org\" target=\"_blank\">" . BSApp
::get_application() . ' ' . BSApp
::get_app_version() . ", ©2002 - " . gmdate('Y') . " Blue Static</a>\n</p>";
282 if (!defined('ISSO_PRINTER_HIDE_SETUP'))
288 if (BSApp::get_debug())
290 if (defined('SVN') AND preg_match('#^\$Id:?#', constant('SVN')))
292 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'));
295 if (defined('ISSO_MT_START'))
297 echo "\n
<div align
=\"center\"
>Executed in
" . round(BSFunctions::fetch_microtime_diff(ISSO_MT_START), 10) . ' seconds</div>';
300 echo "\n
<br
/><div align
=\"center\"
>" . BSApp::get_debug_list() . "</div
>\n";
302 if (BSApp::GetType('Db'))
304 $queries = BSApp::GetType('Db')->getHistory();
306 $table = new BSPrinterRootElementTable();
307 $head = new BSPrinterTableElement();
308 $head->addChild(new BSPrinterLabelElement('Query Debug'));
309 $head->setCssClass('thead');
310 $table->addHeadingChild($head);
312 foreach ($queries AS $query)
314 $tr = new BSPrinterTableElement();
315 $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"));
316 $table->addChild($tr);
319 $table->setWidth('30%');
321 echo $table->paint();
326 echo "\n\n
</body
>\n</html
>";