From ea5a7fcd0b4acb3c5a0aabcbb3331ec16fb1db40 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 8 Jun 2005 23:01:01 +0000 Subject: [PATCH] r252: Making it so that custom bug fields work better and will operate with language independence. --- admin/fields.php | 24 ++++++++------ editreport.php | 3 ++ includes/functions.php | 46 +++++++++++++++++++++------ templates/bugfield_input_checkbox.tpl | 2 +- templates/bugfield_input_text.tpl | 2 +- templates/bugfield_select_single.tpl | 2 +- 6 files changed, 57 insertions(+), 22 deletions(-) diff --git a/admin/fields.php b/admin/fields.php index c98a0bf..d199f13 100644 --- a/admin/fields.php +++ b/admin/fields.php @@ -41,7 +41,7 @@ if ($_REQUEST['do'] == 'kill') } $db->query("DELETE FROM " . TABLE_PREFIX . "bugfield WHERE fieldid = $field[fieldid]"); - $db->query("ALTER TABLE " . TABLE_PREFIX . "bugvaluefill DROP $field[shortname]"); + $db->query("ALTER TABLE " . TABLE_PREFIX . "bugvaluefill DROP field$field[fieldid]"); $db->query("OPTIMIZE TABLE " . TABLE_PREFIX . "bugvaluefill"); $admin->redirect('fields.php?do=modify', 'The field has been successfully removed from the system.'); @@ -86,10 +86,10 @@ if ($_REQUEST['do'] == 'update') { $admin->error('You must specify a short name/call name.'); } - if ((preg_match('#[^a-z0-9_]#', $bugsys->in['shortname']) OR !preg_match('#^[a-z]#', $bugsys->in['shortname']) OR preg_match('#[^a-z0-9]$#', $bugsys->in['shortname'])) AND $add) + /*if ((preg_match('#[^a-z0-9_]#', $bugsys->in['shortname']) OR !preg_match('#^[a-z]#', $bugsys->in['shortname']) OR preg_match('#[^a-z0-9]$#', $bugsys->in['shortname'])) AND $add) { $admin->error('The short name can only contain lowercase letters, numbers, and underscores; it must also begin with a letter and cannot end in anything but a letter or a number.'); - } + }*/ if (empty($bugsys->in['name'])) { @@ -140,15 +140,21 @@ if ($_REQUEST['do'] == 'update') $db->query(" INSERT INTO bugfield - (shortname, name, description, type, required, cansearch, $extrafields) + ( + #shortname, + name, description, type, required, cansearch, $extrafields) VALUES - ('" . $bugsys->in['shortname'] . "', '" . $bugsys->in['name'] . "', + ( + #'" . $bugsys->in['shortname'] . "', + '" . $bugsys->in['name'] . "', '" . $bugsys->in['description'] . "', '$type', " . intval($bugsys->in['required']) . ", " . intval($bugsys->in['cansearch']) . ", $extradata )" ); - $db->query("ALTER TABLE " . TABLE_PREFIX . "bugvaluefill ADD " . $bugsys->in['shortname'] . " MEDIUMTEXT NULL"); + $fieldid = $db->insert_id(); + + $db->query("ALTER TABLE " . TABLE_PREFIX . "bugvaluefill ADD field$fieldid MEDIUMTEXT NULL"); $db->query("OPTIMIZE TABLE " . TABLE_PREFIX . "bugvaluefill"); } else @@ -232,7 +238,7 @@ if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit') // global fields $admin->row_span('Global Fields', 'thead', 'center'); $admin->row_text('Field Type', $TYPES["$type"]); - $admin->row_input('Short Name/Call Name', 'shortname', $field['shortname']); + #$admin->row_input('Short Name/Call Name', 'shortname', $field['shortname']); $admin->row_input('Display Name', 'name', $field['name']); $admin->row_textarea('Description', 'description', $field['description']); $admin->row_yesno('Required', 'required', $field['required']); @@ -276,7 +282,7 @@ if ($_REQUEST['do'] == 'modify') $admin->table_start(); $admin->table_head(phrase('additional_bug_fields'), 3); - $admin->table_column_head(array('Display Name/Description', 'Short Name/Field ID', 'Actions')); + $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)) @@ -284,7 +290,7 @@ if ($_REQUEST['do'] == 'modify') $admin->row_multi_item( array( "$field[name]
$field[description]
" => 'l', - "$field[shortname] (fieldid: $field[fieldid])" => 'c', + "(fieldid: $field[fieldid])" => 'c', "[Edit] [Delete]" => 'c' ) ); diff --git a/editreport.php b/editreport.php index 5c7808f..82e0af3 100644 --- a/editreport.php +++ b/editreport.php @@ -72,6 +72,7 @@ if ($_POST['do'] == 'update') $hist[0] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]"); $hist2[0] = (array)$temp = $noinitialcustom = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]"); + process_custom_field_names($hist2[0]); process_custom_fields($bug['bugid']); $dependencies = preg_split('#([^0-9].*?)#', $bugsys->in['dependency'], -1, PREG_SPLIT_NO_EMPTY); @@ -100,6 +101,8 @@ if ($_POST['do'] == 'update') $hist[1] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]"); $hist2[1] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]"); + process_custom_field_names($hist2[1]); + $diff[0] = array_diff_assoc($hist[0], $hist[1]); $diff[1] = array_diff_assoc($hist[1], $hist[0]); diff --git a/includes/functions.php b/includes/functions.php index e60e1c1..fd8db42 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -360,9 +360,9 @@ function construct_custom_fields($bug = array()) foreach ($fields AS $field) { - if (!is_null($bug["$field[shortname]"])) + if (!is_null($bug["field$field[fieldid]"])) { - $value = $bug["$field[shortname]"]; + $value = $bug["field$field[fieldid]"]; } else { @@ -443,8 +443,8 @@ function process_custom_fields($bugid, $inputdata = array()) { if ($field['type'] == 'input_checkbox') { - $fieldbuild[] = $field['shortname']; - if (isset($inputdata["$field[shortname]"])) + $fieldbuild[] = 'field' . $field['fieldid']; + if (isset($inputdata["field$field[fieldid]"])) { $fieldvalue[] = 1; } @@ -455,30 +455,30 @@ function process_custom_fields($bugid, $inputdata = array()) continue; } - if ($field['required'] AND empty($inputdata["$field[shortname]"])) + if ($field['required'] AND empty($inputdata["field$field[fieldid]"])) { $errorlist[] = phrase('field_x_is_required', $field['name']); continue; } - if (isset($inputdata["$field[shortname]"])) + if (isset($inputdata["field$field[fieldid]"])) { - $fieldbuild[] = $field['shortname']; + $fieldbuild[] = 'field' . $field['fieldid']; if ($field['type'] == 'input_text') { - $fieldvalue[] = "'" . $inputdata["$field[shortname]"] . "'"; + $fieldvalue[] = "'" . $inputdata["field$field[fieldid]"] . "'"; } else { - if ($inputdata["$field[shortname]"] == -1) + if ($inputdata["field$field[fieldid]"] == -1) { $fieldvalue[] = "''"; continue; } $temp = unserialize($field['selects']); - $fieldvalue[] = "'" . trim($temp[ intval($inputdata["$field[shortname]"]) ]) . "'"; + $fieldvalue[] = "'" . trim($temp[ intval($inputdata["field$field[fieldid]"]) ]) . "'"; } } } @@ -496,6 +496,32 @@ function process_custom_fields($bugid, $inputdata = array()) $bugsys->db->query("REPLACE INTO " . TABLE_PREFIX . "bugvaluefill (bugid, " . implode(', ', $fieldbuild) . ") VALUES ($bugid, " . implode(', ', $fieldvalue) . ")"); } +// ################# Start process_custom_field_names ################ +// renames all custom fields for logging +function process_custom_field_names(&$array) +{ + global $bugsys; + static $fields; + + if (!is_array($fields)) + { + $fields = array(); + $fields_fetch = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "bugfield"); + $fields['bugid'] = 'bugid'; + while ($field = $bugsys->db->fetch_array($fields_fetch)) + { + $fields["field$field[fieldid]"] = $field['shortname']; + } + } + + foreach ($array AS $idname => $value) + { + $newarray[ $fields["$idname"] ] = $value; + } + + $array = $newarray; +} + /*=====================================================================*\ || ################################################################### || # $HeadURL$ diff --git a/templates/bugfield_input_checkbox.tpl b/templates/bugfield_input_checkbox.tpl index 1526db3..5db95cd 100644 --- a/templates/bugfield_input_checkbox.tpl +++ b/templates/bugfield_input_checkbox.tpl @@ -1 +1 @@ -
$field[name]: custom[$field[shortname]]$field[shortname]" type="checkbox" value="1"$selected />
\ No newline at end of file +
$field[name]: custom[$field[fieldid]]field$field[fieldid]" type="checkbox" value="1"$selected />
\ No newline at end of file diff --git a/templates/bugfield_input_text.tpl b/templates/bugfield_input_text.tpl index 9d05e3a..e0e140a 100644 --- a/templates/bugfield_input_text.tpl +++ b/templates/bugfield_input_text.tpl @@ -1 +1 @@ -
$field[name]: custom[$field[shortname]]$field[shortname]" type="text" value="$value" size="35"maxlength="$field[maxlength] />
\ No newline at end of file +
$field[name]: custom[$field[fieldid]]field$field[fieldid]" type="text" value="$value" size="35"maxlength="$field[maxlength] />
\ No newline at end of file diff --git a/templates/bugfield_select_single.tpl b/templates/bugfield_select_single.tpl index a8611a9..9ed7daf 100644 --- a/templates/bugfield_select_single.tpl +++ b/templates/bugfield_select_single.tpl @@ -1 +1 @@ -
$field[name]:
\ No newline at end of file +
$field[name]:
\ No newline at end of file -- 2.22.5