<?php
/************************************************************************/
/* Maximus CMS: Web Portal System                                       */
/* ==============================                                       */
/*                                                                      */
/* Copyright (c) 2002 - 2006                                            */
/* http://www.php-maximus.fr                                            */
/* dev@php-maximus.org                                                  */
/*                                                                      */
/* 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.       */
/************************************************************************/
/* Based on PHP-NUKE: Web Portal System                                 */
/************************************************************************/
defined('MAXIMUS') or die ('Access denied block max who is online MAXIMUS directly...');

$block_name = "Max-Who_is_Online";
get_blang("$block_name");

if (is_file('kernel/popup.php')) {
	include_once ('kernel/popup.php');
}

$content   = "";
if (defined('ADMIN_ALLOW')) {
	$block_retention  = CACHE_BL_MAXWHOISONLINE;
	$block_name_cache = "WhoIsOnline2Admin";
	$extension        = "php";
} elseif (defined('USER_ALLOW')) {
	$block_retention  = CACHE_BL_MAXWHOISONLINE;
	$block_name_cache = "WhoIsOnline2User";
	$extension        = "html";
} else {
	$block_retention  = CACHE_BL_MAXWHOISONLINE;
	$block_name_cache = "WhoIsOnline2";
	$extension        = "html";
}
if ( $content = opencacheb ( "".$block_name_cache."", "".$extension."", "".$block_retention."" ) ) {
 } else {

global $user, $prefix, $cookie, $currentlang;

cookiedecode($user);
$ip = get_ip();
$uname = $cookie[1];
if (!isset($uname)) {
    $uname = "$ip";
    $guest = 1;
}
$sql = "SELECT `uname` FROM `".TABLE_SESSION."` WHERE `guest`='1'";
if ( !($result = $GLOBALS['db']->sql_query($sql)) )
{ query_die(MODULE_ERROR, 'Could not obtain _session', '', __LINE__, __FILE__, $sql);}
$guest_online_num = $GLOBALS['db']->sql_numrows($result);


$sql1 = "SELECT `uname` FROM `".TABLE_SESSION."` WHERE `guest`='0'";
if ( !($result1 = $GLOBALS['db']->sql_query($sql1)) )
{ query_die(MODULE_ERROR, 'Could not obtain _session', '', __LINE__, __FILE__, $sql1);}
$member_online_num = $GLOBALS['db']->sql_numrows($result1);


$total = $guest_online_num +  $member_online_num;
if ($total == 0) {
$content = ""._NOONLINE."<br /><br />";
} elseif ($total == 1) {
$content = ""._ONEONLINE."<br /><br />";
} elseif ($total > 1) {
$content = "<b>$total</b> "._ONLINE."<br /><br />";
}

if ($member_online_num == 0) {
$content .= ""._NOMEMBERSONLINE."<br />";
} elseif ($member_online_num == 1) {
$content .= ""._ONEMEMBERONLINE."<br />";
} elseif ($member_online_num > 1) {
$content .= ""._MEMBERONLINE." <b>$member_online_num</b><br />";
}

if ($guest_online_num == 0) {
$content .= ""._NOGUESTONLINE."<br /><br />";
} elseif ($guest_online_num == 1) {
$content .= ""._ONEGUESTONLINE."<br /><br />";
} elseif ($guest_online_num > 1) {
$content .= ""._GUESTONLINE." <b>$guest_online_num</b><br /><br />";
}

$a = 0;
$max = $GLOBALS['db']->sql_numrows($result1);
while ($row1 = $GLOBALS['db']->sql_fetchrow($result1)) {
$uname = stripslashes($row1['uname']);

$content .= "<a href=\"modules.php?name=Your_Account&amp;op=userinfo&amp;username=$uname\"><b>$uname</b></a>";
if (($max > 1) && ($a < ($max-1))) {
$content .= ", ";}
$a++;
}

$content .= "<br /><a href=\"?livemembers\" onclick=\"NewsReadWindow(this.href,'livemembers','600','400','yes');return false;\"><b>"._PLUS."</b></a>";

if (defined('USER_ALLOW')) {
    $content .= "<hr />"._BWEL.", <b>$cookie[1]</b>.<br />\n<hr>\n";
    $sql4 = "SELECT `privmsgs_to_userid` FROM `".$prefix."_bbprivmsgs` WHERE `privmsgs_to_userid`='$cookie[0]' AND (`privmsgs_type`='5' OR `privmsgs_type`='1')";
    if ( !($result4 = $GLOBALS['db']->sql_query($sql4)) )
{ query_die(MODULE_ERROR, 'Could not obtain _bbprivmsgs', '', __LINE__, __FILE__, $sql4);}
    $newpms = $GLOBALS['db']->sql_numrows($resultat4);
    $sql5 = "SELECT `privmsgs_to_userid` FROM `".$prefix."_bbprivmsgs` WHERE `privmsgs_to_userid`='$cookie[0]' AND `privmsgs_type`='0'";
    if ( !($result5 = $GLOBALS['db']->sql_query($sql5)) )
{ query_die(MODULE_ERROR, 'Could not obtain _bbprivmsgs', '', __LINE__, __FILE__, $sql5);}
    $oldpms = $GLOBALS['db']->sql_numrows($result5);
    $content .= "<img src=\"images/blocks/email-y.gif\" height=\"10\" width=\"14\" alt='' /> <a href=\"modules.php?name=Private_Messages\"><b>"._BPM."</b></a><br />\n";
    $content .= "<img src=\"images/blocks/email-r.gif\" height=\"10\" width=\"14\" alt='' /> "._BUNREAD.": <b>$newpms</b><br />\n";
    $content .= "<img src=\"images/blocks/email-g.gif\" height=\"10\" width=\"14\" alt='' /> "._BREAD.": <b>$oldpms</b><br />\n<hr />\n";
$GLOBALS['db']->sql_freeresult($result4);
$GLOBALS['db']->sql_freeresult($result5);

} else {
    $content .= "<form action=\"modules.php?name=Your_Account\" method=\"post\">";
    $content .= "<hr /><center><img src='images/login.gif' alt='"._LOGIN."' title='"._LOGIN."' /></center><br /> <table width='100%'><tr><td width='50%'>";
    $content .= "Pseudo</td><td><input type=\"text\" name=\"username\" size=\"8\" maxlength=\"25\" /></td></tr>";
    $content .= "<tr><td width='50%'>Pass</td><td><input type=\"password\" name=\"user_password\" size=\"8\" maxlength=\"20\" /></td></tr></table>";
    $content .= "<input type=\"hidden\" name=\"random_num\" value=\"$random_num\" />";
    $content .= "<input type=\"hidden\" name=\"gfx_check\" value=\"$code\" />";
    $content .= "<input type=\"hidden\" name=\"op\" value=\"login\" />";
    $content .= "<center><input type=\"submit\" value=\""._LOGIN."\" /></center></form><br /><center><a href=\"modules.php?name=Your_Account&amp;op=new_user\">"._BREG."</a></center>";
}

$GLOBALS['db']->sql_freeresult($result);
$GLOBALS['db']->sql_freeresult($result1);

closecacheb ( "".$content."", "".$block_name_cache."", "".$extension."", "".$block_retention."" );
}