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

	if($data->famconsig == 0 && $data->famleader == 0){
	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 method="post">
<table align="center" width="600">
	<tr>
		<td class="subTitle">
		<b>Netwerk - Netwerk bank</b>
		</td>
	</tr>
	<tr>
		<td class="mainTxt" align="center">

<?php

$dbres		=	mysql_query("SELECT * FROM `familie` WHERE `naam`='{$data->familie}'");
$family		=	mysql_fetch_object($dbres);
$bank		=	$family->bank;
	if(isset($_POST['Submit']) && $_POST['amount'] > 0 && $_POST['amount'] != "" && (is_numeric($_POST['amount']) != 0)){
		if($_POST['action1'] == "afhalen"){
			if($family->bank >= $_POST['amount']){
			$bankoff1		=	round($_POST['amount']);
			$bankoff2		=	geld($bankoff1);
			mysql_query("INSERT INTO `logs`(`time`,`ip`,`van`,`naar`,`bedrag`,`message`) VALUES(NOW(),'{$_SERVER['REMOTE_ADDR']}','{$data->familie}','{$data->login}','$bankoff1','Bedrag van het netwerk...')"); 
			mysql_query("UPDATE `familie` SET `bank`=`bank`-'$bankoff1' WHERE `naam`='{$data->familie}'");
			mysql_query("UPDATE `gebruiker` SET `bank`=`bank`+'$bankoff1' WHERE `login`='{$data->login}'");
			echo "Je hebt €{$bankoff2} van de netwerkbank afgehaald.<meta http-equiv=\"refresh\" content=\"3\">";
			} else {
			echo "Er staat niet genoeg geld op de netwerkbank.<meta http-equiv=\"refresh\" content=\"3\">";
			}
		} else if($_POST['action1'] == "storten"){
			if($data->bank >= $_POST['amount']){
			$bankoff1		=	round($_POST['amount']);
			$bankoff2		=	geld($bankoff1);
			mysql_query("INSERT INTO `logs`(`time`,`ip`,`van`,`naar`,`bedrag`,`message`) VALUES(NOW(),'{$_SERVER['REMOTE_ADDR']}','{$data->login}','{$data->familie}','$bankoff1','Bedrag voor het netwerk...')"); 
			mysql_query("UPDATE `familie` SET `bank`=`bank`+'$bankoff1' WHERE `naam`='{$data->familie}'");
			mysql_query("UPDATE `gebruiker` SET `bank`=`bank`-'$bankoff1' WHERE `login`='{$data->login}'");
			echo "Je hebt €{$bankoff2} op de netwerkbank gezet.<meta http-equiv=\"refresh\" content=\"3\">";
			} else {
			echo "Je hebt niet genoeg geld contant staan.<meta http-equiv=\"refresh\" content=\"3\">";
			}
		}
	} else {

?>

		<form method="post">
		<table width="80%" align="center">
			<tr> 
				<td width="50%">Geld in de bank:</td>
				<td width="50%">€<?php echo geld($bank); ?></td>
			</tr>
			<tr> 
				<td width="50%">Bedrag:</td>
				<td width="50%"><input type="text" name="amount"></td>
			</tr>
			<tr> 
				<td width="50%" valign="top">Actie:</td>
				<td width="50%"><input type="radio" name="action1" value="storten" checked> Storten<br><input type="radio" name="action1" value="afhalen"> Pinnen</td>
			</tr>
			<tr>
				<td width="50%"></td>
				<td width="50%"><input type="submit" name="Submit" value="Doe transactie"></td>
			</tr>
		</table>
		</form>

<?php

	}

?>

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

<?php

$dbres		=	mysql_query("SELECT *,DATE_FORMAT(`time`,'%d-%m-%Y %H:%i') AS `time` FROM `logs` WHERE `naar`='{$data->familie}' ORDER BY `id` DESC LIMIT 5");

?>

	<tr>
		<td class="subtitle" align="center">Laatste bijschrijvingen van het netwerk</td>
	</tr>
	<tr>
		<td class="mainTxt">

<?php

	while($info = mysql_fetch_object($dbres)){

?>
		<table width="565" border="0" align="center" cellpadding="0" cellspacing="0">
			<tr>
				<td width="25" valign="top"><img src="layout/images/icons/light_money_plus.jpg" width="16" height="16"></td>
				<td width="190"><a href="speler-profiel.php?x=<?php echo $info->van; ?>" target="content"><strong><?php echo $info->van; ?></strong></a></td>
				<td><strong><?php echo $info->time; ?></strong></td>
				<td align="right"><strong>&euro; <?php echo geld($info->bedrag); ?></strong></td>
			</tr>
			</tr>
			<tr>
				<td width="25"></td>
				<td colspan="3"><i><?php echo $info->message; ?></i></td>
			</tr>
			<tr>
				<td colspan="4">&nbsp;</td>
			</tr>
		</table>

<?php

	}

?>

		&nbsp;</td>
	</tr>

<?php

	$dbres		=	mysql_query("SELECT *,DATE_FORMAT(`time`,'%d-%m-%Y %H:%i') AS `time` FROM `logs` WHERE `van`='{$data->familie}' ORDER BY `id` DESC LIMIT 5");

?>

	<tr>
		<td colspan="2" class="subtitle" align="center">Laatste afschrijvingen van het netwerk</td>
	</tr>
	<tr>
		<td class="mainTxt" colspan="2">

<?php

	while($info = mysql_fetch_object($dbres)){

?>
		<table width="565" border="0" align="center" cellpadding="0" cellspacing="0">
			<tr>
				<td width="25" valign="top"><img src="layout/images/icons/light_money_plus.jpg" width="16" height="16"></td>
				<td width="190"><a href="speler-profiel.php?x=<?php echo $info->naar; ?>" target="content"><strong><?php echo $info->naar; ?></strong></a></td>
				<td><strong><?php echo $info->time; ?></strong></td>
				<td align="right"><strong>&euro; <?php echo geld($info->bedrag); ?></strong></td>
			</tr>
			<tr>
				<td width="25"></td>
				<td colspan="3"><i><?php echo $info->message; ?></i></td>
			</tr>
			<tr>
				<td colspan="4">&nbsp;</td>
			</tr>
		</table>	 
<?php

	}

?>

		&nbsp;</td>
	</tr>
</table>
</body>
</html>
