set_focus('tab', 'fields', null); if (!can_perform('canadminfields')) { admin_login(); } // ################################################################### if (empty($_REQUEST['do'])) { $_REQUEST['do'] = 'modify'; } // ################################################################### if ($_REQUEST['do'] == 'kill') { $field = new FieldAPI($bugsys); $field->set('fieldid', $bugsys->in['fieldid']); $field->set_condition(); $field->delete(); $admin->redirect('field.php?do=modify'); } // ################################################################### if ($_REQUEST['do'] == 'delete') { $admin->page_confirm(_('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' => $bugsys->in['fieldid'])); } // ################################################################### if ($_REQUEST['do'] == 'update') { $edit = false; $add = true; $type = $bugsys->in['type']; $field = new FieldAPI($bugsys); if ($bugsys->in['fieldid']) { $field->set('fieldid', $bugsys->in['fieldid']); $field->set_condition(); $field->fetch(); $edit = true; $add = false; $type = $field->objdata['type']; } else { $field->set('type', $type); } switch ($type) { case 'input_text': $field->set('defaultvalue', $bugsys->in['defaultvalue']); $field->set('regexmatch', $bugsys->in['regexmatch']); $field->set('maxlength', $bugsys->in['maxlength']); break; case 'input_checkbox': $field->set('defaultvalue', $bugsys->in['defaultvalue']); break; case 'select_single': $field->set('selects', $bugsys->in['selects']); $field->set('usedefault', $bugsys->in['usedefault']); break; } $field->set('name', $bugsys->in['name']); $field->set('description', $bugsys->in['description']); $field->set('required', $bugsys->in['required']); $field->set('cansearch', $bugsys->in['cansearch']); if ($add) { $field->insert(); $fieldid = $field->insertid; $db->query("ALTER TABLE " . TABLE_PREFIX . "bugvaluefill ADD field$fieldid MEDIUMTEXT NULL"); $db->query("OPTIMIZE TABLE " . TABLE_PREFIX . "bugvaluefill"); } else { $field->update(); $fieldid = $field->values['fieldid']; } $bugsys->input_clean('custom', TYPE_UINT); foreach ($bugsys->in['custom'] AS $usergroupid => $mask) { $values[] = $bugsys->clean($usergroupid, TYPE_UINT) . ", $fieldid, " . $mask; } $db->query(" REPLACE INTO " . TABLE_PREFIX . "bugfieldpermission (usergroupid, fieldid, mask) VALUES (" . implode("),\n\t\t\t(", $values) . ")" ); $admin->redirect('field.php?do=modify', ($add ? _('The custom field has been added') : _('The custom field has been updated'))); } // ################################################################### if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit') { $field = new FieldAPI($bugsys); $add = (($_REQUEST['do'] == 'add') ? true : false); $typeselect = (($add AND empty($bugsys->in['step'])) ? true : false); $edit = (($add) ? false : true); if ($add) { NavLinks::fieldsAdd(); $navigator->set_focus('link', 'fields-add', 'fields'); } else { NavLinks::fieldsEdit($bugsys->in['fieldid']); $navigator->set_focus('link', 'fields-pages-fields', 'fields-pages'); } $admin->page_start(($add ? _('Add New Custom Field') : _('Edit Custom Field'))); $admin->form_start('field.php', ($typeselect ? 'add' : 'update')); if ($add AND !$typeselect) { $admin->form_hidden_field('type', $bugsys->in['type']); } if ($typeselect) { $admin->form_hidden_field('step', 1); $admin->table_start(true, '40%'); $admin->table_head(_('Select Type')); } else { $admin->table_start(); $admin->table_head(($add ? _('Add New Bug Field') . ' - ' . FieldAPI::field_types($bugsys->in['type']) : _('Edit Field'))); } if ($edit) { $field->set('fieldid', $bugsys->in['fieldid']); $field->set_condition(); $field->fetch(); $admin->form_hidden_field('fieldid', $field->objdata['fieldid']); } if (!$typeselect) { $type = (($add) ? $bugsys->in['type'] : $field->objdata['type']); } // show type selector if (empty($bugsys->in['step']) AND $add) { foreach (FieldAPI::field_types() AS $name => $description) { $admin->list_item($description, $name); } $admin->row_list(_('Field Type'), 'type', false); $admin->row_submit(); $admin->table_end(); } // have type, do that funkay thing! else { $field->set('type', $type); // global fields $admin->row_span(_('Global Fields'), 'thead', 'center'); $admin->row_text(_('Field Type'), FieldAPI::field_types($type)); $admin->row_input(_('Display Name'), 'name', $field->objdata['name']); $admin->row_textarea(_('Description'), 'description', $field->objdata['description']); $admin->row_yesno(_('Required'), 'required', $field->objdata['required']); $admin->row_yesno(_('Can Be Searched'), 'cansearch', ((isset($field->objdata['cansearch'])) ? $field->objdata['cansearch'] : true)); // type-specific fields $admin->row_span(_('Type-Specific Fields'), 'thead', 'center'); switch ($type) { case 'input_text': $admin->row_input(_('Default Value'), 'defaultvalue', $field->objdata['defaultvalue']); $admin->row_input(_('Regular Expression Match'), 'regexmatch', $field->objdata['regexmatch']); $admin->row_input(_('Maximum Length'), 'maxlength', $field->objdata['maxlength'], 2, 10); break; case 'input_checkbox': $admin->row_yesno(_('Checked By Default'), 'defaultvalue', $field->objdata['defaultvalue']); break; case 'select_single': $admin->row_textarea(_('Selection Values'), 'selects', stripslashes(implode("\n", (array)unserialize($field->objdata['selects'])))); $admin->row_yesno(_('Make the First Option Default'), 'usedefault', $field->objdata['usedefault']); break; } $admin->table_end(); // custom field permissions $admin->table_start(); $admin->table_head(_('Custom Field Permissions')); if ($edit) { $perms = $db->query("SELECT usergroupid, mask FROM " . TABLE_PREFIX . "bugfieldpermission WHERE fieldid = " . $field->objdata['fieldid']); while ($perm = $db->fetch_array($perms)) { $permissions["$perm[usergroupid]"] = $perm['mask']; } } $usergroups = $db->query("SELECT * FROM " . TABLE_PREFIX . "usergroup ORDER BY usergroupid"); while ($usergroup = $db->fetch_array($usergroups)) { unset($listitem); $admin->list_item(_('No Permission'), 0, $permissions["$usergroup[usergroupid]"] == 0); $admin->list_item(_('Can View Field'), 1, $permissions["$usergroup[usergroupid]"] == 1); $admin->list_item(_('Can View, Edit Field'), 2, $permissions["$usergroup[usergroupid]"] == 2); $admin->row_list($usergroup['title'], "custom[$usergroup[usergroupid]]"); } $admin->table_end(); // end table $admin->table_start(); $admin->row_submit(); $admin->table_end(); $admin->form_end(); } $admin->page_end(); } // ################################################################### if ($_REQUEST['do'] == 'modify') { NavLinks::fieldsAdd(); $navigator->set_focus('link', 'fields-pages-fields', 'fields-pages'); $admin->page_start(_('Additional Bug Fields')); $admin->table_start(); $admin->table_head(_('Additional Bug Fields'), 3, 'custom_bug_fields'); $admin->table_column_head(array(_('Display Name/Description'), _('Field ID'), _('Actions'))); $fields = $db->query("SELECT * FROM " . TABLE_PREFIX . "bugfield ORDER BY fieldid ASC"); while ($field = $db->fetch_array($fields)) { $admin->row_multi_item( array( "$field[name]