<?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("FOLLOWERS", $engine_session->getuserrelations(PROFILE_USER, "FOLLOWERS"), 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 getfollowers($user,$nr,$users)
	{
		$message = '';
		if($users=='') $users=100;
		$sqlquery = "SELECT DISTINCT username FROM users_friends WHERE friend = '".$user."' AND status = '1' ORDER BY time DESC limit ".$nr.", ".$users."";
		$query = mysql_query($sqlquery);
		if(mysql_num_rows($query) != 0)
		{	
			while($ii = mysql_fetch_assoc($query))
			{	
				$user_id = $ii['username']; 
				$sql = "SELECT * FROM users WHERE username = '$user_id' ORDER BY visit DESC";
				$userquery = mysql_query($sql);
				if(@mysql_num_rows($userquery) != 0)
				{
					while($iii = mysql_fetch_assoc($userquery))
					{
						$message .= "<div class='tcpeople'><div class='tccounter'></div>";
						$username = $iii['username'];
		                $photo = $iii['photo'];
		                $time = counttime(usertime($iii['visit']));
						$now = ''.langVar(861).'';
						$somesecondsago = ''.langVar(855).'';
						if($time==$now || strlen(strstr($time,$somesecondsago))>0)
						{ 
							$visit = '<img src="http://'.SITE_DOMAIN.'/media/images/online.gif" />';
						} 
						else
						{ 
							$visit = langVar(34).': '.counttime(usertime($iii['visit']));
						}
						if (file_exists('../../media/images/users/' . $photo . ''))
						{
		                    $image = "<a href='http://" . SITE_DOMAIN . "/" . $username . "'><div class='img imgLiquid' style='width:75px; height:75px'><img src='http://" . SITE_DOMAIN . "/media/images/users/" . $photo . "' class='ppphoto'></div></a>";
		                } 
						else 
						{
		                    $image = "<a href='http://" . SITE_DOMAIN . "/" . $username . "'><div class='img imgLiquid' style='width:75px; height:75px'><img src='http://" . SITE_DOMAIN . "/media/images/users/photo_default.png' class='ppphoto'></div></a>";
		                }
						$status = $iii['what_ask'];
						$message .= "<div class='tcimage'>".$image."</div>";
						$message .= '<div class="tcinfo""><a href="http://' . SITE_DOMAIN . '/' . $username . '"><p>'.$username.'</p></a><p>'.$status.'</p><p>'.$visit.'</p></div>';
						$message .= "<div class='tcfoll'>";
						if ($username != USER_USERNAME && USER_USERNAME!="") 
						{
		                    $queryfollow = "SELECT * FROM users_friends WHERE username = '" . USER_USERNAME . "' and friend = '" . $username . "'";
		                    $resultfollow = mysql_query($queryfollow);
		                    $follow = mysql_num_rows($resultfollow);
		                    if ($follow > 0) 
		                    {
		                        $end = "<span class='followb$username'><a class='btn btn-danger' name='removefriend' onclick=removefr('$username'); return false;>" . langVar(411) . "</a></span>";
		                    } 
		                    else 
		                    {
		                        $end = "<span class='followb$username'><a class='btn btn-success' name='addfriend' onclick=addfr('$username'); return false;>" . langVar(410) . "</a></span>";
		                    }
		                }
		                else $end = "";
						$message .= $end."</div><div class='clear'></div></div>";
						$i++;
					}
				}
			}
		}
		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("followers");
			}
			
			$template_session->loadtpl("footer");
			$template_session->loadend();
		}
		else
		{
			header('Location: http://'.SITE_DOMAIN.'/site/disabled');
		}
	}
	else
	{
		header('Location: http://'.SITE_DOMAIN.'/site/error');
	}
?>