2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright (c)2004-2009 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 $fetchtemplates = array(
26 require_once('./global.php');
27 require_once('./includes/api_field.php');
29 if (!can_perform('canadminfields'))
34 // ###################################################################
36 if (empty($_REQUEST['do']))
38 $_REQUEST['do'] = 'modify';
41 // ###################################################################
43 if ($_REQUEST['do'] == 'kill')
45 $field = new FieldAPI();
46 $field->set('fieldid', $input->in
['fieldid']);
47 $field->set_condition();
50 $admin->redirect('field.php?do=modify');
53 // ###################################################################
55 if ($_REQUEST['do'] == 'delete')
57 $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']));
60 // ###################################################################
62 if ($_REQUEST['do'] == 'update')
67 $type = $input->in
['type'];
69 $field = new FieldAPI();
71 if ($input->in
['fieldid'])
73 $field->set('fieldid', $input->in
['fieldid']);
74 $field->set_condition();
79 $type = $field->record
['type'];
83 $field->set('type', $type);
89 $field->set('defaultvalue', $input->in
['defaultvalue']);
90 $field->set('regexmatch', $input->in
['regexmatch']);
91 $field->set('maxlength', $input->in
['maxlength']);
94 case 'input_checkbox':
95 $field->set('defaultvalue', $input->in
['defaultvalue']);
99 $field->set('selects', $input->in
['selects']);
100 $field->set('usedefault', $input->in
['usedefault']);
104 $field->set('name', $input->in
['name']);
105 $field->set('description', $input->in
['description']);
106 $field->set('required', $input->in
['required']);
107 $field->set('cansearch', $input->in
['cansearch']);
112 $fieldid = $field->insertid
;
114 $db->query("ALTER TABLE " . TABLE_PREFIX
. "bug ADD custom$fieldid MEDIUMTEXT NULL");
115 $db->query("OPTIMIZE TABLE " . TABLE_PREFIX
. "bug");
120 $fieldid = $field->values
['fieldid'];
123 $input->inputClean('custom', TYPE_UINT
);
124 foreach ($input->in
['custom'] AS $usergroupid => $mask)
126 $values[] = $bugsys->clean($usergroupid, TYPE_UINT
) . ", $fieldid, " . $mask;
130 REPLACE INTO " . TABLE_PREFIX
. "bugfieldpermission
131 (usergroupid, fieldid, mask)
133 (" . implode("),\n\t\t\t(", $values) . ")"
136 $admin->redirect('field.php?do=modify', ($add ?
T('The custom field has been added') : T('The custom field has been updated')));
139 // ###################################################################
141 if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit')
143 $field = new FieldAPI();
145 $add = (($_REQUEST['do'] == 'add') ? true
: false
);
146 $typeselect = (($add AND empty($input->in
['step'])) ? true
: false
);
147 $edit = (($add) ? false
: true
);
151 NavLinks
::fieldsAdd();
152 $navigator->set_focus('link', 'fields-add', 'fields');
156 NavLinks
::fieldsEdit($input->in
['fieldid']);
157 $navigator->set_focus('link', 'fields-pages-fields', 'fields-pages');
160 $admin->page_start(($add ?
T('Add New Custom Field') : T('Edit Custom Field')));
161 $admin->form_start('field.php', ($typeselect ?
'add' : 'update'));
162 if ($add AND !$typeselect)
164 $admin->form_hidden_field('type', $input->in
['type']);
168 $admin->form_hidden_field('step', 1);
169 $admin->table_start(true
, '40%');
170 $admin->table_head(T('Select Type'));
174 $admin->table_start();
175 $admin->table_head(($add ?
T('Add New Bug Field') . ' - ' . FieldAPI
::field_types($input->in
['type']) : T('Edit Field')));
180 $field->set('fieldid', $input->in
['fieldid']);
181 $field->set_condition();
184 $admin->form_hidden_field('fieldid', $field->record
['fieldid']);
189 $type = (($add) ?
$input->in
['type'] : $field->record
['type']);
192 // show type selector
193 if (empty($input->in
['step']) AND $add)
195 foreach (FieldAPI
::field_types() AS $name => $description)
197 $admin->list_item($description, $name);
199 $admin->row_list(T('Field Type'), 'type', false
);
201 $admin->row_submit();
204 // have type, do that funkay thing!
207 $field->set('type', $type);
210 $admin->row_span(T('Global Fields'), 'thead', 'center');
211 $admin->row_text(T('Field Type'), FieldAPI
::field_types($type));
212 $admin->row_input(T('Display Name'), 'name', $field->record
['name']);
213 $admin->row_textarea(T('Description'), 'description', $field->record
['description']);
214 $admin->row_yesno(T('Required'), 'required', $field->record
['required']);
215 $admin->row_yesno(T('Can Be Searched'), 'cansearch', ((isset($field->record
['cansearch'])) ?
$field->record
['cansearch'] : true
));
217 // type-specific fields
218 $admin->row_span(T('Type-Specific Fields'), 'thead', 'center');
223 $admin->row_input(T('Default Value'), 'defaultvalue', $field->record
['defaultvalue']);
224 $admin->row_input(T('Regular Expression Match'), 'regexmatch', $field->record
['regexmatch']);
225 $admin->row_input(T('Maximum Length'), 'maxlength', $field->record
['maxlength'], 2, 10);
228 case 'input_checkbox':
229 $admin->row_yesno(T('Checked By Default'), 'defaultvalue', $field->record
['defaultvalue']);
232 case 'select_single':
233 $admin->row_textarea(T('Selection Values'), 'selects', stripslashes(implode("\n", (array)unserialize($field->record
['selects']))));
234 $admin->row_yesno(T('Make the First Option Default'), 'usedefault', $field->record
['usedefault']);
240 // custom field permissions
241 $admin->table_start();
242 $admin->table_head(T('Custom Field Permissions'));
246 $perms = $db->query("SELECT usergroupid, mask FROM " . TABLE_PREFIX
. "bugfieldpermission WHERE fieldid = " . $field->record
['fieldid']);
247 foreach ($perms as $perm)
249 $permissions["$perm[usergroupid]"] = $perm['mask'];
253 $usergroups = $db->query("SELECT * FROM " . TABLE_PREFIX
. "usergroup ORDER BY usergroupid");
254 foreach ($usergroups as $usergroup)
257 $admin->list_item(T('No Permission'), 0, $permissions["$usergroup[usergroupid]"] == 0);
258 $admin->list_item(T('Can View Field'), 1, $permissions["$usergroup[usergroupid]"] == 1);
259 $admin->list_item(T('Can View, Edit Field'), 2, $permissions["$usergroup[usergroupid]"] == 2);
260 $admin->row_list($usergroup['title'], "custom[$usergroup[usergroupid]]");
266 $admin->table_start();
267 $admin->row_submit();
275 // ###################################################################
277 if ($_REQUEST['do'] == 'modify')
279 $tpl = new BSTemplate('field');
280 $tpl->vars
['fields'] = $db->query("SELECT * FROM " . TABLE_PREFIX
. "bugfield ORDER BY fieldid ASC");
281 $tpl->evaluate()->flush();