Location: PHPKode > projects > ProNuke. Postnuke To Oracle > postnuke/html/includes/blocks/online.php
<?php
// File: $Id: online.php,v 1.23 2001/12/06 14:46:31 jgm Exp $ $Name:  $
// ----------------------------------------------------------------------
// POST-NUKE Content Management System
// Copyright (C) 2001 by the Post-Nuke Development Team.
// http://www.postnuke.com/
// ----------------------------------------------------------------------
// Based on:
// PHP-NUKE Web Portal System - http://phpnuke.org/
// Thatware - http://thatware.org/
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// 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.  See the
// GNU General Public License for more details.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------
// Original Author of file: Francisco Burzi
// Purpose of file: count number of guests/members online
//                                      20/09/2001 - modified sql to cope with there being 0 members online
// ----------------------------------------------------------------------

$blocks_modules['online'] = array(
    'func_display' => 'blocks_online_block',
    'text_type' => 'Online',
    'text_type_long' => 'Online',
    'allow_multiple' => false,
    'form_content' => false,
    'form_refresh' => false,
    'show_preview' => true
);

// Security
addinstanceschemainfo('Onlineblock::', '::');

function blocks_online_block($row) {
    global $user, $cookie, $pntable, $dbconn;
    cookiedecode($user);

    if (!authorised(0, 'Onlineblock::', '::', ACCESS_OVERVIEW)) {
        return;
    }

    if(getenv("HTTP_X_FORWARDED_FOR")) {
        $ip = getenv("HTTP_X_FORWARDED_FOR"); 
    } else { 
        $ip = getenv("REMOTE_ADDR"); 
    };

    if (empty($cookie[1])) {
        $username = "$ip";
        $guest = 1;
    } else {
        $username = $cookie[1];
        $guest = '0';
    }
    $past = time()-900;
    $column = &$pntable['session_column'];
    $dbconn->Execute("DELETE FROM $pntable[session] WHERE $column[time] < $past");
    $ctime = time();
    $update_result = $dbconn->Execute("UPDATE $pntable[session]
                                     SET $column[time]='$ctime', $column[host_addr]='$ip'
                                     WHERE $column[username]='$username'");
    if ( $dbconn->Affected_Rows() <= 0) {
        $column = &$pntable['session_column'];
        $dbconn->Execute("INSERT INTO $pntable[session] ($column[username], $column[time], $column[host_addr], $column[guest]) VALUES ('$username', '$ctime', '$ip', '$guest')");
    }

    $column = &$pntable['session_column'];
    $result = $dbconn->Execute("SELECT COUNT(*) FROM $pntable[session] WHERE $column[guest]='1'");
    list($guest_online_num) = $result->fields;
    $result = $dbconn->Execute("SELECT COUNT(*) FROM $pntable[session] WHERE $column[guest]='0'");
    list($member_online_num) = $result->fields;

    $who_online = "<font class=\"pn-normal\">"._CURRENTLY." $guest_online_num "._GUESTS." $member_online_num "._MEMBERS."<br>\n";
    $content = "$who_online";
    if (is_user($user)) {
    $content .= "<br>"._YOUARELOGGED." <b>$username</b>.<br>";
    $column = &$pntable['users_column'];
    $result = $dbconn->Execute("SELECT $column[uid] FROM $pntable[users] WHERE $column[uname]='$username'");
    list($uid) = $result->fields;
    $column = &$pntable['priv_msgs_column'];
    $result2 = $dbconn->Execute("SELECT count(*) FROM $pntable[priv_msgs] WHERE $column[to_userid]='$uid'");
    list($numrow) = $result2->fields;
    if ($numrow == 0) {
        $content .= "<br></font>";
    } else {
        $content .= "<br>"._YOUHAVE." <a class=\"pn-normal\" href=\"modules.php?op=modload&amp;name=Messages&amp;file=index\"><b>$numrow</b></a> "._PRIVATEMSG."</font><br>";
    }
    } else {
        $content .= "<br>"._YOUAREANON."</font><br>";
    }
    $row['title'] = _WHOSONLINE;
    $row['content'] = $content;
    themesideblock($row);
}
?>
Return current item: ProNuke. Postnuke To Oracle