r112: Select the current script for us in the navigation menu
[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
81 echo "<div class=\"tcat\" style=\"padding: 5px; border-bottom: 4px outset\">\n";
82 echo "\n\t<form action=\"jump.php\" method=\"post\" title=\"navigation\" style=\"display: inline\">";
83 echo "\n\t\tNavigation: <select name=\"jumplocation\" onchange=\"this.form.submit()\">";
84 foreach ($globalnav AS $grouptitle => $links)
85 {
86 echo "\n\t\t<optgroup label=\"$grouptitle\">";
87 foreach ($links AS $title => $url)
88 {
89 $selected = ((preg_match("#$location[path]$#i", $url)) ? ' selected="selected"' : '');
90 echo "\n\t\t\t<option value=\"$url\"$selected>$title</option>";
91 }
92 echo "\n\t\t</optgroup>";
93 }
94 echo "\n\t\t</select>";
95 echo "\n\t\t<input type=\"submit\" name=\"go\" value=\"&nbsp;Go&nbsp;\" />";
96 echo "\n\t</form>";
97 echo "\n</div>";
98 }
99
100 echo "<div style=\"margin: {$pagemargin}px;\">\n<!-- / page head -->\n\n";
101 }
102
103 function page_code($code)
104 {
105 echo "\n\n$code\n\n";
106 }
107
108 function page_message($title, $message)
109 {
110 $this->table_start(true, '75%');
111 $this->table_head($title, 1);
112 $this->row_span("<blockquote>$message</blockquote>", ':swap:', 'left', 1);
113 $this->table_end();
114 }
115
116 function page_confirm($message, $location)
117 {
118 $this->page_start(phrase('confirm'));
119
120 $this->page_message(phrase('confirm'), $message . '<p><input type="button" name="confirm" value=" ' . phrase('yes') . ' " onclick="window.location = \'' . $location . '\';" />');
121
122 $this->page_end();
123 }
124
125 function page_end()
126 {
127 global $bugsys;
128
129 $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>";
130
131 if (!defined('HIDE_SETUP'))
132 {
133 echo "\n<!-- page end -->\n</div>\n$copyright";
134 }
135 else
136 {
137 echo "\n<!-- page end -->\n</div>";
138 }
139
140 echo "\n\n</body>\n</html>";
141
142 exit;
143 }
144
145 // ###################################################################
146 // ##################### TABLE SKELETON RENDERING ####################
147 // ###################################################################
148 function table_start($break = true, $width = '90%')
149 {
150 if ($break)
151 {
152 echo '<br />';
153 }
154
155 echo "\n<table cellpadding=\"4\" cellspacing=\"0\" border=\"0\" align=\"center\" width=\"$width\" class=\"tborder\">\n";
156 }
157
158 function table_head($title, $colspan = 2, $strong = true)
159 {
160 echo "<tr>\n\t<td class=\"tcat\" align=\"center\" colspan=\"$colspan\">" . (($strong) ? "<strong>$title</strong>" : $title) . "</td>\n</tr>\n";
161 }
162
163 function table_column_head($columnarray)
164 {
165 if (is_array($columnarray))
166 {
167 $render = "<tr valign=\"top\" align=\"center\">\n";
168
169 foreach ($columnarray AS $header)
170 {
171 $render .= "\t<td class=\"thead\" align=\"center\">$header</td>\n";
172 }
173
174 $render .= "</tr>\n";
175
176 echo $render;
177 }
178 }
179
180 function table_end()
181 {
182 echo "\n</table>\n";
183 }
184
185 // ###################################################################
186 // ########################## FORM CREATION ##########################
187 // ###################################################################
188 function form_start($action, $do, $enctype = false, $name = 'inputform', $submitmethod = 'post')
189 {
190 echo "\n<!-- input form -->\n<form name=\"$name\" action=\"$action\"" . (($enctype) ? " enctype=\"$enctype\"" : '') . " method=\"$submitmethod\">\n";
191 $this->form_hidden_field('do', $do);
192 }
193
194 function form_hidden_field($name, $value)
195 {
196 echo "<input type=\"hidden\" name=\"$name\" value=\"$value\" />\n";
197 }
198
199 function form_end()
200 {
201 echo "</form>\n<!-- / input form -->\n";
202 }
203
204 // ###################################################################
205 // ####################### TABLE ROW RENDERING #######################
206 // ###################################################################
207 function row_span($text, $class = ':swap:', $align = 'left', $colspan = 2)
208 {
209 global $bugsys;
210 if ($class === ':swap:')
211 {
212 $bugsys->funct->exec_swap_bg();
213 $row_class = $bugsys->funct->bgcolour;
214 $is_style_element = false;
215 }
216 else
217 {
218 if (preg_match('#:style:(.*?)#i', $class))
219 {
220 $is_style_element = true;
221 $style = str_replace(':style:', '', $class);
222 }
223 else
224 {
225 $row_class = $class;
226 $is_style_element = false;
227 }
228 }
229
230 echo "<tr>\n\t<td ". (($is_style_element) ? "style=\"$style\"" : "class=\"$row_class\"") . " colspan=\"$colspan\" align=\"$align\">$text</td>\n</tr>";
231 }
232
233 function row_multi_item($row_array)
234 {
235 global $bugsys;
236 $bugsys->funct->exec_swap_bg();
237
238 foreach ($row_array AS $item => $align)
239 {
240 $row_data["$align"][] = $item;
241 }
242
243 echo "<tr valign=\"top\">";
244
245 foreach ($row_data AS $align_key => $item_array)
246 {
247 if ($align_key == 'c')
248 {
249 $align = 'center';
250 }
251 else if ($align_key == 'l')
252 {
253 $align = 'left';
254 }
255 else if ($align_key == 'r')
256 {
257 $align = 'right';
258 }
259
260 foreach ($item_array AS $value)
261 {
262 echo "\n\t<td class=\"{$bugsys->funct->bgcolour}\" align=\"$align\">$value</td>";
263 }
264 }
265
266 echo "\n</tr>\n";
267 }
268
269 function row_text($label, $value = '&nbsp;', $valign = 'top', $colspan = 2, $class = -1)
270 {
271 global $bugsys, $IS_SETTINGS;
272
273 if ($class == -1)
274 {
275 if (!$IS_SETTINGS)
276 {
277 $bugsys->funct->exec_swap_bg();
278 $row_class = $bugsys->funct->bgcolour;
279 }
280 else
281 {
282 $row_class = 'alt2';
283 }
284 }
285 else
286 {
287 $row_class = $class;
288 }
289
290 echo "<tr valign=\"$valign\">";
291 echo "\n\t<td class=\"$row_class\">$label</td>";
292 echo "\n\t<td class=\"$row_class\">$value</td>";
293
294 if ($colspan > 2)
295 {
296 echo "\n\t<td class=\"$row_class\" colspan=\"" . $colspan - 2 . "\">&nbsp;</td>";
297 }
298
299 echo "\n</tr>\n";
300 }
301
302 function row_input($label, $name, $value = '', $colspan = 2, $size = 35, $length = false, $password = false, $lalign = 'top')
303 {
304 $this->row_text($label, "<input type=\"" . (($password) ? 'password' : 'text') . "\" class=\"input\" name=\"$name\" value=\"$value\" size=\"$size\" " . (($length) ? "maxlength=\"$length\" " : '') . "/>", $lalign, $colspan);
305 }
306
307 function row_textarea($label, $name, $value = '', $colspan = 2, $rows = 7, $cols = 50, $code = false, $style = '')
308 {
309 $this->row_text($label, "<textarea name=\"$name\" class=\"" . (($code) ? 'code' : 'input') . "\" rows=\"$rows\" cols=\"$cols\"" . (($style) ? ' style="' . $style . '"' : '') . ">$value</textarea>", 'top', $colspan);
310 }
311
312 function row_tfoot($data, $colspan = 2)
313 {
314 echo $this->row_span($data, 'tfoot', 'center');
315 }
316
317 function row_submit($extra = false, $submit = ':save:', $reset = ':reset:', $colspan = 2)
318 {
319 if ($submit === ':save:')
320 {
321 $submit = " " . phrase('submit') . " ";
322 }
323 else
324 {
325 $submit = " $submit ";
326 }
327
328 if ($reset === ':reset:')
329 {
330 $reset = " " . phrase('reset') . " ";
331 }
332 else
333 {
334 $reset = (($reset) ? " $reset " : '');
335 }
336
337 $output = "\n\t\t<input type=\"submit\" class=\"button\" value=\"$submit\" accesskey=\"s\" />";
338 $output .= (($reset) ? "\n\t\t<input type=\"reset\" class=\"button\" value=\"$reset\" accesskey=\"r\" /> $extra\n\t" : '');
339 $this->row_tfoot($output);
340 }
341
342 function row_upload($label, $name, $colspan = 2)
343 {
344 $this->row_text($label, "<input type=\"file\" class=\"button\" name=\"$name\" size=\"35\" />", 'top', $colspan);
345 }
346
347 function list_item($name, $value, $selected = false)
348 {
349 global $listitem;
350
351 $listitem[] = "\n\t<option value=\"$value\"" . (($selected == true) ? ' selected="selected"' : '') . ">$name</option>";
352 }
353
354 function row_list($label, $name, $is_jump = true, $colspan = 2)
355 {
356 global $listitem;
357
358 foreach ($listitem AS $option)
359 {
360 $optionlist .= $option;
361 }
362
363 $listitem = '';
364
365 $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);
366 }
367
368 function row_yesno($label, $name, $value, $colspan = 2)
369 {
370 $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);
371 }
372 }
373
374 /*=====================================================================*\
375 || ###################################################################
376 || # $HeadURL$
377 || # $Id$
378 || ###################################################################
379 \*=====================================================================*/
380 ?>