Title: Total Members And Guests Stats v1.0

Author: John Briggs

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

Copyright:  2006 John Briggs. All rights reserved.

Compatability: XMB 1.9.5 Final

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

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

Author Note:
You downloaded this hack from XMBMods.com, the #1 source for XMB related downloads.
Please visit http://www.xmbmods.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:
================================

// 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 already visited the site today ";

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

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

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

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

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

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

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

$lang['last50today'] = "50 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 $table_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'

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

,'forums','guests'

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

,'restricted'

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

,'restricted','robots'

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

    // clear out old entries and guests
    $db->query("DELETE FROM $table_whosonline WHERE ((ip = '$onlineip' && username = 'xguest123') OR (username = '$xmbuser') OR (time < '$newtime') )");
    $db->query("INSERT INTO $table_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 $table_whosonline WHERE ((ip = '$onlineip' && username = 'xguest123') OR (username = '$xmbuser') OR (time < '$newtime') )");

    $addonline  = true;
    $robotquery = $db->query("SELECT COUNT(ipaddress) FROM $table_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 $table_robots WHERE (useragent = '$useragent')");
            $foundrobot = $db->result($robotquery, 0);
            if ($foundrobot > 0) {
                $db->query("INSERT INTO $table_robots (ipaddress, useragent) values ('$onlineip', '$useragent')");
                $addonline = false;
            }
        }
    }

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

    if ($addonline == true)
        $db->query("INSERT INTO $table_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 $table_whosonline w LEFT JOIN $table_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 $table_whosonline w LEFT JOIN $table_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 $table_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 -> index_whosonline
==================================================

==========
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="$cattext">[+] $lang[last50today] $memontoday $todayguests</font></strong></a></td>
</tr>

=======================================================================================================================================