- BSPrinterTableElement::RowSubmit() now will ignore buttons if they're null
[isso.git] / PrinterRootElementPage.php
1 <?php
2 /*=====================================================================*
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright ©2002-[#]year[#] 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 [#]gpl[#] 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)2002 - [#]year[#], Blue Static
38 * @version $Revision$
39 * @package ISSO
40 *
41 */
42 class BSPrinterRootElementPage extends BSPrinterRootElement
43 {
44 /**
45 * The page title
46 * @var string
47 */
48 private $title;
49
50 /**
51 * Language information array: ('langcode' =>, 'direction' =>, 'charset' =>)
52 * @var array
53 */
54 private $language = array('langcode' => 'en_US', 'direction' => 'ltr', 'charset' => 'utf-8');
55
56 /**
57 * The CSS stylesheet
58 * @var string
59 */
60 private $stylesheet;
61
62 // ###################################################################
63 /**
64 * Constructor
65 *
66 * @param string Page title
67 */
68 function __construct($title)
69 {
70 $this->title = $title;
71 }
72
73 // ###################################################################
74 /**
75 * Creates a redirect to another page; constructs the header and footer
76 * (therefore execution stops)
77 *
78 * @param string Controller
79 * @param string Action
80 * @param string Redirect message to be shown
81 * @param array An aray of POST variables to send through on the redirect
82 */
83 public static function Redirect($controller, $action, $message = null, $postvars = array())
84 {
85 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
86 {
87 define('ISSO_PRINTER_NO_NAVIGATION', 1);
88 }
89
90 $page = new BSPrinterRootElementPage(_('Redirect'));
91
92 $page->addChild(new BSPrinterLabelElement('
93 <script type="text/javascript">
94 <!--
95 var timeout = 2000;
96
97 if (timeout > 0)
98 {
99 setTimeout("redirect()", timeout);
100 }
101 else
102 {
103 redirect();
104 }
105
106 function redirect()
107 {
108 ' . ($postvars ? 'document.forms.postvars.submit();' : 'window.location = "' . (BSRegister::GetType('Router') ? (defined('ISSO_ROUTER_NO_REWRITE') ? "index.php?controller=$controller&action=$action" : "$controller.$action") : "$controller.php?action=$action") . '";') . '
109 }
110
111 //-->
112 </script>'));
113
114 if ($postvars)
115 {
116 $vars = new BSPrinterRootElementForm($controller, $action, 'postvars');
117
118 foreach ($postvars AS $key => $value)
119 {
120 $vars->addChild(new BSPrinterBaseElement('hidden', $key, $value));
121 }
122
123 $page->addChild($vars);
124 }
125
126 $redir = _('Please wait to be redirected. This page will load in a few seconds.');
127 $override = false;
128 if ($message == null)
129 {
130 $showmessage = $redir;
131 }
132 else
133 {
134 $showmessage = '<blockquote>' . $message . '</blockquote>';
135 $showmessage .= "\n<p>" . $redir . "</p>";
136 $override = true;
137 }
138
139 $page->addChild(BSPrinterRootElementPage::Message(_('Redirect'), $showmessage));
140
141 $page->paint();
142 exit;
143 }
144
145 // ###################################################################
146 /**
147 * Prints a complete table message
148 *
149 * @param string Message title
150 * @param string Message text
151 *
152 * @return BSPrinterRootElementTable A table
153 */
154 public static function Message($title, $message)
155 {
156 $table = new BSPrinterRootElementTable();
157
158 $head = new BSPrinterTableElement();
159 $head->setCssClass('tcat');
160 $head->addChild(new BSPrinterLabelElement($title));
161 $table->addHeadingChild($head);
162
163 $msg = new BSPrinterTableElement();
164 $msg->addChild(new BSPrinterLabelElement((strpos($message, '<blockquote') === false ? "<blockquote>$message</blockquote>" : $message)));
165 $table->addChild($msg);
166
167 return $table;
168 }
169
170 // ###################################################################
171 /**
172 * Produces an entire page layout that asks the user whether or not
173 * they want to perform X action and provides a link to the YES and NO
174 * action
175 *
176 * @param string Message that asks if they want to do X
177 * @param string Controller to go for YES
178 * @param string Action to pass
179 * @param array Hidden parameters to pass to the next page
180 */
181 public static function Confirm($message, $controller, $action, $params)
182 {
183 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
184 {
185 define('ISSO_PRINTER_NO_NAVIGATION', 1);
186 }
187
188 $page = new BSPrinterRootElementPage(_('Confirm'));
189
190 $form = new BSPrinterRootElementForm($controller, $action);
191 foreach ($params AS $key => $value)
192 {
193 $form->addChild(new BSPrinterBaseElement('hidden', $key, $value));
194 }
195 $page->addChild($form);
196
197 $table = new BSPrinterRootElementTable();
198 $table->setWidth('75%');
199
200 $head = new BSPrinterTableElement();
201 $head->addChild(new BSPrinterLabelElement(_('Confirm')));
202 $head->setCssClass('tcat');
203 $table->addChild($head);
204
205 $table->addChild(new BSPrinterTableElement(new BSPrinterLabelElement("<blockquote>$message</blockquote>")));
206 $no = new BSPrinterBaseElement('button', '__no__', _('No'));
207 $no->setOnClick('history.back(1); return false;');
208 $table->addChild(BSPrinterTableElement::RowSubmit(array($no), _('Yes'), null));
209
210 $form->addChild($table);
211
212 $page->paint();
213 exit;
214 }
215
216 // ###################################################################
217 /**
218 * Throws a fatal error message
219 *
220 * @param string Error string
221 */
222 public static function Error($message)
223 {
224 if (!defined('ISSO_PRINTER_NO_NAVIGATION'))
225 {
226 define('ISSO_PRINTER_NO_NAVIGATION', 1);
227 }
228
229 $page = new BSPrinterRootElementPage(_('Error'));
230 $page->addChild(BSPrinterRootElementPage::Message(_('Error'), $message));
231 $page->paint();
232
233 exit;
234 }
235
236 // ###################################################################
237 /**
238 * Sets the language array information
239 *
240 * @param array Language array
241 */
242 public function setLanguageInformation($lang)
243 {
244 $this->language = $lang;
245 }
246
247 // ###################################################################
248 /**
249 * Sets the path to the CSS style sheet
250 *
251 * @param string Path
252 */
253 public function setStylesheet($stylesheet)
254 {
255 $this->stylesheet = $stylesheet;
256 }
257
258 // ###################################################################
259 /**
260 * Returns the HTML for all printed children elements
261 *
262 * @return string Printed HTML
263 */
264 protected function _paintChildren()
265 {
266 $builder = '';
267
268 foreach ($this->children AS $child)
269 {
270 $this->builder .= "\n" . $child->paint() . "\n";
271 }
272
273 return $this->builder;
274 }
275
276 // ###################################################################
277 /**
278 * Tells the element to paint itself (and any children)
279 */
280 public function paint()
281 {
282 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
283 echo "<html xml:lang=\"" . $this->language['langcode'] . "\" lang=\"" . $this->language['langcode'] . "\" dir=\"" . $this->language['direction'] . "\">\n<head>";
284 echo "\n\t<title>" . sprintf(_('%1$s - %2$s'), BSRegister::GetApplication(), $this->title) . "</title>";
285 echo "\n\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" . $this->language['charset'] . "\" />";
286 echo "\n\t<link rel=\"stylesheet\" href=\"" . $this->stylesheet . "\" />";
287 echo "\n</head>\n<body>\n";
288
289 if (BSRegister::GetType('PrinterNavigation') AND (!defined('ISSO_PRINTER_NO_NAVIGATION') OR !constant('ISSO_PRINTER_NO_NAVIGATION')))
290 {
291 echo BSRegister::GetType('PrinterNavigation')->generate_header_html();
292 }
293
294 echo $this->_paintChildren();
295
296 if (BSRegister::GetType('PrinterNavigation') AND (!defined('ISSO_PRINTER_NO_NAVIGATION') OR !constant('ISSO_PRINTER_NO_NAVIGATION')))
297 {
298 echo BSRegister::GetType('PrinterNavigation')->generate_footer_html();
299 }
300
301 $copyright = "\n<br />\n<p align=\"center\" class=\"copyright\">\n\t<a href=\"http://www.bluestatic.org\" target=\"_blank\">" . BSRegister::GetApplication() . ' ' . BSRegister::GetAppVersion() . ", &copy;2002 - " . gmdate('Y') . " Blue Static</a>\n</p>";
302
303 if (!defined('ISSO_PRINTER_HIDE_SETUP'))
304 {
305 echo "\n$copyright";
306
307 echo "\n\n\n";
308
309 if (BSRegister::GetDebug())
310 {
311 if (defined('SVN') AND preg_match('#^\$Id:?#', constant('SVN')))
312 {
313 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'));
314 }
315
316 if (defined('ISSO_MT_START'))
317 {
318 echo "\n<div align=\"center\">Executed in " . round(BSFunctions::FetchMicrotimeDiff(ISSO_MT_START), 10) . ' seconds</div>';
319 }
320
321 echo "\n<br /><div align=\"center\">" . BSRegister::GetDebugList() . "</div>\n";
322
323 if (BSRegister::GetType('Db'))
324 {
325 $queries = BSRegister::GetType('Db')->getHistory();
326
327 $table = new BSPrinterRootElementTable();
328 $head = new BSPrinterTableElement();
329 $head->addChild(new BSPrinterLabelElement('Query Debug'));
330 $head->setCssClass('thead');
331 $table->addHeadingChild($head);
332
333 foreach ($queries AS $query)
334 {
335 $tr = new BSPrinterTableElement();
336 $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"));
337 $table->addChild($tr);
338 }
339
340 $table->setWidth('30%');
341
342 echo $table->paint();
343 }
344 }
345 }
346
347 echo "\n\n</body>\n</html>";
348 }
349 }
350
351 /*=====================================================================*
352 || ###################################################################
353 || # $HeadURL$
354 || # $Id$
355 || ###################################################################
356 \*=====================================================================*/
357 ?>