-
Notifications
You must be signed in to change notification settings - Fork 0
/
doFrameSearch.php
225 lines (134 loc) · 5.8 KB
/
doFrameSearch.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
<?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>";
}
}
}
if ( is_array($HTTP_POST_VARS[select]) ) {
$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( $HTTP_POST_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 .= ") ";
} else {
print $header;
print "You must select at least one company\n";
print $footer;
exit;
}
if ( strlen($HTTP_POST_VARS[product]) > 0 ) {
$product = mysql_escape_string($HTTP_POST_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($HTTP_POST_VARS[year_start]) > 0 && strlen($HTTP_POST_VARS[year_end]) > 0 ) {
$query .= " AND rv.year >= $HTTP_POST_VARS[year_start] AND rv.year <= $HTTP_POST_VARS[year_end] ";
}
if ( strlen($HTTP_POST_VARS[min_length]) > 0 && strlen($HTTP_POST_VARS[max_length]) > 0 ) {
$query .= " AND rv.size >= $HTTP_POST_VARS[min_length] AND rv.size <= $HTTP_POST_VARS[max_length] ";
}
if ( is_numeric($HTTP_POST_VARS[min_rating]) && is_numeric($HTTP_POST_VARS[max_rating]) ) {
$min_rating = intval($HTTP_POST_VARS[min_rating] * 10);
$max_rating = intval($HTTP_POST_VARS[max_rating] * 10);
$query .= " AND rv.rating_1 >= $min_rating AND
rv.rating_1 <= $max_rating ";
}
if ( is_numeric($HTTP_POST_VARS[min_exp]) && is_numeric($HTTP_POST_VARS[max_exp]) ) {
$query .= " AND au.years_exp >= $HTTP_POST_VARS[min_exp] AND au.years_exp <= $HTTP_POST_VARS[max_exp] ";
}
if ( is_numeric($HTTP_POST_VARS[min_age]) && is_numeric($HTTP_POST_VARS[max_age]) ) {
$query .= " AND au.age >= $HTTP_POST_VARS[min_age] AND au.age <= $HTTP_POST_VARS[max_age] ";
}
if ( is_numeric($HTTP_POST_VARS[min_weight]) && is_numeric($HTTP_POST_VARS[max_weight]) ) {
$query .= " AND au.weight >= $HTTP_POST_VARS[min_weight] AND au.age <= $HTTP_POST_VARS[max_weight] ";
}
if ( !isset($HTTP_POST_VARS[male]) ) {
$query .= " AND au.sex = 'female' ";
}
if ( !isset($HTTP_POST_VARS[female]) ) {
$query .= " AND au.sex = 'male' ";
}
$query .= " ORDER BY rv.company, rv.model, rv.size DESC, rv.year DESC ";
# print "<p>Query = $query\n";
$result = mysql_query($query) or die("$header Unable to execute query.\n$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=\"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] = ''; }
$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);
exit;
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;
}
?>