-
Notifications
You must be signed in to change notification settings - Fork 0
/
Search.php
295 lines (179 loc) · 7.68 KB
/
Search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<?php
require('Common.inc.php');
require('HTML.inc.php'); # import $header and $footer HTML
if (0) {
$vars = array();
foreach( $HTTP_POST_VARS as $key=>$value) {
$vars = $value;
if ( is_array($value) ) {
print " $key = " . join(", ",$value) . "<br>";
} else {
print " $key = $value<br>";
}
}
}
# This script is called from two sources: the search form
# (searchForm.php) and the company browser (Browse.php)
if ( is_array($HTTP_POST_VARS[select]) ) { # called from search form
$query = process_search_form($HTTP_POST_VARS);
$is_browse = 0;
} elseif ( isset($HTTP_GET_VARS[company])
&& isset($HTTP_GET_VARS[count]) ) { # called from browse page
$query = process_company_browse_request($HTTP_GET_VARS);
$is_browse = 1;
} else {
error_exit("You must select at least one company\n");
}
#print "<p>Query = $query\n";
show_list_as_frames($query,$is_browse);
exit;
#################### END OF MAIN PROGRAM ######################
function process_company_browse_request ($VARS) {
$query = "SELECT rv.review_id,
rv.year,
rv.company,
rv.model,
rv.size,
au.first_name,
au.last_name
FROM reviewers au, reviews rv WHERE
rv.approved = 1 AND
au.author_id = rv.author_id AND
rv.company = '" . $VARS[company] . "'" .
"ORDER BY rv.year DESC, rv.model, rv.size";
return $query;
}
function process_search_form ($VARS) {
$query .= "SELECT rv.review_id,
rv.year,
rv.company,
rv.model,
rv.size,
au.first_name,
au.last_name
FROM reviewers au, reviews rv WHERE
rv.approved = 1 AND
au.author_id = rv.author_id AND (";
$first = 1;
foreach( $VARS[select] as $value) {
# $co = mysql_escape_string($value);
$co = $value;
if ( $first == 1 ) { $first = 0; } else { $query .= " OR "; }
$query .= "rv.company = '$co' ";
}
# preg_replace ( pattern, replacement, subject )
# Searches 'subject' for matches to 'pattern' and replaces them with 'replacement'
# $query = preg_replace("/OR $/","",$query);
$query .= ") ";
if ( strlen($VARS[product]) > 0 ) {
$product = mysql_escape_string($VARS[product]);
$query .= " AND rv.product = '$product' ";
} else {
print $header;
print "You must select at least one product type\n";
print $footer;
exit;
}
if ( strlen($VARS[year_start]) > 0
&& strlen($VARS[year_end]) > 0 ) {
$query .= " AND rv.year >= $VARS[year_start]
AND rv.year <= $VARS[year_end] ";
}
if ( strlen($VARS[min_length]) > 0
&& strlen($VARS[max_length]) > 0 ) {
$query .= " AND rv.size >= $VARS[min_length]
AND rv.size <= $VARS[max_length] ";
}
if ( is_numeric($VARS[min_rating]) && is_numeric($VARS[max_rating]) ) {
$min_rating = intval($VARS[min_rating] * 10);
$max_rating = intval($VARS[max_rating] * 10);
$query .= " AND rv.rating_1 >= $min_rating AND
rv.rating_1 <= $max_rating ";
}
if ( is_numeric($VARS[min_exp]) && is_numeric($VARS[max_exp]) ) {
$query .= " AND rv.years_exp >= $VARS[min_exp]
AND rv.years_exp <= $VARS[max_exp] ";
}
if ( is_numeric($VARS[min_age]) && is_numeric($VARS[max_age]) ) {
$this_year = date("Y");
$max_year = $this_year - $VARS[min_age];
$min_year = $this_year - $VARS[max_age];
$query .= " AND au.year_born >= $min_year
AND au.year_born <= $max_year ";
}
if ( is_numeric($VARS[min_weight])
&& is_numeric($VARS[max_weight]) ) {
$query .= " AND au.weight >= $VARS[min_weight]
AND au.weight <= $VARS[max_weight] ";
}
if ( !isset($VARS[male]) ) {
$query .= " AND au.sex = 'female' ";
}
if ( !isset($VARS[female]) ) {
$query .= " AND au.sex = 'male' ";
}
$query .= " ORDER BY rv.company, rv.model, rv.size DESC, rv.year DESC ";
#print $query;
return $query;
}
function show_list_as_frames ($query,$is_browse) {
$result = mysql_query($query) or die("$header <p>Sorry, try another query! $footer");
$row_count = mysql_num_rows($result);
if ( $row_count == 0 ) {
error_exit("<b>Sorry, there weren't any reviews matching your search.</b>");
} else {
$search_list = "<center><h3>$row_count Reviews Found</h3>
<p>
<a href=\"Browse.php\" target=\"_top\"><font size=\"-1\">Browse All</font></a> |
<a href=\"searchForm.php\" target=\"_top\"><font size=\"-1\">New Search </font></a></center>";
}
while ( $row = mysql_fetch_assoc($result) ) {
if ( $row[size] < 100 ) { $row[size] = ''; }
if ( $row[model] == $row[size] ) { $row[model] = ''; }
if ( $is_browse == 1 ) {
$search_list .= "<p><a href=\"showReview.php?id=$row[review_id]\" target=\"reviewWindow\"> $row[model] $row[size] ($row[year]) </a> ";
} else {
$search_list .= "<p><a href=\"showReview.php?id=$row[review_id]\" target=\"reviewWindow\"> $row[company] $row[model] $row[size] ($row[year]) </a> ";
}
}
$current_time = time();
$search_id = md5( $current_time . $search_list );
# $search_list = mysql_escape($search_list);
$insert = "INSERT INTO search_queue VALUES ( NULL, '$search_id', '$search_list', $current_time )";
mysql_query($insert) or die("$header Unable to insert search list.\n$footer");
# print "<p>" . mysql_error();
if (0) { # show banners based on what company was searched for
$company_query = "SELECT ov.banner_html
FROM companies c, company_banners cb, online_vendors ov
WHERE c.company IN ('$row[company]')
AND cb.company_id = c.company_id
AND cb.vendor_id = ov.vendor_id
";
$banners = mysql_query($company_query);
if ( mysql_num_rows($banners) > 0 ) {
# create a showBanner.php?list_id=xxxx
# and place a link below instead of showing choose.htm
}
}
print <<<FRAME
<html><head><title>Board Reviews Search Results</title></head>
<frameset COLS="25%,75%">
<frame NAME="reviewList" SRC="searchList.php?search_id=$search_id">
<frame NAME="reviewWindow" SRC="choose.htm">
</frameset>
FRAME;
$one_hour_ago = $current_time - 3600;
$delete = "DELETE FROM search_queue WHERE timestamp < $one_hour_ago";
mysql_query($delete);
}
function error_exit ($error_msg) {
global $header;
global $footer;
print $header; # $header and $footer from HTML.inc.php
print "<p><center><img src=\"BoardReviewsLogo.gif\" width=\"288\" height=\"72\"></center></p>";
echo("<p><center><h2>$error_msg</h2></center>");
echo("<p><center><a href=\"javascript:history.go(-1)\">Click Here To Try Again!</a></center><p>");
print $footer;
exit;
}
?>