Title: Total Members And Guests Stats v1.0

Author: John Briggs

Description:
This modification will provide a stat on index for total actual members and guests who have visited your site in the last 24 hours.
This modification will add 5 queries to your forum so be warned ahead of time.

Copyright:  2006 John Briggs. All rights reserved.

Compatability: XMB 1.9.8 Engage Final SP2/SP3

Updated for 1.9.8 by: WormHole @ XMB Garage

Install Note: Before adding this mod to your forum, you should back up all files related to this mod.

License Note: This modification is released under the GPL License. A copy is provided with this software package.

Author Note:
You downloaded this modification from XMBGarage.com, the #1 source for XMB related downloads.
Please visit http://www.xmbgarage.com/ for support.

=======================================================================================================================================
=======
Step 1:
=======
==============================
Go To Admin Panel -> Insert Raw SQL
==============================

Upload provided file named "SQL.txt" & click "Submit Changes" button.

=======================================================================================================================================
=======
Step 2:
=======
=======================
Edit File: lang/English.lang.php
=======================
==========
Find Code:
==========

==================================
Add Code At Very Bottom Of File Above ?>
==================================

// Total Members And Guests Stats Mod Begin
$lang['tgmvisitno'] = " and no Guests have visited the site in the last 24 hours.";
$lang['tgmvisit1'] = " and 1 Guest have visited the site in the last 24 hours.";
$lang['tgmvisitand'] = " and ";
$lang['tgmvisitcount'] = " Guests have visited the site in the last 24 hours.";
// Total Members And Guests Stats Mod End

==========
Find Code:
==========

$lang['textmembertoday'] = " member has visited the site today ";

==================
Replace Code With:
==================

$lang['textmembertoday'] = " member ";

==========
Find Code:
==========

$lang['textmemberstoday'] = " members have visited the site today";

==================
Replace Code With:
==================

$lang['textmemberstoday'] = " Members ";

==========
Find Code:
==========

$lang['last50today'] = "Last $onlinetodaycount Members Who Have Visited Today (if applicable)";

==================
Replace Code With:
==================

$lang['last50today'] = "A total of ";

=======================================================================================================================================
=======
Step 3:
=======

=================
Edit File: header.php
=================
==========
Find Code:
==========

// Checks the format of the URL, blocks if necessary....
if (eregi("\?[0-9]+$", $url)) {
    exit("Invalid String Format, Please Check Your URL");
}

===============
Add Code Below:
===============

// Total Members And Guests Stats Mod Begin
// check for user agent
if (isset($robot) && !empty($robot) && isset($agent) && !empty($agent)) {
    $db->query("INSERT INTO ".X_PREFIX."robots (ipaddress, useragent) values ('$robot', '$agent')");
}

$useragent = '';
if (getenv($_SERVER['HTTP_USER_AGENT'])) {
    $useragent = getenv($_SERVER['HTTP_USER_AGENT']);
}
// Total Members And Guests Stats Mod  End

==========
Find Code:
==========

    'forums',

==================
Add Code Below:
==================

    'guests',

==========
Find Code:
==========

    'restricted',

==================
Add Code Below:
==================

    'robots',

==========
Find Code:
==========

// clear out old entries and guests
$db->query("DELETE FROM ".X_PREFIX."whosonline WHERE ((ip='$onlineip' && username='xguest123') OR (username='$xmbuser') OR (time < '$newtime'))");
$db->query("INSERT INTO ".X_PREFIX."whosonline (username, ip, time, location, invisible) VALUES ('$onlineuser', '$onlineip', ".$db->time($onlinetime).", '$wollocation', '$invisible')");

==================
Replace Code With:
==================

// Total Members And Guests Stats Mod  Begin
$db->query("DELETE FROM ".X_PREFIX."whosonline WHERE ((ip = '$onlineip' && username = 'xguest123') OR (username = '$xmbuser') OR (time < '$newtime') )");

$addonline  = true;
$robotquery = $db->query("SELECT COUNT(ipaddress) FROM ".X_PREFIX."robots WHERE (ipaddress = '$onlineip')");
$foundrobot = $db->result($robotquery, 0);
if ($foundrobot > 0) {
    $addonline = false;
} else {
    if (!empty($useragent)) {
        $robotquery = $db->query("SELECT COUNT(useragent) FROM ".X_PREFIX."robots WHERE (useragent = '$useragent')");
        $foundrobot = $db->result($robotquery, 0);
        if ($foundrobot > 0) {
            $db->query("INSERT INTO ".X_PREFIX."robots (ipaddress, useragent) values ('$onlineip', '$useragent')");
            $addonline = false;
        }
    }
}

if ($addonline == true)
    $db->query("INSERT INTO ".X_PREFIX."whosonline (username, ip, time, location, invisible) VALUES ('$onlineuser', '$onlineip', ".$db->time($onlinetime).", '$wollocation', '$invisible')");
    $online24 = $onlinetime - (60 * 60 * 24);
    $db->query("DELETE FROM ".X_PREFIX."guests WHERE ((ipaddress = '$onlineip') OR (onlinetime < '$online24'))");

if ($addonline == true)
    $db->query("INSERT INTO ".X_PREFIX."guests (ipaddress, onlinetime) VALUES ('$onlineip', '$onlinetime')");
// Total Members And Guests Stats Mod  End

=======================================================================================================================================
=======
Step 4:
=======
================
Edit File: index.php
================

==========
Find Code:
==========

        $query  = $db->query("SELECT m.status, m.username, m.invisible, w.* FROM ".X_PREFIX."whosonline w LEFT JOIN ".X_PREFIX."members m ON m.username=w.username ORDER BY w.username");

==================
Replace Code With:
==================

        // Total Members And Guests Stats Mod Begin
        $query = $db->query("SELECT w.*, m.status, m.invisible, m.username<>'xguest123' AS guests FROM ".X_PREFIX."whosonline w LEFT JOIN ".X_PREFIX."members m ON m.username=w.username ORDER BY w.username");
        // Total Members And Guests Stats Mod End

==========
Find Code:
==========

            if ($todaymembersnum == 1) {
                $memontoday = $todaymembersnum.$lang['textmembertoday'];
            } else {
                $memontoday = $todaymembersnum.$lang['textmemberstoday'];
            }

===============
Add Code Below:
===============

            // Total Members And Guests Stats Mod Begin
            $query = $db->query("SELECT COUNT(*) AS guests FROM ".X_PREFIX."guests WHERE onlinetime >= '$datecut'");
            $gueststoday = $db->fetch_array($query);
            $gueststodaycount = $gueststoday['guests'];

            if ($gueststodaycount == '') {
                $gueststodaycount = 0;
            }

            if ($gueststodaycount == 0) {
                $todayguests = $lang['tgmvisitno'];
            } elseif ($gueststodaycount == 1) {
                $todayguests = $lang['tgmvisit1'];
            } else {
                $todayguests = $lang['tgmvisitand'].''.$gueststodaycount.''.$lang['tgmvisitcount'];
            }
            // Total Members And Guests Stats Mod End

=======================================================================================================================================
=======
Step 5:
=======
=========================================
Edit File: portal.php (If the Portal System v2.4 is installed)
=========================================
==========
Find Code:
==========

    $query  = $db->query("SELECT m.status, m.username, m.invisible, w.* FROM ".X_PREFIX."whosonline w LEFT JOIN ".X_PREFIX."members m ON m.username=w.username ORDER BY w.username");

================
Replace Code With:
================

    // Total Members And Guests Stats Mod Begin
    $sql = $db->query("SELECT w.*, m.status, m.location, m.username<>'xguest123' AS guests FROM ".X_PREFIX."whosonline w LEFT JOIN ".X_PREFIX."members m ON m.username=w.username ORDER BY w.username");
    // Total Members And Guests Stats Mod End

==========
Find Code:
==========

        if ($todaymembersnum == 1) {
            $memontoday = $todaymembersnum.$lang['textmembertoday'];
        } else {
            $memontoday = $todaymembersnum.$lang['textmemberstoday'];
        }

===============
Add Code Below:
===============

        // Total Members And Guests Stats Mod Begin
        $query = $db->query("SELECT COUNT(*) AS guests FROM ".X_PREFIX."guests WHERE onlinetime >= '$datecut'");
        $gueststoday = $db->fetch_array($query);
        $gueststodaycount = $gueststoday['guests'];

        if ($gueststodaycount == '') {
            $gueststodaycount = 0;
        }

        if ($gueststodaycount == 0) {
            $todayguests = $lang['tgmvisitno'];
        } elseif ($gueststodaycount == 1) {
            $todayguests = $lang['tgmvisit1'];
        } else {
            $todayguests = $lang['tgmvisitand'].''.$gueststodaycount.''.$lang['tgmvisitcount'];
        }
        // Total Members And Guests Stats Mod End

=======================================================================================================================================
=======
Step 5:
=======
==========================
Go To Admin Panel -> Templates
==========================
=============================
Edit Template: index_whosonline_today
=============================
==========
Find Code:
==========

<tr>
<td colspan="2" class="category">
<a href="misc.php?action=onlinetoday"><strong><font color="$cattext">[+] $lang[last50today]</font></strong></a>
</td>
</tr>

==================
Replace Code With:
==================

<tr>
<td colspan="2" class="category">
<a href="misc.php?action=onlinetoday"><strong><font color="$THEME[cattext]">[+] $lang[last50today] $memontoday $todayguests</font></strong></a>
</td>
</tr>

=======================================================================================================================================
Enjoy!