r908: Implementing new navigation system for the entire "Fields" tab
[bugdar.git] / admin / field.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 require_once('./global.php');
23 require_once('./includes/api_field.php');
24
25 NavLinks::fieldsPages();
26 $navigator->set_focus('tab', 'fields', null);
27
28 if (!can_perform('canadminfields'))
29 {
30 admin_login();
31 }
32
33 // ###################################################################
34
35 if (empty($_REQUEST['do']))
36 {
37 $_REQUEST['do'] = 'modify';
38 }
39
40 // ###################################################################
41
42 if ($_REQUEST['do'] == 'kill')
43 {
44 $field = new FieldAPI($bugsys);
45 $field->set('fieldid', $bugsys->in['fieldid']);
46 $field->set_condition();
47 $field->delete();
48
49 $admin->redirect('field.php?do=modify');
50 }
51
52 // ###################################################################
53
54 if ($_REQUEST['do'] == 'delete')
55 {
56 $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=" . $bugsys->in['fieldid']);
57 }
58
59 // ###################################################################
60
61 if ($_REQUEST['do'] == 'update')
62 {
63 $edit = false;
64 $add = true;
65
66 $type = $bugsys->in['type'];
67
68 $field = new FieldAPI($bugsys);
69
70 if ($bugsys->in['fieldid'])
71 {
72 $field->set('fieldid', $bugsys->in['fieldid']);
73 $field->set_condition();
74 $field->fetch();
75
76 $edit = true;
77 $add = false;
78 $type = $field->objdata['type'];
79 }
80 else
81 {
82 $field->set('type', $type);
83 }
84
85 switch ($type)
86 {
87 case 'input_text':
88 $field->set('defaultvalue', $bugsys->in['defaultvalue']);
89 $field->set('regexmatch', $bugsys->in['regexmatch']);
90 $field->set('maxlength', $bugsys->in['maxlength']);
91 break;
92
93 case 'input_checkbox':
94 $field->set('defaultvalue', $bugsys->in['defaultvalue']);
95 break;
96
97 case 'select_single':
98 $field->set('selects', $bugsys->in['selects']);
99 $field->set('usedefault', $bugsys->in['usedefault']);
100 break;
101 }
102
103 $field->set('name', $bugsys->in['name']);
104 $field->set('description', $bugsys->in['description']);
105 $field->set('required', $bugsys->in['required']);
106 $field->set('cansearch', $bugsys->in['cansearch']);
107
108 if ($add)
109 {
110 $field->insert();
111 $fieldid = $field->insertid;
112
113 $db->query("ALTER TABLE " . TABLE_PREFIX . "bugvaluefill ADD field$fieldid MEDIUMTEXT NULL");
114 $db->query("OPTIMIZE TABLE " . TABLE_PREFIX . "bugvaluefill");
115 }
116 else
117 {
118 $field->update();
119 $fieldid = $field->values['fieldid'];
120 }
121
122 $bugsys->input_clean('custom', TYPE_UINT);
123 foreach ($bugsys->in['custom'] AS $usergroupid => $mask)
124 {
125 $values[] = $bugsys->clean($usergroupid, TYPE_UINT) . ", $fieldid, " . $mask;
126 }
127
128 $db->query("
129 REPLACE INTO " . TABLE_PREFIX . "bugfieldpermission
130 (usergroupid, fieldid, mask)
131 VALUES
132 (" . implode("),\n\t\t\t(", $values) . ")"
133 );
134
135 $admin->redirect('field.php?do=modify', ($add ? $lang->string('The custom field has been added') : $lang->string('The custom field has been updated')));
136 }
137
138 // ###################################################################
139
140 if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit')
141 {
142 $field = new FieldAPI($bugsys);
143
144 $add = (($_REQUEST['do'] == 'add') ? true : false);
145 $typeselect = (($add AND empty($bugsys->in['step'])) ? true : false);
146 $edit = (($add) ? false : true);
147
148 if ($add)
149 {
150 NavLinks::fieldsAdd();
151 $navigator->set_focus('link', 'fields-add', 'fields');
152 }
153 else
154 {
155 NavLinks::fieldsEdit($bugsys->in['fieldid']);
156 $navigator->set_focus('link', 'fields-pages-fields', 'fields-pages');
157 }
158
159 $admin->page_start(($add ? $lang->string('Add New Custom Field') : $lang->string('Edit Custom Field')));
160 $admin->form_start('field.php', ($typeselect ? 'add' : 'update'));
161 if ($add AND !$typeselect)
162 {
163 $admin->form_hidden_field('type', $bugsys->in['type']);
164 }
165 if ($typeselect)
166 {
167 $admin->form_hidden_field('step', 1);
168 $admin->table_start(true, '40%');
169 $admin->table_head($lang->string('Select Type'), 2, 'custom_bug_fields');
170 }
171 else
172 {
173 $admin->table_start();
174 $admin->table_head(($add ? $lang->string('Add New Bug Field') . ' - ' . FieldAPI::field_types($bugsys->in['type']) : $lang->string('Edit Field')), 2, 'custom_bug_fields_options');
175 }
176
177 if ($edit)
178 {
179 $field->set('fieldid', $bugsys->in['fieldid']);
180 $field->set_condition();
181 $field->fetch();
182
183 $admin->form_hidden_field('fieldid', $field->objdata['fieldid']);
184 }
185
186 if (!$typeselect)
187 {
188 $type = (($add) ? $bugsys->in['type'] : $field->objdata['type']);
189 }
190
191 // show type selector
192 if (empty($bugsys->in['step']) AND $add)
193 {
194 foreach (FieldAPI::field_types() AS $name => $description)
195 {
196 $admin->list_item($description, $name);
197 }
198 $admin->row_list($lang->string('Field Type'), 'type', false);
199
200 $admin->row_submit();
201 $admin->table_end();
202 }
203 // have type, do that funkay thing!
204 else
205 {
206 $field->set('type', $type);
207
208 // global fields
209 $admin->row_span($lang->string('Global Fields'), 'thead', 'center');
210 $admin->row_text($lang->string('Field Type'), FieldAPI::field_types($type));
211 $admin->row_input($lang->string('Display Name'), 'name', $field->objdata['name']);
212 $admin->row_textarea($lang->string('Description'), 'description', $field->objdata['description']);
213 $admin->row_yesno($lang->string('Required'), 'required', $field->objdata['required']);
214 $admin->row_yesno($lang->string('Can Be Searched'), 'cansearch', ((isset($field->objdata['cansearch'])) ? $field->objdata['cansearch'] : true));
215
216 // type-specific fields
217 $admin->row_span($lang->string('Type-Specific Fields'), 'thead', 'center');
218
219 switch ($type)
220 {
221 case 'input_text':
222 $admin->row_input($lang->string('Default Value'), 'defaultvalue', $field->objdata['defaultvalue']);
223 $admin->row_input($lang->string('Regular Expression Match'), 'regexmatch', $field->objdata['regexmatch']);
224 $admin->row_input($lang->string('Maximum Length'), 'maxlength', $field->objdata['maxlength'], 2, 10);
225 break;
226
227 case 'input_checkbox':
228 $admin->row_yesno($lang->string('Checked By Default'), 'defaultvalue', $field->objdata['defaultvalue']);
229 break;
230
231 case 'select_single':
232 $admin->row_textarea($lang->string('Selection Values'), 'selects', stripslashes(implode("\n", unserialize($field->objdata['selects']))));
233 $admin->row_yesno($lang->string('Make the First Option Default'), 'usedefault', $field->objdata['usedefault']);
234 break;
235 }
236
237 $admin->table_end();
238
239 // custom field permissions
240 $admin->table_start();
241 $admin->table_head($lang->string('Custom Field Permissions'));
242
243 if ($edit)
244 {
245 $perms = $db->query("SELECT usergroupid, mask FROM " . TABLE_PREFIX . "bugfieldpermission WHERE fieldid = " . $field->objdata['fieldid']);
246 while ($perm = $db->fetch_array($perms))
247 {
248 $permissions["$perm[usergroupid]"] = $perm['mask'];
249 }
250 }
251
252 $usergroups = $db->query("SELECT * FROM " . TABLE_PREFIX . "usergroup ORDER BY usergroupid");
253 while ($usergroup = $db->fetch_array($usergroups))
254 {
255 unset($listitem);
256 $admin->list_item($lang->string('No Permission'), 0, $permissions["$usergroup[usergroupid]"] == 0);
257 $admin->list_item($lang->string('Can View Field'), 1, $permissions["$usergroup[usergroupid]"] == 1);
258 $admin->list_item($lang->string('Can View, Edit Field'), 2, $permissions["$usergroup[usergroupid]"] == 2);
259 $admin->row_list($usergroup['title'], "custom[$usergroup[usergroupid]]");
260 }
261
262 $admin->table_end();
263
264 // end table
265 $admin->table_start();
266 $admin->row_submit((($edit) ? '<a href="field.php?do=delete&amp;fieldid=' . $field->objdata['fieldid'] . '">[' . $lang->string('Delete Field') . ']</a>' : ''));
267 $admin->table_end();
268 $admin->form_end();
269 }
270
271 $admin->page_end();
272 }
273
274 // ###################################################################
275
276 if ($_REQUEST['do'] == 'modify')
277 {
278 NavLinks::fieldsAdd();
279 $navigator->set_focus('link', 'fields-pages-fields', 'fields-pages');
280
281 $admin->page_start($lang->string('Additional Bug Fields'));
282
283 $admin->table_start();
284 $admin->table_head($lang->string('Additional Bug Fields'), 3, 'custom_bug_fields');
285 $admin->table_column_head(array($lang->string('Display Name/Description'), $lang->string('Field ID'), $lang->string('Actions')));
286
287 $fields = $db->query("SELECT * FROM " . TABLE_PREFIX . "bugfield ORDER BY fieldid ASC");
288 while ($field = $db->fetch_array($fields))
289 {
290 $admin->row_multi_item(
291 array(
292 "$field[name]<div class=\"smallfont\"><em>$field[description]</em></div>" => 'l',
293 "$field[fieldid]" => 'c',
294 "<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'
295 )
296 );
297 }
298
299 $admin->table_end();
300
301 $admin->page_end();
302 }
303
304 /*=====================================================================*\
305 || ###################################################################
306 || # $HeadURL$
307 || # $Id$
308 || ###################################################################
309 \*=====================================================================*/
310 ?>