<?php
/*
 ########################################################################
#                                                                        #
#           Version 4       /                        /   /               #
#          -----------__---/__---__------__----__---/---/-               #
#           | /| /  /___) /   ) (_ `   /   ) /___) /   /                 #
#          _|/_|/__(___ _(___/_(__)___/___/_(___ _/___/___               #
#                       Free Content / Management System                 #
#                                   /                                    #
#                                                                        #
#                                                                        #
#   Copyright 2005-2006 by webspell.org                                  #
#                                                                        #
#   visit webSPELL.org, webspell.info to get webSPELL for free           #
#   - Script runs under the GNU GENERAL PUBLIC LICENSE                   #
#   - It's NOT allowed to remove this copyright-tag                      #
#   -- http://www.fsf.org/licensing/licenses/gpl.html                    #
#                                                                        #
#   Code based on WebSPELL Clanpackage (Michael Gruber - webspell.at),   #
#   Far Development by Development Team - webspell.org                   #
#                                                                        #
#   visit webspell.org                                                   #
#                                                                        #
 ########################################################################
*/

// WHO IS ONLINE

eval ("\$title_whoisonline = \"".gettemplate("title_whoisonline")."\";");
echo $title_whoisonline;

$result_guests = safe_query("SELECT * FROM ".PREFIX."whoisonline WHERE userID=''");
$guests = mysql_num_rows($result_guests);
$result_user = safe_query("SELECT * FROM ".PREFIX."whoisonline WHERE ip=''");
$user = mysql_num_rows($result_user);
$useronline = $guests + $user;
if($user==1) $user_on='<b>1</b> registered user';
else $user_on='<b>'.$user.'</b> registered users';

if($guests==1) $guests_on='<b>1</b> guest';
else $guests_on= '<b>'.$guests.'</b> guests';

$online='Now online: '.$user_on.' and '.$guests_on;

$sort = $_GET['sort'];
$type = $_GET['type'];
if(!isset($sort)) $sort = "time";
if(!isset($type)) $type = "DESC";


if($type=="ASC")
		    $sorter='<a href="index.php?site=whoisonline&sort='.$sort.'&type=DESC">Sort:</a> <img src="images/icons/asc.gif" width="9" height="7" border="0">';
		else
		    $sorter='<a href="index.php?site=whoisonline&sort='.$sort.'&type=ASC">Sort:</a> <img src="images/icons/desc.gif" width="9" height="7" border="0">';

echo'<table width="100%" border="0" cellspacing="0" cellpadding="2">
       <tr>
	     <td>'.$sorter.'</td>
		 <td align="right">'.$online.'</td>
	   </tr>
	 </table><br>';

$ergebnis = safe_query("SELECT * FROM ".PREFIX."whoisonline ORDER BY $sort $type");

eval ("\$whoisonline_head = \"".gettemplate("whoisonline_head")."\";");
echo $whoisonline_head;

$n=1;
while($ds=mysql_fetch_array($ergebnis)) {
    if($n%2) {
		$bg1=BG_1;
		$bg2=BG_2;
	}
	else {
		$bg1=BG_3;
		$bg2=BG_4;
	}
	if($ds[ip]=='') {
		$nickname='<a href="index.php?site=profile&id='.$ds[userID].'"><b>'.$ds[nickname].'</b></a>';
		if(isclanmember($ds[userID])) $member=' <img src="images/icons/member.gif" width="6" height="11" alt="Clanmember">';
		else $member='';
		$email='<a href="mailto:'.getemail($ds[userID]).'"><img src="images/icons/email.gif" border="0" width="15" height="11" alt="e-mail"></a>';

		$country='[flag]'.getcountry($ds[userID]).'[/flag]';
		$country=flags($country);
		$sem = '^[http://]+[a-z0-9_\.-]+[a-z0-9_-]+$';
	    if(!(eregi($sem, $ds[clanhp]))) $homepage='';
		else $homepage='<a href="'.gethomepage($ds[userID]).'" target="_blank"><img src="images/icons/hp.gif" border="0" width="14" height="14" alt="homepage"></a>';

		$pm='';
		$buddy='';
		if($loggedin && $ds[userID] != $userID) {
			$pm='<a href="index.php?site=messenger&action=touser&touser='.$ds[userID].'"><img src="images/icons/pm.gif" border="0" width="12" height="13" alt="messenger"></a>';
			if(isignored($userID, $ds[userID])) $buddy='<a href="buddys.php?action=readd&id='.$ds[userID].'&userID='.$userID.'"><img src="images/icons/buddy_readd.gif" width="16" height="16" border="0" alt="back to buddy-list"></a>';
			elseif(isbuddy($userID, $ds[userID])) $buddy='<a href="buddys.php?action=ignore&id='.$ds[userID].'&userID='.$userID.'"><img src="images/icons/buddy_ignore.gif" width="16" height="16" border="0" alt="ignore user"></a>';
			elseif($userID==$ds[userID]) $buddy='';
			else $buddy='<a href="buddys.php?action=add&id='.$ds[userID].'&userID='.$userID.'"><img src="images/icons/buddy_add.gif" width="16" height="16" border="0" alt="add to buddylist"></a>';
		}
	}
	else {
		$nickname="Guest";
		$member="";
		$email="";
		$country="";
		$homepage="";
		$pm="";
		$buddy="";
	}

	if($ds[site]=="articles") $status='is reading <a href="index.php?site=articles">articles</a>';
	elseif($ds[site]=="about") $status='is reading the <a href="index.php?site=about">about</a>';
	elseif($ds[site]=="awards") $status='is watching the <a href="index.php?site=awards">awards</a>';
	elseif($ds[site]=="buddys") $status='is watching his <a href="index.php?site=buddys">buddys</a>';
	elseif($ds[site]=="calendar") $status='is watching the <a href="index.php?site=calendar">calendar</a>';
	elseif($ds[site]=="clans") $status='is watching the <a href="index.php?site=clans">clanlist</a>';
	elseif($ds[site]=="clanwars") $status='is watching the <a href="index.php?site=clanwars">clanwars</a>';
	elseif($ds[site]=="clanwars_details") $status='is watching the details of a clanwar';
	elseif($ds[site]=="contact") $status='is reading the <a href="index.php?site=contact">contact information</a>';
	elseif($ds[site]=="counter_stats") $status='is watching the <a href="index.php?site=counter_stats">counter statistics</a>';
	elseif($ds[site]=="demos") $status='is watching the <a href="index.php?site=demos">demos</a>';
	elseif($ds[site]=="faq") $status='is reading the <a href="index.php?site=faq">FAQ</a>';
	elseif($ds[site]=="files") $status='is watching the <a href="index.php?site=files">files</a>';
	elseif($ds[site]=="forum") $status='is watching the <a href="index.php?site=forum">forum</a>';
	elseif($ds[site]=="forum_topic") $status='is reading the forum';
	elseif($ds[site]=="gallery") $status='is watching the <a href="index.php?site=gallery">gallery</a>';
	elseif($ds[site]=="guestbook") $status='is reading the <a href="index.php?site=guestbook">guestbook</a>';
	elseif($ds[site]=="history") $status='is reading the <a href="index.php?site=history">history</a>';
	elseif($ds[site]=="imprint") $status='is reading the <a href="index.php?site=imprint">imprint</a>';
	elseif($ds[site]=="links") $status='is watching the <a href="index.php?site=links">links</a>';
	elseif($ds[site]=="linkus") $status='is watching <a href="index.php?site=linkus">link us</a>';
	elseif($ds[site]=="loginoverview") $status='is watching the <a href="index.php?site=loginoverview">loginoverview</a>';
	elseif($ds[site]=="members") $status='is watching the <a href="index.php?site=members">members</a>';
	elseif($ds[site]=="messenger") $status='is watching his <a href="index.php?site=messenger">messenger</a>';
	elseif($ds[site]=="myprofile") $status='is editing his <a href="index.php?site=profile&id='.$ds[userID].'">profile</a>';
	elseif($ds[site]=="news_comments") $status='is reading newscomments';
	elseif($ds[site]=="polls") $status='is watching the <a href="index.php?site=polls">polls</a>';
	elseif($ds[site]=="profile") $status='is watching a profile';
	elseif($ds[site]=="registered_users") $status='is watching the <a href="index.php?site=registered_users">registered users</a>';
	elseif($ds[site]=="server") $status='is watching the <a href="index.php?site=server">server</a>';
	elseif($ds[site]=="sponsors") $status='is watching the <a href="index.php?site=sponsors">sponsors</a>';
	elseif($ds[site]=="squads") $status='is watching the <a href="index.php?site=squads">squads</a>';
	elseif($ds[site]=="whoisonline") $status='is watching <a href="index.php?site=whoisonline">who is online</a>';

	else $status='is watching the <a href="index.php?site=news">news</a>';

	eval ("\$whoisonline_content = \"".gettemplate("whoisonline_content")."\";");
	echo $whoisonline_content;
	$n++;
}

eval ("\$whoisonline_foot = \"".gettemplate("whoisonline_foot")."\";");
echo $whoisonline_foot;


// WHO WAS ONLINE

echo'<br><br><a name="was"></a><h2>WHO WAS ONLINE (last 24H)</h2>';

if(!isset($sort)) $sort = "time";
if(!isset($type)) $type = "DESC";


if($type=="ASC")
		    $sorter='<a href="index.php?site=whoisonline&sort='.$sort.'&type=DESC">Sort:</a> <img src="images/icons/asc.gif" width="9" height="7" border="0">';
		else
		    $sorter='<a href="index.php?site=whoisonline&sort='.$sort.'&type=ASC">Sort:</a> <img src="images/icons/desc.gif" width="9" height="7" border="0">';

echo'<table width="100%" border="0" cellspacing="0" cellpadding="2">
       <tr>
	     <td>'.$sorter.'</td>
	   </tr>
	 </table><br>';

$ergebnis = safe_query("SELECT * FROM ".PREFIX."whowasonline ORDER BY $sort $type");

eval ("\$whowasonline_head = \"".gettemplate("whowasonline_head")."\";");
echo $whowasonline_head;

$n=1;
while($ds=mysql_fetch_array($ergebnis)) {
    if($n%2) {
		$bg1=BG_1;
		$bg2=BG_2;
	}
	else {
		$bg1=BG_3;
		$bg2=BG_4;
	}

	$date=date("d.m.Y - H:i", $ds[time]);
	$nickname='<a href="index.php?site=profile&id='.$ds[userID].'"><b>'.$ds[nickname].'</b></a>';
	if(isclanmember($ds[userID])) $member=' <img src="images/icons/member.gif" width="6" height="11" alt="Clanmember">';
	else $member='';
	$email='<a href="mailto:'.getemail($ds[userID]).'"><img src="images/icons/email.gif" border="0" width="15" height="11" alt="e-mail"></a>';

	$country='[flag]'.getcountry($ds[userID]).'[/flag]';
	$country=flags($country);
	$sem = '^[http://]+[a-z0-9_\.-]+[a-z0-9_-]+$';
    if(!(eregi($sem, $ds[clanhp]))) $homepage='';
	else $homepage='<a href="'.gethomepage($ds[userID]).'" target="_blank"><img src="images/icons/hp.gif" border="0" width="14" height="14" alt="homepage"></a>';

	$pm='';
	$buddy='';
	if($loggedin && $ds[userID] != $userID) {
		$pm='<a href="index.php?site=messenger&action=touser&touser='.$ds[userID].'"><img src="images/icons/pm.gif" border="0" width="12" height="13" alt="messenger"></a>';
		if(isignored($userID, $ds[userID])) $buddy='<a href="buddys.php?action=readd&id='.$ds[userID].'&userID='.$userID.'"><img src="images/icons/buddy_readd.gif" width="16" height="16" border="0" alt="back to buddy-list"></a>';
		elseif(isbuddy($userID, $ds[userID])) $buddy='<a href="buddys.php?action=ignore&id='.$ds[userID].'&userID='.$userID.'"><img src="images/icons/buddy_ignore.gif" width="16" height="16" border="0" alt="ignore user"></a>';
		elseif($userID==$ds[userID]) $buddy='';
		else $buddy='<a href="buddys.php?action=add&id='.$ds[userID].'&userID='.$userID.'"><img src="images/icons/buddy_add.gif" width="16" height="16" border="0" alt="add to buddylist"></a>';
	}

	if($ds[site]=="articles") $status='was reading <a href="index.php?site=articles">articles</a>';
	elseif($ds[site]=="about") $status='was reading the <a href="index.php?site=about">about</a>';
	elseif($ds[site]=="awards") $status='was watching the <a href="index.php?site=awards">awards</a>';
	elseif($ds[site]=="buddys") $status='was watching his <a href="index.php?site=buddys">buddys</a>';
	elseif($ds[site]=="calendar") $status='was watching the <a href="index.php?site=calendar">calendar</a>';
	elseif($ds[site]=="clans") $status='was watching the <a href="index.php?site=clans">clanlist</a>';
	elseif($ds[site]=="clanwars") $status='was watching the <a href="index.php?site=clanwars">clanwars</a>';
	elseif($ds[site]=="clanwars_details") $status='was watching the details of a clanwar';
	elseif($ds[site]=="contact") $status='was reading the <a href="index.php?site=contact">contact information</a>';
	elseif($ds[site]=="counter_stats") $status='was watching the <a href="index.php?site=counter_stats">counter statistics</a>';
	elseif($ds[site]=="demos") $status='was watching the <a href="index.php?site=demos">demos</a>';
	elseif($ds[site]=="faq") $status='was reading the <a href="index.php?site=faq">FAQ</a>';
	elseif($ds[site]=="files") $status='was watching the <a href="index.php?site=files">files</a>';
	elseif($ds[site]=="forum") $status='was watching the <a href="index.php?site=forum">forum</a>';
	elseif($ds[site]=="forum_search") $status='was searching the forum';
	elseif($ds[site]=="forum_topic") $status='was reading the forum';
	elseif($ds[site]=="guestbook") $status='was reading the <a href="index.php?site=guestbook">guestbook</a>';
	elseif($ds[site]=="history") $status='was reading the <a href="index.php?site=history">history</a>';
	elseif($ds[site]=="interviews") $status='was reading <a href="index.php?site=interviews">interviews</a>';
	elseif($ds[site]=="leagues") $status='was watching the <a href="index.php?site=leagues">leagues</a>';
	elseif($ds[site]=="links") $status='was watching the <a href="index.php?site=links">links</a>';
	elseif($ds[site]=="linkus") $status='was watching <a href="index.php?site=linkus">link us</a>';
	elseif($ds[site]=="loginoverview") $status='was watching the <a href="index.php?site=loginoverview">loginoverview</a>';
	elseif($ds[site]=="members") $status='was watching the <a href="index.php?site=members">members</a>';
	elseif($ds[site]=="messenger") $status='was watching his <a href="index.php?site=messenger">messenger</a>';
	elseif($ds[site]=="myprofile") $status='was editing his <a href="index.php?site=profile&id='.$ds[userID].'">profile</a>';
	elseif($ds[site]=="news_comments") $status='was reading newscomments';
	elseif($ds[site]=="polls") $status='was watching the <a href="index.php?site=polls">polls</a>';
	elseif($ds[site]=="profile") $status='was watching a profile';
	elseif($ds[site]=="registered_users") $status='was watching the <a href="index.php?site=registered_users">registered users</a>';
	elseif($ds[site]=="server") $status='was watching the <a href="index.php?site=server">server</a>';
	elseif($ds[site]=="sponsors") $status='was watching the <a href="index.php?site=sponsors">sponsors</a>';
	elseif($ds[site]=="whoisonline") $status='was watching <a href="index.php?site=whoisonline">who is online</a>';
	else $status='was watching the <a href="index.php?site=news">news</a>';

	eval ("\$whowasonline_content = \"".gettemplate("whowasonline_content")."\";");
	echo $whowasonline_content;
	$n++;
}

eval ("\$whoisonline_foot = \"".gettemplate("whoisonline_foot")."\";");
echo $whoisonline_foot;
?>