<?php
if (!isset($_SESSION))
{
	session_start();
}
require_once ('header.php');
if ($aangemeld == "ja")
{
	if (ISSET($_GET['naam']))
	{
		function no_nothing($string_check)
		{
			if (($string_check == "") or ($string_check == "0000-00-00 00:00:00"))
			{
				return "-";
			}
			else
			{
				return $string_check;
			}
		}
		echo "<h1>Profiel van ".$_GET['naam']."</h1>";
		echo "<center>";
		echo "<form action='profiel.php' method='get'>";
		echo "<input type='text' length='20' maxlength='20' name='naam'>";
		echo "<input type='submit' value='Ga'>";
		echo "</form>";
		error_reporting(0);
   		$bestaat_mss_al = halen("SELECT * FROM members WHERE naam='".$_GET['naam']."';");
	   	error_reporting(E_ALL);
		if($bestaat_mss_al != "")
		{
			
			$posts = halen("SELECT posts FROM members WHERE naam='".$_GET['naam']."';");
			$ip = halen("SELECT ip FROM members WHERE naam='".$_GET['naam']."';");
			$pass = halen("SELECT wachtwoord FROM members WHERE naam='".$_GET['naam']."';");
			$ban = halen("SELECT ban FROM members WHERE naam='".$_GET['naam']."';");
			$online = no_nothing(halen("SELECT last_online FROM members WHERE naam='".$_GET['naam']."';"));
			$actie = halen("SELECT actie FROM members WHERE naam='".$_GET['naam']."';");
			$geld = halen("SELECT money FROM members WHERE naam='".$_GET['naam']."';");
			$alle_posts = 0;
			$sql = "SELECT posts FROM members"; 
			$res = mysql_query($sql); 
			if (mysql_num_rows($res) >= 1) 
			{ 
				while ($row = mysql_fetch_array($res)) 
				{
					$alle_posts = $alle_posts + $row['posts'];
				}
			}
			if ($posts != 0)
			{
				$percentuale = (($posts * 100) / $alle_posts);
			}
	        else
	        {
	            $percentuale=0;
	        }
			$tralala = status($_SESSION['naam'], $_SESSION['member_posts']);
			$tralala2 = status($_GET['naam'], $posts);
			echo "<table class='tabel' class='bigborder' cellspacing='0' cellpadding='0' width='auto' style='border: 1px solid black;'><tr><td>";
			echo "<table class='tabel' border='0' cellspacing='0' cellpadding='3' bgcolor='#B8C0CE' width='525'><tr bgcolor='#102750'><td valign='top' style='color: #A0ABC8; vertical-align: middle;' colspan='2'>";
			echo "Profiel</td></tr>";
			echo "<tr class='kleurenhemel_twee'><td>Pageviews: </td><td>".$actie."</td></tr>\n";
			echo "<tr class='kleurenhemel_een'><td>Status: </td><td><b>".$tralala2."</b></td></tr>\n";
			echo "<tr class='kleurenhemel_twee'><td>Laatst online: </td><td>".$online."</td></tr>\n";
			echo "</table class='tabel'></td></tr></table class='tabel'><br>";
			echo "<table class='tabel' class='bigborder' cellspacing='0' cellpadding='0' width='auto' style='border: 1px solid black;'><tr><td>";
			echo "<table class='tabel' border='0' cellspacing='0' cellpadding='3' bgcolor='#B8C0CE' width='525'><tr bgcolor='#102750'><td valign='top' style='color: #A0ABC8; vertical-align: middle;' colspan='2'>";
			echo "Forum</td></tr>";
			echo "<tr class='kleurenhemel_een'><td>Posts: </td><td>".$posts." (".round($percentuale,1)."% van alle posts)</td></tr>\n";
			echo "</table class='tabel'></td></tr></table class='tabel'><br>";
			if ($_SESSION['naam'] != $_GET['naam'])
			{
				echo "<table class='tabel' class='bigborder' cellspacing='0' cellpadding='0' width='auto' style='border: 1px solid black;'><tr><td>";
				echo "<table class='tabel' border='0' cellspacing='0' cellpadding='3' bgcolor='#B8C0CE' width='525'><tr bgcolor='#102750'><td valign='top' style='color: #A0ABC8; vertical-align: middle;' colspan='2'>";
				echo "Extra's</td></tr>";
				if (($tralala == "manager") or ($tralala == "staff"))
				{
					if ($tralala == "manager")
					{
						echo "<tr class='kleurenhemel_een'><td><b>Wachtwoord:</b> </td><td><b>'".$pass."'</b></td></tr>\n";
					}
					echo "<tr class='kleurenhemel_een'><td>IP: </td><td>".$ip."</td></tr>\n";
					echo "<tr class='kleurenhemel_een'><td>Geld: </td><td>".$geld." Credit(s)</td></tr>\n";
					$csql = "SELECT * FROM strafblad WHERE member='".$_GET['naam']."';"; 
					$cres = mysql_query($csql); 
					if (mysql_num_rows($cres) >= 1) 
					{
						echo "<tr class='kleurenhemel_een'><td>Strafblad: </td><td>";
						while ($row = mysql_fetch_array($cres)) 
    					{
	    					echo "- ".nl2br($row['straf'])."<br>";
    					}
    					echo "</td></tr>\n";
					}
					else
					{
						echo "<tr class='kleurenhemel_een'><td>Strafblad: </td><td>Deze persoon heeft nog niets misdaan.</td></tr>\n";
					}
					$csql = "SELECT * FROM members WHERE ip='".$ip."' AND naam!='".$_GET['naam']."' AND naam!='meiappeltaart'";
					$cres = mysql_query($csql); 
					if (mysql_num_rows($cres) >= 1) 
					{
						echo "<tr class='kleurenhemel_een'><td>Zelfde IP: </td><td>";
						while ($row = mysql_fetch_array($cres)) 
    					{
	    					echo "<a href='profiel.php?naam=".$row['naam']."'>".$row['naam']."</a><br>";
    					}
    					echo "</td></tr>\n";
					}
					else
					{
						echo "<tr class='kleurenhemel_een'><td>Zelfde IP: </td><td>Er zijn geen accounts met hetzelfde IP.</td></tr>\n";
					}
				}
				if ($tralala != "jabbo")
				{
					echo "<tr class='kleurenhemel_twee'><td>Acties: </td><td>";
					if (ISSET($_GET['action']))
					{
						if ($_GET['action'] == "warning")
						{
							if (ISSET($_GET['doe']))
							{
								$warning = $_GET['doe'];
								if ($warning == "")
								{
									$warning = $_SESSION['naam']." gaf je een waarschuwing met onbekende reden.";
								}
								else
								{
									$warning = $_SESSION['naam']." gaf je een waarschuwing met de reden:\n".$warning;
								}
								$warning = str_replace("\n", "[br]", $warning);
								mysql_query("UPDATE members SET warning='".$warning."' WHERE naam='".$_GET['naam']."';");
								if ($_GET['straf'] != "")
								{
									mysql_query("INSERT INTO strafblad SET member='".$_GET['naam']."', straf='".$_GET['straf']."';");
								}
								action("geeft ".$_GET['naam']." een waarschuwing");
								echo "Waarschuwing gegeven.";
							}
							else
							{
								echo "<form action='' method='get'>";
								echo "<input type='hidden' name='naam' value='".$_GET['naam']."'>";
								echo "<input type='hidden' name='action' value='warning'>";
								echo "<u><b>Geef ".$_GET['naam']." een waarschuwing</b></u>";
								echo "<table class='tabel' border='0'>";
								echo "<tr><td>Reden:</td><td><textarea name='doe' cols='30' rows='6'></textarea></td></tr>";
								echo "<tr><td>Voor strafblad:</td><td><textarea name='straf' cols='30' rows='6'></textarea></td></tr>";
								echo "<tr><td colspan='2'><center><input type='submit' value='Geef waarschuwing'></center></td></tr>";
								echo "</table class='tabel'>";
								echo "</form>";
							}
						}
						elseif ($_GET['action'] == "ban")
						{
							if ($ban == "yes")
							{
								mysql_query("UPDATE members SET ban = 'no' WHERE naam='".$_GET['naam']."';");
								action("deblokkeert het account van ".$_GET['naam']);
								echo "Account is gedeblokkeert.";
							}
							elseif ($ban == "no")
							{
								mysql_query("UPDATE members SET ban = 'yes' WHERE naam='".$_GET['naam']."';");
								action("blokkeert het account van ".$_GET['naam']);
								echo "Account is geblokkeert.";
							}
						}
						else
						{
							action("kiest een onbekende actie in de profielen ".$_GET['naam']);
							echo "Onbekende actie gekozen.";
						}
					}
					else
					{
						if (($tralala == "manager") or ($tralala == "staff") or ($tralala == "hoofdjobba"))
						{
							if (($tralala == "staff") and (($tralala2 == "manager") or ($tralala2 == "staff")))
							{
								echo "Je kan deze persoon niet bannen/waarschuwen.";
							}
							else
							{
								action("bekijkt het profiel van ".$_GET['naam']);
								echo "<a href='?naam=".$_GET['naam']."&action=warning'>Geef waarschuwing</a> - <a href='?naam=".$_GET['naam']."&action=ban'>";
								if ($ban == "yes")
								{
									echo "Deblokeer";
								}
								elseif ($ban == "no")
								{
									echo "Blokeer";
								}
								echo "</a>";
							}
						}
						else
						{
							if ($tralala2 != "jabbo")
							{
								echo "Je kan deze persoon niet bannen/waarschuwen.";
							}
							else
							{
								action("bekijkt het profiel van ".$_GET['naam']);
								echo "<a href='?naam=".$_GET['naam']."&action=warning'>Geef waarschuwing</a>";
							}
						}
					}
					echo "</td></tr>\n";
					echo "<tr class='kleurenhemel_een'><td></td></tr>\n";
				}
				echo "</table class='tabel'></td></tr></table class='tabel'>";
			}
			else
			{
				action("bekijkt het profiel van ".$_GET['naam']);
			}
			echo "</center><br>";
		}
		else
		{
			echo "Dit account bestaat niet.</center>";
		}
	}
	else
	{
		action("gaat naar de profielen");
		echo "<h1>Profielen</h1>";
		echo "<center>";
		echo "<form action='profiel.php' method='get'>";
		echo "<input type='text' length='20' maxlength='20' name='naam'>";
		echo "<input type='submit' value='Ga'>";
		echo "</form>";
		echo "</center><br>";
	}
}
else
{
	echo "Oeps! Hiervoor moet je aangemeld zijn!";
}
require_once('footer.php');
?>