Hey folks!
So get ready for some agonizingly sloppy code, because I'm an amateur here.
I've been playing around with index.php in order to tweak the "What's Going On" box. I wanted it to list only registered users and mods (id: 2 & 7) as "Currently Active Users", and instead of guests representing unregistered users (who have no access to the board anyhow), I wanted that variable to reflect the number of browsing users who had yet to be moderated (id: 4 -- we allow unmoderated users to browse only, but not post). Those who haven't confirmed their email yet (id: 3), have no access at all.
Since only fully registered users' names have been approved, we only wanted to list them (not folks awaiting email verification nor moderation). My boss panicked a few times when it appeared as if students had managed to sign up with lewd usernames, so that's why he's got me doing this.
So I think I've got it all done (albeit sloppily, as I said), except that there's always an extra comma somewhere (plus one extra user in the active user count), and since it's right after the logged in user when in alpha order, I'm assuming it's reading me twice.
Any ideas? It says BIOME_EDIT wherever I changed something...
PHP Code:
// ### LOGGED IN USERS #################################################
$activeusers = '';
if (($vbulletin->options['displayloggedin'] == 1 OR $vbulletin->options['displayloggedin'] == 2 OR ($vbulletin->options['displayloggedin'] > 2 AND $vbulletin->userinfo['userid'])) AND !$show['search_engine'])
{
$datecut = TIMENOW - $vbulletin->options['cookietimeout'];
$numbervisible = 0;
$numberregistered = 0;
$numberguest = 0;
$hook_query_fields = $hook_query_joins = $hook_query_where = '';
($hook = vBulletinHook::fetch_hook('forumhome_loggedinuser_query')) ? eval($hook) : false;
$forumusers = $db->query_read_slave("
SELECT
user.username, (user.options & " . $vbulletin->bf_misc_useroptions['invisible'] . ") AS invisible, user.usergroupid,
session.userid, session.inforum, session.lastactivity,
IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid, infractiongroupid
$hook_query_fields
FROM " . TABLE_PREFIX . "session AS session
LEFT JOIN " . TABLE_PREFIX . "user AS user ON(user.userid = session.userid)
$hook_query_joins
WHERE session.lastactivity > $datecut
$hook_query_where
" . iif($vbulletin->options['displayloggedin'] == 1 OR $vbulletin->options['displayloggedin'] == 3, "ORDER BY username ASC") . "
");
if ($vbulletin->userinfo['userid'])
{
// fakes the user being online for an initial page view of index.php
$vbulletin->userinfo['joingroupid'] = iif($vbulletin->userinfo['displaygroupid'], $vbulletin->userinfo['displaygroupid'], $vbulletin->userinfo['usergroupid']);
$userinfos = array
(
$vbulletin->userinfo['userid'] => array
(
'userid' =>& $vbulletin->userinfo['userid'],
'username' =>& $vbulletin->userinfo['username'],
'invisible' =>& $vbulletin->userinfo['invisible'],
'inforum' => 0,
'lastactivity' => TIMENOW,
'usergroupid' =>& $vbulletin->userinfo['usergroupid'],
'displaygroupid' =>& $vbulletin->userinfo['displaygroupid'],
'infractiongroupid' =>& $vbulletin->userinfo['infractiongroupid'],
)
);
}
else
{
$userinfos = array();
}
$inforum = array();
while ($loggedin = $db->fetch_array($forumusers))
{
$usergroupid = $loggedin['usergroupid']; //BIOME_EDIT
$userid = $loggedin['userid'];
if ($usergroupid == 4)
{ // Guest BIOME_EDIT(Pending)
$numberguest++;
//**BIOME_EDIT $inforum["$loggedin[inforum]"]++;
}
else if (empty($userinfos["$userid"]) OR ($userinfos["$userid"]['lastactivity'] < $loggedin['lastactivity']))
{
$userinfos["$userid"] = $loggedin;
}
}
//**BIOME_EDIT
// if (!$vbulletin->userinfo['userid'] AND $numberguest == 0)
// {
// $numberguest++;
// }
//
if ($userinfos["$userid"]['usergroupid'] == 2 OR $userinfos["$userid"]['usergroupid'] == 5 OR $userinfos["$userid"]['usergroupid']== 6 OR $userinfos["$userid"]['usergroupid'] == 7)
{
foreach ($userinfos AS $userid => $loggedin)
{
$numberregistered++;
if ($userid != $vbulletin->userinfo['userid'])
{
$inforum["$loggedin[inforum]"]++;
}
fetch_musername($loggedin);
($hook = vBulletinHook::fetch_hook('forumhome_loggedinuser')) ? eval($hook) : false;
if (fetch_online_status($loggedin))
{
$numbervisible++;
$show['comma_leader'] = ($activeusers != '');
eval('$activeusers .= "' . fetch_template('forumhome_loggedinuser') . '";');
}
}
}
// memory saving
unset($userinfos, $loggedin);
$db->free_result($forumusers);
$totalonline = $numberregistered; //BIOME_EDIT Prevent guests from being counted in total online and records + $numberguest;
$numberinvisible = $numberregistered - $numbervisible;
// ### MAX LOGGEDIN USERS ################################
if (intval($vbulletin->maxloggedin['maxonline']) <= $totalonline)
{
$vbulletin->maxloggedin['maxonline'] = $totalonline;
$vbulletin->maxloggedin['maxonlinedate'] = TIMENOW;
build_datastore('maxloggedin', serialize($vbulletin->maxloggedin), 1);
}
$recordusers = vb_number_format($vbulletin->maxloggedin['maxonline']);
$recorddate = vbdate($vbulletin->options['dateformat'], $vbulletin->maxloggedin['maxonlinedate'], true);
$recordtime = vbdate($vbulletin->options['timeformat'], $vbulletin->maxloggedin['maxonlinedate']);
$show['loggedinusers'] = true;
}
else
{
$show['loggedinusers'] = false;
}