Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 250 lines (219 sloc) 8.239 kb
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
1 <?php
2
3 $errors = array();
4 $warnings = array();
5 $order_options = array(
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
6 '' => 'relevance',
7 'id' => 'ID',
8 'ts1' => 'date',
9 'ts2' => 'last modified',
10 'package_name' => 'package',
11 'bug_type' => 'bug_type',
12 'status' => 'status',
13 'php_version' => 'php_version',
14 'php_os' => 'os',
15 'sdesc' => 'summary',
16 'assign' => 'assignment',
31662ab @felipensp - Added order by number of votes
felipensp authored
17 'avg_score' => 'avg. vote score',
18 'votes_count' => 'number of votes'
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
19 );
20
21 // Fetch pseudo packages
22 $pseudo_pkgs = get_pseudo_packages($site);
23
24 // Setup input variables..
25 $boolean_search = isset($_GET['boolean']) ? (int) $_GET['boolean'] : 0;
26 $status = !empty($_GET['status']) ? $_GET['status'] : 'Open';
27 $search_for = !empty($_GET['search_for']) ? $_GET['search_for'] : '';
28 $bug_type = (!empty($_GET['bug_type']) && $_GET['bug_type'] != 'All') ? $_GET['bug_type'] : '';
99ced3c - Fixed bug #51722.
Derick Rethans authored
29 $bug_age = (int) (isset($_GET['bug_age']) ? $_GET['bug_age'] : 0);
30 $bug_updated = (int) (isset($_GET['bug_updated']) ? $_GET['bug_updated'] : 0);
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
31 $php_os = !empty($_GET['php_os']) ? $_GET['php_os'] : '';
32 $php_os_not = !empty($_GET['php_os_not']) ? 'not' : '';
33 $phpver = !empty($_GET['phpver']) ? $_GET['phpver'] : '';
3f640e5 @felipensp - Added field to CVE-ID
felipensp authored
34 $cve_id = !empty($_GET['cve_id']) ? $_GET['cve_id'] : '';
15bd8e4 @felipensp - Added NOT option to CVE-ID bug search
felipensp authored
35 $cve_id_not = !empty($_GET['cve_id_not']) ? 'not' : '';
beffeed @felipensp - Added possibility to search only for bugs with patch attached
felipensp authored
36 $patch = !empty($_GET['patch']) ? $_GET['patch'] : '';
99ced3c - Fixed bug #51722.
Derick Rethans authored
37 $begin = (int) (!empty($_GET['begin']) ? $_GET['begin'] : 0);
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
38 $limit = (defined('MAX_BUGS_RETURN')) ? MAX_BUGS_RETURN : 30;
39 if (!empty($_GET['limit'])) {
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
40 $limit = ($_GET['limit'] == 'All') ? 'All' : (($_GET['limit'] > 0) ? (int) $_GET['limit'] : $limit);
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
41 }
42 $direction = (!empty($_GET['direction']) && $_GET['direction'] != 'DESC') ? 'ASC' : 'DESC';
47b5807 @LawnGnome Fix bug #52472 (Bug tracker relevance sort doesn't work). Based (loosely...
LawnGnome authored
43 $order_by = (!empty($_GET['order_by']) && array_key_exists($_GET['order_by'], $order_options)) ? $_GET['order_by'] : '';
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
44 $reorder_by = (!empty($_GET['reorder_by']) && array_key_exists($_GET['reorder_by'], $order_options)) ? $_GET['reorder_by'] : '';
45 $assign = !empty($_GET['assign']) ? $_GET['assign'] : '';
46 $author_email = (!empty($_GET['author_email']) && is_valid_email($_GET['author_email'])) ? $_GET['author_email'] : '';
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
47 $package_name = (isset($_GET['package_name']) && is_array($_GET['package_name'])) ? $_GET['package_name'] : array();
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
48 $package_nname = (isset($_GET['package_nname']) && is_array($_GET['package_nname'])) ? $_GET['package_nname'] : array();
49
50 if (isset($_GET['cmd']) && $_GET['cmd'] == 'display')
51 {
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
52 $query = '
53 SELECT SQL_CALC_FOUND_ROWS
54 bugdb.*,
55 TO_DAYS(NOW())-TO_DAYS(bugdb.ts2) AS unchanged,
9926d38 - Fix some RSS/RDF issues (rss feeds actually validate now, search feeds...
Jani Taskinen authored
56 UNIX_TIMESTAMP(ts1) AS submitted,
57 UNIX_TIMESTAMP(ts2) AS modified
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
58 FROM bugdb
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
59 ';
dc4f1bb @felipensp - Added order by avg. vote scores
felipensp authored
60
31662ab @felipensp - Added order by number of votes
felipensp authored
61 if (in_array($order_by, array('votes_count', 'avg_score'))) {
dc4f1bb @felipensp - Added order by avg. vote scores
felipensp authored
62 $query .= 'LEFT JOIN bugdb_votes v ON bugdb.id = v.bug';
63 }
3f640e5 @felipensp - Added field to CVE-ID
felipensp authored
64
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
65 $where_clause = ' WHERE 1 = 1 ';
3f640e5 @felipensp - Added field to CVE-ID
felipensp authored
66
15bd8e4 @felipensp - Added NOT option to CVE-ID bug search
felipensp authored
67 if ($user_flags & (BUGS_SECURITY_DEV | BUGS_TRUSTED_DEV)) {
3f640e5 @felipensp - Added field to CVE-ID
felipensp authored
68 /* Non trusted developer should see the Security related bug report just when it is public */
e073c2d @felipensp - Updated the search part
felipensp authored
69 $where_clause .= ' AND (bugdb.bug_type <> "Security" OR private = "N") ';
3f640e5 @felipensp - Added field to CVE-ID
felipensp authored
70 }
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
71
72 if (!empty($package_name)) {
73 $where_clause .= ' AND bugdb.package_name';
74 if (count($package_name) > 1) {
75 $where_clause .= " IN ('" . join("', '", escapeSQL($package_name)) . "')";
76 } else {
77 $where_clause .= ' = ' . $dbh->quote($package_name[0]);
78 }
79 }
80
81 if (!empty($package_nname)) {
82 $where_clause .= ' AND bugdb.package_name';
83 if (count($package_nname) > 1) {
84 $where_clause .= " NOT IN ('" . join("', '", escapeSQL($package_nname)) . "')";
85 } else {
86 $where_clause .= ' <> ' . $dbh->quote($package_nname[0]);
87 }
88 }
89
90 // Ensure status is valid and tweak search clause to treat assigned, analyzed, critical and verified bugs as open
91 switch ($status) {
92 case 'All':
93 break;
94 case 'Closed':
95 case 'Re-Opened':
96 case 'Duplicate':
97 case 'Critical':
98 case 'Assigned':
99 case 'Analyzed':
100 case 'Verified':
101 case 'Suspended':
102 case 'Wont fix':
103 case 'No Feedback':
104 case 'Feedback':
105 case 'Bogus':
106 $where_clause .= " AND bugdb.status='$status'";
107 break;
108 case 'Old Feedback':
109 $where_clause .= " AND bugdb.status='Feedback'
110 AND TO_DAYS(NOW())-TO_DAYS(bugdb.ts2) > 60";
111 break;
112 case 'Fresh':
113 $where_clause .= " AND bugdb.status NOT IN ('Closed', 'Duplicate', 'Bogus')
114 AND TO_DAYS(NOW())-TO_DAYS(bugdb.ts2) < 30";
115 break;
116 case 'Stale':
117 $where_clause .= " AND bugdb.status NOT IN ('Closed', 'Duplicate', 'Bogus')
118 AND TO_DAYS(NOW())-TO_DAYS(bugdb.ts2) > 30";
119 break;
120 case 'Not Assigned':
121 $where_clause .= " AND bugdb.status NOT IN ('Closed', 'Duplicate', 'Bogus', 'Assigned', 'Wont Fix', 'Suspended')";
122 break;
123 case 'OpenFeedback':
124 $where_clause .= " AND bugdb.status IN ('Open', 'Re-Opened', 'Assigned','Analyzed', 'Critical', 'Verified', 'Feedback')";
125 break;
126 default:
127 case 'Open':
128 $where_clause .= " AND bugdb.status IN ('Open', 'Re-Opened', 'Assigned', 'Analyzed', 'Critical', 'Verified')";
129 }
130
131 if ($search_for != '') {
132 list($sql_search, $ignored) = format_search_string($search_for, $boolean_search);
133 $where_clause .= $sql_search;
134 if (count($ignored) > 0 ) {
135 $warnings[] = 'The following words were ignored: ' . implode(', ', array_unique($ignored));
136 }
137 }
138
139 if ($bug_type != '') {
140 if ($bug_type == 'Bugs') {
141 $where_clause .= ' AND (bugdb.bug_type = "Bug" OR bugdb.bug_type="Documentation Problem")';
142 } else {
143 $where_clause .= ' AND bugdb.bug_type = ' . $dbh->quote($bug_type);
144 }
145 }
146
147 if ($bug_age > 0) {
148 $where_clause .= " AND bugdb.ts1 >= DATE_SUB(NOW(), INTERVAL $bug_age DAY)";
149 }
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
150
151 if ($bug_updated > 0) {
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
152 $where_clause .= " AND bugdb.ts2 >= DATE_SUB(NOW(), INTERVAL $bug_updated DAY)";
153 }
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
154
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
155 if ($php_os != '') {
156 $where_clause .= " AND bugdb.php_os {$php_os_not} LIKE '%" . $dbh->escape($php_os) . "%'";
157 }
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
158
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
159 if ($phpver != '') {
160 $where_clause .= " AND bugdb.php_version LIKE '" . $dbh->escape($phpver) . "%'";
161 }
beffeed @felipensp - Added possibility to search only for bugs with patch attached
felipensp authored
162
3f640e5 @felipensp - Added field to CVE-ID
felipensp authored
163 if ($cve_id != '') {
15bd8e4 @felipensp - Added NOT option to CVE-ID bug search
felipensp authored
164 $where_clause .= " AND bugdb.cve_id {$cve_id_not} LIKE '" . $dbh->escape($cve_id) . "%'";
3f640e5 @felipensp - Added field to CVE-ID
felipensp authored
165 }
166
beffeed @felipensp - Added possibility to search only for bugs with patch attached
felipensp authored
167 if ($patch != '') {
168 $where_clause .= " AND EXISTS (SELECT 1 FROM bugdb_patchtracker WHERE bugdb_id = bugdb.id LIMIT 1)";
169 }
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
170
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
171 if ($assign != '') {
172 $where_clause .= ' AND bugdb.assign = ' . $dbh->quote($assign);
173 }
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
174
175 if ($author_email != '') {
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
176 $where_clause .= ' AND bugdb.email = ' . $dbh->quote($author_email);
177 }
178
179 $where_clause .= ' AND (1=1';
180
181 if ($pseudo = array_intersect(array_keys($pseudo_pkgs), $package_name)) {
182 $where_clause .= " OR bugdb.package_name";
183 if (count($pseudo) > 1) {
184 $where_clause .= " IN ('" . join("', '", escapeSQL($pseudo)) . "')";
185 } else {
186 $where_clause .= " = '" . implode('', escapeSQL($pseudo)) . "'";
187 }
188 } else {
189 $where_clause .= " OR bugdb.package_name IN ('" . join("', '", escapeSQL(array_keys($pseudo_pkgs))) . "')";
190 }
191
192 $query .= "$where_clause )";
193
194 if ($reorder_by != '') {
195 if ($order_by == $reorder_by) {
196 $direction = $direction == 'ASC' ? 'DESC' : 'ASC';
197 } else {
7df4a0d - When sorting by "last modified", show results in descenting order by d...
Jani Taskinen authored
198 $direction = $reorder_by == 'ts2' ? 'DESC' : 'ASC';
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
199 $order_by = $reorder_by;
200 }
201 }
dc4f1bb @felipensp - Added order by avg. vote scores
felipensp authored
202
47b5807 @LawnGnome Fix bug #52472 (Bug tracker relevance sort doesn't work). Based (loosely...
LawnGnome authored
203 $order_by_clauses = array();
31662ab @felipensp - Added order by number of votes
felipensp authored
204 if (in_array($order_by, array('votes_count', 'avg_score'))) {
adf592b @felipensp - Fix GROUP BY
felipensp authored
205 $query .= ' GROUP BY bugdb.id';
31662ab @felipensp - Added order by number of votes
felipensp authored
206
207 switch ($order_by) {
208 case 'avg_score':
47b5807 @LawnGnome Fix bug #52472 (Bug tracker relevance sort doesn't work). Based (loosely...
LawnGnome authored
209 $order_by_clauses = array(
210 "IFNULL(AVG(v.score), 0)+3 $direction",
211 "COUNT(v.bug) DESC"
212 );
31662ab @felipensp - Added order by number of votes
felipensp authored
213 break;
214 case 'votes_count':
47b5807 @LawnGnome Fix bug #52472 (Bug tracker relevance sort doesn't work). Based (loosely...
LawnGnome authored
215 $order_by_clauses = array("COUNT(v.bug) $direction");
31662ab @felipensp - Added order by number of votes
felipensp authored
216 break;
217 }
47b5807 @LawnGnome Fix bug #52472 (Bug tracker relevance sort doesn't work). Based (loosely...
LawnGnome authored
218 } elseif ($order_by != '') {
219 $order_by_clauses = array("$order_by $direction");
dc4f1bb @felipensp - Added order by avg. vote scores
felipensp authored
220 }
47b5807 @LawnGnome Fix bug #52472 (Bug tracker relevance sort doesn't work). Based (loosely...
LawnGnome authored
221
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
222 if ($status == 'Feedback') {
47b5807 @LawnGnome Fix bug #52472 (Bug tracker relevance sort doesn't work). Based (loosely...
LawnGnome authored
223 $order_by_clauses[] = "bugdb.ts2 $direction";
224 }
225
226 if (count($order_by_clauses)) {
227 $query .= ' ORDER BY ' . implode(', ', $order_by_clauses);
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
228 }
229
230 if ($limit != 'All' && $limit > 0) {
231 $query .= " LIMIT $begin, $limit";
232 }
233
234 if (stristr($query, ';')) {
235 $errors[] = 'BAD HACKER!! No database cracking for you today!';
236 } else {
237 $res = $dbh->prepare($query)->execute();
238 if (!PEAR::isError($res)) {
239 $rows = $res->numRows();
240 $total_rows = $dbh->prepare('SELECT FOUND_ROWS()')->execute()->fetchOne();
b236d21 - Merge some more php-bugs-web stuff into this codebase
Jani Taskinen authored
241 } else {
242 $error = MDB2::errorMessage($res);
243 $errors[] = $error;
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
244 }
245 if (defined('MAX_BUGS_RETURN') && $total_rows > $rows) {
246 $warnings[] = 'The search was too general, only ' . MAX_BUGS_RETURN . ' bugs will be returned';
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
247 }
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
248 }
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
249 }
Something went wrong with that request. Please try again.