$lang->string('Single-Line Text Box'), 'input_checkbox' => $lang->string('Checkbox Flag'), 'select_single' => $lang->string('Drop-Down Menu'), ); // ################################################################### if (empty($_REQUEST['do'])) { $_REQUEST['do'] = 'modify'; } // ################################################################### if ($_REQUEST['do'] == 'kill') { $field = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugfield WHERE fieldid = " . intval($bugsys->in['fieldid'])); if (!$field) { $admin->error($lang->getlex('error_invalid_id')); } $db->query("DELETE FROM " . TABLE_PREFIX . "bugfield WHERE fieldid = $field[fieldid]"); $db->query("DELETE FROM " . TABLE_PREFIX . "bugfieldpermission WHERE fieldid = $field[fieldid]"); $db->query("ALTER TABLE " . TABLE_PREFIX . "bugvaluefill DROP field$field[fieldid]"); $db->query("OPTIMIZE TABLE " . TABLE_PREFIX . "bugvaluefill"); build_user_help(); $admin->redirect('field.php?do=modify'); } // ################################################################### if ($_REQUEST['do'] == 'delete') { $field = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugfield WHERE fieldid = " . intval($bugsys->in['fieldid'])); if (!$field) { $admin->error($lang->getlex('error_invalid_id')); } $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]"); } // ################################################################### if ($_REQUEST['do'] == 'update') { $edit = false; $add = true; $type = $bugsys->in['type']; if ($bugsys->in['fieldid']) { $field = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugfield WHERE fieldid = " . intval($bugsys->in['fieldid'])); if (!$field) { $admin->error($lang->getlex('error_invalid_id')); } $edit = true; $add = false; $type = $field['type']; } if (empty($bugsys->in['name'])) { $admin->error($lang->string('You must specify a display name.')); } if (!isset($TYPES["$type"]) AND $add) { $admin->error($lang->string('Invalid field type specified.')); } switch ($type) { case 'input_text': $extrafields = 'defaultvalue, regexmatch, maxlength'; $extradata = "'" . $bugsys->in['defaultvalue'] . "', '" . $bugsys->in['regexmatch'] . "', " . intval($bugsys->in['maxlength']); $extraupdate = "defaultvalue = '" . $bugsys->in['defaultvalue'] . "', regexmatch = '" . $bugsys->in['regexmatch'] . "', maxlength = " . intval($bugsys->in['maxlength']); break; case 'input_checkbox': $extrafields = 'defaultvalue'; $extradata = intval($bugsys->in['defaultvalue']); $extraupdate = "defaultvalue = " . intval($bugsys->in['defaultvalue']); break; case 'select_single': $extrafields = 'selects, usedefault'; // can't use explode() here because explode() returns !empty() when splitting an empty string // so we have to use preg_split with the PREG_SPLIT_NO_EMPTY flag to prevent this $selects = preg_split("#\n#", trim($bugsys->in['selects']), 0, PREG_SPLIT_NO_EMPTY); array_walk($selects, 'trim'); if (count($selects) < 1) { $admin->error($lang->string('You need to specify some select values.')); } $extradata = "'" . $bugsys->escape(serialize($selects)) . "', " . intval($bugsys->in['usedefault']); $extraupdate = "selects = '" . $bugsys->escape(serialize($selects)) . "', usedefault = " . intval($bugsys->in['usedefault']); break; } if ($add) { $db->query(" INSERT INTO " . TABLE_PREFIX . "bugfield (name, description, type, required, cansearch, $extrafields) VALUES ('" . $bugsys->in['name'] . "', '" . $bugsys->in['description'] . "', '$type', " . intval($bugsys->in['required']) . ", " . intval($bugsys->in['cansearch']) . ", $extradata )" ); $fieldid = $db->insert_id(); $db->query("ALTER TABLE " . TABLE_PREFIX . "bugvaluefill ADD field$fieldid MEDIUMTEXT NULL"); $db->query("OPTIMIZE TABLE " . TABLE_PREFIX . "bugvaluefill"); } else { $db->query(" UPDATE " . TABLE_PREFIX . "bugfield SET name = '" . $bugsys->in['name'] . "', description = '" . $bugsys->in['description'] . "', required = " . intval($bugsys->in['required']) . ", cansearch = " . intval($bugsys->in['cansearch']) . ", $extraupdate WHERE fieldid = " . intval($bugsys->in['fieldid']) ); $fieldid = intval($bugsys->in['fieldid']); } foreach ($bugsys->in['custom'] AS $usergroupid => $mask) { $values[] = intval($usergroupid) . ", $fieldid, " . intval($mask); } $db->query(" REPLACE INTO " . TABLE_PREFIX . "bugfieldpermission (usergroupid, fieldid, mask) VALUES (" . implode("),\n\t\t\t(", $values) . ")" ); build_user_help(); $admin->redirect('field.php?do=modify', ($add ? $lang->string('The custom field has been added') : $lang->string('The custom field has been updated'))); } // ################################################################### if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit') { $add = (($_REQUEST['do'] == 'add') ? true : false); $typeselect = (($add AND empty($bugsys->in['step'])) ? true : false); $edit = (($add) ? false : true); $admin->page_start(($add ? $lang->string('Add New Custom Field') : $lang->string('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($lang->string('Select Type'), 2, 'custom_bug_fields'); } else { $admin->table_start(); $admin->table_head(($add ? $lang->string('Add New Bug Field') . ' - ' . $TYPES[ $bugsys->in['type'] ] : $lang->string('Edit Field')), 2, 'custom_bug_fields_options'); } if ($edit) { $field = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugfield WHERE fieldid = " . intval($bugsys->in['fieldid'])); if (!$field) { $admin->error($lang->getlex('error_invalid_id')); } $admin->form_hidden_field('fieldid', $field['fieldid']); } if (!$typeselect) { $type = (($add) ? $bugsys->in['type'] : $field['type']); } // show type selector if (empty($bugsys->in['step']) AND $add) { foreach ($TYPES AS $name => $description) { $admin->list_item($description, $name); } $admin->row_list($lang->string('Field Type'), 'type', false); $admin->row_submit(); $admin->table_end(); } // have type, do that funkay thing! else { if (!isset($TYPES["$type"])) { $admin->error($lang->getlex('error_invalid_id')); } // global fields $admin->row_span($lang->string('Global Fields'), 'thead', 'center'); $admin->row_text($lang->string('Field Type'), $TYPES["$type"]); $admin->row_input($lang->string('Display Name'), 'name', $field['name']); $admin->row_textarea($lang->string('Description'), 'description', $field['description']); $admin->row_yesno($lang->string('Required'), 'required', $field['required']); $admin->row_yesno($lang->string('Can Be Searched'), 'cansearch', ((isset($field['cansearch'])) ? $field['cansearch'] : true)); // type-specific fields $admin->row_span($lang->string('Type-Specific Fields'), 'thead', 'center'); switch ($type) { case 'input_text': $admin->row_input($lang->string('Default Value'), 'defaultvalue', $field['defaultvalue']); $admin->row_input($lang->string('Regular Expression Match'), 'regexmatch', $field['regexmatch']); $admin->row_input($lang->string('Maximum Length'), 'maxlength', $field['maxlength'], 2, 10); break; case 'input_checkbox': $admin->row_yesno($lang->string('Checked By Default'), 'defaultvalue', $field['defaultvalue']); break; case 'select_single': $admin->row_textarea($lang->string('Selection Values'), 'selects', stripslashes(implode("\n", unserialize($field['selects'])))); $admin->row_yesno($lang->string('Make the First Option Default'), 'usedefault', $field['usedefault']); break; } $admin->table_end(); // custom field permissions $admin->table_start(); $admin->table_head($lang->string('Custom Field Permissions')); if ($edit) { $perms = $db->query("SELECT usergroupid, mask FROM " . TABLE_PREFIX . "bugfieldpermission WHERE fieldid = $field[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($lang->string('No Permission'), 0, $permissions["$usergroup[usergroupid]"] == 0); $admin->list_item($lang->string('Can View Field'), 1, $permissions["$usergroup[usergroupid]"] == 1); $admin->list_item($lang->string('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((($edit) ? '[' . $lang->string('Delete Field') . ']' : '')); $admin->table_end(); $admin->form_end(); } $admin->page_end(); } // ################################################################### if ($_REQUEST['do'] == 'modify') { $admin->page_start($lang->string('Additional Bug Fields')); $admin->table_start(); $admin->table_head($lang->string('Additional Bug Fields'), 3, 'custom_bug_fields'); $admin->table_column_head(array($lang->string('Display Name/Description'), $lang->string('Field ID'), $lang->string('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]
$field[description]
" => 'l', "$field[fieldid]" => 'c', "[" . $lang->string('Edit') . "] [" . $lang->string('Delete') . "]" => 'c' ) ); } $admin->row_span('[' . $lang->string('Add New Bug Field') . ']', 'tfoot', 'center', 3); $admin->table_end(); $admin->page_end(); } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>