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