<?php
	/* WebWall */
	define("ONLINE", 1);
	$root = dirname( dirname( dirname(__FILE__) ) );
	require_once "$root/core.php";
	$get["data"] = "STATUS";
	define("NR_USERS", text_filter(ucfirst(strtolower($_GET["unr"])), 1), true);
	define("PROFILE_USER", text_filter(ucfirst(strtolower($_GET["user"])), 1), true);
	$info = $engine_session->getuserdata(PROFILE_USER, "*");
	define("PROFILE_PHOTO", $info['photo'], true);
	define("PROFILE_REAL_NAME", $info['real_name'], true);
	define("PROFILE_REAL_SURNAME", $info['real_surname'], true);
	define("PROFILE_ANONYMOUS", $info['anonymous_view'], true);
	define("GIFTS", $engine_session->getuserdata(PROFILE_USER, "GIFTS"), true);
	if($engine_session->profileuserexists(''.PROFILE_USER.'') != 0) { $result["userExists"] = true; } else { $result["userExists"] = false; }
	if($engine_session->getuserdata(''.PROFILE_USER.'', $get["data"]) != 0) { $result["userStatus"] = true; } else { $result["userStatus"] = false; }
	if($engine_session->getuserdata(''.PROFILE_USER.'', "A_VIEW") == 0 && SESSION_STATUS == false) { $result["userView"] = true; } else { $result["userView"] = false; }
	
	function getgifts($user,$nr,$users)
	{
		$message = '';
		if($users=='') $users=100;
		$sqlquery = "SELECT * FROM gifts WHERE to_user = '".$user."' ORDER BY time DESC limit ".$nr.", ".$users."";
		$query = mysql_query($sqlquery);
		if(mysql_num_rows($query) != 0)
		{	
			while($iii = mysql_fetch_assoc($query))
			{	
				$gift_id = $iii['gift_id'];
				$date = $iii['time'];
				$from_user = $iii['from_user'];
				$type = $iii['type'];
				$sqlimage = @mysql_query("SELECT image FROM giftstype WHERE id = '".$iii['gift_id']."'") or die(mysql_error());
				$readimage = @mysql_fetch_assoc($sqlimage);
				$image = $readimage["image"];
				$sqlname = @mysql_query("SELECT real_name, real_surname, photo, user_status FROM users WHERE username = '".$iii['from_user']."'") or die(mysql_error());
				$readname = @mysql_fetch_assoc($sqlname);
				$name = $readname["real_name"];
				$surname = $readname["real_surname"];
				$unknown = ANONYMOUS;
				$message .= "<div class='tcpeople'><div class='tccounter'></div>";
				if($image)
				{
					if($type==0)
					{
						$message .= "<div class='tcimage'><img src='http://".SITE_DOMAIN."/media/images/users/photo_anonymous.png' width='75px' height='75px'></div>";
						$message .= '<div class="tcinfo"><p class="name">'.$unknown.'</p><p>'.counttime(usertime($date)).'</p></div>';			
						$message .= "<div class='tcfoll'>";
						$message .= '<img src="http://'.SITE_DOMAIN.'/media/images/gifts/'.$image.'" width="75" />';
						$message .= "</div>";
						$message .= "<div class='clear'></div></div>";
					}
					if($type==1)
					{
						if($iii['to_user']==USER_USERNAME)
						{
							$message .= "<div class='tcimage'><a href='http://" . SITE_DOMAIN . "/" . $iii['from_user'] . "'><div class='img imgLiquid' style='width:75px; height:75px'><img src='http://".SITE_DOMAIN."/media/images/users/".$readname["photo"]."' width='75px' height='75px' /></div></a></div>";
						}
						else
						{
							$message .= "<div class='tcimage'><img src='http://".SITE_DOMAIN."/media/images/users/photo_anonymous.png' width='75px' height='75px' /></div>";
						}
						$message .= '<div class="tcinfo">';
						if($iii['to_user']==USER_USERNAME)
						{
							$message .= '<a href="http://' . SITE_DOMAIN . '/' . $iii['from_user'] . '"><p>@'.$iii['from_user'].'</p></a>';
						}
						else
						{
							$message .= '<p class="name">'.$unknown.'</p>';
						}
						$message .= '<p>'.counttime(usertime($date)).'</p></div>';			
						$message .= "<div class='tcfoll'>";
						$message .= '<img src="http://'.SITE_DOMAIN.'/media/images/gifts/'.$image.'" width="75" />';
						$message .= "</div>";
						$message .= "<div class='clear'></div></div>";
					}
					if($type==2)
					{
						$message .= "<div class='tcimage'><a href='http://" . SITE_DOMAIN . "/" . $iii['from_user'] . "'><div class='img imgLiquid' style='width:75px; height:75px'><img src='http://".SITE_DOMAIN."/media/images/users/".$readname["photo"]."' width='75px' height='75px' /></div></a></div>";
						$message .= '<div class="tcinfo">';
						$message .= '<a href="http://' . SITE_DOMAIN . '/' . $iii['from_user'] . '"><p>@'.$iii['from_user'].'</p></a>';
						$message .= '<p>'.counttime(usertime($date)).'</p></div>';			
						$message .= "<div class='tcfoll'>";
						$message .= '<img src="http://'.SITE_DOMAIN.'/media/images/gifts/'.$image.'" width="75" />';
						$message .= "</div>";
						$message .= "<div class='clear'></div></div>";
					}
				}
			}
		}
		echo $message;
	}

	if($result["userExists"] != false)
	{
		if($result["userStatus"] != false)
		{
			$template_session->loadhead(''.PROFILE_USER.' - ('.PROFILE_REAL_NAME.' '.PROFILE_REAL_SURNAME.')');
			$template_session->loadlogo(); 
			$template_session->loadmenu(); 
			if($result["userView"] != false || $result["access"] != false)
			{
				$template_session->addline('<center>');
				$template_session->loadtpl("security");
				$template_session->addline('</center>');
			}
			else
			{
				$template_session->loadtpl("gifts");
			}
			
			$template_session->loadtpl("footer");
			$template_session->loadend();
		}
		else
		{
			header('Location: http://'.SITE_DOMAIN.'/site/disabled');
		}
	}
	else
	{
		header('Location: http://'.SITE_DOMAIN.'/site/error');
	}
?>