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