<?php
/*=======================================================================
| UberCMS - Advanced Website and Content Management System for uberEmu
| #######################################################################
| Copyright (c) 2010, Roy 'Meth0d' and updates by Matthew 'MDK'
| http://www.meth0d.org & http://www.sulake.biz
| #######################################################################
| This program is free software: you can redistribute it and/or modify
| it under the terms of the GNU General Public License as published by
| the Free Software Foundation, either version 3 of the License, or
| (at your option) any later version.
| #######################################################################
| This program is distributed in the hope that it will be useful,
| but WITHOUT ANY WARRANTY; without even the implied warranty of
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
| GNU General Public License for more details.
\======================================================================*/

require_once "global.php";

if (!LOGGED_IN)
{
	header("Location: ".WWW);
	exit;
}

$result = dbquery("SELECT `user_two_id` FROM `messenger_friendships` WHERE `user_one_id` = '".USER_ID."' LIMIT 10;");
$num = mysql_num_rows($result);
if ($num == 0)
{
	echo "<ul>Friends Offline</ul>";
}
else
{
	$friends = array("online" => array(), "offline" => array());
	while ($row = mysql_fetch_array($result, MYSQL_NUM))
	{
		if ($users->Is_Online($row[0]))
		{
			$friends['online'][] = $users->Id2Name($row[0]);
		}
		else
		{
			$friends['offline'][] = $users->Id2Name($row[0]);
		}
	}

	echo "<ul><li><center><b>Note:</b> <small><i>This shows max. 10 friends!</small></i></center></li></ul>";

	if($friends['online'])
	{
		echo "<div class=\"qtab-subtitle even\"><div class=\"qtab-category\">Online friends</div></div>";
		echo "<ul id=\"online-friends\">";

		$oddeven = "even";

		foreach($friends['online'] as $friend)
		{
			if ($oddeven == "even")
			{
				$oddeven = "odd";
			}
			else if ($oddeven == "odd")
			{
				$oddeven = "even";
			}
			echo "<li class='".$oddeven."'><a href='/home/".$friend."'>".$friend."</a></li>";
		}

		echo "</ul>";
	}

	if($friends['offline'])
	{
		echo "<div class=\"qtab-subtitle even\"><div class=\"qtab-category\">Offline friends</div></div>";
		echo "<ul id=\"offline-friends\">";

		$oddeven = "even";

		foreach($friends['offline'] as $friend)
		{
			if ($oddeven == "even")
			{
				$oddeven = "odd";
			}
	        	else if ($oddeven == "odd")
			{
				$oddeven = "even";
			}
			echo "<li class='".$oddeven."'><a href='/home/".$friend."'>".$friend."</a></li>";
		}

		echo "</ul>";
	}
}

echo "<p class='manage-friends'><a href='".WWW."/profile/friendsmanagement?tab=6'>Friend management</a></p>";
?>