<?php
$lcheck = "b";
$z = "b";

if ($online == "no") {
	echo "Sorry, but ".$sitename." is offline.";
} else {
if ($ipbancheck1 == "0") {
if ($numvb == "0"){
	if ($warn == $naum) {
	echo "You are banned from the site...now go away!";
} else {

if ($_GET['view'] == "") {
headera();
echo "<form action='index.php?load=search&view=results' method='post'><table cellpadding='2' cellspacing='2' border='0'><tr><td><input type='text' name='search' value='".$_GET['search']."'></td><td><select name='type'><option value='content'>Content</option><option value='games'>Games</option></select></td></tr><tr><td><input type='submit' name='submit' value='Search'></td></tr></table></form>";
}

if ($_GET['view'] == "results") {
if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
}

if ($_GET['search']) {
$searchentry = $_GET['search'];
} else {
$searchentry = $_POST['search'];
}

$from = (($page * $max_results) - $max_results);

if ($_POST['type'] == "games") {
$searca = mysql_query("SELECT * FROM ".$pre."games WHERE name LIKE '%" . $searchentry . "%'");
$results = mysql_num_rows($searca);
} else {
$searca = mysql_query("SELECT * FROM ".$pre."content WHERE name LIKE '%" . $searchentry . "%'");
$results = mysql_num_rows($searca);
}

if ($results == "1") {
if ($_POST['type'] == "content") {
$fet = mysql_fetch_row(mysql_query("SELECT id,name,cat FROM ".$pre."content WHERE name LIKE '%" . $searchentry . "%'"));
header("location: ".$part1.$fet[0].fthrough($fet[1], $fet[2]).$part2);
} else {
$fet = mysql_fetch_row(mysql_query("SELECT id,name FROM ".$pre."games WHERE name LIKE '%" . $searchentry . "%'"));
header("location: ".$gamepart1.$fet[0].fthrough($fet[1], "").$gamepart2);
}
} else {
headera();
echo "<title>".$sitename." :: ".$results." Search Results For - ".$searchentry."</title><a href='index.php'>Home</a> > <a href='search.php'>Search</a> > ".$searchentry." - ".$results." Results<br><br><table cellpadding='5' cellspacing='3' border='0' align='center'>";
    if ($_POST['type'] == "content") {
	$search = mysql_query("SELECT * FROM ".$pre."content WHERE name LIKE '%" . $searchentry . "%' ORDER BY `date` DESC LIMIT $from, $max_results");
	} else {
	$search = mysql_query("SELECT * FROM ".$pre."games WHERE name LIKE '%" . $searchentry . "%' ORDER BY `id` DESC LIMIT $from, $max_results");
	}
	for($i = 1; $row = mysql_fetch_assoc($search); $i++) {
	$icona = mysql_fetch_row(mysql_query("SELECT icon FROM ".$pre."systems WHERE id = '".$row[systems]."'"));
		if ($row[systems]) {
		$icon = "<img src='".$icona[0]."'>";
		} else {
		$icon = "";
		}
		$n1 = $searchentry;
		$n2 = hilite($searchentry);
		$name = str_replace($n1, $n2, $row[name]);

		similar_text($searchentry, $row[name], $p);
		$p = str_replace(".", "", $p);

		echo "<tr><td><b>".$i.".</b></td><td><a href='";

		if ($_POST['type'] == "games") {
	    echo $gamepart1.$row[id].fthrough($row[name], "");
		} else {
		echo $part1.$row[id].fthrough($row[name], $row[cat]);
		}

		if ($_POST['type'] == "games") {
		echo $gamepart2;
		} else {
		echo $part2;
		}
		
		echo "'>".$name."</a>";
		
		if ($_POST['type'] == "content") {
		echo "&nbsp;&nbsp;(<i>".$row[cat]."</i>)&nbsp;&nbsp;";
		}
		echo $icon."</td>";
		if ($_POST['type'] == "content") {
		echo "<td>".date($dformat, $row[date])."</td>";
		}
		
		echo "<td><b>Relevance</b>: ".substr($p,0,2)."%</td>";

		if ($_POST['type'] == "games") {
			echo "<td>".stripslashes($row[des])."</td>";
		}
		echo "</tr>";
	}

if ($_POST['type'] == "content") {
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ".$pre."content WHERE name LIKE '%" . $searchentry . "%'"),0);
} else {
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ".$pre."games WHERE name LIKE '%" . $searchentry . "%'"),0);
}

$total_pages = ceil($total_results / $max_results);

echo "</table>";

if ($total_pages > "1") {

echo "<br><center>Select a Page<br>";

// Build Previous Link
if($page > 1){
    $prev = ($page - 1);
    echo "<a href=\"index.php?load=search&view=results&page=$prev\"><<Previous</a>&nbsp;";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i&nbsp;";
        } else {
            echo "<a href=\"index.php?load=search&view=results&page=$i\">$i</a>&nbsp;&nbsp;";
    }
}

// Build Next Link
if($page < $total_pages){
    $next = ($page + 1);
    echo "<a href=\"index.php?load=search&view=results&page=$next\">Next>></a>&nbsp;";
}
echo "</center>";
}
}
}

if ($_GET['view'] == "forums") {
if ($forumskin == "") {
$ffetch1 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."fskins WHERE id = '1'"));
$ffetch2 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."fskins WHERE id = '4'"));
if (($ffetch1 > "0") or ($ffetch2 > "0")) {
if ($ffetch1 > "0") {
$forumskin = "1";
}
if ($ffetch2 > "0") {
$forumskin = "4";
}
} else {
$forumskin = "3";
}
}
$tempfetch = mysql_fetch_row(mysql_query("SELECT header,footer,header2,footer2,homeheader,homefooter,flist,clist,subforum,forumheader,forumfooter,topicheader,tlist,post,fbcolor1,fbgcolor1,fbgcolor2,fbgcolor3 FROM ".$pre."fskins WHERE id = '".$forumskin."'"));//subforum - header (for the forum part it gets the flist)

if ($_POST['search'] == "") {
	$skin1[] = "/{version}/";
	$skin1[] = "/{sitename}/";
	$skin1[] = "/{users}/"; // amount of users online
	$skin1[] = "/{online}/"; // the users that are online
	$skin1[] = "/{pms}/"; // amount of private messages
	$skin1[] = "/{new}/"; // amount of new private messages
	$skin1[] = "/{pm}/"; // display new private messages
	$skin1[] = "/{welcome}/"; // Displays "Welcome username" if person is logged in, other wise "Welcome Guest" and a link to login
	$skin1[] = "/{chooseskin}/";
	$skin1[] = "/{skinname}/"; // the name of the current skin being used
	$skin2[] = $version;
	$skin2[] = $sitename;
	$skin2[] = online();
	$skin2[] = usersonline();
	$skin2[] = totalpms();
	$skin2[] = newpms();
	$skin2[] = pms();
	$skin2[] = welcome();
	$skin2[] = fskin();
	$skin2[] = skinname();
eval (" ?>" . str_replace($skin1, $skin2, stripslashes($tempfetch[0])) . " <?php ");
echo "<center><form action='index.php?load=search&view=forums' method='post'><input type='text' name='search'>&nbsp;<input type='submit' value='Search'></form></center>";
}
if ($_POST['search']) {
if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
}

$from = (($page * $max_results) - $max_results);

$fid = $_GET['f'];

if ($_POST['type']) {
$ex = explode("|", $_POST['type']);
if ($ex[0] == "topic") {
$searca = mysql_query("SELECT * FROM ".$pre."posts WHERE message LIKE '%" . $_POST['search'] . "%' AND tid = '".$ex[1]."'");
$results = mysql_num_rows($searca);
} else {
$searca = mysql_query("SELECT * FROM ".$pre."posts WHERE subject LIKE '%" . $_POST['search'] . "%' AND fid = '".$ex[1]."' OR message LIKE '%" . $_POST['search'] . "%' AND fid = '".$ex[1]."'");
$results = mysql_num_rows($searca);
}
} else {
if ($_GET['f']) {
$searca = mysql_query("SELECT * FROM ".$pre."posts WHERE subject LIKE '%" . $_POST['search'] . "%'  AND fid = '".$fid."' OR message LIKE '%" . $_POST['search'] . "%' AND fid = '".$fid."'");
$results = mysql_num_rows($searca);
} else {
$searca = mysql_query("SELECT * FROM ".$pre."posts WHERE subject LIKE '%" . $_POST['search'] . "%' OR message LIKE '%" . $_POST['search'] . "%'");
$results = mysql_num_rows($searca);
}
}

if ($results == "1") {
if ($_POST['type']) {
$ex = explode("|", $_POST['type']);
if ($ex[0] == "topic") {
$fet = mysql_fetch_row(mysql_query("SELECT tid,type,id FROM ".$pre."posts WHERE message LIKE '%" . $_POST['search'] . "%' AND tid = '".$ex[1]."'"));
} else {
$fet = mysql_fetch_row(mysql_query("SELECT tid,type,id FROM ".$pre."posts WHERE subject LIKE '%" . $_POST['search'] . "%' AND fid = '".$ex[1]."' OR message LIKE '%" . $_POST['search'] . "%' AND fid = '".$ex[1]."'"));
}
} else {
if ($_GET['f']) {
$fet = mysql_fetch_row(mysql_query("SELECT tid,type,id FROM ".$pre."posts WHERE subject LIKE '%" . $_POST['search'] . "%'  AND fid = '".$fid."' OR message LIKE '%" . $_POST['search'] . "%' AND fid = '".$fid."'"));
} else {
$fet = mysql_fetch_row(mysql_query("SELECT tid,type,id FROM ".$pre."posts WHERE subject LIKE '%" . $_POST['search'] . "%' OR message LIKE '%" . $_POST['search'] . "%'"));
}
}
if ($fet[1] == "post") {
header("location: ".$f2part1.$fet[0].$f2part2."#".$fet[2]);
} else {
header("location: ".$f2part1.$fet[0].$f2part2);
}
} else {
	$skin1[] = "/{version}/";
	$skin1[] = "/{sitename}/";
	$skin1[] = "/{users}/"; // amount of users online
	$skin1[] = "/{online}/"; // the users that are online
	$skin1[] = "/{pms}/"; // amount of private messages
	$skin1[] = "/{new}/"; // amount of new private messages
	$skin1[] = "/{pm}/"; // display new private messages
	$skin1[] = "/{welcome}/"; // Displays "Welcome username" if person is logged in, other wise "Welcome Guest" and a link to login
	$skin1[] = "/{chooseskin}/";
	$skin1[] = "/{skinname}/"; // the name of the current skin being used
	$skin2[] = $version;
	$skin2[] = $sitename;
	$skin2[] = online();
	$skin2[] = usersonline();
	$skin2[] = totalpms();
	$skin2[] = newpms();
	$skin2[] = pms();
	$skin2[] = welcome();
	$skin2[] = fskin();
	$skin2[] = skinname();
eval (" ?>" . str_replace($skin1, $skin2, stripslashes($tempfetch[0])) . " <?php ");


echo "<title>".$sitename." :: ".$results." Search Results For - ".$_POST['search']."</title><br><table cellpadding='3' cellspacing='0' border='0' width='98%' style='border:1px solid ".$tempfetch[14]."' align='center'><tr bgcolor='".$tempfetch[16]."'><td><b><a href='".$forumsurl."'>Home</a> > <a href='index.php?load=search&view=forums'>Search</a> > ".$_POST['search']."</b> - ".$results." Results</td><td align='right'>".$results." Results For :: ".$_POST['search']."</td></tr></table><br>";

echo "<table cellpadding='3' cellspacing='0' border='0' width='98%' style='border:1px solid ".$tempfetch[14]."' align='center'><tr bgcolor='".$tempfetch[15]."'><td align='center'><b>#</b></td><td align='center'><b>Topic Name</b></td>";
if ($fid) {
echo "<td align='center'><b>Forum</b></td>";
}
echo "<td align='center'><b>Poster</b></td><td align='center'><b>Replies</b></td><td align='center'><b>Last Post</b></td><td align='center'><b>Relevance</b></td></tr>";


    if ($_POST['type']) {
	$ex = explode("|", $_POST['type']);
	if ($ex[0] == "topic") {
	$search = mysql_query("SELECT * FROM ".$pre."posts WHERE message LIKE '%" . $_POST['search'] . "%' AND tid = '".$ex[1]."' ORDER BY `date` DESC LIMIT $from, $max_results");
	} else {
	$search = mysql_query("SELECT * FROM ".$pre."posts WHERE subject LIKE '%" . $_POST['search'] . "%' AND fid = '".$ex[1]."' OR message LIKE '%" . $_POST['search'] . "%' AND fid = '".$ex[1]."' ORDER BY `date` DESC LIMIT $from, $max_results");
	}
	} else {
    if ($_GET['f']) {
	$search = mysql_query("SELECT * FROM ".$pre."posts WHERE subject LIKE '%" . $_POST['search'] . "%'  AND fid = '".$fid."' OR message LIKE '%" . $_POST['search'] . "%' AND fid = '".$fid."' ORDER BY `date` DESC LIMIT $from, $max_results");
	} else {
	$search = mysql_query("SELECT * FROM ".$pre."posts WHERE subject LIKE '%" . $_POST['search'] . "%' OR message LIKE '%" . $_POST['search'] . "%' ORDER BY `id` DESC LIMIT $from, $max_results");
	}
	}
	for($i = 1; $row = mysql_fetch_assoc($search); $i++) {
		$n1 = $_POST['search'];
		$n2 = hilite($_POST['search']);
		$name = str_replace($n1, $n2, $row[subject]);

		similar_text($_POST['search'], $row[subject], $p4);
		similar_text($_POST['search'], $row[message], $p2);

		$p3 = $p4 * $p2/2;

		$p = str_replace(".", "", $p3);

		$fname = mysql_fetch_row(mysql_query("SELECT name FROM ".$pre."forums WHERE id = '".$fid."'"));
		$tid = $row[tid];

		echo "<tr bgcolor='".$tempfetch[17]."'><td align='center' style='border:1px solid ".$tempfetch[14]."'><b>".$i.".</b></td><td align='center' style='border:1px solid ".$tempfetch[14]."'><a href='";

		if ($row[type] == "post") {
		echo $f2part1.$row[tid].$f2part2."#".$row[id];
		} else {
		echo $f2part1.$row[id].$f2part2;
		}

		echo "'>".$name."</a></td>";
		if ($fid) {
		echo "<td align='center' style='border:1px solid ".$tempfetch[14]."'><a href='".$f1part1.$fid.$f1part2."'>".$fname[0]."</a></td>";
		}
		echo "<td align='center' style='border:1px solid ".$tempfetch[14]."'>";

	if ($row[uid]) {
	$user = mysql_fetch_row(mysql_query("SELECT username FROM ".$pre."profile WHERE id = '".$row[uid]."' LIMIT 1"));
	$usera = mysql_fetch_row(mysql_query("SELECT rank FROM ".$pre."users WHERE username = '".$user[0]."'"));
	$s = mysql_fetch_row(mysql_query("SELECT color FROM ".$pre."ranks WHERE name = '".$usera[0]."' ORDER BY `points` DESC"));

	$rank = "<a href='elite.php?user=".$row[uid]."'><font color='".$s[0]."'>".$user[0]."</font></a>";

if ($rank == "") {
echo "<a href='elite.php?user=".$row[uid]."'>".$user[0]."</a>";
} else {
print $rank;
}
	} else {
	echo "Visitor";
	}

	$replies = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."posts WHERE type = 'post' AND tid = '".$tid."'"));

	$lcount = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."posts WHERE type = 'post' AND tid = '".$tid."'"));

    if ($lcount > "0") {
	$user3 = mysql_fetch_row(mysql_query("SELECT uid FROM ".$pre."posts WHERE type = 'post' AND tid = '".$tid."' ORDER BY `date` DESC LIMIT 1"));
	$user4 = mysql_fetch_row(mysql_query("SELECT username FROM ".$pre."profile WHERE id = '".$user3[0]."'"));
	$user1 = $user3[0];
	$user2 = $user4[0];
	$query3w = mysql_fetch_row(mysql_query("SELECT date FROM ".$pre."posts WHERE type = 'post' AND tid = '".$tid."' ORDER BY `date` DESC LIMIT 1"));
	$date9 = $query3w[0];
	} else {
	$user1 = $row[uid];
	$user3 = mysql_fetch_row(mysql_query("SELECT username FROM ".$pre."profile WHERE id = '".$row[uid]."'"));
	$user2 = $user3[0];
    $query3w = mysql_fetch_row(mysql_query("SELECT date FROM ".$pre."posts WHERE id = '".$tid."' ORDER BY `date` DESC LIMIT 1"));
	$date9 = $query3w[0];
	}

	$last = date($dformat, $date9)."<br>";

	if ($user1) {
	$ranks2 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."posts WHERE uid = '".$user1."'"));
	$user = mysql_fetch_row(mysql_query("SELECT rank FROM ".$pre."users WHERE username = '".$user2."'"));
	$s = mysql_fetch_row(mysql_query("SELECT color FROM ".$pre."ranks WHERE name = '".$user[0]."' ORDER BY `points` DESC"));

	$rank = "<a href='elite.php?user=".$user1."'><font color='".$s[0]."'>".$user2."</font></a>";

if ($rank == "") {
$last .= "<a href='elite.php?user=".$user1."'>".$user2."</a>";
} else {
$last .= $rank;
}
		} else {
		$last .= "Visitor";
		}
	echo "</td><td align='center' style='border:1px solid ".$tempfetch[14]."'>".$replies."</td><td align='center' style='border:1px solid ".$tempfetch[14]."'>".$last."</td><td align='center' style='border:1px solid ".$tempfetch[14]."'>".substr($p,0,2)."%</td></tr>";
	}

if ($fid) {
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ".$pre."posts WHERE subject LIKE '%" . $_POST['search'] . "%' OR message LIKE '%" . $_POST['search'] . "%' AND fid = '".$fid."'"),0);
} else {
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ".$pre."posts WHERE subject LIKE '%" . $_POST['search'] . "%' OR message LIKE '%" . $_POST['search'] . "%'"),0);
}

$total_pages = ceil($total_results / $max_results);

echo "</table>";

if ($total_pages > "1") {

echo "<br><center>Select a Page<br>";

// Build Previous Link
if($page > 1){
    $prev = ($page - 1);
    echo "<a href=\"index.php?load=search&view=results&page=$prev\"><<Previous</a>&nbsp;";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i&nbsp;";
        } else {
            echo "<a href=\"index.php?load=search&view=results&page=$i\">$i</a>&nbsp;&nbsp;";
    }
}

// Build Next Link
if($page < $total_pages){
    $next = ($page + 1);
    echo "<a href=\"index.php?load=search&view=results&page=$next\">Next>></a>&nbsp;";
}
echo "</center>";
}
}
}
}

}
}
}
}
if ($_GET['view'] == "forums") {
	$skin1[] = "/{version}/";
	$skin1[] = "/{sitename}/";
	$skin1[] = "/{users}/"; // amount of users online
	$skin1[] = "/{online}/"; // the users that are online
	$skin1[] = "/{pms}/"; // amount of private messages
	$skin1[] = "/{new}/"; // amount of new private messages
	$skin1[] = "/{pm}/"; // display new private messages
	$skin1[] = "/{welcome}/"; // Displays "Welcome username" if person is logged in, other wise "Welcome Guest" and a link to login
	$skin1[] = "/{chooseskin}/";
	$skin1[] = "/{skinname}/"; // the name of the current skin being used
	$skin2[] = $version;
	$skin2[] = $sitename;
	$skin2[] = online();
	$skin2[] = usersonline();
	$skin2[] = totalpms();
	$skin2[] = newpms();
	$skin2[] = pms();
	$skin2[] = welcome();
	$skin2[] = fskin();
	$skin2[] = skinname();
eval (" ?>" . str_replace($skin1, $skin2, stripslashes($tempfetch[1])) . " <?php ");
} else {
footera();
}
?>