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