Copying printer class from bugtrack
[isso.git] / printer.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Iris Studios Shared Object Framework [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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
24 * printer.php
25 *
26 * @package ISSO
27 */
28
29 /**
30 * Printer
31 *
32 * This framework generates standard HTML through various functions. The purpose
33 * is generally so that things like the admin system can be created without templates.
34 *
35 * @author Iris Studios, Inc.
36 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
37 * @version $Revision$
38 * @package ISSO
39 *
40 */
41 class Printer
42 {
43 function redirect($location, $timeout = 10)
44 {
45 global $bugsys;
46
47 $timeout = $timeout * 200;
48
49 $js =
50 <<<EOD
51 <script type="text/javascript">
52 <!--
53 var timeout = $timeout;
54
55 if (timeout > 0)
56 {
57 setTimeout("redirect()", $timeout);
58 }
59 else
60 {
61 redirect();
62 }
63
64 function redirect()
65 {
66 window.location = "$location";
67 }
68 -->
69 </script>
70 EOD;
71
72 $this->page_start($bugsys->lang->string('Redirect'), ':default:', 15, $js);
73
74 $this->page_message($bugsys->lang->string('Redirect'), sprintf($bugsys->lang->string('Please wait to be redirected. If you are not redirected in a few seconds, click <a href="%1$s">here</a>.'), $location));
75
76 $this->page_end();
77 }
78
79 function error($message)
80 {
81 global $bugsys;
82
83 $this->page_start($bugsys->lang->string('Error'));
84 $this->page_message($bugsys->lang->string('Error'), $message);
85 $this->page_end();
86
87 exit;
88 }
89
90 // ###################################################################
91 // ########################### PAGE CONTROL ##########################
92 // ###################################################################
93 function page_start($actiontitle, $pageclass = ':default:', $pagemargin = 15, $extra = '', $onload = false, $margin = 0, $dotpath = '.', $override = false)
94 {
95 global $bugsys;
96
97 if (constant('DONE_HEADER') AND !$override)
98 {
99 return;
100 }
101
102 $title = sprintf($bugsys->lang->string('BugStrike - Administration - %1$s'), $actiontitle);
103
104 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
105 echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>";
106 echo "\n\t<title>$title</title>";
107 echo "\n\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />";
108 echo "\n\t<link rel=\"stylesheet\" href=\"$dotpath/admin.css\" />" . (($extra) ? "\n$extra" : '');
109 echo "\n</head>\n<body style=\"margin: {$margin}px;\"" . (($pageclass !== ':default:') ? " class=\"$pageclass\"" : '') . (($onload) ? " onload=\"$onload\"" : '') . ">\n";
110
111 if (!defined('HIDE_SETUP') AND $bugsys->userinfo['adminsession'])
112 {
113 global $globalnav;
114
115 $location = parse_url($_SERVER['SCRIPT_URL']);
116 $location['path'] = preg_quote(end(explode('/', $location['path'])));
117 $location['path'] = ((!$location['path']) ? 'index.php' : $location['path']);
118
119 echo "<div class=\"tcat\" style=\"padding: 5px; border-bottom: 4px outset\">\n";
120 echo "\n\t<form action=\"jump.php\" method=\"post\" title=\"navigation\" style=\"display: inline\">";
121 echo "\n\t<span style=\"float: right\"><a href=\"../\">" . $bugsys->lang->string('Tracker Home') . "</a></span>";
122 echo "\n\t\t" . $bugsys->lang->string('Navigation') . ": <select name=\"jumplocation\" onchange=\"this.form.submit()\">";
123 foreach ($globalnav AS $grouptitle => $links)
124 {
125 echo "\n\t\t<optgroup label=\"$grouptitle\">";
126 foreach ($links AS $title => $url)
127 {
128 $selected = ((preg_match("#$location[path]$#i", $url)) ? ' selected="selected"' : '');
129 echo "\n\t\t\t<option value=\"$url\"$selected>$title</option>";
130 }
131 echo "\n\t\t</optgroup>";
132 }
133 echo "\n\t\t</select>";
134 echo "\n\t\t<input type=\"submit\" name=\"go\" value=\"&nbsp;" . $bugsys->lang->string('Go') . "&nbsp;\" />";
135 echo "\n\t</form>";
136 echo "\n</div>";
137 }
138
139 echo "<div style=\"margin: {$pagemargin}px;\">\n<!-- / page head -->\n\n";
140
141 if (!defined('DONE_HEADER'))
142 {
143 define('DONE_HEADER', 1);
144 }
145 }
146
147 function page_code($code)
148 {
149 echo "\n\n$code\n\n";
150 }
151
152 function page_message($title, $message)
153 {
154 $this->table_start(true, '75%');
155 $this->table_head($title, 1);
156 $this->row_span("<blockquote>$message</blockquote>", ':swap:', 'left', 1);
157 $this->table_end();
158 }
159
160 function page_confirm($message, $location)
161 {
162 global $bugsys;
163
164 $this->page_start($bugsys->lang->string('Confirm'));
165
166 $this->page_message($bugsys->lang->string('Confirm'), $message . '<p><input type="button" name="confirm" value=" ' . $bugsys->lang->string('Yes') . ' " onclick="window.location = \'' . $location . '\';" />');
167
168 $this->page_end();
169 }
170
171 function page_end()
172 {
173 global $bugsys;
174
175 $copyright = "\n<br />\n<p align=\"center\" class=\"copyright\">\n\t<a href=\"http://www.iris-studios.com\" target=\"_blank\">BugStrike " . $bugsys->options['trackerversion'] . ", &copy; 2002 - " . date('Y') . " Iris Studios, Inc.</a>\n</p>";
176
177 if (!defined('HIDE_SETUP'))
178 {
179 echo "\n<!-- page end -->\n</div>\n$copyright";
180 }
181 else
182 {
183 echo "\n<!-- page end -->\n</div>";
184 }
185
186 echo "\n\n</body>\n</html>";
187
188 exit;
189 }
190
191 // ###################################################################
192 // ##################### TABLE SKELETON RENDERING ####################
193 // ###################################################################
194 function table_start($break = true, $width = '90%')
195 {
196 if ($break)
197 {
198 echo '<br />';
199 }
200
201 echo "\n<table cellpadding=\"4\" cellspacing=\"0\" border=\"0\" align=\"center\" width=\"$width\" class=\"tborder\">\n";
202 }
203
204 function table_head($title, $colspan = 2, $strong = true)
205 {
206 echo "<tr>\n\t<td class=\"tcat\" align=\"center\" colspan=\"$colspan\">" . (($strong) ? "<strong>$title</strong>" : $title) . "</td>\n</tr>\n";
207 }
208
209 function table_column_head($columnarray)
210 {
211 if (is_array($columnarray))
212 {
213 $render = "<tr valign=\"top\" align=\"center\">\n";
214
215 foreach ($columnarray AS $header)
216 {
217 $render .= "\t<td class=\"thead\" align=\"center\">$header</td>\n";
218 }
219
220 $render .= "</tr>\n";
221
222 echo $render;
223 }
224 }
225
226 function table_end()
227 {
228 echo "\n</table>\n";
229 }
230
231 // ###################################################################
232 // ########################## FORM CREATION ##########################
233 // ###################################################################
234 function form_start($action, $do, $enctype = false, $name = 'inputform', $submitmethod = 'post')
235 {
236 echo "\n<!-- input form -->\n<form name=\"$name\" action=\"$action\"" . (($enctype) ? " enctype=\"$enctype\"" : '') . " method=\"$submitmethod\">\n";
237 $this->form_hidden_field('do', $do);
238 }
239
240 function form_hidden_field($name, $value)
241 {
242 echo "<input type=\"hidden\" name=\"$name\" value=\"$value\" />\n";
243 }
244
245 function form_end()
246 {
247 echo "</form>\n<!-- / input form -->\n";
248 }
249
250 // ###################################################################
251 // ####################### TABLE ROW RENDERING #######################
252 // ###################################################################
253 function row_span($text, $class = ':swap:', $align = 'left', $colspan = 2)
254 {
255 global $bugsys;
256 if ($class === ':swap:')
257 {
258 $bugsys->funct->exec_swap_bg();
259 $row_class = $bugsys->funct->bgcolour;
260 $is_style_element = false;
261 }
262 else
263 {
264 if (preg_match('#:style:(.*?)#i', $class))
265 {
266 $is_style_element = true;
267 $style = str_replace(':style:', '', $class);
268 }
269 else
270 {
271 $row_class = $class;
272 $is_style_element = false;
273 }
274 }
275
276 echo "<tr>\n\t<td ". (($is_style_element) ? "style=\"$style\"" : "class=\"$row_class\"") . " colspan=\"$colspan\" align=\"$align\">$text</td>\n</tr>";
277 }
278
279 function row_multi_item($row_array)
280 {
281 global $bugsys;
282 $bugsys->funct->exec_swap_bg();
283
284 foreach ($row_array AS $item => $align)
285 {
286 $row_data["$align"][] = $item;
287 }
288
289 echo "<tr valign=\"top\">";
290
291 foreach ($row_data AS $align_key => $item_array)
292 {
293 if ($align_key == 'c')
294 {
295 $align = 'center';
296 }
297 else if ($align_key == 'l')
298 {
299 $align = 'left';
300 }
301 else if ($align_key == 'r')
302 {
303 $align = 'right';
304 }
305
306 foreach ($item_array AS $value)
307 {
308 echo "\n\t<td class=\"{$bugsys->funct->bgcolour}\" align=\"$align\">$value</td>";
309 }
310 }
311
312 echo "\n</tr>\n";
313 }
314
315 function row_text($label, $value = '&nbsp;', $valign = 'top', $colspan = 2, $class = -1)
316 {
317 global $bugsys, $IS_SETTINGS;
318
319 if ($class == -1)
320 {
321 if (!$IS_SETTINGS)
322 {
323 $bugsys->funct->exec_swap_bg();
324 $row_class = $bugsys->funct->bgcolour;
325 }
326 else
327 {
328 $row_class = 'alt2';
329 }
330 }
331 else
332 {
333 $row_class = $class;
334 }
335
336 echo "<tr valign=\"$valign\">";
337 echo "\n\t<td class=\"$row_class\">$label</td>";
338 echo "\n\t<td class=\"$row_class\">$value</td>";
339
340 if ($colspan > 2)
341 {
342 echo "\n\t<td class=\"$row_class\" colspan=\"" . $colspan - 2 . "\">&nbsp;</td>";
343 }
344
345 echo "\n</tr>\n";
346 }
347
348 function row_input($label, $name, $value = '', $colspan = 2, $size = 35, $length = false, $password = false, $lalign = 'top')
349 {
350 $this->row_text($label, "<input type=\"" . (($password) ? 'password' : 'text') . "\" class=\"input\" name=\"$name\" value=\"$value\" size=\"$size\" " . (($length) ? "maxlength=\"$length\" " : '') . "/>", $lalign, $colspan);
351 }
352
353 function row_textarea($label, $name, $value = '', $colspan = 2, $rows = 7, $cols = 50, $code = false, $style = '')
354 {
355 $this->row_text($label, "<textarea name=\"$name\" class=\"" . (($code) ? 'code' : 'input') . "\" rows=\"$rows\" cols=\"$cols\"" . (($style) ? ' style="' . $style . '"' : '') . ">$value</textarea>", 'top', $colspan);
356 }
357
358 function row_tfoot($data, $colspan = 2)
359 {
360 echo $this->row_span($data, 'tfoot', 'center');
361 }
362
363 function row_submit($extra = false, $submit = ':save:', $reset = ':reset:', $colspan = 2)
364 {
365 global $bugsys;
366
367 if ($submit === ':save:')
368 {
369 $submit = " " . $bugsys->lang->string('Submit') . " ";
370 }
371 else
372 {
373 $submit = " $submit ";
374 }
375
376 if ($reset === ':reset:')
377 {
378 $reset = " " . $bugsys->lang->string('Reset') . " ";
379 }
380 else
381 {
382 $reset = (($reset) ? " $reset " : '');
383 }
384
385 $output = "\n\t\t<input type=\"submit\" class=\"button\" value=\"$submit\" accesskey=\"s\" />";
386 $output .= (($reset) ? "\n\t\t<input type=\"reset\" class=\"button\" value=\"$reset\" accesskey=\"r\" /> $extra\n\t" : '');
387 $this->row_tfoot($output);
388 }
389
390 function row_upload($label, $name, $colspan = 2)
391 {
392 $this->row_text($label, "<input type=\"file\" class=\"button\" name=\"$name\" size=\"35\" />", 'top', $colspan);
393 }
394
395 function list_item($name, $value, $selected = false)
396 {
397 global $listitem;
398
399 $listitem[] = "\n\t<option value=\"$value\"" . (($selected == true) ? ' selected="selected"' : '') . ">$name</option>";
400 }
401
402 function row_list($label, $name, $is_jump = false, $colspan = 2)
403 {
404 global $listitem;
405
406 foreach ($listitem AS $option)
407 {
408 $optionlist .= $option;
409 }
410
411 $listitem = '';
412
413 $this->row_text($label, "\n<select class=\"button\" name=\"$name\"" . (($is_jump) ? " onchange=\"this.form.submit();\"" : '') . ">$optionlist\n</select>" . (($is_jump) ? "\n<input type=\"submit\" class=\"button\" value=\" " . $bugsys->lang->string('Go') . " \" accesskey=\"g\" />" : '') . "\n", $colspan);
414 }
415
416 function row_yesno($label, $name, $value, $colspan = 2)
417 {
418 global $bugsys;
419
420 $this->row_text($label, "<input type=\"radio\" name=\"$name\" value=\"1\"" . (($value) ? ' checked="checked"' : '') . " /> " . $bugsys->lang->string('Yes') . " <input type=\"radio\" name=\"$name\" value=\"0\"" . ((!$value) ? ' checked="checked"' : '') . " /> " . $bugsys->lang->string('No'), $colspan);
421 }
422 }
423
424 /*=====================================================================*\
425 || ###################################################################
426 || # $HeadURL$
427 || # $Id$
428 || ###################################################################
429 \*=====================================================================*/
430 ?>