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