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