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