<?php
ob_start();
include("config.php");
	if(! check_login()) { 
	exit;
	}

	if($data->level != 3 && $_GET['actie'] != "t"){
	exit;
	}

$dbres	=	mysql_query("SELECT * FROM `spel_statestieken` WHERE `id`='1'");
$link	=	mysql_fetch_object($dbres);

?>

<html>
<head>
<title>ultimatecrime</title>
<link rel="stylesheet" type="text/css" href="style_general.css">
</head>
<body background="layout/images/layout_12.gif" bgproperties="fixed">


<?php

	if($_GET['actie'] == "t"){

?>

<table align="center" width="600">
	<tr>
		<td class="subTitle" colspan="3">
		<b>Admin search</b>
		</td>
	</tr>

<?php

	$dbres = mysql_query("SELECT * FROM `gebruiker` WHERE `login`='{$_GET['login']}'");
		if($data = mysql_fetch_object($dbres)){
		setcookie("login", $data->login, time()+1*60*60, "/");
		$_SESSION['login']     = $data->login;
		echo "<tr><td width=\"600\" class=\"mainTxt\" align=\"center\">Je bent weer terug ingelogd op {$data->login}.<script language=\"javascript\">setTimeout('window.close()',1500)</script></td></tr>";
		}
	} else if($_GET['actie'] == "i"){

?>

<table align="center" width="600">
	<tr>
		<td class="subTitle" colspan="3">
		<b>Admin search</b>
		</td>
	</tr>

<?php

	$dbres = mysql_query("SELECT * FROM `gebruiker` WHERE `login`='{$_GET['x']}'");
		if($data = mysql_fetch_object($dbres)) {
		echo "<tr><td width=\"600\" class=\"mainTxt\" align=\"center\">Je bent ingelogd op {$_GET['x']}.<br><br>Klik <a href=\"admin-search.php?actie=t&login={$_SESSION['login']}\">hier</a> om weer terug te loggen op {$_SESSION['login']}.</td></tr>";
		setcookie("login", $data->login, time()+1*60*60, "/");
		$_SESSION['login']     = $data->login;
		}
	} else if(isset($_GET['y'])){

?>
<br>
<br>
<br>
<table align="center" width="600">
	<tr>
		<td class="subTitle" colspan="3">
		<b>Admin search</b>
		</td>
	</tr>
	<tr>
		<td align="center" class="subTitle" width="100">
		<b>Actie:</b>
		</td>
		<td align="center" class="subTitle" width="250">
		<b>Login:</b>
		</td>
		<td align="center" class="subTitle" width="250">
		<b>IP:</b>
		</td>
	</tr>

<?php

	$begin	=	($_GET['b'] >= 0) ? $_GET['b']*30 : 0;
	$y	=	preg_replace('/\*/','%',$_GET['y']);
	$dbres	=	mysql_query("SELECT `login`,`ip` FROM `gebruiker` WHERE `ip` LIKE '$y' ORDER BY `login` LIMIT $begin,30");
		while($gebruiker = mysql_fetch_object($dbres)){

?>

	<tr>
		<td align="center" class="mainTxt" width="100">
		<a href="admin-paneel.php?login=<?php echo $gebruiker->login; ?>">[D]</a> 
		<a href="javascript://" onClick="window.open('admin-search.php?actie=i&x=<?php echo $gebruiker->login; ?>','','width=620,height=130,toolbar=no,status=no')">[I]</a>
		</td>
		<td align="center" class="mainTxt" width="250">
		<a href="speler-profiel.php?x=<?php echo $gebruiker->login; ?>"><?php echo $gebruiker->login; ?></a>
		</td>
		<td align="center" class="mainTxt" width="250">
		<a href="admin-search.php?y=<?php echo $gebruiker->ip; ?>"><?php echo $gebruiker->ip; ?></a>
		</td>
	</tr>

<?php

		}

	$dbres				= mysql_query("SELECT `id` FROM `gebruiker` WHERE `ip` LIKE '$y' ORDER BY `login`");
	print "</table><table width=\"600\" align=\"center\"><tr><td class=\"mainTxt\" align=\"center\">";
		if(mysql_num_rows($dbres) <= 30){
		echo  "< 1 >";
		} else {
		$y				= preg_replace('/%/','*',$y);
			if($begin/30 == 0){
			echo "<<";
			} else {
			echo "<a href=\"admin-search.php?y=$y&b=". ($begin/30-1) ."\"><<</a>";
			}

			for($i=0; $i<mysql_num_rows($dbres)/30; $i++) {
			echo " <a href=\"admin-search.php?y=$y&b=$i\">". ($i+1) ."</a> ";
			}

			if($begin+30 >= mysql_num_rows($dbres)){
			echo ">>";
			} else { 
			echo "<a href=\"admin-search.php?y=$y&b=". ($begin/30+1) ."\">>></a>";
			}
		}
	echo "</td></tr>";

	} else if(isset($_GET['x'])){

?>
<br>
<br>
<br>
<table align="center" width="600">
	<tr>
		<td class="subTitle" colspan="3">
		<b>Admin search</b>
		</td>
	</tr>
	<tr>
		<td align="center" class="subTitle" width="100">
		<b>Actie:</b>
		</td>
		<td align="center" class="subTitle" width="250">
		<b>Login:</b>
		</td>
		<td align="center" class="subTitle" width="250">
		<b>IP:</b>
		</td>
	</tr>

<?php

	$begin	=	($_GET['b'] >= 0) ? $_GET['b']*30 : 0;
	$x	=	preg_replace('/\*/','%',$_GET['x']);
	$dbres	=	mysql_query("SELECT `login`,`ip` FROM `gebruiker` WHERE `login` LIKE '$x' ORDER BY `login` LIMIT $begin,30");
		while($gebruiker = mysql_fetch_object($dbres)){

?>

	<tr>
		<td align="center" class="mainTxt" width="100">
		<a href="admin-paneel.php?login=<?php echo $gebruiker->login; ?>">[D]</a> 
		<a href="javascript://" onClick="window.open('admin-search.php?actie=i&x=<?php echo $gebruiker->login; ?>','','width=620,height=130,toolbar=no,status=no')">[I]</a>
		</td>
		<td align="center" class="mainTxt" width="250">
		<a href="speler-profiel.php?x=<?php echo $gebruiker->login; ?>"><?php echo $gebruiker->login; ?></a>
		</td>
		<td align="center" class="mainTxt" width="250">
		<a href="admin-search.php?y=<?php echo $gebruiker->ip; ?>"><?php echo $gebruiker->ip; ?></a>
		</td>
	</tr>

<?php

		}

	$dbres				= mysql_query("SELECT `id` FROM `gebruiker` WHERE `login` LIKE '$x' ORDER BY `login`");
	echo "</table><table width=\"600\" align=\"center\"><tr><td class=\"mainTxt\" align=\"center\">";
		if(mysql_num_rows($dbres) <= 30){
		echo "< 1 >";
		} else {
		$x				= preg_replace('/%/','*',$x);
			if($begin/30 == 0){
			echo "<<";
			} else {
			echo "<a href=\"admin-search.php?x=$x&b=". ($begin/30-1) ."\"><<</a>";
			}

			for($i=0; $i<mysql_num_rows($dbres)/30; $i++) {
			echo " <a href=\"admin-search.php?x=$x&b=$i\">". ($i+1) ."</a> ";
			}

			if($begin+30 >= mysql_num_rows($dbres)){
			echo ">>";
			} else { 
			echo "<a href=\"admin-search.php?x=$x&b=". ($begin/30+1) ."\">>></a>";
			}
		}
	echo "</td></tr>";
	} else {

?>
<br>
<br>
<br>
<table align="center" width="600">
	<tr>
		<td class="subTitle" colspan="3">
		<b>Admin search</b>
		</td>
	</tr>
	<tr>
		<td class="mainTxt" align="center">
		<form method="get">
		<table>
		Gebruik <b>*</b> als wildcard<br>
		<input type="text" name="x"> <input type="submit" value="Zoek!" style="width: 75px;">
		</form>
		</td>
	</tr>

<?php

	}

?>

</table>
</body>
</html>