<?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 user info MAXIMUS directly...');

if (defined('ADMIN_ALLOW')) {
	$block_retention  = CACHE_BL_USERINFO;
	$block_name_cache = "UserInfoAdmin";
	$extension        = "php";
} elseif (defined('USER_ALLOW')) {
	$block_retention  = CACHE_BL_USERINFO;
	$block_name_cache = "UserInfoUser";
	$extension        = "html";
} else {
	$block_retention  = CACHE_BL_USERINFO;
	$block_name_cache = "UserInfo";
	$extension        = "html";
}

if ( $content = opencacheb ( "".$block_name_cache."", "".$extension."", "".$block_retention."" ) ) {
 } else {

$block_name = "User_Info";
get_blang("$block_name");

$content = "";

global $user, $cookie, $anonymous, $sitekey, $prefix;
mt_srand ((double)microtime()*1000000);
$maxran  = 1000000;
$random_num = mt_rand(0, $maxran);
$datekey = date("F j");
$rcode   = hexdec(md5($_SERVER['HTTP_USER_AGENT'] . $sitekey . $random_num . $datekey));
$code    = substr($rcode, 2, 6);
cookiedecode($user);
$uname   = $cookie[1];

$resultat  = $GLOBALS['db']->sql_query("SELECT `username` FROM `".TABLE_USERS."` ORDER BY `user_id` DESC LIMIT 0,1");
$lasturow  = $GLOBALS['db']->sql_fetchrow($resultat);
$lastuser  = stripslashes($lasturow['username']);
$resultat1 = $GLOBALS['db']->sql_query("SELECT `user_id` FROM `".TABLE_USERS."`");
$numrows   = $GLOBALS['db']->sql_numrows($resultat1);

$result = $GLOBALS['db']->sql_query("SELECT `uname`, `guest` FROM `".TABLE_SESSION."` WHERE `guest`='0'");
$member_online_num = $GLOBALS['db']->sql_numrows($result);
$who_online_now    = "";
$i = 1;
while ($session = $GLOBALS['db']->sql_fetchrow($result)) {
$sesguest = $GLOBALS['db']->XMFnum($session["guest"]);
    if (isset($sesguest) and $sesguest == 0) {
        if ($i < 10) {
$who_online_now .= "0$i:&nbsp;<a href=\"modules.php?name=Your_Account&amp;op=userinfo&amp;username=$session[uname]\">$session[uname]</a><br />\n";
        } else {
$who_online_now .= "$i:&nbsp;<a href=\"modules.php?name=Your_Account&amp;op=userinfo&amp;username=$session[uname]\">$session[uname]</a><br />\n";
        }
        $who_online_now .= ($i != $member_online_num ? "  " : "");
        $i++;
    }
}
$Today = getdate();
//Formatting Current Date
$month = $Today['month'];
$mday  = $Today['mday'];
$year  = $Today['year'];
//Formatting Previous Date
$pmonth = $Today['month'];
$pmday  = $Today['mday'];
$pmday  = $mday-1;
$pyear  = $Today['year'];
//Month conversion into numeric mode
if ($pmonth=="January") { $pmonth=1; } else
if ($pmonth=="February") { $pmonth=2; } else
if ($pmonth=="March") { $pmonth=3; } else
if ($pmonth=="April") { $pmonth=4; } else
if ($pmonth=="May") { $pmonth=5; } else
if ($pmonth=="June") { $pmonth=6; } else
if ($pmonth=="July") { $pmonth=7; } else
if ($pmonth=="August") { $pmonth=8; } else
if ($pmonth=="September") { $pmonth=9; } else
if ($pmonth=="October") { $pmonth=10; } else
if ($pmonth=="November") { $pmonth=11; } else
if ($pmonth=="December") { $pmonth=12; };
$test = mktime (0,0,0,$pmonth,$pmday,$pyear,1);

//Creating SQL parameter
$curDate2 = "%".$month[0].$month[1].$month[2]."%".$mday."%".$year."%";
$preday   = strftime ("%d",$test);
$premonth = strftime ("%B",$test);
$preyear  = strftime ("%Y",$test);
$curDateP = "%".$premonth[0].$premonth[1].$premonth[2]."%".$preday."%".$preyear."%";

//Executing SQL Today
$resultat2 = $GLOBALS['db']->sql_query("SELECT COUNT(user_id) AS userCount FROM `".TABLE_USERS."` WHERE `user_regdate` LIKE '$curDate2'");
$row       = $GLOBALS['db']->sql_fetchrow($resultat2);
$userCount = $GLOBALS['db']->XMFnum($row['userCount']);
//end

//Executing SQL Today
$resultat3  = $GLOBALS['db']->sql_query("SELECT COUNT(user_id) AS userCount FROM `".TABLE_USERS."` WHERE `user_regdate` LIKE '$curDateP'");
$raaw3      = $GLOBALS['db']->sql_fetchrow($resultat3);
$userCount2 = $GLOBALS['db']->XMFnum($raaw3['userCount']);
//end
$resultat3 = $GLOBALS['db']->sql_query("SELECT `uname` FROM `".TABLE_SESSION."` WHERE `guest`='1'");
$guest_online_num = $GLOBALS['db']->sql_numrows($resultat3);
$resultat4 = $GLOBALS['db']->sql_query("SELECT `uname` FROM `".TABLE_SESSION."` WHERE `guest`='0'");
$member_online_num = $GLOBALS['db']->sql_numrows($resultat4);

$who_online_num = $guest_online_num + $member_online_num;
$content .= "<form action=\"modules.php?name=Your_Account\" method=\"post\">";

if (is_user($user)) {
    $content .= "<br /><img src=\"images/blocks/group-4.gif\" alt=\"\" height=\"14\" width=\"17\" /> "._BWEL.", <b>$uname</b>.<br />\n<hr />\n";
    $result3 = $GLOBALS['db']->sql_query("SELECT `user_id` FROM `".TABLE_USERS."` WHERE `username`='$uname'");
    $row3 = $GLOBALS['db']->sql_fetchrow($result3);
    $uid  = $GLOBALS['db']->XMFnum($row3['user_id']);
    $resultat5 = $GLOBALS['db']->sql_query("SELECT `privmsgs_to_userid` FROM `".$prefix."_bbprivmsgs` WHERE `privmsgs_to_userid`='$uid' AND (`privmsgs_type`='5' OR `privmsgs_type`='1')");
    $newpms  = $GLOBALS['db']->sql_numrows($resultat5);
    $result4 = $GLOBALS['db']->sql_query("SELECT `privmsgs_to_userid` FROM `".$prefix."_bbprivmsgs` WHERE `privmsgs_to_userid`='$uid' AND `privmsgs_type`='0'");
    $oldpms = $GLOBALS['db']->sql_numrows($result4);
    $content .= "<img src=\"images/blocks/email-y.gif\" alt=\"\" height=\"10\" width=\"14\" /> <a href=\"modules.php?name=Private_Messages\"><b>"._BPM."</b></a><br />\n";
    $content .= "<img src=\"images/blocks/email-r.gif\" alt=\"\" height=\"10\" width=\"14\" /> "._BUNREAD.": <b>$newpms</b><br />\n";
    $content .= "<img src=\"images/blocks/email-g.gif\" alt=\"\" height=\"10\" width=\"14\" /> "._BREAD.": <b>$oldpms</b><br />\n<hr />\n";
    // NSN Groups Memberships
    $content .= "<br /><u><b>Group Memberships:</b></u><br />\n";
    $result5  = $GLOBALS['db']->sql_query("select `user_id` from `".TABLE_USERS."` where `username`='$uname'");
    $raw5 = $GLOBALS['db']->sql_fetchrow($result5);
    $uid  = $GLOBALS['db']->XMFnum($raw5['user_id']);
    $grpmem = $GLOBALS['db']->sql_query("SELECT `gid`, `edate` FROM `".TABLE_NSNGR_USERS."` WHERE `uid`='$uid' ORDER BY `gid`");
    while($raw = $GLOBALS['db']->sql_fetchrow($grpmem)) {
    $gid    = $GLOBALS['db']->XMFnum($raw['gid']);
    $expire = $raw['edate'];
        if ($expire == 0) { $edate = "Unset"; } else { $edate = date("Y-m-d", $expire); }
	$result6 = $GLOBALS['db']->sql_query("SELECT `gname` FROM `".TABLE_NSNGR_GROUPS."` WHERE `gid`='$gid'");
        $raw6  = $GLOBALS['db']->sql_fetchrow($result6);
	$gname = stripslashes($raw6['gname']);
        $content .= "<big><b>&middot;</b></big> $gname<br />\n";
        $content .= "<big><b>&nbsp;&nbsp;</b></big> Expires: <i>$edate</i><hr />\n";
    }
} else {
    $content .= "<img src=\"images/blocks/group-4.gif\" alt=\"\" height=\"14\" width=\"17\" /> "._BWEL.", <b>$anonymous</b>\n<hr>";
    $content .= ""._NICKNAME." <input type=\"text\" name=\"username\" size=\"10\" maxlength=\"25\" /><br />";
    $content .= ""._PASSWORD." <input type=\"password\" name=\"user_password\" size=\"10\" maxlength=\"20\" /><br />";
if (extension_loaded("gd") AND ($gfx_chk == 2 OR $gfx_chk == 4 OR $gfx_chk == 5 OR $gfx_chk == 7)) {
    $content .="</tr></td><tr><td>"._UMSECURITYCODE."</td><td height=\"20\" align=\"right\"><img src='./?gfx=gfx&amp;random_num=$random_num' border='0' alt='"._UMSECURITYCODE."' title='"._UMSECURITYCODE."' />\n";
    $content .="</tr></td><tr><td>"._UMTYPESECCODE."</td><td align=\"right\"><input type=\"text\" name=\"gfx_check\" size=\"10\" maxlenght=\"6\" />\n";
}
    $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 .= "<input type=\"submit\" value=\""._LOGIN."\" />\n (<a href=\"modules.php?name=Your_Account&amp;op=new_user\">"._BREG."</a>)<hr />";
}
$content .= "<img src=\"images/blocks/group-2.gif\" alt=\"\" height=\"14\" width=\"17\" /> <b><u>"._BMEMP.":</u></b><br />\n";
$content .= "<img src=\"images/blocks/ur-moderator.gif\" alt=\"\" height=\"14\" width=\"17\" /> "._BLATEST.": <A HREF=\"modules.php?name=Your_Account&amp;op=userinfo&amp;username=$lastuser\"><b>$lastuser</b></a><br />\n";
$content .= "<img src=\"images/blocks/ur-author.gif\" alt=\"\" /> "._BTD.": <b>$userCount</b><br />\n";
$content .= "<img src=\"images/blocks/ur-admin.gif\" alt=\"\" /> "._BYD.": <b>$userCount2</b><br />\n";
$content .= "<img src=\"images/blocks/ur-guest.gif\" alt=\"\" /> "._BOVER.": <b>$numrows</b><br />\n<hr />\n";
$content .= "<img src=\"images/blocks/group-3.gif\" alt=\"\" /> <b><u>"._BVISIT.":</u></b>\n<br />\n";
$content .= "<img src=\"images/blocks/ur-anony.gif\" alt=\"\" /> "._BVIS.": <b>$guest_online_num</b><br />\n";
$content .= "<img src=\"images/blocks/ur-member.gif\" alt=\"\" /> "._BMEM.": <b>$member_online_num</b><br />\n";
$content .= "<img src=\"images/blocks/ur-registered.gif\" alt=\"\" /> "._BTT.": <b>$who_online_num</b><br />\n";
if ($member_online_num > 0) {
    $content .= "<hr>\n<img src=\"images/blocks/group-1.gif\" alt=\"\" /> <b><u>"._BON.":</u></b><br />$who_online_now";
}
$content .= "</form>";

$GLOBALS['db']->sql_freeresult($resultat);$GLOBALS['db']->sql_freeresult($resultat1);$GLOBALS['db']->sql_freeresult($resultat2);$GLOBALS['db']->sql_freeresult($resultat3);$GLOBALS['db']->sql_freeresult($resultat4);$GLOBALS['db']->sql_freeresult($resultat5);$GLOBALS['db']->sql_freeresult($result);$GLOBALS['db']->sql_freeresult($result3);$GLOBALS['db']->sql_freeresult($result3);$GLOBALS['db']->sql_freeresult($result4);$GLOBALS['db']->sql_freeresult($result5);$GLOBALS['db']->sql_freeresult($result6);

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