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

$dbres	=	mysql_query("SELECT `gevangenistijd`,UNIX_TIMESTAMP(`gevangenis`) AS `gevangenis`,0 FROM `gebruiker` WHERE `login`='{$data->login}'");
$member	=	mysql_fetch_object($dbres);

	if($member->gevangenis + $member->gevangenistijd > time()){
	header("Location: netwerken-gevangenis.php"); 
	exit;
	}

?>

<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">
<br>
<br>
<br>
<table align="center" width="600">
	<tr>
		<td class="subTitle" width="100%" colspan="4">
		<b>Detective bureau</b>
		</td>
	</tr>
	<tr>
		<td class="subTitle" width="25%">
		<b>Login:</b>
		</td>
		<td class="subTitle" width="25%">
		<b>Land:</b>
		</td>
		<td class="subTitle" width="25%">
		<b>Tijd:</b>
		</td>
		<td class="subTitle" width="25%">
		<b>Status:</b>
		</td>
	</tr>

<?php

$dbres	=	mysql_query("SELECT `zoeker`,`land`,`uren`,`status`,UNIX_TIMESTAMP(`tijd`) AS `tijd`,0 FROM `detective` WHERE `owner`='{$data->login}'");

	while($detective = mysql_fetch_object($dbres)){
	$tijda	=	($detective->uren*60)*60;
	$tijdb	=	$detective->tijd+$tijda-time()-3600;
	$tijd	=	date("H:i:s",$tijdb);

		if($detective->status == 0){
		$status	=	"Nog bezig";
		} else {
		$status	=	"Gevonden";
		}

?>

	<tr>
		<td class="mainTxt" width="25%" align="center">
		<?php echo $detective->zoeker; ?>
		</td>
		<td class="mainTxt" width="25%" align="center">
		<?php echo $detective->land; ?>
		</td>
		<td class="mainTxt" width="25%" align="center">
		<?php echo $tijd; ?>
		</td>
		<td class="mainTxt" width="25%" align="center">
		<?php echo $status; ?>
		</td>
	</tr>

<?php

	}

?>

</table>
<br>
<table align="center" width="600">
	<tr>
		<td class="subTitle">
		<b>Inhuren</b>	
		</td>
	</tr>
	<tr>
		<td class="mainTxt" align="center">

<?php

	if(isset($_POST['submit'])){
	$getal1			=	md5($_SESSION['getal']);
	$getal2			=	$_GET['code'];
		if($getal1 != "" && $getal1 == $getal2){
		$_POST['naam']	=	$_POST['naam'];
		$_POST['uren']	=	$_POST['uren'];
		$_POST['land']	=	$_POST['land'];
		$geld		=	$_POST['uren']*20000;
		$dbres		=	mysql_query("SELECT `land`,`login` FROM `gebruiker` WHERE `login`='{$_POST['naam']}' AND `level`!='-2' AND `level`!='-1' AND `level`!='0'");
		$controlle	=	mysql_num_rows($dbres);
		$man		=	mysql_fetch_object($dbres);

			if(strlen($_POST['naam']) < 0){
			echo "Vul een geldige naam in.<meta http-equiv=\"refresh\" content=\"3\">";
			} else if($geld > $data->cash){
			echo "je hebt niet genoeg geld.<meta http-equiv=\"refresh\" content=\"3\">";
			} else if($man->login == $data->login){
			echo "Je weet toch al waar jezelf zit?<meta http-equiv=\"refresh\" content=\"3\">";
			} else if($controlle == 0){
			echo "Deze gebruiker bestaat niet is verbannen of is dood.<meta http-equiv=\"refresh\" content=\"3\">";
			} else {

				if($man->land == $_POST['land']){
				$vind	=	rand(600,$_POST['uren']*60*60);
				} else {
				$vind	=	0;
				}
	
			mysql_query("UPDATE `gebruiker` SET `cash`=`cash`-'$geld' WHERE `login`='{$data->login}'");
			mysql_query("INSERT INTO `detective`(`owner`,`zoeker`,`tijd`,`land`,`uren`,`minuten`) VALUES('{$data->login}','{$_POST['naam']}',NOW(),'{$_POST['land']}','{$_POST['uren']}','$vind')");
			mysql_query("INSERT INTO `berichten`(`tijd`,`ip`,`van`,`naar`,`titel`,`bericht`) VALUES(NOW(),'{$_SERVER['REMOTE_ADDR']}','Ultimatecrime','{$man->login}','Aanslag','Iemand heeft een detective ingehuurd in {$_POST['land']} op jou om je waarschijnlijk te doden. Je bent gewaarschuwt.')");
			echo "Je hebt de detective ingehuurd om {$_POST['naam']} te gaan zoeken in $land.<meta http-equiv=\"refresh\" content=\"3\">";
			}
		}
	} else {

	$getal			=	rand(1,10);
	$_SESSION['getal']	=	$getal;
	$getalb			=	md5($getal);

?>

		<form method="post" action="netwerken-detective.php?code=<?php echo $getalb; ?>">
		<table width="62%" border="0" align="center" cellpadding="0" cellspacing="2">
			<tr>
				<td width="54%">Naam:</td>
				<td width="46%"><input type="text" name="naam" maxlength="16" style="width: 250;" value="" /></td>
			</tr>
			<tr>
				<td>Uren:</td>
				<td>
				<select name="uren" style="width: 250" class="form_select">
				<option value="1">1 Uur</option>
				<option value="2">2 Uren</option>
				<option value="3">3 Uren</option>
				<option value="4">4 Uren</option>
				<option value="5">5 Uren</option>
				</select>
				</td>
			</tr>
				<td>Land:</td>
				<td>		
				<select name="land" style="width:250" class="form_select">
				<option value="Colombia">Colombia</option>
				<option value="Cuba">Cuba</option>
				<option value="Duitsland">Duitsland</option>
				<option value="Frankrijk">Frankrijk</option>
				<option value="Irak">Irak</option>
				<option value="Italië">Italië</option>
				<option value="Japan">Japan</option>
				<option value="Mexico">Mexico</option>
				<option value="Nederland">Nederland</option>
				<option value="Turkije">Turkije</option>
				<option value="USA">USA</option>
				<option value="Zuid-Afrika">Zuid-Afrika</option>
				</select>
				</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td><input type=submit name=submit value=Zoek style="width: 250;"></td>
			</tr>
		</table>
		</form>

<?php

	}

?>

		</td>
	</tr>
</table>
</body>
</html>