2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright ©2002-2007 Blue Static
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 2 of the License.
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
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 \*=====================================================================*/
22 require_once('./global.php');
23 require_once('./includes/api_field.php');
25 APIError(array(new API_Error_Handler($admin), 'admin_error'));
27 NavLinks
::fieldsPages();
28 $navigator->set_focus('tab', 'fields', null
);
30 if (!can_perform('canadminfields'))
35 // ###################################################################
37 if (empty($_REQUEST['do']))
39 $_REQUEST['do'] = 'modify';
42 // ###################################################################
44 if ($_REQUEST['do'] == 'kill')
46 $field = new FieldAPI();
47 $field->set('fieldid', $input->in
['fieldid']);
48 $field->set_condition();
51 $admin->redirect('field.php?do=modify');
54 // ###################################################################
56 if ($_REQUEST['do'] == 'delete')
58 $admin->page_confirm(T('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', 'kill', array('fieldid' => $input->in
['fieldid']));
61 // ###################################################################
63 if ($_REQUEST['do'] == 'update')
68 $type = $input->in
['type'];
70 $field = new FieldAPI();
72 if ($input->in
['fieldid'])
74 $field->set('fieldid', $input->in
['fieldid']);
75 $field->set_condition();
80 $type = $field->record
['type'];
84 $field->set('type', $type);
90 $field->set('defaultvalue', $input->in
['defaultvalue']);
91 $field->set('regexmatch', $input->in
['regexmatch']);
92 $field->set('maxlength', $input->in
['maxlength']);
95 case 'input_checkbox':
96 $field->set('defaultvalue', $input->in
['defaultvalue']);
100 $field->set('selects', $input->in
['selects']);
101 $field->set('usedefault', $input->in
['usedefault']);
105 $field->set('name', $input->in
['name']);
106 $field->set('description', $input->in
['description']);
107 $field->set('required', $input->in
['required']);
108 $field->set('cansearch', $input->in
['cansearch']);
113 $fieldid = $field->insertid
;
115 $db->query("ALTER TABLE " . TABLE_PREFIX
. "bug ADD custom$fieldid MEDIUMTEXT NULL");
116 $db->query("OPTIMIZE TABLE " . TABLE_PREFIX
. "bug");
121 $fieldid = $field->values
['fieldid'];
124 $input->inputClean('custom', TYPE_UINT
);
125 foreach ($input->in
['custom'] AS $usergroupid => $mask)
127 $values[] = $bugsys->clean($usergroupid, TYPE_UINT
) . ", $fieldid, " . $mask;
131 REPLACE INTO " . TABLE_PREFIX
. "bugfieldpermission
132 (usergroupid, fieldid, mask)
134 (" . implode("),\n\t\t\t(", $values) . ")"
137 $admin->redirect('field.php?do=modify', ($add ?
T('The custom field has been added') : T('The custom field has been updated')));
140 // ###################################################################
142 if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit')
144 $field = new FieldAPI();
146 $add = (($_REQUEST['do'] == 'add') ? true
: false
);
147 $typeselect = (($add AND empty($input->in
['step'])) ? true
: false
);
148 $edit = (($add) ? false
: true
);
152 NavLinks
::fieldsAdd();
153 $navigator->set_focus('link', 'fields-add', 'fields');
157 NavLinks
::fieldsEdit($input->in
['fieldid']);
158 $navigator->set_focus('link', 'fields-pages-fields', 'fields-pages');
161 $admin->page_start(($add ?
T('Add New Custom Field') : T('Edit Custom Field')));
162 $admin->form_start('field.php', ($typeselect ?
'add' : 'update'));
163 if ($add AND !$typeselect)
165 $admin->form_hidden_field('type', $input->in
['type']);
169 $admin->form_hidden_field('step', 1);
170 $admin->table_start(true
, '40%');
171 $admin->table_head(T('Select Type'));
175 $admin->table_start();
176 $admin->table_head(($add ?
T('Add New Bug Field') . ' - ' . FieldAPI
::field_types($input->in
['type']) : T('Edit Field')));
181 $field->set('fieldid', $input->in
['fieldid']);
182 $field->set_condition();
185 $admin->form_hidden_field('fieldid', $field->record
['fieldid']);
190 $type = (($add) ?
$input->in
['type'] : $field->record
['type']);
193 // show type selector
194 if (empty($input->in
['step']) AND $add)
196 foreach (FieldAPI
::field_types() AS $name => $description)
198 $admin->list_item($description, $name);
200 $admin->row_list(T('Field Type'), 'type', false
);
202 $admin->row_submit();
205 // have type, do that funkay thing!
208 $field->set('type', $type);
211 $admin->row_span(T('Global Fields'), 'thead', 'center');
212 $admin->row_text(T('Field Type'), FieldAPI
::field_types($type));
213 $admin->row_input(T('Display Name'), 'name', $field->record
['name']);
214 $admin->row_textarea(T('Description'), 'description', $field->record
['description']);
215 $admin->row_yesno(T('Required'), 'required', $field->record
['required']);
216 $admin->row_yesno(T('Can Be Searched'), 'cansearch', ((isset($field->record
['cansearch'])) ?
$field->record
['cansearch'] : true
));
218 // type-specific fields
219 $admin->row_span(T('Type-Specific Fields'), 'thead', 'center');
224 $admin->row_input(T('Default Value'), 'defaultvalue', $field->record
['defaultvalue']);
225 $admin->row_input(T('Regular Expression Match'), 'regexmatch', $field->record
['regexmatch']);
226 $admin->row_input(T('Maximum Length'), 'maxlength', $field->record
['maxlength'], 2, 10);
229 case 'input_checkbox':
230 $admin->row_yesno(T('Checked By Default'), 'defaultvalue', $field->record
['defaultvalue']);
233 case 'select_single':
234 $admin->row_textarea(T('Selection Values'), 'selects', stripslashes(implode("\n", (array)unserialize($field->record
['selects']))));
235 $admin->row_yesno(T('Make the First Option Default'), 'usedefault', $field->record
['usedefault']);
241 // custom field permissions
242 $admin->table_start();
243 $admin->table_head(T('Custom Field Permissions'));
247 $perms = $db->query("SELECT usergroupid, mask FROM " . TABLE_PREFIX
. "bugfieldpermission WHERE fieldid = " . $field->record
['fieldid']);
248 foreach ($perms as $perm)
250 $permissions["$perm[usergroupid]"] = $perm['mask'];
254 $usergroups = $db->query("SELECT * FROM " . TABLE_PREFIX
. "usergroup ORDER BY usergroupid");
255 foreach ($usergroups as $usergroup)
258 $admin->list_item(T('No Permission'), 0, $permissions["$usergroup[usergroupid]"] == 0);
259 $admin->list_item(T('Can View Field'), 1, $permissions["$usergroup[usergroupid]"] == 1);
260 $admin->list_item(T('Can View, Edit Field'), 2, $permissions["$usergroup[usergroupid]"] == 2);
261 $admin->row_list($usergroup['title'], "custom[$usergroup[usergroupid]]");
267 $admin->table_start();
268 $admin->row_submit();
276 // ###################################################################
278 if ($_REQUEST['do'] == 'modify')
280 NavLinks
::fieldsAdd();
281 $navigator->set_focus('link', 'fields-pages-fields', 'fields-pages');
283 $admin->page_start(T('Additional Bug Fields'));
285 $admin->table_start();
286 $admin->table_head(T('Additional Bug Fields'), 3, 'custom_bug_fields');
287 $admin->table_column_head(array(T('Display Name/Description'), T('Field ID'), T('Actions')));
289 $fields = $db->query("SELECT * FROM " . TABLE_PREFIX
. "bugfield ORDER BY fieldid ASC");
290 foreach ($fields as $field)
292 $admin->row_multi_item(
294 "$field[name]<div class=\"smallfont\"><em>$field[description]</em></div>" => 'l',
295 "$field[fieldid]" => 'c',
296 "<a href=\"field.php?do=edit&fieldid=$field[fieldid]\">[" . T('Edit') . "]</a> <a href=\"field.php?do=delete&fieldid=$field[fieldid]\">[" . T('Delete') . "]</a>" => 'c'
306 /*=====================================================================*\
307 || ###################################################################
310 || ###################################################################
311 \*=====================================================================*/