Fixing a documentation and error mistake that weren't fixed through our sesarch/repla...
[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 /**
57 * Constructor
58 *
59 * @param string Page title
60 */
61 function __construct($title)
62 {
63 $this->title = $title;
64 }
65
66 /**
67 * Makes a new instance of the object in a static fashion
68 *
69 * @return object
70 */
71 public static function make()
72 {
73 $obj = new ReflectionClass(__CLASS__);
74 $args = func_get_args();
75 return $obj->newInstanceArgs($args);
76 }
77
78 /**
79 * Sets the navigation object
80 *
81 * @param BSPrinterNavigation Navigator
82 *
83 * @return fluent interface
84 */
85 public function setNavigator(BSPrinterNavigation $nav)
86 {
87 $this->navigator = $nav;
88 return $this;
89 }
90
91 /**
92 * Returns the printer navigation object
93 *
94 * @return BSPrinterNavigation Navigation object
95 */
96 public function getNavigatior()
97 {
98 return $this->navigatior;
99 }
100
101 // ###################################################################
102 /**
103 * Creates a redirect to another page; constructs the header and footer
104 * (therefore execution stops)
105 *
106 * @param string Controller
107 * @param string Action
108 * @param string Redirect message to be shown
109 * @param array An aray of POST variables to send through on the redirect
110 */
111 public static function redirect($controller, $action, $message = null, $postvars = array())
112 {
113 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
114 {
115 define('ISSO_PRINTER_NO_NAVIGATION', 1);
116 }
117
118 $page = new BSPrinterRootPage(_('Redirect'));
119
120 $page->addChild(new BSPrinterElementLabel('
121 <script type="text/javascript">
122 <!--
123 var timeout = 2000;
124
125 if (timeout > 0)
126 {
127 setTimeout("redirect()", timeout);
128 }
129 else
130 {
131 redirect();
132 }
133
134 function redirect()
135 {
136 ' . ($postvars ? 'document.forms.postvars.submit();' : 'window.location = "' . "$controller.php?action=$action" . '";') . '
137 }
138
139 //-->
140 </script>'));
141
142 if ($postvars)
143 {
144 $vars = new BSPrinterRootForm($controller, $action, 'postvars');
145
146 foreach ($postvars as $key => $value)
147 {
148 $vars->addChild(new BSPrinterElement('hidden', $key, $value));
149 }
150
151 $page->addChild($vars);
152 }
153
154 $redir = _('Please wait to be redirected. This page will load in a few seconds.');
155 $override = false;
156 if ($message == null)
157 {
158 $showmessage = $redir;
159 }
160 else
161 {
162 $showmessage = '<blockquote>' . $message . '</blockquote>';
163 $showmessage .= "\n<p>" . $redir . "</p>";
164 $override = true;
165 }
166
167 $page->addChild(BSPrinterRootPage::message(_('Redirect'), $showmessage));
168
169 $page->paint();
170 exit;
171 }
172
173 // ###################################################################
174 /**
175 * Prints a complete table message
176 *
177 * @param string Message title
178 * @param string Message text
179 *
180 * @return BSPrinterRootTable A table
181 */
182 public static function message($title, $message)
183 {
184 $table = new BSPrinterRootTable();
185
186 $head = new BSPrinterElementTable();
187 $head->setCssClass('tcat');
188 $head->addChild(new BSPrinterElementLabel($title));
189 $table->addHeadingChild($head);
190
191 $msg = new BSPrinterElementTable();
192 $msg->addChild(new BSPrinterElementLabel((strpos($message, '<blockquote') === false ? "<blockquote>$message</blockquote>" : $message)));
193 $table->addChild($msg);
194
195 return $table;
196 }
197
198 // ###################################################################
199 /**
200 * Produces an entire page layout that asks the user whether or not
201 * they want to perform X action and provides a link to the YES and NO
202 * action
203 *
204 * @param string Message that asks if they want to do X
205 * @param string Controller to go for YES
206 * @param string Action to pass
207 * @param array Hidden parameters to pass to the next page
208 */
209 public static function confirm($message, $controller, $action, $params)
210 {
211 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
212 {
213 define('ISSO_PRINTER_NO_NAVIGATION', 1);
214 }
215
216 $page = new BSPrinterRootPage(_('Confirm'));
217
218 $form = new BSPrinterRootForm($controller, $action);
219 foreach ($params as $key => $value)
220 {
221 $form->addChild(new BSPrinterElement('hidden', $key, $value));
222 }
223 $page->addChild($form);
224
225 $table = new BSPrinterRootTable();
226 $table->setWidth('75%');
227
228 $head = new BSPrinterElementTable();
229 $head->addChild(new BSPrinterElementLabel(_('Confirm')));
230 $head->setCssClass('tcat');
231 $table->addChild($head);
232
233 $table->addChild(new BSPrinterElementTable(new BSPrinterElementLabel("<blockquote>$message</blockquote>")));
234 $no = new BSPrinterElement('button', '__no__', _('No'));
235 $no->setOnClick('history.back(1); return false;');
236 $table->addChild(BSPrinterElementTable::row_submit(array($no), _('Yes'), null));
237
238 $form->addChild($table);
239
240 $page->paint();
241 exit;
242 }
243
244 // ###################################################################
245 /**
246 * Throws a fatal error message
247 *
248 * @param string Error string
249 */
250 public static function error($message)
251 {
252 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
253 {
254 define('ISSO_PRINTER_NO_NAVIGATION', 1);
255 }
256
257 $page = new BSPrinterRootPage(_('Error'));
258 $page->addChild(BSPrinterRootPage::message(_('Error'), $message));
259 $page->paint();
260
261 exit;
262 }
263
264 // ###################################################################
265 /**
266 * Returns the HTML for all printed children elements
267 *
268 * @return string Printed HTML
269 */
270 protected function _paintChildren()
271 {
272 $builder = '';
273
274 foreach ($this->children as $child)
275 {
276 $builder .= "\n" . $child->paint() . "\n";
277 }
278
279 return $builder;
280 }
281
282 // ###################################################################
283 /**
284 * Tells the element to paint itself (and any children)
285 */
286 public function paint()
287 {
288 $language = BSPrinter::get_language_information();
289
290 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
291 echo "<html xml:lang=\"" . $language['langcode'] . "\" lang=\"" . $language['langcode'] . "\" dir=\"" . $language['direction'] . "\">\n<head>";
292 echo "\n\t<title>" . BSPrinter::get_realm() . " - " . $this->title . "</title>";
293 echo "\n\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" . $language['charset'] . "\" />";
294 echo "\n\t<link rel=\"stylesheet\" href=\"" . BSPrinter::get_stylesheet() . "\" />";
295 echo "\n</head>\n<body>\n";
296
297 if ($this->navigator && (!defined('ISSO_PRINTER_NO_NAVIGATION') || !constant('ISSO_PRINTER_NO_NAVIGATION')))
298 {
299 echo $this->navigator->constructHeaderHtml();
300 }
301
302 echo $this->_paintChildren();
303
304 if ($this->navigator && (!defined('ISSO_PRINTER_NO_NAVIGATION') || !constant('ISSO_PRINTER_NO_NAVIGATION')))
305 {
306 echo $this->navigator->constructFooterHtml();
307 }
308
309 $copyright = "\n<br />\n<p align=\"center\" class=\"copyright\">\n\t" . BSPrinter::get_copyright() . "\n</p>";
310
311 if (!defined('ISSO_PRINTER_HIDE_SETUP'))
312 {
313 echo "\n$copyright";
314
315 echo "\n\n\n";
316
317 if (BSApp::get_debug())
318 {
319 if (defined('SVN') && preg_match('#^\$Id:?#', constant('SVN')))
320 {
321 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'));
322 }
323
324 if (defined('ISSO_MT_START'))
325 {
326 echo "\n<div align=\"center\">Executed in " . round(BSFunctions::fetch_microtime_diff(ISSO_MT_START), 10) . ' seconds</div>';
327 }
328
329 echo "\n<br /><div align=\"center\">" . BSApp::get_debug_list() . "</div>\n";
330
331 if (BSApp::$db)
332 {
333 $queries = BSApp::$db->getHistory();
334
335 $table = new BSPrinterRootTable();
336 $head = new BSPrinterElementTable();
337 $head->addChild(new BSPrinterElementLabel('Query Debug'));
338 $head->setCssClass('thead');
339 $table->addHeadingChild($head);
340
341 foreach ($queries as $query)
342 {
343 $tr = new BSPrinterElementTable();
344 $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"));
345 $table->addChild($tr);
346 }
347
348 $table->setWidth('30%');
349
350 echo $table->paint();
351 }
352 }
353 }
354
355 echo "\n\n</body>\n</html>";
356 }
357 }
358
359 ?>