<?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" action="kopen.php?x=submit">
<table align="center" width="600">
	<tr>
		<td class="subTitle" colspan="4">
		<b>Ultimatecrime - Kopen</b>
		</td>
	</tr>

<?php

	if(isset($_POST['submit'])){
		if(preg_match("/a_/",$_POST['type']) != 0){
			if($data->cash < 20000000){
			echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\" colspan=\"4\">Je hebt te weinig geld.<meta http-equiv=\"refresh\" content=\"3\"></td></tr>";
			} else if($data->kogelfabriek_aantal >= 1 && $data->level == 1){
			echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\" colspan=\"4\">Je hebt al een Ammo depot, en je mag er maximaal 1 hebben.<meta http-equiv=\"refresh\" content=\"3\"></td></tr>";
			} else if($data->kogelfabriek_aantal >= 2 && $data->level == 2){
			echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\" colspan=\"4\">Je hebt al een Ammo depot, en je mag er maximaal 2 hebben.<meta http-equiv=\"refresh\" content=\"3\"></td></tr>";
			} else {
			mysql_query("UPDATE `clipsfabriek` SET `owner`='{$data->login}' WHERE `land`='{$data->land}'");
			mysql_query("UPDATE `gebruiker` SET `cash`=`cash`-'20000000',`kogelfabriek_aantal`=`kogelfabriek_aantal`+'1' WHERE `login`='{$data->login}'");
			echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\" colspan=\"4\">Je hebt een Ammo depot gekocht.<meta http-equiv=\"refresh\" content=\"3\"></td></tr>";
			}
		} else if(preg_match("/b_/",$_POST['type']) != 0){
			if($data->cash < 20000000){
			echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\" colspan=\"4\">Je hebt te weinig geld.<meta http-equiv=\"refresh\" content=\"3\"></td></tr>";
			} else if($data->ziekenhuis_aantal >= 1 && $data->level == 1){
			echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\" colspan=\"4\">Je hebt al een Ziekenhuis, en je mag er maximaal 1 hebben.<meta http-equiv=\"refresh\" content=\"3\"></td></tr>";
			} else if($data->ziekenhuis_aantal >= 2 && $data->level == 2){
			echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\" colspan=\"4\">Je hebt al een Ziekenhuis, en je mag er maximaal 2 hebben.<meta http-equiv=\"refresh\" content=\"3\"></td></tr>";
			} else {
			mysql_query("UPDATE `ziekenhuis` SET `owner`='{$data->login}' WHERE `land`='{$data->land}'");
			mysql_query("UPDATE `gebruiker` SET `cash`=`cash`-'20000000',`ziekenhuis_aantal`=`ziekenhuis_aantal`+'1' WHERE `login`='{$data->login}'");
			echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\" colspan=\"4\">Je hebt een ziekenhuis gekocht.<meta http-equiv=\"refresh\" content=\"3\"></td></tr>";
			}
		} else if(preg_match("/c_/",$_POST['type']) != 0){
			if($data->cash < 5000000){
			echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\" colspan=\"4\">Je hebt te weinig geld.<meta http-equiv=\"refresh\" content=\"3\"></td></tr>";
			} else if($data->casino_aantal >= 1 && $data->level == 1){
			echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\" colspan=\"4\">Je hebt al een casino, en je mag er maximaal 1 hebben.<meta http-equiv=\"refresh\" content=\"3\"></td></tr>";
			} else if($data->casino_aantal >= 2 && $data->level == 2){
			echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\" colspan=\"4\">Je hebt al een casino, en je mag er maximaal 2 hebben.<meta http-equiv=\"refresh\" content=\"3\"></td></tr>";
			} else {
			mysql_query("UPDATE `casino` SET `owner`='{$data->login}' WHERE `land`='{$data->land}' AND `spel`='1'");
			mysql_query("UPDATE `[users]` SET `cash`=`cash`-'5000000',`casino_aantal`=`casino_aantal`+'1' WHERE `login`='{$data->login}'");
			echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\" colspan=\"4\">Je hebt een nummerspel gekocht.<meta http-equiv=\"refresh\" content=\"3\"></td></tr>";
			}
		} else if(preg_match("/d_/",$_POST['type']) != 0){
			if($data->cash < 10000000){
			echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\" colspan=\"4\">Je hebt te weinig geld.<meta http-equiv=\"refresh\" content=\"3\"></td></tr>";
			} else if($data->casino_aantal >= 1 && $data->level == 1){
			echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\" colspan=\"4\">Je hebt al een casino, en je mag er maximaal 1 hebben.<meta http-equiv=\"refresh\" content=\"3\"></td></tr>";
			} else if($data->casino_aantal >= 2 && $data->level == 2){
			echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\" colspan=\"4\">Je hebt al een casino, en je mag er maximaal 2 hebben.<meta http-equiv=\"refresh\" content=\"3\"></td></tr>";
			} else {
			mysql_query("UPDATE `casino` SET `owner`='{$data->login}' WHERE `land`='{$data->land}' AND `spel`='2'");
			mysql_query("UPDATE `[users]` SET `cash`=`cash`-'10000000',`casino_aantal`='1' WHERE `login`='{$data->login}'");
			echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\" colspan=\"4\">Je hebt een gokkast gekocht.<meta http-equiv=\"refresh\" content=\"3\"></td></tr>";
			}
		} else if(preg_match("/e_/",$_POST['type']) != 0){
			if($data->cash < 10000000){
			echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\" colspan=\"4\">Je hebt te weinig geld.<meta http-equiv=\"refresh\" content=\"3\"></td></tr>";
			} else if($data->casino_aantal == 1 && $data->level == 1){
			echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\" colspan=\"4\">Je hebt al een casino, en je mag er maximaal 1 hebben.<meta http-equiv=\"refresh\" content=\"3\"></td></tr>";
			} else if($data->casino_aantal == 2 && $data->level == 2){
			echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\" colspan=\"4\">Je hebt al een casino, en je mag er maximaal 2 hebben.<meta http-equiv=\"refresh\" content=\"3\"></td></tr>";
			} else {
			mysql_query("UPDATE `casino` SET `owner`='{$data->login}' WHERE `land`='{$data->land}' AND `spel`='3'");
			mysql_query("UPDATE `[users]` SET `cash`=`cash`-'10000000',`casino_aantal`='1' WHERE `login`='{$data->login}'");
			echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\" colspan=\"4\">Je hebt een roulette gekocht.<meta http-equiv=\"refresh\" content=\"3\"></td></tr>";
			}
		}
	} else {
	$dbres	=	mysql_query("SELECT * FROM `clipsfabriek` WHERE `owner`='' AND `land`='{$data->land}'");
	$num1	=	mysql_num_rows($dbres);
	$dbres	=	mysql_query("SELECT * FROM `ziekenhuis` WHERE `owner`='' AND `land`='{$data->land}'");
	$num6	=	mysql_num_rows($dbres);
	$dbres	=	mysql_query("SELECT * FROM `casino` WHERE `owner`='' AND `spel`='1' AND `land`='{$data->land}'");
	$num2	=	mysql_num_rows($dbres);
	$dbres	=	mysql_query("SELECT * FROM `casino` WHERE `owner`='' AND `spel`='2' AND `land`='{$data->land}'");
	$num3	=	mysql_num_rows($dbres);
	$dbres	=	mysql_query("SELECT * FROM `casino` WHERE `owner`='' AND `spel`='3' AND `land`='{$data->land}'");
	$num4	=	mysql_num_rows($dbres);
	$totaal	=	$num1+$num2+$num3+$num4+$num6;
		if($totaal != 0){
		echo "<tr align=\"center\"><td width=\"10%\" class=\"subTitle\">#</td><td width=\"30%\" class=\"subTitle\"><b>Soort:</b></td><td width=\"30%\" class=\"subTitle\"><b>Land:</b></td><td width=\"30%\" class=\"subTitle\"><b>prijs:</b></td></tr>";

		$dbres	=	mysql_query("SELECT * FROM `clipsfabriek` WHERE `owner`='' AND `land`='{$data->land}'");
			while($deal = mysql_fetch_object($dbres)){
			$id	=	"a_{$deal->land}";
			$land	=	$deal->land;
			echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\"><input type=\"radio\" name=\"type\" value=\"{$id}\" checked></td><td width=\"30%\" class=\"mainTxts\">Ammo depot</td><td width=\"30%\" class=\"mainTxts\">{$land}</td><td width=\"30%\" class=\"mainTxts\">€20.000.000,-</td></tr>";
			}
		$dbres	=	mysql_query("SELECT * FROM `ziekenhuis` WHERE `owner`='' AND `land`='{$data->land}'");
			while($deal = mysql_fetch_object($dbres)){
			$id	=	"b_{$deal->land}";
			$land	=	$deal->land;
			echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\"><input type=\"radio\" name=\"type\" value=\"{$id}\" checked></td><td width=\"30%\" class=\"mainTxts\">ziekenhuis</td><td width=\"30%\" class=\"mainTxts\">{$land}</td><td width=\"30%\" class=\"mainTxts\">€20.000.000,-</td></tr>";
			}
		$dbres	=	mysql_query("SELECT * FROM `casino` WHERE `owner`='' AND `spel`='1' AND `land`='{$data->land}'");
			while($deal = mysql_fetch_object($dbres)){
			$id	=	"c_{$deal->land}";
			$land	=	$deal->land;
			echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\"><input type=\"radio\" name=\"type\" value=\"{$id}\" checked></td><td width=\"30%\" class=\"mainTxts\">Nummerspel</td><td width=\"30%\" class=\"mainTxts\">{$land}</td><td width=\"30%\" class=\"mainTxts\">€5.000.000,-</td></tr>";
			}
		$dbres	=	mysql_query("SELECT * FROM `casino` WHERE `owner`='' AND `spel`='2' AND `land`='{$data->land}'");
			while($deal = mysql_fetch_object($dbres)){
			$id	=	"d_{$deal->land}";
			$land	=	$deal->land;
			echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\"><input type=\"radio\" name=\"type\" value=\"{$id}\" checked></td><td width=\"30%\" class=\"mainTxts\">Gokkast</td><td width=\"30%\" class=\"mainTxts\">{$land}</td><td width=\"30%\" class=\"mainTxts\">€10.000.000,-</td></tr>";
			}
		$dbres	=	mysql_query("SELECT * FROM `casino` WHERE `owner`='' AND `spel`='3' AND `land`='{$data->land}'");
			while($deal = mysql_fetch_object($dbres)){
			$id	=	"e_{$deal->land}";
			$land	=	$deal->land;
			echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\"><input type=\"radio\" name=\"type\" value=\"{$id}\" checked></td><td width=\"30%\" class=\"mainTxts\">Roulette</td><td width=\"30%\" class=\"mainTxts\">{$land}</td><td width=\"30%\" class=\"mainTxts\">€10.000.000,-</td></tr>";
			}
		echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\" colspan=\"4\"><input type=\"submit\" value=\"kopen!\" name=\"submit\"></td></tr>";
		} else {
		echo "<tr align=\"center\"><td width=\"10%\" class=\"mainTxts\" colspan=\"4\">Er is op dit moment niets te koop in dit land.</td></tr>";
		}
	}

?>

	<tr>
		<td class="subtitle" colspan="4">&nbsp;</td>
	</tr>
</table>
</form>
</body>
</html>
