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

	if($data->level == 1){
	$max	=	10;
	} else if($data->level == 2){
	$max	=	25;
	} else {
	$max	=	100;
	}

?>

<html>
<head>
<title>Ultimatecrime - Partners in crime!</title>
<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">
<link rel="stylesheet" type="text/css" href="style_general.css">
</head>
<body background="layout/images/layout_12.gif" bgproperties="fixed">
<br>
<br>
<br>
<table width="600" border="0" align="center">
	<tr>
		<td class="subtitle">Ultimatecrime - Partners in crime van <?php echo $data->login; ?></td>
	</tr>
	<tr>
		<td class="maintxt"><table width="560" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td width="20" valign="top"><img src="layout/images/icons/light_info.jpg" width="16" height="16" /></td>
				<td><span class="tekstheader"><?php echo $data->partners; ?> partners van maximaal <?php echo $max; ?>!</span></td>
			</tr>
		</table></td>
	</tr>	  
	<tr>
		<td class="maintxt">

<?php

	if(isset($_GET['add'])){
	$_GET['add']	=	$_GET['add'];
	$dbres		=	mysql_query("SELECT `id` FROM `partners` WHERE (`login`='{$_GET['add']}' AND `vriend`='{$data->login}') OR (`login`='{$data->login}' AND `vriend`='{$_GET['add']}')");
	$controlle	=	mysql_num_rows($dbres);
	$dbres		=	mysql_query("SELECT `login`,`partners`,`level` FROM `gebruiker` WHERE `login`='{$_GET['add']}'");
	$rijen		=	mysql_num_rows($dbres);

		if($_GET['add'] == $data->login){

?>

		<table width="560" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td width="20"><img src="layout/images/icons/light_error.jpg" width="16" height="16" /></td>
				<td><span class="header_rood">Je mag jezelf niet als partner hebben!</span></td>
			</tr>
		</table>
	 

<?php
	
		} else if($controlle != 0){

?>

		<table width="560" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td width="20"><img src="layout/images/icons/light_error.jpg" width="16" height="16" /></td>
				<td><span class="header_rood">Je hebt deze persoon al als partner!</span></td>
			</tr>
		</table>
	 

<?php
	
		} else {

			if($rijen != 0){
			$user	=	mysql_fetch_object($dbres);
				if(($user->partners < 11 && $user->level == 1) && ($user->partners < 26 && $user->level == 2) && ($user->partners < 101 && $user->level == 3)){

?>

		<table width="560" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td width="20"><img src="layout/images/icons/light_error.jpg" width="16" height="16" /></td>
				<td><span class="header_rood">De partnerlijst van die crimineel zit vol!</span></td>
			</tr>
		</table>
	 

<?php
				} else if(($data->partners < 11 && $data->level == 1) && ($datar->partners < 26 && $data->level == 2) && ($data->partners < 101 && $data->level == 3)){

?>

		<table width="560" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td width="20"><img src="layout/images/icons/light_error.jpg" width="16" height="16" /></td>
				<td><span class="header_rood">Jouw partnerlijst zit vol!</span></td>
			</tr>
		</table>
	 

<?php

				} else {
				mysql_query("INSERT INTO `partners`(`login`,`vriend`) VALUES('{$data->login}','{$user->login}')");
				mysql_query("UPDATE `gebruiker` SET `partners`=`partners`+'1' WHERE `login`='{$data->login}'");
				mysql_query("UPDATE `gebruiker` SET `partners`=`partners`+'1' WHERE `login`='{$user->login}'");
				mysql_query("INSERT INTO `berichten`(`tijd`,`ip`,`van`,`naar`,`titel`,`bericht`) VALUES(NOW(),'{$_SERVER['REMOTE_ADDR']}','{$data->login}','{$user->login}','Partner verzoek','Hey {$user->login}! Partners in crime worden?\nIk wil jou graag als een van mijn partners in crime, zodat ik handige informatie kan zien over je... Als jij mijn verzoek bevestigt, kan jij dezelfde informatie over mij zien!')");

?>

		<table width="560" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td width="20" valign="top"><img src="layout/images/icons/light_vink.jpg" width="16" height="16" /></td>
				<td><span class="tekstheader">Partner met succes toegevoegd!</span><br /><i>Je wacht nu op bevestiging, diegene heeft een email ontvangen!</i></td>
			</tr>
		</table>

<?php

				}
			}
		}
	} else if(isset($_GET['del'])){
	$_GET['del']	=	$_GET['del'];
	$dbres		=	mysql_query("SELECT `id` FROM `partners` WHERE `id`='{$_GET['del']}' AND (`login`='{$data->login}' OR `vriend`='{$data->login}')");
	$partner	=	mysql_fetch_object($dbres);

	mysql_query("UPDATE `gebruiker` SET `partners`=`partners`-'1' WHERE `login`='{$partner->login}'");
	mysql_query("UPDATE `gebruiker` SET `partners`=`partners`-'1' WHERE `login`='{$partner->vriend}'");
	mysql_query("DELETE FROM `partners` WHERE `id`='{$_GET['del']}'");

?>

		<table width="560" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td width="20"><img src="layout/images/icons/light_vink.jpg" width="16" height="16" /></td>
				<td><span class="tekstheader">Partner met succes verwijderd!</span></td>
			</tr>
		</table>

<?php

	} else if(isset($_GET['bevestig'])){
	$_GET['bevestig']	=	$_GET['bevestig'];
	mysql_query("UPDATE `partners` SET `status`='1' WHERE `id`='{$_GET['bevestig']}' AND `vriend`='{$data->login}'");

?>

		<table width="560" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td width="20"><img src="layout/images/icons/light_vink.jpg" width="16" height="16" /></td>
				<td><span class="tekstheader">Jullie zijn vanaf nu partners in crime!</span></td>
			</tr>
		</table>

<?php

	} else {

	$dbres1	=	mysql_query("SELECT `id`,`vriend` FROM `partners` WHERE `login`='{$data->login}' OR `vriend`='{$data->login}' AND `status`='1'");
	$rijen1	=	mysql_num_rows($dbres1);

	$dbres2	=	mysql_query("SELECT `id`,`vriend` FROM `partners` WHERE `login`='{$data->login}' AND `status`='0'");
	$rijen2	=	mysql_num_rows($dbres2);

		if($rijen1 != 0){
		echo "<table width=\"560\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">";
		$dbres1		=	mysql_query("SELECT * FROM `partners` WHERE `login`='{$data->login}' AND `status`='1'");
			while($partner = mysql_fetch_object($dbres1)){
			$dbres	=	mysql_query("SELECT UNIX_TIMESTAMP(`online`) AS `online`,0 FROM `gebruiker` WHERE `login`='{$partner->vriend}'");
			$member	=	mysql_fetch_object($dbres);

				if($member->online + 300 > time()){
				$status1	=	"online";
				} else {				
				$status1	=	"offline";
				}

			$dbres	=	mysql_query("SELECT `land`,`login`,UNIX_TIMESTAMP(`wachttijd_heist`) AS `wachttijd_heist`,0 FROM `gebruiker` WHERE `login`='{$partner->vriend}'");
			$member	=	mysql_fetch_object($dbres);

				if($member->wachttijd_heist + 10800 > time()){
				$status2	=	"no";
				} else {
				$status2	=	"yes";
				}

?>

			<tr> 
				<td width="40"><img src="layout/images/icons/light_<?php echo $status1; ?>.jpg" width="16" height="16" /><img src="layout/images/icons/light_duojob_<?php echo $status2; ?>.jpg" width="20" height="16" /></td>
				<td width="190"><a href="speler-profiel.php?x=<?php echo $member->login; ?>" target="content"><?php echo $member->login; ?></a></td>
				<td width="20"><img src="layout/images/icons/light_world.jpg" width="16" height="16" /></td>
				<td width="150"><?php echo $member->land; ?></td>
				<td width="20"><img src="layout/images/icons/light_email.jpg" width="16" height="16" /></td>
				<td width="60"><a href="internet-email.php?p=new&to=<?php echo $user->login; ?>" target="content">Email</a></td>
				<td width="20"><a href="speler-partners.php?del=<?php echo $partner->id; ?>" target="content"><img src="layout/images/icons/light_delete.jpg" alt="Verwijder partner" width="16" height="16" border="0" /></a></td>
			</tr>

<?php

			}

		$dbres1	=	mysql_query("SELECT `id`,`login` FROM `partners` WHERE `vriend`='{$data->login}' AND `status`='1'");

			while($partner = mysql_fetch_object($dbres1)){
			$dbres	=	mysql_query("SELECT UNIX_TIMESTAMP(`online`) AS `online`,0 FROM `gebruiker` WHERE `login`='{$partner->login}'");
			$member	=	mysql_fetch_object($dbres);

				if($member->online + 300 > time()){
				$status1	=	"online";
				} else {				
				$status1	=	"offline";
				}

			$dbres	=	mysql_query("SELECT `land`,`login`,UNIX_TIMESTAMP(`wachttijd_heist`) AS `wachttijd_heist`,0 FROM `gebruiker` WHERE `login`='{$partner->login}'");
			$member	=	mysql_fetch_object($dbres);

				if($member->wachttijd_heist + 10800 > time()){
				$status2	=	"no";
				} else {
				$status2	=	"yes";
				}

?>

			<tr> 
				<td width="40"><img src="layout/images/icons/light_<?php echo $status1; ?>.jpg" width="16" height="16" /><img src="layout/images/icons/light_duojob_<?php echo $status2; ?>.jpg" width="20" height="16" /></td>
				<td width="190"><a href="speler-profiel.php?x=<?php echo $member->login; ?>" target="content"><?php echo $member->login; ?></a></td>
				<td width="20"><img src="layout/images/icons/light_world.jpg" width="16" height="16" /></td>
				<td width="150"><?php echo $member->land; ?></td>
				<td width="20"><img src="layout/images/icons/light_email.jpg" width="16" height="16" /></td>
				<td width="60"><a href="internet-email.php?p=new&to=<?php echo $member->login; ?>" target="content">Email</a></td>
				<td width="20"><a href="speler-partners.php?del=<?php echo $partner->id; ?>" target="content"><img src="layout/images/icons/light_delete.jpg" alt="Verwijder partner" width="16" height="16" border="0" /></a></td>
			</tr>

<?php

			}
		echo "</table>";
		} else {

?>

		<table width="560" border="0" align="center" cellpadding="0" cellspacing="0">
			<tr>
				<td width="20"><img src="layout/images/icons/light_error.jpg" width="16" height="16" /></td><td><span class="header_rood">Je hebt geen bevestigde partners in crime!</span></td>
			</tr>	  
		</table>

<?php

		} if($rijen2 != 0){
		echo "<table width=\"560\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">";
			while($partner = mysql_fetch_object($dbres2)){

?>

		  <tr>
			<td width="20"><img src="layout/images/icons/light_usergo.jpg" width="16" height="16" /></td>
			<td width="200"><a href="speler-profiel.php?x=<?php echo $partner->vriend; ?>" target="content"><?php echo $partner->vriend; ?></a></td>
			<td width="260"><i>moet nog bevestiging geven...</i></td>
			<td width="20"><a href="speler-partners.php?del=<?php echo $partner->id; ?>" target="content"><img src="layout/images/icons/light_delete.jpg" alt="Verwijder partner" width="16" height="16" border="0" /></a></td>
		  </tr>

<?php

			}
		echo "</table>";
		}

	$dbres	=	mysql_query("SELECT `id`,`login` FROM `partners` WHERE `vriend`='{$data->login}' AND `status`='0'");
	$rijen3	=	mysql_num_rows($dbres);

		if($rijen3 != 0){
		echo "<table width=\"560\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">";
			while($partner = mysql_fetch_object($dbres)){

?>

		  <tr>
			<td width="20"><img src="layout/images/icons/light_usergo.jpg" width="16" height="16" /></td>
			<td width="200"><a href="speler-profiel.php?x=<?php echo $partner->login; ?>" target="content"><?php echo $partner->login; ?></a></td>
			<td width="260"><i>heeft je uitgenodigd partner te worden!</i></td>
			<td width="40"><a href="speler-partners.php?bevestig=<?php echo $partner->id; ?>" target="content"><img src="layout/images/icons/light_vink.jpg" alt="Bevestig partner" width="16" height="16" border="0" /></a>&nbsp;<a href="speler-partners.php?del=<?php echo $partner->id; ?>" target="content"><img src="layout/images/icons/light_delete.jpg" alt="Verwijder partner" width="16" height="16" border="0" /></a></td>
		  </tr>

<?php

			}
		echo "</table>";
		}
	}

?>

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

