]> src.bluestatic.org Git - isso.git/blob - PrinterRootPage.php
Update version number
[isso.git] / PrinterRootPage.php
1 <?php
2 /*=====================================================================*
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2005-2008 Blue Static
6 || #
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.
10 || #
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
14 || # more details.
15 || #
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 \*=====================================================================*/
21
22 /**
23 * Printer Root Element: Page (PrinterRootPage.php)
24 *
25 * @package ISSO
26 */
27
28 require_once(ISSO . '/PrinterRootAbstract.php');
29
30 /**
31 * Printer Root Element: Page
32 *
33 * This root element represents the entire page and is usually used for all
34 * printer applications
35 *
36 * @author Blue Static
37 * @copyright Copyright (c)2005 - 2008, Blue Static
38 * @package ISSO
39 *
40 */
41 class BSPrinterRootPage extends BSPrinterRootAbstract
42 {
43 /**
44 * The page title
45 * @var string
46 */
47 private $title;
48
49 /**
50 * Navigation object
51 * @var BSPrinterNavigation
52 */
53 private $navigator;
54
55 /**
56 * The header code for the page
57 * @var string
58 */
59 private $headerCode;
60
61 /**
62 * Constructor
63 *
64 * @param string Page title
65 */
66 function __construct($title)
67 {
68 $this->title = $title;
69 }
70
71 /**
72 * Makes a new instance of the object in a static fashion
73 *
74 * @return object
75 */
76 public static function make()
77 {
78 $obj = new ReflectionClass(__CLASS__);
79 $args = func_get_args();
80 return $obj->newInstanceArgs($args);
81 }
82
83 /**
84 * Sets the navigation object
85 *
86 * @param BSPrinterNavigation Navigator
87 *
88 * @return fluent interface
89 */
90 public function setNavigator(BSPrinterNavigation $nav)
91 {
92 $this->navigator = $nav;
93 return $this;
94 }
95
96 /**
97 * Returns the printer navigation object
98 *
99 * @return BSPrinterNavigation Navigation object
100 */
101 public function getNavigatior()
102 {
103 return $this->navigatior;
104 }
105
106 /**
107 * Sets the code to inject into the <head> element of the page
108 *
109 * @param string Code
110 */
111 public function setHeaderCode($code)
112 {
113 $this->headerCode = $code;
114 }
115
116 /**
117 * Creates a redirect to another page; constructs the header and footer
118 * (therefore execution stops)
119 *
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
123 */
124 public static function redirect($location, $message = null, $postvars = array())
125 {
126 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
127 {
128 define('ISSO_PRINTER_NO_NAVIGATION', 1);
129 }
130
131 $page = new BSPrinterRootPage(_('Redirect'));
132
133 $page->addChild(new BSPrinterElementLabel('
134 <script type="text/javascript">
135 <!--
136 var timeout = 2000;
137
138 if (timeout > 0)
139 {
140 setTimeout("redirect()", timeout);
141 }
142 else
143 {
144 redirect();
145 }
146
147 function redirect()
148 {
149 ' . ($postvars ? 'document.forms.postvars.submit();' : 'window.location = "' . $location . '";') . '
150 }
151
152 //-->
153 </script>'));
154
155 if ($postvars)
156 {
157 $vars = new BSPrinterRootForm($location, $postvars['do'], 'postvars');
158 unset($postvars['do']);
159
160 foreach ($postvars as $key => $value)
161 {
162 $vars->addChild(new BSPrinterElement('hidden', $key, $value));
163 }
164
165 $page->addChild($vars);
166 }
167
168 $redir = _('Please wait to be redirected. This page will load in a few seconds.');
169 if ($message == null)
170 {
171 $showmessage = $redir;
172 }
173 else
174 {
175 $showmessage = '<blockquote>' . $message . '</blockquote>';
176 $showmessage .= "\n<p>" . $redir . "</p>";
177 }
178
179 $page->addChild(BSPrinterRootPage::message(_('Redirect'), $showmessage));
180
181 $page->paint();
182 exit;
183 }
184
185 /**
186 * Prints a complete table message
187 *
188 * @param string Message title
189 * @param string Message text
190 *
191 * @return BSPrinterRootTable A table
192 */
193 public static function message($title, $message)
194 {
195 $table = new BSPrinterRootTable();
196
197 $head = new BSPrinterElementTable();
198 $head->setCssClass('tcat');
199 $head->addChild(new BSPrinterElementLabel($title));
200 $table->addHeadingChild($head);
201
202 $msg = new BSPrinterElementTable();
203 $msg->addChild(new BSPrinterElementLabel((strpos($message, '<blockquote') === false ? "<blockquote>$message</blockquote>" : $message)));
204 $table->addChild($msg);
205
206 return $table;
207 }
208
209 /**
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
212 * action
213 *
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
218 */
219 public static function confirm($message, $action, $do, $params)
220 {
221 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
222 {
223 define('ISSO_PRINTER_NO_NAVIGATION', 1);
224 }
225
226 $page = new BSPrinterRootPage(_('Confirm'));
227
228 $form = new BSPrinterRootForm($action, $do);
229 foreach ($params as $key => $value)
230 {
231 $form->addChild(new BSPrinterElement('hidden', $key, $value));
232 }
233 $page->addChild($form);
234
235 $table = new BSPrinterRootTable();
236 $table->setWidth('75%');
237
238 $head = new BSPrinterElementTable();
239 $head->addChild(new BSPrinterElementLabel(_('Confirm')));
240 $head->setCssClass('tcat');
241 $table->addChild($head);
242
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));
247
248 $form->addChild($table);
249
250 $page->paint();
251 exit;
252 }
253
254 /**
255 * Throws a fatal error message
256 *
257 * @param string Error string
258 */
259 public static function error($message)
260 {
261 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
262 {
263 define('ISSO_PRINTER_NO_NAVIGATION', 1);
264 }
265
266 $page = new BSPrinterRootPage(_('Error'));
267 $page->addChild(BSPrinterRootPage::message(_('Error'), $message));
268 $page->paint();
269
270 exit;
271 }
272
273 /**
274 * Returns the HTML for all printed children elements
275 *
276 * @return string Printed HTML
277 */
278 protected function _paintChildren()
279 {
280 $builder = '';
281
282 foreach ($this->children as $child)
283 {
284 $builder .= "\n" . $child->paint() . "\n";
285 }
286
287 return $builder;
288 }
289
290 /**
291 * Tells the element to paint itself (and any children)
292 */
293 public function paint()
294 {
295 $language = BSPrinter::get_language_information();
296
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";
304
305 if ($this->navigator && (!defined('ISSO_PRINTER_NO_NAVIGATION') || !constant('ISSO_PRINTER_NO_NAVIGATION')))
306 {
307 echo $this->navigator->constructHeaderHtml();
308 }
309
310 echo $this->_paintChildren();
311
312 if ($this->navigator && (!defined('ISSO_PRINTER_NO_NAVIGATION') || !constant('ISSO_PRINTER_NO_NAVIGATION')))
313 {
314 echo $this->navigator->constructFooterHtml();
315 }
316
317 $copyright = "\n<br />\n<p align=\"center\" class=\"copyright\">\n\t" . BSPrinter::get_copyright() . "\n</p>";
318
319 if (!defined('ISSO_PRINTER_HIDE_SETUP'))
320 {
321 echo "\n$copyright";
322
323 echo "\n\n\n";
324
325 if (BSApp::get_debug())
326 {
327 if (defined('SVN') && preg_match('#^\$Id:?#', constant('SVN')))
328 {
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> &mdash; r\2</div>', constant('SVN'));
330 }
331
332 if (defined('ISSO_MT_START'))
333 {
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>';
336 }
337
338 echo "\n<br /><div align=\"center\">" . BSApp::get_debug_list() . "</div>\n";
339
340 if (BSApp::$db)
341 {
342 $queries = BSApp::$db->getHistory();
343
344 $table = new BSPrinterRootTable();
345 $head = new BSPrinterElementTable();
346 $head->addChild(new BSPrinterElementLabel('Query Debug'));
347 $head->setCssClass('thead');
348 $table->addHeadingChild($head);
349
350 foreach ($queries as $query)
351 {
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);
355 }
356
357 $table->setWidth('30%');
358
359 echo $table->paint();
360 }
361 }
362 }
363
364 echo "\n\n</body>\n</html>";
365 }
366 }
367
368 ?>