<?php

if(!$_GET['term']) {
	die('You forgot to enter a search term!  <a href=http://projects.csail.mit.edu/films/searchPage6.php>Go back</a> and try again.  ');
}
elseif((!$_GET['subject']) && (!$_GET['title']) && (!$_GET['description']) &&  (!$_GET['comments']) && (!$_GET['notes']) && (!$_GET['people'])) {
	die('You chose no fields within which to search!  <a href=http://projects.csail.mit.edu/films/searchPage6.php>Go back</a> and try again.  ');
}
else {
	$term=$_GET['term'];
	$search = array('title' => $_GET['title'], 'subject' => $_GET['subject'], 'people' => $_GET['people'], 'description' => $_GET['description'], 'notes' => $_GET['notes']);
	$commentsearch = $_GET['comments'];
}

$db=@mysql_connect("mysql.csail.mit.edu","filmsai","filmsAI+3456") or die("Foo!");
@mysql_select_db("filmsAI",$db) or die("Bar!");

$added = array();
$foo = array();
foreach ($search as $sea => $value) {
	if ($value == 'on') {
		$try=@mysql_query("SELECT * FROM `testTJG2` WHERE MATCH ($sea) AGAINST ('$term')",$db) or die('The search on '.$sea.' failed; please try again in a minute or contact the webmaster.');	
		for ($i = 0; $i <= mysql_num_rows($try); $i++) {
			$temp = @mysql_fetch_array($try);
			if ($temp['reel']) {
				if (!in_array($temp['reel'], $added)) {
					array_push($foo, $temp);
					array_push($added, $temp['reel']);
				}
			}
		}
	}
}

$list = '';
foreach ($foo as $bar) {
	$list = $list.$bar["reel"].":";
}
$list = substr($list, 0, -1);

foreach ($foo as $current) {	
	$number = $current["reel"];																		
	$title = $current["title"];
	$date = $current["date"];
	$description = $current["description"];
	$desc = substr($description,0,80);
	$filename = $current["url"];
	$firstnum = $filename{0} + 1;
	$firstbitarray = split('-', $filename);
	$firstbit = $firstbitarray[0];
	$firstchar = (string) $firstnum;
			
	echo ('
	<center>
	<table style="text-align: left; width: 100%;" border="0" cellpadding="0" cellspacing="0">
		<tbody>
			<tr>
				<td width="5%">
				</td>
				<td width="25%">
					<a href="http://projects.csail.mit.edu/films/dynamicPage.php?reel%23='.$firstbit.'&amp;res='.$list.'"><img style="border: 0px solid ; height: 150px ; width: 180px ;" alt="'.$title.'" title="'.$title.'" src="http://projects.csail.mit.edu/films/pictures/Screenshots/'.$filename.'.jpg" /></a>
				</td>
				<td width="5%">
				</td>
				<td width="65%">
					'.$title.' - '.$date.'<br />
					'.$desc.' . . . <br />
					<a href="http://projects.csail.mit.edu/films/dynamicPage.php?reel%23='.$firstbit.'&amp;res='.$list.'">Check it out!</a>
				</td>
			</tr>
		</tbody>
	</table>
	</center>
	<br><br>
	');
	echo "<br>\n<br>\n";
}

if ($commentsearch == 'on') {
	@mysql_query("SELECT * FROM `comments` WHERE (`filename` = $filmnumber)",$dbcnt);
}


//POST METHOD CODE
//							<form action="dynamicPage.php" name="dynamicPage.php" method="post">
//								<input name="reel#" value="'.$reel.'" type="hidden" />
//								<input name="submit" value="Check it out!" type="submit" />
//							</form>
?>