From 90535e48d3345a008500685e350b4bc38a153112 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 8 Jun 2005 02:17:08 +0000 Subject: [PATCH] r246: - Searching of custom fields is done - Added some things to The List regarding searching --- docs/todo.txt | 3 +- search.php | 122 ++++++++++++++++++++++++-- templates/bugfield_input_checkbox.tpl | 2 +- templates/bugfield_input_text.tpl | 2 +- templates/bugfield_select_single.tpl | 2 +- templates/search.tpl | 2 + 6 files changed, 123 insertions(+), 10 deletions(-) diff --git a/docs/todo.txt b/docs/todo.txt index 5704411..c800b33 100755 --- a/docs/todo.txt +++ b/docs/todo.txt @@ -10,7 +10,6 @@ BUGTRACK 1.0 ---------------------------------------- - Admin auto-actions - Put either inline admin help or a "what this does" description on each of the widget pages -- Searchability of custom fields - Phrase tools for import/export/translating ---------------------------------------- @@ -48,6 +47,8 @@ BUGTRACK 1.1 - Have a favourite queries list - Mass updates and deletes - Search attachment filenames and descriptions +- Allow multi selections for all select options +- Key words should be applied to custom text fields so they won't have their own text box ---------------------------------------- GENERAL USER END diff --git a/search.php b/search.php index c5504fb..e0e0d25 100644 --- a/search.php +++ b/search.php @@ -30,6 +30,8 @@ define('MODE_RAW', ((MODE == 3) ? 1 : 0)); define('SEARCH_WORD_MIN', 3); +$show['search'] = true; + // ################################################################### if (empty($_REQUEST['do'])) @@ -169,6 +171,44 @@ if ($_REQUEST['do'] == 'results') $message->error('bad sort'); } + // ------------------------------------------------------------------- + // custom fields + $fields_fetch = $bugsys->db->query(" + SELECT bugfield.* + FROM " . TABLE_PREFIX . "bugfield AS bugfield + LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission + ON (bugfield.fieldid = permission.fieldid) + WHERE permission.mask <> 0 + AND permission.usergroupid = {$bugsys->userinfo['usergroupid']} + AND bugfield.cansearch = 1" + ); + while ($field = $bugsys->db->fetch_array($fields_fetch)) + { + if (!empty($bugsys->in['custom']["$field[shortname]"]) OR $field['type'] == 'select_single') + { + if ($field['type'] == 'input_checkbox') + { + $querybuild[] = "AND bugfieldvalue.$field[shortname] = " . (($bugsys->in['custom']["$field[shortname]"] == 1) ? 0 : 1); + } + else if ($field['type'] == 'input_text') + { + $querybuild[] = "AND bugfieldvalue.$field[shortname] LIKE '%" . $bugsys->in['custom']["$field[shortname]"] . "%'"; + } + else if ($field['type'] == 'select_single' AND $bugsys->in['custom']["$field[shortname]"] != -1) + { + $temp = unserialize($field['selects']); + $querybuild[] = "AND bugfieldvalue.$field[shortname] = '" . trim($temp[ intval($bugsys->in['custom']["$field[shortname]"]) ]) . "'"; + } + } + } + + // ------------------------------------------------------------------- + // have to search something + if (count($querybuild) < 1) + { + $message->error('you need to search for something!'); + } + // ------------------------------------------------------------------- // do the search $search = $db->query(" @@ -178,10 +218,12 @@ if ($_REQUEST['do'] == 'results') FROM " . TABLE_PREFIX . "bug AS bug LEFT JOIN " . TABLE_PREFIX . "comment AS comment ON (bug.bugid = comment.bugid) - LEFT JOIN user AS user1 + LEFT JOIN " . TABLE_PREFIX . "user AS user1 ON (bug.userid = user1.userid) - LEFT JOIN user AS user2 + LEFT JOIN " . TABLE_PREFIX . "user AS user2 ON (bug.lastpostby = user2.userid) + LEFT JOIN " . TABLE_PREFIX . "bugvaluefill AS bugfieldvalue + ON (bug.bugid = bugfieldvalue.bugid) WHERE bug.bugid <> 0 " . implode("\n\t\t\t", $querybuild) . ((!can_perform('canviewhidden')) ? " AND !bug.hidden @@ -189,9 +231,11 @@ if ($_REQUEST['do'] == 'results') $sortclause GROUP BY bug.bugid" ); - + $numrows = $db->num_rows($search); + print_r($querybuild); + if ($numrows < 1) { $message->error('no results found'); @@ -210,8 +254,6 @@ if ($_REQUEST['do'] == 'results') } eval('$template->flush("' . $template->fetch('search_results') . '");'); - -// print_r($querybuild); } // ################################################################### @@ -220,6 +262,74 @@ if ($_REQUEST['do'] == 'search') { $pcv_select = construct_pcv_select('radio', '--'); + // ------------------------------------------------------------------- + // custom fields + $fields_fetch = $bugsys->db->query(" + SELECT bugfield.* + FROM " . TABLE_PREFIX . "bugfield AS bugfield + LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission + ON (bugfield.fieldid = permission.fieldid) + WHERE permission.mask <> 0 + AND permission.usergroupid = {$bugsys->userinfo['usergroupid']} + AND bugfield.cansearch = 1" + ); + while ($field = $bugsys->db->fetch_array($fields_fetch)) + { + switch ($field['type']) + { + case 'input_text': + eval('$tempfield = "' . $bugsys->template->fetch('bugfield_input_text') . '";'); + break; + + case 'input_checkbox': + $selected = (($value) ? ' checked="checked"' : ''); + + // ignore + $value = 0; + $label = ''; + $selected = true; + eval('$options = "' . $bugsys->template->fetch('selectoption') . '";'); + + // on + $value = 1; + $label = 'Checked'; + $selected = false; + eval('$options .= "' . $bugsys->template->fetch('selectoption') . '";'); + + // off + $value = 2; + $label = 'Un-Checked'; + $selected = false; + eval('$options .= "' . $bugsys->template->fetch('selectoption') . '";'); + + eval('$tempfield = "' . $bugsys->template->fetch('bugfield_select_single') . '";'); + break; + + case 'select_single': + $selectopts = unserialize($field['selects']); + $value = trim($value); + $options = ''; + + $id = -1; + $select = ''; + $selected = ' selected="selected"'; + eval('$options .= "' . $bugsys->template->fetch('bugfield_select_single_option') . '";'); + $selected = ''; + + foreach ($selectopts AS $id => $select) + { + $select = trim($select); + eval('$options .= "' . $bugsys->template->fetch('bugfield_select_single_option') . '";'); + } + eval('$tempfield = "' . $bugsys->template->fetch('bugfield_select_single') . '";'); + break; + } + $fieldbits .= $tempfield; + } + unset($select); + + // ------------------------------------------------------------------- + // built-in fields $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', $selectedvalue = 0, $includeblank = true); $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', $selectedvalue = 0, $includeblank = true); $select['status'] = construct_datastore_select('status', 'status', 'statusid', $selectedvalue = 0, $includeblank = true); @@ -232,7 +342,7 @@ if ($_REQUEST['do'] == 'search') $label = construct_user_display($dev, false); eval('$select[dev] .= "' . $template->fetch('selectoption') . '";'); } - + eval('$template->flush("' . $template->fetch('search') . '");'); } diff --git a/templates/bugfield_input_checkbox.tpl b/templates/bugfield_input_checkbox.tpl index 693afe2..1526db3 100644 --- a/templates/bugfield_input_checkbox.tpl +++ b/templates/bugfield_input_checkbox.tpl @@ -1 +1 @@ -
$field[name]:
\ No newline at end of file +
$field[name]: custom[$field[shortname]]$field[shortname]" 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 d3d4146..9d05e3a 100644 --- a/templates/bugfield_input_text.tpl +++ b/templates/bugfield_input_text.tpl @@ -1 +1 @@ -
$field[name]: maxlength="$field[maxlength] />
\ No newline at end of file +
$field[name]: custom[$field[shortname]]$field[shortname]" 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 2f92034..a8611a9 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 diff --git a/templates/search.tpl b/templates/search.tpl index 0ca12d9..8de23e6 100644 --- a/templates/search.tpl +++ b/templates/search.tpl @@ -51,6 +51,8 @@ $pcv_select Descending +
$fieldbits
+
-- 2.22.5