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