<?
###############################################################################
# Copyright (C) 2000 Derek Leung
#
# 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 2 of the License, or
# (at your option) any later version.
#
# You may modify your copy or copies of this Program or any portion of it,
# but you must cause the modified files to carry prominent notices stating
# that you changed the files and the date of any change. And you are required
# to keep a copy of this License along with this Program.
#
# You are not required to accept this License, since you have not signed it.
# However, nothing else grants you permission to modify or distribute this
# Program or its derivative works. These actions are prohibited by law if
# you do not accept this License. Therefore, by modifying or distributing
# this Program (or any work based on this Program), you indicate your
# acceptance of this License to do so, and all its terms and conditions
# for copying, distributing or modifying this Program or works based on it.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# See the GNU General Public License for more details.
# http://www.opensource.org/licenses/gpl-license.html
###############################################################################
// the function show who is online at this moment.
require("mainfile.php");
global $config;
ps_header("");
$userArray = getCookie($config[user_cookie_name]);
// grap any users who have access our site in the last 10 minutes
$rs = mysql_query("select ipAddr,username,action,accessTime from ps_onlineUsers where NOW() - accessTime <= 1000");
while (list($ip,$username,$action,$accessTime) = mysql_fetch_row($rs)) {
$db_uname = fixquotes($username);
// now we find that user information
$result = mysql_query("select status,commentPostNum,userTitle from ps_users where uname='$db_uname'");
list($status,$postNum,$dbTitle) = mysql_fetch_row($result);
mysql_free_result($result);
// we caculate the user title base on comments he has post
if ($dbTitle == "") {
$titleList = FILE("$config[root_path]/usertitles");
foreach ($titleList as $userTitle) {
list($num,$myTitle) = split("\t",$userTitle);
if ($postNum =="") {
$postNum = 0;
}
if ($postNum >= $num) {
$newTitle = $myTitle;
}
}
if ($newTitle == "") {
$newTitle = translate("Anonymous");
$postNum = "null";
}
} else {
$newTitle = $dbTitle;
}
// put the information in either a member array or an anonymous array
if ($status == "") {
if ($userArray[status] == "Admin" || $userArray[status] == "Moderator") {
$myUser[username] = "ANON-".$ip;
} else {
$myUser[username] = "Anonymou";
}
$myUser[ts] = formatShortTimestamp($accessTime);
$myUser[action] = $action;
$anonArray[] = $myUser;
} else {
$myUser[username] = $username;
$myUser[status] = $status;
$myUser[title] = $newTitle;
$myUser[ts] = formatShortTimestamp($accessTime);
$myUser[action] = $action;
$memArray[] = $myUser;
}
$myUser = NULL;
}
mysql_free_result($rs);
// sort the array
if (sizeof($memArray) != 0) {
sort($memArray);
reset($memArray);
}
if (sizeof($anonArray) != 0) {
sort($anonArray);
reset($anonArray);
}
// we show the page now
$title = translate("Who's Online?");
?>
<table border=1 cellspacing=2 cellpadding=4 width=100% class="sidebox">
<tr>
<td class=sideboxtop valign="middle" colspan=5>
<b><font size=+1><?echo $title; ?></font></b>
</td>
</tr>
<tr>
<td valign=top width="20%" class="sidebox"><?=translate("Below is a list of Users that have been active within the last 10 minutes.");?></td>
</tr>
</table>
<br>
<?
echo translate("Current time") . ": " . date("m/d/y h:i:s A") . " $config[timezone]";
echo "<br>";
// we are doing the member array
if (sizeof($memArray) != 0) {
foreach ($memArray as $key) {
if ($key[status] == "Admin") {
$color = "red";
} elseif ($key[status] == "Moderator") {
$color = "green";
} else {
$color = "";
}
$content .= "<tr>";
$content .= "<td valign=top width=\"20%\" class=\"sidebox\"><b><font color=$color>";
$content .= $key[username];
$content .= "</font></b></td>";
$content .= "<td valign=top width=\"20%\" class=\"sidebox\">";
$content .= $key[status];
$content .= "</td>";
$content .= "<td valign=top width=\"20%\" class=\"sidebox\">";
$content .= $key[title];
$content .= "</td>";
$content .= "<td valign=top width=\"20%\" class=\"sidebox\">";
$content .= $key[ts];
$content .= "</td>";
$content .= "<td valign=top width=\"20%\" class=\"sidebox\">";
$content .= $key[action];
$content .= "</td>";
$content .= "</tr>";
}
}
$title = sprintf(translate("%s Online Member(s)"),sizeof($memArray));
?>
<table border=1 cellspacing=2 cellpadding=4 class="sidebox" width="100%">
<tr>
<td class=sideboxtop valign="middle" colspan=5>
<b><center><font size=+1><?echo $title; ?></font></center></b>
</td>
</tr>
<tr>
<td valign=top width="20%" class="sidebox"><?=translate("Username")?></td>
<td valign=top width="20%" class="sidebox"><?=translate("Status")?></td>
<td valign=top width="20%" class="sidebox"><?=translate("Title")?></td>
<td valign=top width="20%" class="sidebox"><?=translate("Last Activity")?></td>
<td valign=top width="20%" class="sidebox"><?=translate("Location")?></td>
</tr>
<?
echo $content;
unset($content,$tilte);
?>
</table>
<br>
<?
// now we are doing the anonymous user array
echo "<br><br><br>";
if (sizeof($anonArray) != 0) {
foreach ($anonArray as $key) {
$content .= "<tr>";
$content .= "<td valign=top width=\"33%\" class=\"sidebox\">";
$content .= $key[username];
$content .= "</td>";
$content .= "<td valign=top width=\"33%\" class=\"sidebox\">";
$content .= $key[ts];
$content .= "</td>";
$content .= "<td valign=top width=\"33%\" class=\"sidebox\">";
$content .= $key[action];
$content .= "</td>";
$content .= "</tr>";
}
}
$title = sprintf(translate("%s Online Guest(s)"),sizeof($anonArray));
?>
<table border=1 cellspacing=2 cellpadding=4 class="sidebox" width="100%">
<tr>
<td class=sideboxtop valign="middle" colspan=3>
<b><center><font size=+1><?echo $title; ?></font></center></b>
</td>
</tr>
<tr>
<td valign=top width="20%" class="sidebox"><?=translate("IP Address")?></td>
<td valign=top width="20%" class="sidebox"><?=translate("Last Activity")?></td>
<td valign=top width="20%" class="sidebox"><?=translate("Location")?></td>
</tr>
<?
echo $content;
unset($content,$tilte);
?>
</table>
<br>
<?
ps_footer("");
?>