From ee86bee47a2c066bf32e83e4f2490c03ff5ae59d Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Tue, 8 Feb 2005 07:09:07 +0000 Subject: [PATCH] r50: WHERE claus built. *BLIND COMMIT* --- search.php | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 1 deletion(-) diff --git a/search.php b/search.php index 557483c..f50ef75 100644 --- a/search.php +++ b/search.php @@ -29,6 +29,8 @@ define('MODE_ANY', iff(MODE == 1, 1, 0)); define('MODE_ALL', iff(MODE == 2, 1, 0)); define('MODE_RAW', iff(MODE == 3, 1, 0)); +define('SEARCH_WORD_MIN', 3); + // ################################################################### if (empty($_REQUEST['do'])) @@ -40,7 +42,121 @@ if (empty($_REQUEST['do'])) if ($_REQUEST['do'] == 'results') { - //print_r($_POST); + sanitize(array( + 'summary' => STR, // done + 'reporter' => STR, // done + 'pcv_select' => STR, // done + 'severity' => INT, // done + 'priority' => INT, // done + 'status' => INT, // done + 'resolution' => INT, // done + 'assignedto' => INT, // done + 'date' => INT) // done + ); + + // ------------------------------------------------------------------- + // parse out our product/component/version + $vars['pcv'] = parse_pcv_select($vars['pcv_select']); + + // ------------------------------------------------------------------- + // handle keywords + if ($vars['summary']) + { + $keywords = preg_split('#\s+#', $vars['summary']); + + foreach ($keywords AS $word) + { + if (strlen($word) < SEARCH_WORD_MIN) + { + continue; + } + + if (MODE_ALL) + { + $querybuild['where']['text'] .= " +$word"; + } + else + { + $querybuild['where']['text'] .= " $word"; + } + } + + $temp = trim($querybuild['where']['text']); + + if (MODE_ALL OR MODE_RAW) + { + // do some operations for those who use str boolean operators + $querybuild['where']['text'] = "AND MATCH (bug.summary, comment.comment) AGAINST ('$temp' IN BOOLEAN MODE)"; + } + else + { + $querybuild['where']['text'] = "AND MATCH (bug.summary, comment.comment) AGAINST ('$temp')"; + } + } + + // ------------------------------------------------------------------- + // reporter + if ($vars['reporter']) + { + // force email or name?? make a distinction? + // more elegant way to do this? probably + $user = $DB_sql->query_first("SELECT * FROM user WHERE email = '$vars[reporter]' OR MATCH (displayname) AGAINST ('$vars[reporter]')"); + if ($user['userid']) + { + $querybuild['where']['reporter'] = "AND bug.userid = $user[userid] OR comment.userid = $user[userid]"; + } + } + + // ------------------------------------------------------------------- + // product/component/version stuff + if (is_array($vars['pcv'])) + { + $querybuild['where']['pcv'] = "AND bug.productid = {$vars['pcv']['product']} AND bug.componentid = {$vars['pcv']['component']} AND bug.versionid = {$vars['pcv']['version']}"; + } + + // ------------------------------------------------------------------- + // severity, priority, status, resolution, assignedto + + // severity + if ($vars['severity']) + { + $querybuild['where']['severity'] = "AND bug.severity = $vars[severity]"; + } + + // priority + if ($vars['priority']) + { + $querybuild['where']['priority'] = "AND bug.priority = $vars[priority]"; + } + + // status + if ($vars['status']) + { + $querybuild['where']['status'] = "AND bug.status = $vars[status]"; + } + + // resolution + if ($vars['resolution']) + { + $querybuild['where']['resolution'] = "AND bug.resolution = $vars[resolution]"; + } + + // assignment + if ($vars['assignedto']) + { + $querybuild['where']['assignedto'] = "AND bug.assignedto = $vars[assignedto]"; + } + + // ------------------------------------------------------------------- + // date + if ($vars['date']) + { + // now - (seconds/day * number of days) + $dateline = time() - ($vars['date'] * 3600); + $querybuild['where']['date'] = "AND bug.dateline >= $dateline"; + } + + print_r($querybuild); } // ################################################################### -- 2.43.5