62020c98e3c90ea19c36a9415e2683a0e752f9ba
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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.
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/functions_datastore.php');
25 if (!can_perform('canadminfields'))
31 'input_text' => $lang->string('Single-Line Text Box'),
32 'input_checkbox' => $lang->string('Checkbox Flag'),
33 'select_single' => $lang->string('Drop-Down Menu'),
36 // ###################################################################
38 if (empty($_REQUEST['do']))
40 $_REQUEST['do'] = 'modify';
43 // ###################################################################
45 if ($_REQUEST['do'] == 'kill')
47 $field = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "bugfield WHERE fieldid = " . $bugsys->input_clean('fieldid', TYPE_UINT
));
50 $admin->error($lang->getlex('error_invalid_id'));
53 $db->query("DELETE FROM " . TABLE_PREFIX
. "bugfield WHERE fieldid = $field[fieldid]");
54 $db->query("DELETE FROM " . TABLE_PREFIX
. "bugfieldpermission WHERE fieldid = $field[fieldid]");
55 $db->query("ALTER TABLE " . TABLE_PREFIX
. "bugvaluefill DROP field$field[fieldid]");
56 $db->query("OPTIMIZE TABLE " . TABLE_PREFIX
. "bugvaluefill");
60 $admin->redirect('field.php?do=modify');
63 // ###################################################################
65 if ($_REQUEST['do'] == 'delete')
67 $field = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "bugfield WHERE fieldid = " . $bugsys->input_clean('fieldid', TYPE_UINT
));
70 $admin->error($lang->getlex('error_invalid_id'));
73 $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&fieldid=$field[fieldid]");
76 // ###################################################################
78 if ($_REQUEST['do'] == 'update')
83 $type = $bugsys->in
['type'];
85 if ($bugsys->in
['fieldid'])
87 $field = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "bugfield WHERE fieldid = " . $bugsys->input_clean('fieldid', TYPE_UINT
));
90 $admin->error($lang->getlex('error_invalid_id'));
95 $type = $field['type'];
98 if (empty($bugsys->in
['name']))
100 $admin->error($lang->string('You must specify a display name.'));
102 if (!isset($TYPES["$type"]) AND $add)
104 $admin->error($lang->string('Invalid field type specified.'));
107 $bugsys->input_clean_array(array(
108 'maxlength' => TYPE_UINT
,
109 'usedefault' => TYPE_UINT
,
110 'required' => TYPE_UINT
,
111 'cansearch' => TYPE_UINT
,
112 'fieldid' => TYPE_UINT
118 $extrafields = 'defaultvalue, regexmatch, maxlength';
119 $extradata = "'" . $bugsys->in
['defaultvalue'] . "', '" . $bugsys->in
['regexmatch'] . "', " . $bugsys->in
['maxlength'];
120 $extraupdate = "defaultvalue = '" . $bugsys->in
['defaultvalue'] . "', regexmatch = '" . $bugsys->in
['regexmatch'] . "', maxlength = " . $bugsys->in
['maxlength'];
123 case 'input_checkbox':
124 $extrafields = 'defaultvalue';
125 $extradata = $bugsys->input_clean('defaultvalue', TYPE_UINT
);
126 $extraupdate = "defaultvalue = " . $bugsys->in
['defaultvalue'];
129 case 'select_single':
130 $extrafields = 'selects, usedefault';
132 // can't use explode() here because explode() returns !empty() when splitting an empty string
133 // so we have to use preg_split with the PREG_SPLIT_NO_EMPTY flag to prevent this
134 $selects = preg_split("#\n#", trim($bugsys->in
['selects']), 0, PREG_SPLIT_NO_EMPTY
);
135 array_walk($selects, 'trim');
136 if (sizeof($selects) < 1)
138 $admin->error($lang->string('You need to specify some select values.'));
141 $extradata = "'" . $bugsys->escape(serialize($selects)) . "', " . $bugsys->in
['usedefault'];
142 $extraupdate = "selects = '" . $bugsys->escape(serialize($selects)) . "', usedefault = " . $bugsys->in
['usedefault'];
149 INSERT INTO " . TABLE_PREFIX
. "bugfield
150 (name, description, type, required, cansearch, $extrafields)
152 ('" . $bugsys->in
['name'] . "',
153 '" . $bugsys->in
['description'] . "', '$type', " . $bugsys->input_clean('required', TYPE_UINT
) . ",
154 " . $bugsys->input_clean('cansearch', TYPE_UINT
) . ", $extradata
158 $fieldid = $db->insert_id();
160 $db->query("ALTER TABLE " . TABLE_PREFIX
. "bugvaluefill ADD field$fieldid MEDIUMTEXT NULL");
161 $db->query("OPTIMIZE TABLE " . TABLE_PREFIX
. "bugvaluefill");
166 UPDATE " . TABLE_PREFIX
. "bugfield
167 SET name = '" . $bugsys->in
['name'] . "',
168 description = '" . $bugsys->in
['description'] . "',
169 required = " . $bugsys->in
['required']) . ",
170 cansearch = " . $bugsys->in
['cansearch']) . ",
172 WHERE fieldid = " . $bugsys->in
['fieldid']
175 $fieldid = $bugsys->in
['fieldid'];
178 $bugsys->input_clean('custom', TYPE_UINT
);
179 foreach ($bugsys->in
['custom'] AS $usergroupid => $mask)
181 $values[] = $bugsys->clean($usergroupid, TYPE_UINT
) . ", $fieldid, " . $mask;
185 REPLACE INTO " . TABLE_PREFIX
. "bugfieldpermission
186 (usergroupid, fieldid, mask)
188 (" . implode("),\n\t\t\t(", $values) . ")"
193 $admin->redirect('field.php?do=modify', ($add ?
$lang->string('The custom field has been added') : $lang->string('The custom field has been updated')));
196 // ###################################################################
198 if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit')
200 $bugsys->input_clean('fieldid', TYPE_UINT
);
202 $add = (($_REQUEST['do'] == 'add') ? true
: false
);
203 $typeselect = (($add AND empty($bugsys->in
['step'])) ? true
: false
);
204 $edit = (($add) ? false
: true
);
206 $admin->page_start(($add ?
$lang->string('Add New Custom Field') : $lang->string('Edit Custom Field')));
207 $admin->form_start('field.php', ($typeselect ?
'add' : 'update'));
208 if ($add AND !$typeselect)
210 $admin->form_hidden_field('type', $bugsys->in
['type']);
214 $admin->form_hidden_field('step', 1);
215 $admin->table_start(true
, '40%');
216 $admin->table_head($lang->string('Select Type'), 2, 'custom_bug_fields');
220 $admin->table_start();
221 $admin->table_head(($add ?
$lang->string('Add New Bug Field') . ' - ' . $TYPES[ $bugsys->in
['type'] ] : $lang->string('Edit Field')), 2, 'custom_bug_fields_options');
226 $field = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "bugfield WHERE fieldid = " . $bugsys->in
['fieldid']);
229 $admin->error($lang->getlex('error_invalid_id'));
232 $admin->form_hidden_field('fieldid', $field['fieldid']);
237 $type = (($add) ?
$bugsys->in
['type'] : $field['type']);
240 // show type selector
241 if (empty($bugsys->in
['step']) AND $add)
243 foreach ($TYPES AS $name => $description)
245 $admin->list_item($description, $name);
247 $admin->row_list($lang->string('Field Type'), 'type', false
);
249 $admin->row_submit();
252 // have type, do that funkay thing!
255 if (!isset($TYPES["$type"]))
257 $admin->error($lang->getlex('error_invalid_id'));
261 $admin->row_span($lang->string('Global Fields'), 'thead', 'center');
262 $admin->row_text($lang->string('Field Type'), $TYPES["$type"]);
263 $admin->row_input($lang->string('Display Name'), 'name', $field['name']);
264 $admin->row_textarea($lang->string('Description'), 'description', $field['description']);
265 $admin->row_yesno($lang->string('Required'), 'required', $field['required']);
266 $admin->row_yesno($lang->string('Can Be Searched'), 'cansearch', ((isset($field['cansearch'])) ?
$field['cansearch'] : true
));
268 // type-specific fields
269 $admin->row_span($lang->string('Type-Specific Fields'), 'thead', 'center');
274 $admin->row_input($lang->string('Default Value'), 'defaultvalue', $field['defaultvalue']);
275 $admin->row_input($lang->string('Regular Expression Match'), 'regexmatch', $field['regexmatch']);
276 $admin->row_input($lang->string('Maximum Length'), 'maxlength', $field['maxlength'], 2, 10);
279 case 'input_checkbox':
280 $admin->row_yesno($lang->string('Checked By Default'), 'defaultvalue', $field['defaultvalue']);
283 case 'select_single':
284 $admin->row_textarea($lang->string('Selection Values'), 'selects', stripslashes(implode("\n", unserialize($field['selects']))));
285 $admin->row_yesno($lang->string('Make the First Option Default'), 'usedefault', $field['usedefault']);
291 // custom field permissions
292 $admin->table_start();
293 $admin->table_head($lang->string('Custom Field Permissions'));
297 $perms = $db->query("SELECT usergroupid, mask FROM " . TABLE_PREFIX
. "bugfieldpermission WHERE fieldid = $field[fieldid]");
298 while ($perm = $db->fetch_array($perms))
300 $permissions["$perm[usergroupid]"] = $perm['mask'];
304 $usergroups = $db->query("SELECT * FROM " . TABLE_PREFIX
. "usergroup ORDER BY usergroupid");
305 while ($usergroup = $db->fetch_array($usergroups))
308 $admin->list_item($lang->string('No Permission'), 0, $permissions["$usergroup[usergroupid]"] == 0);
309 $admin->list_item($lang->string('Can View Field'), 1, $permissions["$usergroup[usergroupid]"] == 1);
310 $admin->list_item($lang->string('Can View, Edit Field'), 2, $permissions["$usergroup[usergroupid]"] == 2);
311 $admin->row_list($usergroup['title'], "custom[$usergroup[usergroupid]]");
317 $admin->table_start();
318 $admin->row_submit((($edit) ?
'<a href="field.php?do=delete&fieldid=' . $field['fieldid'] . '">[' . $lang->string('Delete Field') . ']</a>' : ''));
326 // ###################################################################
328 if ($_REQUEST['do'] == 'modify')
330 $admin->page_start($lang->string('Additional Bug Fields'));
332 $admin->table_start();
333 $admin->table_head($lang->string('Additional Bug Fields'), 3, 'custom_bug_fields');
334 $admin->table_column_head(array($lang->string('Display Name/Description'), $lang->string('Field ID'), $lang->string('Actions')));
336 $fields = $db->query("SELECT * FROM " . TABLE_PREFIX
. "bugfield ORDER BY fieldid ASC");
337 while ($field = $db->fetch_array($fields))
339 $admin->row_multi_item(
341 "$field[name]<div class=\"smallfont\"><em>$field[description]</em></div>" => 'l',
342 "$field[fieldid]" => 'c',
343 "<a href=\"field.php?do=edit&fieldid=$field[fieldid]\">[" . $lang->string('Edit') . "]</a> <a href=\"field.php?do=delete&fieldid=$field[fieldid]\">[" . $lang->string('Delete') . "]</a>" => 'c'
348 $admin->row_span('<a href="field.php?do=add">[' . $lang->string('Add New Bug Field') . ']</a>', 'tfoot', 'center', 3);
354 /*=====================================================================*\
355 || ###################################################################
358 || ###################################################################
359 \*=====================================================================*/