<?PHP
include "config.php";
if ($ingelogd == "0"){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=login.php\">";
exit;
}
include('header.php');
?>

<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>
<form method="post">
<table align="center" width="600">
	<tr>
		<td class="subTitle" colspan="2">
		<b>Nummerspel <?php echo $data->land; ?></b>
		</td>
	</tr>

<?php

$dbres		=	mysql_query("SELECT * FROM `casino` WHERE `spel`='1' AND `land`='{$data->land}'"); 
$casino		=	mysql_fetch_object($dbres);    

	if($casino->verkoop == "1"){ 
	echo "<tr><td class=\"mainTxt\" colspan=\"2\" align=\"center\">Deze casino is momenteel te koop gezet op marktplaats.</td></tr>"; 
	} else if($casino->owner == ""){ 
	echo "<tr><td class=\"mainTxt\" colspan=\"2\" align=\"center\">Dit casino is door niemand in bezit.</td></tr>";
	} else if($casino->owner == $data->login){ 
	echo "<tr><td class=\"mainTxt\" colspan=\"2\" align=\"center\">Je kunt niet op je eigen casino spelen.</td></tr>";
	} else {

		if(isset($_POST['submit'])){ 
		$number	=	$_POST['nummer']; 
		$inzet	=	$_POST['inzet']; 
			if($inzet < 1 || $inzet == ""){
			echo "<tr><td class=\"mainTxt\" colspan=\"2\" align=\"center\">Vul een bedrag boven de null euro in.</td></tr>";
			} else if(! is_numeric($inzet)){
			echo "<tr><td class=\"mainTxt\" colspan=\"2\" align=\"center\">Het bedrag bestaat niet helemaal uit cijvers.</td></tr>";
			} else if($inzet > $data->cash){
			echo "<tr><td class=\"mainTxt\" colspan=\"2\" align=\"center\">Je hebt niet genoeg geld.</td></tr>";
			} else if($inzet > $casino->inzet){
			echo "<tr><td class=\"mainTxt\" colspan=\"2\" align=\"center\">Het maximale bedrag wat je mag inzetten is " . geld($casino->inzet) . ".</td></tr>";
			} else {
			$random		=	mt_rand(1,10);
			$geld		=	$inzet*9;
				if($number == $random){
				mysql_query("UPDATE `gebruiker` SET `cash`=`cash`+'$geld' WHERE `login`='{$data->login}'"); 
				mysql_query("UPDATE `gebruiker` SET `bank`=`bank`-'$geld' WHERE `login`='{$casino->owner}'"); 
				mysql_query("UPDATE `opbrensten` SET `geld`=`geld`-'$geld' WHERE `land`='{$data->land}' AND `soort`='1'");
				$dbres		=	mysql_query("SELECT * FROM `gebruiker` WHERE `login`='{$casino->owner}'"); 
				$owner		=	mysql_fetch_object($dbres);
				echo "<tr><td class=\"mainTxt\" colspan=\"2\" align=\"center\">Gefeliciteerd! Je koos $number en het was $random, Je wint €" . geld($geld) . ".</td></tr>";
					if($owner->bank < 0){ 
					mysql_query("UPDATE `gebruiker` SET `bank`='0',`casino_aantal`=`casino_aantal`-'1' WHERE `login`='{$casino->owner}'"); 
					mysql_query("UPDATE `casino` SET `owner`='' WHERE `land`='{$data->land}' AND `spel`='1'");
					mysql_query("INSERT INTO `berichten`(`tijd`,`ip`,`van`,`naar`,`titel`,`bericht`) VALUES(NOW(),'{$_SERVER['REMOTE_ADDR']}','Ultimatecrime','{$casino->owner}','Casino','{$data->login} heeft je getallenspel in {$data->land} is blut gespeeld.')");
					}
				} else {
				mysql_query("UPDATE `gebruiker` SET `cash`=`cash`-'$inzet' WHERE `login`='{$data->login}'"); 
				mysql_query("UPDATE `gebruiker` SET `bank`=`bank`+'$inzet' WHERE `login`='{$casino->owner}'"); 
				mysql_query("UPDATE `opbrensten` SET `geld`=`geld`+'$inzet' WHERE `land`='{$data->land}' AND `soort`='1'");
				echo "<tr><td class=\"mainTxt\" colspan=\"2\" align=\"center\">Je koos $number en het was $random.</td></tr>";
				}
			}
		}

?>

	<tr>
		<td class="mainTxt" colspan="2">Kies een nummer tussen 1-10. Heb je het juiste nummer gekozen? Dan win je je inzet x9!</td>
	</tr>
	<tr>
		<td class="mainTxt" width="300">Eigenaar business</td>
		<td class="mainTxt" width="300"><a href="speler-profiel.php?x=<?php echo $casino->owner; ?>"><?php echo $casino->owner; ?></a></td>
	</tr>
	<tr>
		<td class="mainTxt" width="300">Maximale inzet</td>
		<td class="mainTxt" width="300"><font color="red"><b>&euro;<?php echo geld($casino->inzet); ?></b></font></td>
	</tr>
	<tr>
		<td class="mainTxt" width="300">Ik kies nummer</td>
		<td class="mainTxt" width="300"><input size=9 type="text" name="nummer" maxlength=2></td>
	</tr>
	<tr>
		<td class="mainTxt" width="300">Inzet in &euro;</td>
		<td class="mainTxt" width="300"><input size=9 type="text" name="inzet" maxlength=9 maxlenght="8"></td>
	</tr>
	<tr>
		<td class="mainTxt" width="300">Bevestig</td>
		<td class="mainTxt" width="300"><input type="submit" name="submit" value="Gok"  style="width: 200;"></a></td>
	</tr>
</table>
</form>

<?php

	}

?>

</body>
</html>

