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