<?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">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="description" content="Ultimatecrime is een gratis online multiplayer spel! Ontwikkel je eigen crimineel door verschillende criminele activiteiten te doen! Speel met duizenden andere criminelen en wordt nummer 1!">
<meta name="keywords" content="world, gangster, criminal, mafia, games, game, multiplayer, rpg, mmorpg, online game, online multiplayer">
<meta name="Robots" CONTENT="follow">
<meta name="REVISIT-AFTER" CONTENT="7 days">
<script language="javascript">
	function MM_jumpMenu(targ,selObj,restore){
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
		if(restore)
		selObj.selectedIndex=0;
	}
</script>
</head>
<body background="layout/images/layout_12.gif" bgproperties="fixed">
<br>
<br>
<br>

<?php

$begin		=	($_GET['p'] >= 0) ? $_GET['p']*20 : 0;
$dbres		=	mysql_query("SELECT `waarde` FROM `autos` WHERE `owner`='{$data->login}'");
$totaalautos	=	mysql_num_rows($dbres);
$totaalgeld	=	0;

	while($auto = mysql_fetch_object($dbres)){
	$totaalgeld	=	$auto->waarde+$totaalgeld;
	}

$totaalgeld	=	geld($totaalgeld);

?>

<table align="center" width="600">
	<tr>
		<td class="subTitle" colspan="3"><b>Ultimatecrime - Jouw Garage</b></td>
	</tr>
	<tr>
		<td rowspan="3" width="134"><img src="images/ingame/garage.jpg"></td>
		<td class="maintxts" width="300">Verkrijgbare auto's</td>
		<td class="maintxts" width="166" align="center"><a href="auto-showroom.php">Bekijk showroom</a></td>
	</tr>
	<tr>
  		<td class="maintxts" width="300">Aantal auto's in garage</td>
		<td class="maintxts" align="center"><?php echo $totaalautos;?></td>
	</tr>
	<tr>
		<td class="maintxts" width="300">Totale waarde</td>
		<td class="maintxts" align="center">&euro;<?php echo $totaalgeld;?></td>
	</tr>
	<tr>
		<td class="subTitle" colspan="3">&nbsp;</td>
	</tr>

<?php

	if(isset($_POST['crushall'])){
		if($data->familie != ""){
		$dbres		=	mysql_query("SELECT `maxautos`,`autos`,`kogels` FROM `familie` WHERE `naam`='{$data->familie}'");
		$familie	=	mysql_fetch_object($dbres);

		$kogels		=	0;
		$autos		=	0;

		$dbres		=	mysql_query("SELECT * FROM `autos` WHERE `owner`='{$data->login}' AND `land`='{$data->land}' AND `status`='0'");

			while($auto = mysql_fetch_object($dbres)){
			$kogels		=	$kogels+$familie->kogels;
			$autos		=	$autos+1;
			}

			if($familie->maxautos-$familie->autos-$autos > -1){
			mysql_query("DELETE FROM `autos` WHERE `owner`='{$data->login}' AND `land`='{$data->land}' AND `status`='0'");
			mysql_query("UPDATE `gebruiker` SET `kogels`=`kogels`+'$kogels' WHERE `login`='{$data->login}'");
			mysql_query("UPDATE `familie` SET `autos`=`autos`+'$autos' WHERE `naam`='{$data->familie}'");
			echo "<tr><td class=\"mainTxt\" colspan=\"3\">Je hebt al je auto's in {$data->land} gecrust voor $kogels kogels.</td></tr><tr><td class=\"subtitle\" colspan=\"3\">&nbsp;</td></tr>";
			} else {
			echo "<tr><td class=\"mainTxt\" colspan=\"3\">Zoveel auto's kan de familie niet meer crushen.</td></tr><tr><td class=\"subtitle\" colspan=\"3\">&nbsp;</td></tr>";
			}
	
		}

	} else if(isset($_POST['sellall'])){

	$geld		=	0;
	$dbres		=	mysql_query("SELECT `waarde` FROM `autos` WHERE `owner`='{$data->login}' AND `land`='{$data->land}' AND `status`='0'");

		while($auto = mysql_fetch_object($dbres)){
		$geld		=	$geld+$auto->waarde;
		}

	mysql_query("DELETE FROM `autos` WHERE `owner`='{$data->login}' AND `land`='{$data->land}' AND `status`='0'");
	mysql_query("UPDATE `gebruiker` SET `cash`=`cash`+'$geld' WHERE `login`='{$data->login}'");
	echo "<tr><td class=\"mainTxt\" colspan=\"3\">Je hebt al je auto's in {$data->land} verkocht voor &#8364;" . geld($geld) . ".</td></tr><tr><td class=\"subtitle\" colspan=\"3\">&nbsp;</td></tr>";
	} else if(isset($_GET['land'])){
	$_GET['id']	=	$_GET['id'];
	$_GET['land']	=	$_GET['land'];
	$dbres		=	mysql_query("SELECT `land` FROM `autos` WHERE `owner`='{$data->login}' AND `id`='{$_GET['id']}'");
		if($auto = mysql_fetch_object($dbres)){
			if($data->cash >= 2500 AND $_GET['land'] != $auto->land){
			mysql_query("UPDATE `autos` SET `land`='{$_GET['land']}' WHERE `owner`='{$data->login}' AND `id`='{$_GET['id']}'");
			mysql_query("UPDATE `gebruiker` SET `cash`=`cash`-'2500' WHERE `login`='{$data->login}'");
			echo "<tr><td class=\"mainTxt\" colspan=\"3\">Je hebt je auto getransporteerd naar {$_GET['land']} voor &#8364;2,500.</td></tr><tr><td class=\"subtitle\" colspan=\"3\">&nbsp;</td></tr>";
			} else if($data->cash < 2500){
			echo "<tr><td class=\"mainTxt\" colspan=\"3\">Je hebt niet genoeg geld, je hebt minimaal &#8364;2,500 nodig.</td></tr><tr><td class=\"subtitle\" colspan=\"3\">&nbsp;</td></tr>";
			}
		}
	} else if($_GET['verkopen'] == 1){
	$_GET['x']	=	$_GET['x'];
	$dbres		=	mysql_query("SELECT `waarde` FROM `autos` WHERE `owner`='{$data->login}' AND `id`='{$_GET['x']}' AND `status`='0'");
		if($auto = mysql_fetch_object($dbres)){
		mysql_query("DELETE FROM `autos` WHERE `owner`='{$data->login}' AND `id`='{$_GET['x']}'");
		mysql_query("UPDATE `gebruiker` SET `cash`=`cash`+'{$auto->waarde}' WHERE `login`='{$data->login}'");
		echo "<tr><td class=\"mainTxt\" colspan=\"3\">Je hebt een auto verkocht voor &#8364;" . geld($auto->waarde) . ".</td></tr><tr><td class=\"subtitle\" colspan=\"3\">&nbsp;</td></tr>";
		} else {
		echo "<tr><td class=\"mainTxt\" colspan=\"3\">Deze auto bestaat niet of is al met iets anders bezig!</td></tr><tr><td class=\"subtitle\" colspan=\"3\">&nbsp;</td></tr>";
		}


	} else if($_GET['crush'] == 1){

		if($data->familie != ""){
		$_GET['x']	=	$_GET['x'];
		$dbres		=	mysql_query("SELECT `maxautos`,`autos`,`kogels` FROM `familie` WHERE `naam`='{$data->familie}'");
		$familie	=	mysql_fetch_object($dbres);
		$dbres		=	mysql_query("SELECT `id` FROM `autos` WHERE `owner`='{$data->login}' AND `id`='{$_GET['x']}'");

			if($auto = mysql_fetch_object($dbres)){
				if($familie->maxautos-$familie->autos > 0){

				mysql_query("DELETE FROM `autos` WHERE `owner`='{$data->login}' AND `id`='{$_GET['x']}'");
				mysql_query("UPDATE `gebruiker` SET `kogels`=`kogels`+'{$familie->kogels}' WHERE `login`='{$data->login}'");
				mysql_query("UPDATE `familie` SET `autos`=`autos`+'1' WHERE `naam`='{$data->familie}'");
				echo "<tr><td class=\"mainTxt\" colspan=\"3\">Je hebt een auto gecrust voor {$familie->kogels} kogels.</td></tr><tr><td class=\"subtitle\" colspan=\"3\">&nbsp;</td></tr>";
				} else {
				echo "<tr><td class=\"mainTxt\" colspan=\"3\">Zoveel auto's kan de familie niet meer crushen.</td></tr><tr><td class=\"subtitle\" colspan=\"3\">&nbsp;</td></tr>";
				}
			}
		}

	} else if(isset($_GET['getid'])){
	echo "<tr><td class=\"mainTxt\" colspan=\"3\"><span class=\"tekstheader\">Auto ID</span><br>Het ID van deze auto is: <strong>{$_GET['getid']}</strong></td></tr><tr><td class=\"subtitle\" colspan=\"3\">&nbsp;</td></tr>";
	}

?>

</table>
<br />
<form method="post" action="speler-garage.php">
<input type="hidden" name="pagina" value="0">
<table align="center" width="600">
	<tr>
		<td class="subTitle" colspan="7">
		<b>Ultimatecrime - Jouw auto collectie</b>
		</td>
	</tr>

<?php

$dbres		=	mysql_query("SELECT * FROM `autos` WHERE `owner`='{$data->login}' ORDER BY `id` LIMIT $begin,20");

	while($auto = mysql_fetch_object($dbres)){
	$waarde	=	geld($auto->waarde);
	
		if($auto->tuned == 1){
		$tuned	=	"<span class=\"tekstheader\">Getuned</span>";
		} else {
		$tuned	=	"Niet getuned";
		}


		if($auto->alarm == 1){
		$alarm	=	"<span class=\"tekstheader\">Beveiligd</span>";
		} else {
		$alarm	=	"Geen alarm";
		}

?>
  
	<tr onMouseOver="this.style.backgroundColor='#6F5E4A';" onMouseOut="this.style.backgroundColor='#4B3D32';" style="background-color: #4B3D32;">
		<td class="justborderS" width="50" align="center"><a href="speler-garage.php?getid=<?php echo $auto->id; ?>"><img src="images/autos/1_<?php echo $auto->naam; ?>.jpg" border="0" width="75" height="50"></a></td>

		<td class="justborderS" width="100"><a href="speler-garage.php?getid=<?php echo $auto->id; ?>"><span class="tekstheader"><?php echo $auto->naam; ?></span></a><br>&euro;<?php echo $waarde; ?></td>
		<td class="justborderS" width="100"><?php echo $auto->land; ?><br><?php echo $auto->schade; ?>% schade</td>
		<td class="justborderS" width="100"><?php echo $tuned; ?><br><?php echo $alarm; ?></td>
		<td class="justborderS" width="90"><?php echo $auto->pk; ?> PK<br><?php echo $auto->massa; ?> KG</td>
		<td class="justborderS" width="100" align="center">
		<select onChange="MM_jumpMenu('self',this,0)">
		<option value="#">Transfer</option>
		<option value="#">---------</option>
		<option value="speler-garage.php?land=Colombia&id=<?php echo $auto->id; ?>">Colombia</option>
		<option value="speler-garage.php?land=Cuba&id=<?php echo $auto->id; ?>">Cuba</option>
		<option value="speler-garage.php?land=Duitsland&id=<?php echo $auto->id; ?>">Duitsland</option>
		<option value="speler-garage.php?land=Frankrijk&id=<?php echo $auto->id; ?>">Frankrijk</option>
		<option value="speler-garage.php?land=Irak&id=<?php echo $auto->id; ?>">Irak</option>
		<option value="speler-garage.php?land=Italië&id=<?php echo $auto->id; ?>">Italië</option>
		<option value="speler-garage.php?land=Japan&id=<?php echo $auto->id; ?>">Japan</option>
		<option value="speler-garage.php?land=Mexico&id=<?php echo $auto->id; ?>">Mexico</option>
		<option value="speler-garage.php?land=Nederland&id=<?php echo $auto->id; ?>">Nederland</option>
		<option value="speler-garage.php?land=Turkije&id=<?php echo $auto->id; ?>">Turkije</option>
		<option value="speler-garage.php?land=USA&id=<?php echo $auto->id; ?>">USA</option>
		<option value="speler-garage.php?land=Zuid-Afrika&id=<?php echo $auto->id; ?>">Zuid-Afrika</option>
		</select>
		</td>
		<td class="justborderS" width="60" align="center"><a href="speler-garage.php?x=<?php echo $auto->id; ?>&verkopen=1"><img src="images/ingame/garage_sell.jpg" alt="Verkoop" border="0"></a> <a href="speler-garage.php?x=<?php echo $auto->id; ?>&crush=1"><img src="images/ingame/garage_ammo.jpg" alt="Crushen" border="0"></a></td>
	</tr>

<?php

	}

?>

	<tr>
		<td class="subTitle" colspan="7">&nbsp;</td>
	</tr>
</table>
<table align="center" width="600">

<?php

$dbres		=	mysql_query("SELECT `id` FROM `autos` WHERE `owner`='{$data->login}'");

	if(mysql_num_rows($dbres) > 20){
	echo "<tr><td class=\"maintxt\" align=\"center\" colspan=\"4\">";

		if($begina/20 == 0){
		echo "<<</font>";
		} else {
		echo "<a href=\"speler-garage.php?p=". ($begina/20-1) ."\"><<</a>";
		}

		for($i=0; $i<mysql_num_rows($dbres)/20; $i++){
		echo " <a href=\"speler-garage.php?p=$i\">". ($i+1) ."</a> ";
		}

		if($begina+20 >= mysql_num_rows($dbres)) {
		echo ">>";
		} else {
		echo "<a href=\"speler-garage.php?p=". ($begina/20+1) ."\">>></a>";
		}

	echo "&nbsp; </td></tr><tr>";
	}

?>

</table>
<table align="center" width="600">
	<tr>
		<td class="mainTxt" align="center"><input type="submit" name="crushall" value="Crush alle in <?php echo $data->land; ?>"></td>
		<td class="mainTxt" align="center"><input type="submit" name="sellall" value="Verkoop alle in <?php echo $data->land; ?>"></td>
	</tr>
	<tr>
		<td class="subTitle" colspan="3">&nbsp;</td>
	</tr>
</table>
</form>
</body>
</html>