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

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

	if($data->gevangenis + $data->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>
<form action="handel-cartune.php" method="post">
<table align="center" width="600">
	<tr>
		<td class="subTitle" colspan="3"><b>Ultimatecrime - Car Tune Shop</b></td>
	</tr>
	<tr>
		<td colspan="3" class="mainTxt" align="left">
		<span class="tekstheader">Welkom in de Car Tune Shop van Ultimatecrime!</span><br>
		Het volgende schema geeft weer hoeveel Ultimatecrime in rekening brengt voor het toepassen van een van de diensten op jouw auto.
		</td>
	</tr>
	<tr>
		<td class="subTitle" colspan="3">&nbsp;</td>
	</tr>
	<tr>
		<td rowspan="4" width="126" background="images/ingame/cartune_shop.jpg" height="200"></td>
		<td width="294" height="34" class="maintxts">Kosten schade herstellen</td>
		<td class="maintxts" width="180" align="center">10% restwaarde <br> + schadebedrag</td>
	</tr>
	<tr>
		<td width="294" height="29" class="maintxts">Kosten alarm inbouwen</td>
		<td class="maintxts" width="180" align="center">5% nieuwwaarde</td>
	</tr>
	<tr>
		<td width="294" height="31" class="maintxts">Kosten ChipTunen (+10% PK)</td>
		<td class="maintxts" width="180" align="center">5% nieuwwaarde</td>
	</tr>
	<tr>
		<td width="294" height="80" class="maintxts" colspan="2">&nbsp;</td>
  	</tr>
	<tr>
		<td class="subTitle" colspan="3">&nbsp;</td>
	</tr>
</table>
<br>

<?php

	if(isset($_POST['submit_schade']) && $_POST['auto_schade'] != 0){
	$dbres	=	mysql_query("SELECT * FROM `autos` WHERE `id`='{$_POST['auto_schade']}'");
	$auto	=	mysql_fetch_object($dbres);
	$dbres	=	mysql_query("SELECT * FROM `auto_soorten1` WHERE `naam`='{$auto->naam}'");
		if($auto2 = mysql_fetch_object($dbres)){
		} else {
		$dbres	=	mysql_query("SELECT * FROM `auto_soorten2` WHERE `naam`='{$auto->naam}'");
			if($auto2 = mysql_fetch_object($dbres)){
			} else {
			$dbres	=	mysql_query("SELECT * FROM `auto_soorten3` WHERE `naam`='{$auto->naam}'");
			$auto2	=	mysql_fetch_object($dbres);
			}
		}
	$prijs	=	round((($auto2->waarde/100)*$auto->schade)*2)+round($auto->waarde/10);
		if($prijs > $data->cash){

?>

<table align="center" width="600">
	<tr>
		<td class="subTitle" colspan="2">&nbsp;</td>
	</tr>
	<tr>
		<td class="mainTxt" colspan="2"><font color="red"><strong>Foutmelding</strong></font><br>Je hebt niet genoeg cash op zak!</td>
	</tr>
	<tr>
		<td class="subTitle" colspan="2">&nbsp;</td>
	</tr>
</table>

<?php

		} else {
		mysql_query("UPDATE `autos` SET `schade`='0',`waarde`='{$auto2->waarde}' WHERE `id`='{$auto->id}'");
		mysql_query("UPDATE `gebruiker` SET `cash`=`cash`-'$prijs' WHERE `login`='{$data->login}'");

?>

<table align="center" width="600">
	<tr>
	<td class="subTitle" colspan="2">&nbsp;</td>
	</tr>
	<tr>
	<td class="mainTxt" colspan="2"><span class="tekstheader">Succes</span><br>Je auto is gerepareert voor &euro;<?php echo geld($prijs); ?>!</td>
	</tr>
	<tr>
	<td class="subTitle" colspan="2">&nbsp;</td>
	</tr>
</table>

<?php

		}
	} else if(isset($_POST['submit_alarm']) && $_POST['auto_alarm'] != 0){
	$dbres	=	mysql_query("SELECT * FROM `autos` WHERE `id`='{$_POST['auto_alarm']}'");
	$auto	=	mysql_fetch_object($dbres);
	$prijs	=	round(($auto->waarde/100)*5);
	$waarde	=	round($auto->waarde/60);
		if($prijs > $data->cash){

?>

<table align="center" width="600">
	<tr>
		<td class="subTitle" colspan="2">&nbsp;</td>
	</tr>
	<tr>
		<td class="mainTxt" colspan="2"><font color="red"><strong>Foutmelding</strong></font><br>Je hebt niet genoeg cash op zak!</td>
	</tr>
	<tr>
		<td class="subTitle" colspan="2">&nbsp;</td>
	</tr>
</table>

<?php

		} else {
		mysql_query("UPDATE `autos` SET `alarm`='1',`waarde`=`waarde`+'$waarde' WHERE `id`='{$auto->id}'");
		mysql_query("UPDATE `gebruiker` SET `cash`=`cash`-'$prijs' WHERE `login`='{$data->login}'");

?>

<table align="center" width="600">
	<tr>
	<td class="subTitle" colspan="2">&nbsp;</td>
	</tr>
	<tr>
	<td class="mainTxt" colspan="2"><span class="tekstheader">Succes</span><br>Je auto is beveiligd voor &euro;<?php echo geld($prijs); ?>!</td>
	</tr>
	<tr>
	<td class="subTitle" colspan="2">&nbsp;</td>
	</tr>
</table>

<?php

		}
	} else if(isset($_POST['submit_chiptunen']) && $_POST['auto_chiptunen'] != 0){
	$dbres	=	mysql_query("SELECT * FROM `autos` WHERE `id`='{$_POST['auto_chiptunen']}'");
	$auto	=	mysql_fetch_object($dbres);
	$prijs	=	round(($auto->waarde/100)*2);
	$pk	=	round(($auto->pk/10)+$auto->pk);
	$waarde	=	round($auto->waarde/60);
		if($prijs > $data->cash){

?>

<table align="center" width="600">
	<tr>
		<td class="subTitle" colspan="2">&nbsp;</td>
	</tr>
	<tr>
		<td class="mainTxt" colspan="2"><font color="red"><strong>Foutmelding</strong></font><br>Je hebt niet genoeg cash op zak!</td>
	</tr>
	<tr>
		<td class="subTitle" colspan="2">&nbsp;</td>
	</tr>
</table>

<?php

		} else {
		mysql_query("UPDATE `autos` SET `tuned`='1',`pk`='$pk',`waarde`=`waarde`+'$waarde' WHERE `id`='{$auto->id}'");
		mysql_query("UPDATE `gebruiker` SET `cash`=`cash`-'$prijs' WHERE `login`='{$data->login}'");

?>

<table align="center" width="600">
	<tr><td class="subTitle" colspan="2">&nbsp;</td></tr>
	<tr><td class="mainTxt" colspan="2"><span class="tekstheader">Succes</span><br>Je auto is getuned voor &euro;<?php echo geld($prijs); ?> en heeft nu <?php echo $pk; ?> PK!</td></tr>
	<tr><td class="subTitle" colspan="2">&nbsp;</td></tr>
</table>

<?php

		}
	} else {

?>
	
<table align="center" width="600">
	<tr>
		<td class="subTitle" colspan="2"><b>Jouw autos in <?php echo $data->land;?></b></td>
	</tr>
	<tr>
		<td class="mainTxtS" width="450">
		<select name="auto_schade" class="form_select" style="width: 400;">
		<option value="0">Kies auto....</option>
		<option value="0">----------------</option>

<?php

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

	while($auto = mysql_fetch_object($dbres)){
	$dbres1	=	mysql_query("SELECT * FROM `auto_soorten1` WHERE `naam`='{$auto->naam}'");
		if($auto2 = mysql_fetch_object($dbres1)){
		} else {
		$dbres1	=	mysql_query("SELECT * FROM `auto_soorten2` WHERE `naam`='{$auto->naam}'");
			if($auto2 = mysql_fetch_object($dbres1)){
			} else {
			$dbres1	=	mysql_query("SELECT * FROM `auto_soorten3` WHERE `naam`='{$auto->naam}'");
			$auto2	=	mysql_fetch_object($dbres1);
			}
		}
	$prijs	=	round((($auto2->waarde/100)*$auto->schade)*2)+round($auto->waarde/10);
	echo "<option value=\"{$auto->id}\">{$auto->naam} (ID {$auto->id}) - Kosten repareren = &euro;". geld($prijs) . "</option>";
	}

?>
		<option value="0">----------------</option>
		</td>
		<td class="mainTxtS" width="150" align="center"><input type="submit" name="submit_schade" value="Repareer auto"></td>
	</tr>
	<tr>
		<td class="mainTxtS" width="450">
		<select name="auto_alarm" class="form_select" style="width: 400;">
		<option value="0">Kies auto....</option>
		<option value="0">----------------</option>

<?php

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

	while($auto = mysql_fetch_object($dbres)){
	$prijs	=	round(($auto->waarde/100)*5);
	echo "<option value=\"{$auto->id}\">{$auto->naam} (ID {$auto->id}) - Kosten alarm = &euro;". geld($prijs) . "</option>";
	}

?>
	
		<option value="0">----------------</option>
		</td>
		<td class="mainTxtS" width="150" align="center"><input type="submit" name="submit_alarm" value="Bouw alarm in"></td>
	</tr>
	<tr>
		<td class="mainTxtS" width="450">
		<select name="auto_chiptunen" class="form_select" style="width: 400;">
		<option value="0">Kies auto....</option>
		<option value="0">----------------</option>

<?php

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

	while($auto = mysql_fetch_object($dbres)){
	$prijs	=	round(($auto->waarde/100)*5);
	echo "<option value=\"{$auto->id}\">{$auto->naam} (ID {$auto->id}) - Kosten tunen = &euro;". geld($prijs) . "</option>";
	}

?>
	
		<option value="0">----------------</option>
		</td>
		<td class="mainTxtS" width="150" align="center"><input type="submit" name="submit_chiptunen" value="ChipTune auto"></td>
	</tr>
	<tr>
		<td class="subTitle" colspan="2">&nbsp;</td>
	</tr>
</table>

<?php

	}

?>
</form>
</body>
</html>