]> src.bluestatic.org Git - bugdar.git/blob - admin/field.php
r496: Removing #submitrow from report.css to global.css
[bugdar.git] / admin / field.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 require_once('./global.php');
14
15 if (!can_perform('canadminfields'))
16 {
17 admin_login();
18 }
19
20 $TYPES = array(
21 'input_text' => $lang->string('Single-Line Text Box'),
22 'input_checkbox' => $lang->string('Checkbox Flag'),
23 'select_single' => $lang->string('Drop-Down Menu'),
24 );
25
26 // ###################################################################
27
28 if (empty($_REQUEST['do']))
29 {
30 $_REQUEST['do'] = 'modify';
31 }
32
33 // ###################################################################
34
35 if ($_REQUEST['do'] == 'kill')
36 {
37 $field = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugfield WHERE fieldid = " . intval($bugsys->in['fieldid']));
38 if (!$field)
39 {
40 $admin->error($lang->getlex('error_invalid_id'));
41 }
42
43 $db->query("DELETE FROM " . TABLE_PREFIX . "bugfield WHERE fieldid = $field[fieldid]");
44 $db->query("DELETE FROM " . TABLE_PREFIX . "bugfieldpermission WHERE fieldid = $field[fieldid]");
45 $db->query("ALTER TABLE " . TABLE_PREFIX . "bugvaluefill DROP field$field[fieldid]");
46 $db->query("OPTIMIZE TABLE " . TABLE_PREFIX . "bugvaluefill");
47
48 $admin->redirect('field.php?do=modify');
49 }
50
51 // ###################################################################
52
53 if ($_REQUEST['do'] == 'delete')
54 {
55 $field = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugfield WHERE fieldid = " . intval($bugsys->in['fieldid']));
56 if (!$field)
57 {
58 $admin->error($lang->getlex('error_invalid_id'));
59 }
60
61 $admin->page_confirm($lang->string('Are you sure you want to delete this bug field? Doing so will remove everything for this field and it cannot be undone!'), "field.php?do=kill&amp;fieldid=$field[fieldid]");
62 }
63
64 // ###################################################################
65
66 if ($_REQUEST['do'] == 'update')
67 {
68 $edit = false;
69 $add = true;
70
71 $type = $bugsys->in['type'];
72
73 if ($bugsys->in['fieldid'])
74 {
75 $field = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugfield WHERE fieldid = " . intval($bugsys->in['fieldid']));
76 if (!$field)
77 {
78 $admin->error($lang->getlex('error_invalid_id'));
79 }
80
81 $edit = true;
82 $add = false;
83 $type = $field['type'];
84 }
85
86 if (empty($bugsys->in['name']))
87 {
88 $admin->error($lang->string('You must specify a display name.'));
89 }
90 if (!isset($TYPES["$type"]) AND $add)
91 {
92 $admin->error($lang->string('Invalid field type specified.'));
93 }
94
95 switch ($type)
96 {
97 case 'input_text':
98 $extrafields = 'defaultvalue, regexmatch, maxlength';
99 $extradata = "'" . $bugsys->in['defaultvalue'] . "', '" . $bugsys->in['regexmatch'] . "', " . intval($bugsys->in['maxlength']);
100 $extraupdate = "defaultvalue = '" . $bugsys->in['defaultvalue'] . "', regexmatch = '" . $bugsys->in['regexmatch'] . "', maxlength = " . intval($bugsys->in['maxlength']);
101 break;
102
103 case 'input_checkbox':
104 $extrafields = 'defaultvalue';
105 $extradata = intval($bugsys->in['defaultvalue']);
106 $extraupdate = "defaultvalue = " . intval($bugsys->in['defaultvalue']);
107 break;
108
109 case 'select_single':
110 $extrafields = 'selects, usedefault';
111
112 // can't use explode() here because explode() returns !empty() when splitting an empty string
113 // so we have to use preg_split with the PREG_SPLIT_NO_EMPTY flag to prevent this
114 $selects = preg_split("#\n#", trim($bugsys->in['selects']), 0, PREG_SPLIT_NO_EMPTY);
115 array_walk($selects, 'trim');
116 if (count($selects) < 1)
117 {
118 $admin->error($lang->string('You need to specify some select values.'));
119 }
120
121 $extradata = "'" . $bugsys->escape(serialize($selects)) . "', " . intval($bugsys->in['usedefault']);
122 $extraupdate = "selects = '" . $bugsys->escape(serialize($selects)) . "', usedefault = " . intval($bugsys->in['usedefault']);
123 break;
124 }
125
126 if ($add)
127 {
128 $db->query("
129 INSERT INTO bugfield
130 (name, description, type, required, cansearch, $extrafields)
131 VALUES
132 ('" . $bugsys->in['name'] . "',
133 '" . $bugsys->in['description'] . "', '$type', " . intval($bugsys->in['required']) . ",
134 " . intval($bugsys->in['cansearch']) . ", $extradata
135 )"
136 );
137
138 $fieldid = $db->insert_id();
139
140 $db->query("ALTER TABLE " . TABLE_PREFIX . "bugvaluefill ADD field$fieldid MEDIUMTEXT NULL");
141 $db->query("OPTIMIZE TABLE " . TABLE_PREFIX . "bugvaluefill");
142 }
143 else
144 {
145 $db->query("
146 UPDATE " . TABLE_PREFIX . "bugfield
147 SET name = '" . $bugsys->in['name'] . "',
148 description = '" . $bugsys->in['description'] . "',
149 required = " . intval($bugsys->in['required']) . ",
150 cansearch = " . intval($bugsys->in['cansearch']) . ",
151 $extraupdate
152 WHERE fieldid = " . intval($bugsys->in['fieldid'])
153 );
154 }
155
156 $admin->redirect('field.php?do=modify', ($add ? $lang->string('The custom field has been added') : $lang->string('The custom field has been updated')));
157 }
158
159 // ###################################################################
160
161 if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit')
162 {
163 $add = (($_REQUEST['do'] == 'add') ? true : false);
164 $typeselect = (($add AND empty($bugsys->in['step'])) ? true : false);
165 $edit = (($add) ? false : true);
166
167 $admin->page_start(($add ? $lang->string('Add New Custom Field') : $lang->string('Edit Custom Field')));
168 $admin->form_start('field.php', ($typeselect ? 'add' : 'update'));
169 if ($add AND !$typeselect)
170 {
171 $admin->form_hidden_field('type', $bugsys->in['type']);
172 }
173 if ($typeselect)
174 {
175 $admin->form_hidden_field('step', 1);
176 $admin->table_start(true, '40%');
177 $admin->table_head($lang->string('Select Type'));
178 }
179 else
180 {
181 $admin->table_start();
182 $admin->table_head(($add ? $lang->string('Add New Bug Field') . ' - ' . $TYPES[ $bugsys->in['type'] ] : $lang->string('Edit Field')));
183 }
184
185 if ($edit)
186 {
187 $field = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugfield WHERE fieldid = " . intval($bugsys->in['fieldid']));
188 if (!$field)
189 {
190 $admin->error($lang->getlex('error_invalid_id'));
191 }
192
193 $admin->form_hidden_field('fieldid', $field['fieldid']);
194 }
195
196 if (!$typeselect)
197 {
198 $type = (($add) ? $bugsys->in['type'] : $field['type']);
199 }
200
201 // show type selector
202 if (empty($bugsys->in['step']) AND $add)
203 {
204 foreach ($TYPES AS $name => $description)
205 {
206 $admin->list_item($description, $name);
207 }
208 $admin->row_list($lang->string('Field Type'), 'type', false);
209
210 $admin->row_submit();
211 $admin->table_end();
212 }
213 // have type, do that funkay thing!
214 else
215 {
216 if (!isset($TYPES["$type"]))
217 {
218 $admin->error($lang->getlex('error_invalid_id'));
219 }
220
221 // global fields
222 $admin->row_span($lang->string('Global Fields'), 'thead', 'center');
223 $admin->row_text($lang->string('Field Type'), $TYPES["$type"]);
224 $admin->row_input($lang->string('Display Name'), 'name', $field['name']);
225 $admin->row_textarea($lang->string('Description'), 'description', $field['description']);
226 $admin->row_yesno($lang->string('Required'), 'required', $field['required']);
227 $admin->row_yesno($lang->string('Can Be Searched'), 'cansearch', ((isset($field['cansearch'])) ? $field['cansearch'] : true));
228
229 // type-specific fields
230 $admin->row_span($lang->string('Type-Specific Fields'), 'thead', 'center');
231
232 switch ($type)
233 {
234 case 'input_text':
235 $admin->row_input($lang->string('Default Value'), 'defaultvalue', $field['defaultvalue']);
236 $admin->row_input($lang->string('Regular Expression Match'), 'regexmatch', $field['regexmatch']);
237 $admin->row_input($lang->string('Maximum Length'), 'maxlength', $field['maxlength'], 2, 10);
238 break;
239
240 case 'input_checkbox':
241 $admin->row_yesno($lang->string('Checked By Default'), 'defaultvalue', $field['defaultvalue']);
242 break;
243
244 case 'select_single':
245 $admin->row_textarea($lang->string('Selection Values'), 'selects', stripslashes(implode("\n", unserialize($field['selects']))));
246 $admin->row_yesno($lang->string('Make the First Option Default'), 'usedefault', $field['usedefault']);
247 break;
248 }
249
250 // end table
251 $admin->row_submit((($edit) ? '<a href="field.php?do=delete&amp;fieldid=' . $field['fieldid'] . '">[' . $lang->string('Delete Field') . ']</a>' : ''));
252 $admin->table_end();
253 $admin->form_end();
254 }
255
256 $admin->page_end();
257 }
258
259 // ###################################################################
260
261 if ($_REQUEST['do'] == 'modify')
262 {
263 $admin->page_start($lang->string('Additional Bug Fields'));
264
265 $admin->table_start();
266 $admin->table_head($lang->string('Additional Bug Fields'), 3);
267 $admin->table_column_head(array($lang->string('Display Name/Description'), $lang->string('Field ID'), $lang->string('Actions')));
268
269 $fields = $db->query("SELECT * FROM " . TABLE_PREFIX . "bugfield ORDER BY fieldid ASC");
270 while ($field = $db->fetch_array($fields))
271 {
272 $admin->row_multi_item(
273 array(
274 "$field[name]<div class=\"smallfont\"><em>$field[description]</em></div>" => 'l',
275 "(fieldid: $field[fieldid])" => 'c',
276 "<a href=\"field.php?do=edit&amp;fieldid=$field[fieldid]\">[" . $lang->string('Edit') . "]</a> <a href=\"field.php?do=delete&amp;fieldid=$field[fieldid]\">[" . $lang->string('Delete') . "]</a>" => 'c'
277 )
278 );
279 }
280
281 $admin->row_span('<a href="field.php?do=add">[' . $lang->string('Add New Bug Field') . ']</a>', 'tfoot', 'center', 3);
282 $admin->table_end();
283
284 $admin->page_end();
285 }
286
287 /*=====================================================================*\
288 || ###################################################################
289 || # $HeadURL$
290 || # $Id$
291 || ###################################################################
292 \*=====================================================================*/
293 ?>