<?php
require_once("config_sql.php");
$login_ok = "nee";
if((ISSET($_GET['jouwnaam'])) && (ISSET($_GET['pass'])))
{
	$ok_pass = halen("SELECT wachtwoord FROM members WHERE naam='".$_GET['jouwnaam']."';");
	$ok_functie = halen("SELECT functie FROM members WHERE naam='".$_GET['jouwnaam']."';");
	if ($ok_pass == $_GET['pass'])
	{
		$login_ok = "ja";
	}
}
if (($hotel_status == "online") && ($login_ok == "ja"))
{
	$_GET['missie'] = str_replace ("'", "", $_GET['missie']);
	$_GET['missie'] = str_replace ('"', "", $_GET['missie']);
	mysql_query("UPDATE members SET console='".$_GET['missie']."' WHERE naam='".$_GET['jouwnaam']."';");
	$aantal_berichten = 0;
	$aantal_vv = 0;
	$aantal_v = 0;
	echo "vv_array = '';";
	echo "vv_array = new Array();";
	echo "v_array = '';";
	echo "v_array = new Array();";
	echo "m_array = '';";
	echo "m_array = new Array();";
	$sql = mysql_query("SELECT * FROM vrienden WHERE vriend='".$_GET['jouwnaam']."';");
	if (mysql_num_rows($sql) >= 1) 
	{
		while ($row = mysql_fetch_array($sql)) 
	    {
		    $check = mysql_num_rows(mysql_query("SELECT * FROM vrienden WHERE eigenaar='".$_GET['jouwnaam']."' AND vriend='".$row['eigenaar']."' AND verzoek='nee';"));
		    if ($check != 1)
		    {
				echo "vv_array[".$aantal_vv."] = new Array();";
				echo "vv_array[".$aantal_vv."]['id'] = ".$row['id'].";";
				echo "vv_array[".$aantal_vv."]['naam'] = '".$row['eigenaar']."';";
				$aantal_vv++;
		    }
	    }
    }
    $sql = mysql_query("SELECT * FROM vrienden WHERE eigenaar='".$_GET['jouwnaam']."' AND verzoek='nee';");
	if (mysql_num_rows($sql) >= 1) 
	{
		while ($row = mysql_fetch_array($sql)) 
	    {
		    $check = mysql_num_rows(mysql_query("SELECT * FROM vrienden WHERE eigenaar='".$row['vriend']."' AND vriend='".$_GET['jouwnaam']."' AND verzoek='nee';"));
		    if ($check == 1)
		    {
			    $check_online = mysql_num_rows(mysql_query("SELECT * FROM members WHERE DATE_SUB(NOW(),INTERVAL 2 MINUTE) <= last_online2 AND naam='".$row['vriend']."';"));
			    $check_id = halen("SELECT id FROM members WHERE naam='".$row['vriend']."';");
			    $console = halen("SELECT console FROM members WHERE naam='".$row['vriend']."';");
			    if ($check_online == 1)
	    		{
		    		echo "v_array[".$aantal_v."] = new Array();";
		    		echo "v_array[".$aantal_v."]['id'] = '".$check_id."';";
		    		echo "v_array[".$aantal_v."]['naam'] = '".$row['vriend']."';";
					echo "v_array[".$aantal_v."]['online'] = 'online';";
					echo "v_array[".$aantal_v."]['missie'] = '\"".$console."\"';";
					$aantal_v++;
	    		}
		    }
	    }
    }
    $sql = mysql_query("SELECT * FROM vrienden WHERE eigenaar='".$_GET['jouwnaam']."' AND verzoek='nee';");
	if (mysql_num_rows($sql) >= 1) 
	{
		while ($row = mysql_fetch_array($sql)) 
	    {
		    $check = mysql_num_rows(mysql_query("SELECT * FROM vrienden WHERE eigenaar='".$row['vriend']."' AND vriend='".$_GET['jouwnaam']."' AND verzoek='nee';"));
		    if ($check == 1)
		    {
			    $check_online = mysql_num_rows(mysql_query("SELECT * FROM members WHERE DATE_SUB(NOW(),INTERVAL 2 MINUTE) <= last_online2 AND naam='".$row['vriend']."';"));
			    $check_id = halen("SELECT id FROM members WHERE naam='".$row['vriend']."';");
			    $console = halen("SELECT console FROM members WHERE naam='".$row['vriend']."';");
			    $last_online2 = halen("SELECT last_online FROM members WHERE naam='".$row['vriend']."';");
			    if ($check_online != 1)
	    		{
		    		echo "v_array[".$aantal_v."] = new Array();";
		    		echo "v_array[".$aantal_v."]['id'] = '".$check_id."';";
		    		echo "v_array[".$aantal_v."]['naam'] = '".$row['vriend']."';";
					echo "v_array[".$aantal_v."]['online'] = '".$last_online2."';";
					echo "v_array[".$aantal_v."]['missie'] = '\"".$console."\"';";
					$aantal_v++;
	    		}
		    }
	    }
    }
    $sql = mysql_query("SELECT * FROM berichten WHERE voor='".$_GET['jouwnaam']."' AND `read`='nee';");
	if (mysql_num_rows($sql) >= 1) 
	{
		while ($row = mysql_fetch_array($sql)) 
	    {
			$check_id = halen("SELECT id FROM members WHERE naam='".$row['van']."';");
		 	echo "m_array[".$aantal_berichten."] = new Array();";
		   	echo "m_array[".$aantal_berichten."]['id'] = '".$row['id']."';";
		   	echo "m_array[".$aantal_berichten."]['datum'] = '".$row['datum']."';";
		   	echo "m_array[".$aantal_berichten."]['van_id'] = '".$check_id."';";
			echo "m_array[".$aantal_berichten."]['van_naam'] = '".$row['van']."';";
			echo "m_array[".$aantal_berichten."]['bericht'] = '".$row['bericht']."';";
			$aantal_berichten++;
	    }
    }
    echo "aantal_berichten = ".$aantal_berichten.";";
    echo "aantal_vv = ".$aantal_vv.";";
    echo "aantal_v = ".$aantal_v.";";
    echo "verwerken1 = 0;";
    echo "verwerken2 = 0;";
}
?>