-
Notifications
You must be signed in to change notification settings - Fork 0
/
reviewSearch.php
338 lines (328 loc) · 10.7 KB
/
reviewSearch.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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
<?php
include_once("include/collegeconnection.php");
$oneset = false;
$reviewString = "";
if(isset($_POST['submitted']) && $_POST['submitted'] == 1)
{
$string = "";
if (isset($_POST['category']) && $_POST['category'] != "")
{
$category = $_POST['category'];
$string = $string.'category = "'.$category.'" ';
$oneset = true;
$reviewString = 'category = <b>'.$category.'</b><br>';
}
if($oneset)
{
$string = $string.' AND ';
$oneset = false;
}
if (isset($_POST['subject']) && $_POST['subject'] != "" && $_POST['subject'] != 'search by subject')
{
$subject = $_POST['subject'];
$reviewString = $reviewString.'subject = <b>"'.$subject.'"</b><br>';
$subjectConst = strtoupper($subject);
$finds = array();
$continue = true;
while ($continue)
{
$pos = strpos($subject, " ");
if ($pos > -1)
{
$word = substr($subject, 0, $pos);
}
else
{
$word = substr($subject, 0);
$continue = false;
}
if(strlen($word) > 2)
{
array_push($finds, $word);
}
$subject = substr($subject, $pos + 1);
}
$data = mysql_query('SELECT id, subject FROM reviews WHERE subject = "'.$subject.'" ORDER BY id DESC;', $connection) or die(mysql_error());
$row = mysql_fetch_array($data, MYSQL_ASSOC);
$found = true;
if(strcmp(strtoupper($row['subject']), strtoupper($subject))) //if there is no data matching names exactly...
{
$found = false;
$ids = array(); //initialize a new array to hold the school id numbers
$data = mysql_query('SELECT id, subject FROM reviews;', $connection) or die("error"); //retrieve all the data from schools
$common = array();
while($row = mysql_fetch_array($data, MYSQL_ASSOC)) //while there is still data to be served
{
$occur = 0;
foreach($finds as $find) //for each part of the school name entered...
{
//if the section of the entered data is in the name or the description..
if(!strcmp($find, $row['subject']) ||
(strpos(strtoupper($row['subject']), strtoupper($find)) > -1))
{//|| (strpos(strtoupper($row['description']), $find) > -1)
array_push($ids, $row['id']); //add this school's id.
$occur++;
}//end if
}//end for
$common[$row['id']] = $occur;
}//end while
$ids = array_unique($ids);
} //end if
else
{
$string = $string.'id='.$row['id'];
$found = true;
}
if(!$found)
{
if (isset($common))
{
arsort($common);
$string = $string.'(';
}
else
{
$string = $string.'0';
}
if($common)
{
foreach ($common as $id => $num)
{
if($num > 0)
{
$string = $string.'id = '.$id.' OR ';
}
}
$string = $string.'id=-1) ';
}
$oneset= true;
}
$oneset = true;
}
else
{
$oneset = false;
}
if($oneset)
{
$string = $string.' AND ';
$oneset = false;
}
if (isset($_POST['school']) && $_POST['school'] != "" && $_POST['school'] != "search by school")
{
$school = $_POST['school'];
$reviewString = $reviewString.'school = <b>"'.$school.'"</b><br>';
if(isset($_POST['school']))
{
$school = strtoupper($_POST['school']);
$schoolconst = $school;
}
$finds = array();
$continue = true;
while($continue)
{
$pos = strpos($school, " ");
if($pos)
{
$name = substr($school, 0 , $pos);
}
else
{
$name = substr($school, 0);
$continue = false;
}
if(strlen($name) > 2)
{
array_push($finds, $name);
}
$school = substr($school, $pos + 1);
}
$data = mysql_query('SELECT * FROM schools WHERE name = \''.$schoolconst.'\';', $connection);
$row = mysql_fetch_array($data, MYSQL_ASSOC);
$found = true;
$common = array();
if(strcmp(strtoupper($row['name']), strtoupper($schoolconst))) //if there is no data matching names exactly...
{
$found = false;
$ids = array(); //initialize a new array to hold the school id numbers
$data = mysql_query('SELECT * FROM schools;', $connection) or die("error"); //retrieve all the data from schools
while($row = mysql_fetch_array($data, MYSQL_ASSOC)) //while there is still data to be served
{
$occur = 0;
foreach($finds as $find) //for each part of the school name entered...
{
//if the section of the entered data is in the name or the description..
if(!strcmp($find, $row['abrev']) ||
(strpos(strtoupper($row['name']), $find) > -1) || (!strcmp($find, strtoupper($row['name']))))
{//|| (strpos(strtoupper($row['description']), $find) > -1)
array_push($ids, $row['id']); //add this school's id.
$occur++;
}//end if
}//end for
$common[$row['id']] = $occur;
}//end while
$ids = array_unique($ids);
} //end if
else
{
$common[$row['id']] = 1;
}
if (isset($common))
{
arsort($common);
$string = $string.'(';
}
if($common)
{
foreach ($common as $id => $num)
{
if($num > 0)
{
$string = $string.'schoolid = '.$id.' OR ';
}
}
$string = $string.'schoolid=-1) ';
$oneset= true;
}
}
else
{
$oneset = false;
}
if($oneset)
{
$string = $string.' AND ';
$oneset = false;
}
if (isset($_POST['rating']) && $_POST['rating'] != "")
{
$rating = $_POST['rating'];
$reviewString = $reviewString.'rating = <b>'.$rating.'</b><br>';
$string = $string.'rating = '.$rating.'; ';
}
else
{
$string = $string."1;";
}
if(strlen($string) > 1)
{
$data = mysql_query('SELECT category, subject, rating, id, userid, schoolid FROM reviews WHERE '.$string.';', $connection) or die('error <a href="login.php">Home</a>');
$noSearch = false;
}
else
{
die($string);
$noSearch = true;
}
$posted = 1;
}
include_once("include/header.php");
?>
<html>
<head>
<title>Search Reviews</title>
</head>
<body>
<div id="mainContentPart">
<div class="schoolIndexCenterbox">
<div class="box" style="float: right; margin: 0px; margin-top: 100px; margin-right: 20px; width: 250px;">
<table id="boxTable" cellspacing="0" cellpadding="0" border="0" style="width: 250px; background-color: #E5EAEA;">
<tr class="title4"><td class="titleLeft4"> </td><td><img src="/images/tipTitle.gif"></img></td><td class="titleRight4"> </td></tr>
<tr><td class="bl"></td><td>
<div>
<ul>
<li>Filling out all the fields will greatly narrow your results.</li>
<li>You can specify a school name, part of a name or an abreviation. For Example "Chris", "CNU" and "Christopher Newport University" will all give similar results.</li>
</ul>
</div>
</td><td class="br"></td></tr>
<tr class = "bbm"><td class="bbl"></td><td></td><td class="bbr"></td></tr>
</table>
</div>
<?php
if(isset($posted) && $posted ==1)
{
if ($noSearch)
{
print "<div class='error'>Must Specify a Search</div>";
}
else if (mysql_num_rows($data) == 0)
{
print "<h3>No matches found</h3>";
}
else
{
print "<div class='pagetitle'><u>Search Results</u></div>";
print "<ul class='searchResults'>";
}
if(!$noSearch)
{
while($row = mysql_fetch_array($data, MYSQL_ASSOC))
{
$school = mysql_fetch_array(mysql_query('select name from schools where id = '.$row['schoolid'].';', $connection), MYSQL_ASSOC);
print '<li><a href="review.php?rid='.$row['id'].'">'.$school['name'].' - '.$row['subject'].'('.ucfirst($row['category']).') - rating:"'. $row['rating'].'"</a></li>';
}
print "</ul>";
print '<div id="reviewString">';
print 'Your Search<br>';
print '<p>'.$reviewString.'</p>';
print '</div>';
}
}
?>
<hr>
<div class="box">
<table id="boxTable" cellspacing="0" cellpadding="0" border="0" style="width: 250px; background-color: #E5EAEA;">
<tr class="title1"><td class="titleLeft1"> </td><td><img src="/images/advancedSearch.gif"></img></td><td class="titleRight1"> </td></tr>
<tr><td class="bl"></td><td>
<table id="reviewSearch" cellspacing="0" cellpadding="0">
<form name="reviewSearch" action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">
<tr><td><label for="category">Category:<p>Categories help divide the subject of a review<br /><p class="note">*Note: Organizations can be fraternities, sororities or anything else student run.</p></p></label></td>
<td><select name = "category">
<option value="">Select a Category</option>
<optgroup label="Social Scene">
<option value ="bar">Bar</option>
<option value ="store">Store</option>
<option value ="resturant">Resturant</option>
<option value ="music scene">Music Scene</option>
<option value ="band">Band</option>
<option value ="Off Campus Housing">Off Campus Housing</option>
<option value ="Social Spot">Social Spot</option>
</optgroup>
<optgroup label="School">
<option value ="School">The Entire School</option>
<option value ="teacher">Teacher</option>
<option value ="major">Major</option>
<option value ="class">Class</option>
<option value ="dorm">Dorm</option>
<option value ="dining">Dining Facility</option>
<option value ="sports">Sports</option>
<option value ="Fraternity">Fraternity</option>
<option value ="Sorority">Sorority</option>
<option value ="organization">Group/Organization*</option>
</optgroup>
</select></td></tr>
<tr><td><label for="subject">Subject:<p>Subjects are used to further specify the topic of a review. This should be as specific as can be.</p></label></td><td><input type="text" name="subject"></td></tr>
<tr><td><label for="subject">School:<p>Searching schools allows you to specify a certain school to retrieve reviews about.</p></label></td><td><input type="text" name="school"></td></tr>
<tr><td><label for="rating">Rating:<p>This is the rating the reviewer gave to the subject. (1-lowest: 5-highest)</p></label></td><td>
<select name="rating">
<option selected="selected" value="" >-</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select></td></tr>
<tr><td colspan="100%">
<input class="button" type="image" name="submit" src="images/searchButton.gif"></td></tr>
<input type="hidden" value="1" name="submitted">
</form>
</table>
</td><td class="br"></td></tr>
<tr class = "bbm"><td class="bbl"></td><td></td><td class="bbr"></td></tr>
</table>
</div>
</div>
</div>
</body>
</html>