2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright (c)2002-2015 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 \*=====================================================================*/
23 require_once './includes/init.php';
24 require_once BUGDAR_ROOT
. '/includes/model_field.php';
26 $do = filter_input(INPUT_GET
, 'do');
28 $simple_field_types = [
38 ///////////////////////////////////////////////////////////////////////////////
40 if (in_array($do, $simple_field_types)) {
41 // Get the userhelp for title and description.
42 $stmt = Bugdar
::$db->Prepare("SELECT * FROM " . TABLE_PREFIX
. "fieldhelp WHERE keystring = ?");
43 $stmt->Execute([$do]);
44 $fieldhelp = $stmt->FetchObject();
46 // Find the default value.
47 $stmt = Bugdar
::$db->Prepare("SELECT value FROM " . TABLE_PREFIX
. "setting WHERE varname = ?");
48 if ($do == 'resolution')
49 $stmt->Execute(['defaultresolve']); // Unclear why this ever was.
51 $stmt->Execute(['default' . $do]);
52 $default_setting = $stmt->FetchObject();
54 // Get all the values.
55 $stmt = Bugdar
::$db->Query("SELECT * FROM " . TABLE_PREFIX
. $do . " ORDER BY displayorder");
57 $default_value = NULL
;
58 while ($value = $stmt->Fetch()) {
59 $values[] = $value[$do];
60 if ($value[$do . 'id'] == $default_setting->value
)
61 $default_value = $value[$do];
64 // Create the new field.
65 $field = new bugdar\
Field();
66 $field->title
= $fieldhelp->title
;
67 $field->description
= $fieldhelp->body
;
68 $field->type
= bugdar\Field
::TYPE_LIST
;
69 $field->validator_pattern
= implode("\n", $values);
70 $field->required
= TRUE
;
71 $field->default_value
= $default_value;
72 $field->can_search
= TRUE
;
76 // Migrate the data from field IDs in the bug table to the values in the new
78 $stmt = Bugdar
::$db->Prepare("
79 INSERT INTO ". TABLE_PREFIX
. "bugfield2
81 SELECT bug.bugid, '" . $field->title
. "', field." . $do . "
82 FROM " . TABLE_PREFIX
. "bug AS bug
83 LEFT JOIN " . TABLE_PREFIX
. $do . " AS field
84 ON (bug." . $do . " = field." . $do . "id)
89 ///////////////////////////////////////////////////////////////////////////////
91 if ($do === 'product') {
94 print Bugdar
::$db->ConstructHTMLDebugBlock();