<?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;
	}

$dbres		=	mysql_query("SELECT * FROM `clipsfabriek_spel` WHERE `land`='{$data->land}'");
$fabriek	=	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">
<br>
<br>
<br>
<table align="center" width="600">
	<tr>
		<td class="subTitle" colspan="2"><b>Locale Ammo Depot - <?php echo $data->land; ?></b></td>
	</tr>

<?php

	if(isset($_POST['submit'])){
	$getal1			=	md5($_SESSION['getal']);
	$getal2			=	$_GET['code'];
		if($getal1 != "" && $getal1 == $getal2){
		$_POST['kogels']	=	$_POST['kogels'];
		$totaal			=	$fabriek->prijs*$_POST['kogels'];
			if($totaal > $data->cash){

?>

	<tr>
		<td class="mainTxt" colspan="2" align="center">Ga eerst maar ff flappen halen!</td>
	</tr>

<?php
exit;
			} else if(! is_numeric($_POST['kogels'])){

?>

	<tr>
		<td class="mainTxt" colspan="2" align="center">Het ingevoerde aantal clips bestaat niet helemaal uit cijvers.</td>
	</tr>

<?php
exit;
			} else if($_POST['kogels'] < 1){

?>

	<tr>
		<td class="mainTxt" colspan="2" align="center">Je moet wel boven de nul clips invullen.</td>
	</tr>

<?php
exit;
			} else if($fabriek->aantal-$_POST['kogels'] < 0){

?>

	<tr>
		<td class="mainTxt" colspan="2" align="center">De ammo depot heeft niet genoeg clips.</td>
	</tr>

<?php
exit;
			} else {
			mysql_query("UPDATE `clipsfabriek_spel` SET `aantal`=`aantal`-'{$_POST['kogels']}' WHERE `id`='{$fabriek->id}'");
			mysql_query("UPDATE `gebruiker` SET `cash`=`cash`-'$totaal',`kogels`=`kogels`+'{$_POST['kogels']}' WHERE `login`='{$data->login}'");

?>

	<tr>
		<td class="mainTxt" colspan="2" align="center">Je hebt succesvol <?php echo $_POST['kogels']; ?> clips gekocht.</td>
	</tr>

<?php
exit;
			}
		}
	}

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

?>

	<form method="post" action="netwerken-handel-ammoclips.php?code=<?php echo $getalb; ?>">
	<tr>
		<td class="mainTxt" colspan="2" align="center"><img src="images/bunker.jpg" alt="Mooi heh..."></td>
	</tr>
	<tr>
		<td class="mainTxt" width="600" colspan="2"><span class="tekstheader">Ammo clips in Ultimatecrime</span><br>Een van de belangrijkste factoren om jezelf te bewijzen en in leven te houden, zijn ammo clips! Denk niet in tientallen, maar streef er naar om 100.000+ ammo clips te bezitten!</td>
	</tr>
	 <tr>
		<td class="mainTxt" width="300">Aantal clips in depot</td>
		<td class="mainTxt" width="300"><?php echo $fabriek->aantal; ?></td>
	</tr>
	<tr>
		<td class="mainTxt" width="300">Prijs per clip in &euro;</td>
		<td class="mainTxt" width="300"><?php echo geld($fabriek->prijs); ?></td
	</tr>
	<tr>
		<td class="mainTxt" width="300">Aantal clips dat jij kunt kopen</td>
		<td class="mainTxt" width="300"><?php echo floor($data->cash/$fabriek->prijs); ?></td>
	</tr>
	 <tr>
		<td class="mainTxt" width="300">Koop <input size=9 type="text" name="kogels" maxlength=4 value="<?php echo floor($data->cash/$fabriek->prijs); ?>" style="width: 50;"> clips</td>
		<td class="mainTxt" width="300" align="center"><input type="submit" name="submit" value="Koop" style="width: 200;"></td>
	</tr>
</table>
</form>
</body>
</html>

