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

if (defined('ADMIN_ALLOW')) {
	$block_retention  = CACHE_BL_USERMENU;
	$block_name_cache = "UserMenuAdmin";
	$extension        = "php";
} elseif (defined('USER_ALLOW')) {
	$block_retention  = CACHE_BL_USERMENU;
	$block_name_cache = "UserMenuUser";
	$extension        = "html";
} else {
	$block_retention  = CACHE_BL_USERMENU;
	$block_name_cache = "UserMenu";
	$extension        = "html";
}

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

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

$content = "";

global $user, $admin, $cookie, $prefix, $user_prefix, $anonymous, $sitekey, $userinfo, $mode, $t, $f, $admin, $stop, $module_name, $redirect, $gfx_chk, $language;
getusrinfo($user);
$module_name = "MS_Analysis";
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, 10);
cookiedecode($user);
$uname = $cookie[1];

list($lastuser) = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT `username` FROM `".TABLE_USERS."` ORDER BY `user_id` DESC LIMIT 0,1"));
list($newid) = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT `user_id` FROM `".TABLE_USERS."` WHERE `username`='$lastuser'"));
$numrows = $GLOBALS['db']->sql_numrows($GLOBALS['db']->sql_query("SELECT `user_id` FROM `".TABLE_USERS."`"));
$numrows = ($numrows - 1); //removes admin as user
$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)) {
	list($uid) = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT `user_id` FROM `".TABLE_USERS."` WHERE `username`='$session[uname]'"));
    if (isset($session["guest"]) and $session["guest"] == 0) {
        if ($i < 10) {
            $who_online_now .= "0$i:&nbsp;<a href=\"modules.php?name=Private_Messages&amp;mode=post&amp;u=$uid\"><img src=\"images/blocks/icon_minipost.gif\" border=0 alt=\""._UMSENDPM." $session[uname]\" align='absmiddle' /></a><a href=\"modules.php?name=Your_Account&amp;op=userinfo&amp;username=$session[uname]\"><img src=\"images/blocks/icon_miniprofiles.gif\" border='0' width='10' height='11' alt=\"View profiles of $session[uname]\" align='absmiddle' />&nbsp;$session[uname]</a><br />\n";
        } else {
            $who_online_now .= "$i:&nbsp;<a href=\"messages-post-$uid.html\"><img src=\"images/blocks/icon_minipost.gif\" border='0' alt=\""._UMSENDPM." $session[uname]\" align='absmiddle' /></a><a href=\"album-$session[uname].html\"><img src=\"images/blocks/icon_miniprofiles.gif\" border='0' alt=\"View profiles of $session[uname]\" align='absmiddle' />&nbsp;$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
list($userCount) = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT COUNT(user_id) AS userCount FROM `".TABLE_USERS."` WHERE `user_regdate` LIKE '$curDate2'"));

//end

//Executing SQL Today
list($userCount2) = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT COUNT(user_id) AS userCount FROM `".TABLE_USERS."` WHERE `user_regdate` LIKE '$curDateP'"));

//end

$guest_online_num = $GLOBALS['db']->sql_numrows($GLOBALS['db']->sql_query("SELECT `uname` FROM `".TABLE_SESSION."` WHERE `guest`='1'"));
$member_online_num = $GLOBALS['db']->sql_numrows($GLOBALS['db']->sql_query("SELECT `uname` FROM `".TABLE_SESSION."` WHERE `guest`='0'"));

$who_online_num = $guest_online_num + $member_online_num;



if (defined('USER_ALLOW')) {
    list($uid) = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT `user_id` FROM `".TABLE_USERS."` WHERE `username`='$uname'"));
    $newpms = $GLOBALS['db']->sql_numrows($GLOBALS['db']->sql_query("SELECT `privmsgs_to_userid` FROM `".$prefix."_bbprivmsgs` WHERE `privmsgs_to_userid`='$uid' AND (`privmsgs_type`='1' OR `privmsgs_type`='5')"));
    $oldpms = $GLOBALS['db']->sql_numrows($GLOBALS['db']->sql_query("SELECT `privmsgs_to_userid` FROM `".$prefix."_bbprivmsgs` WHERE `privmsgs_to_userid`='$uid' AND `privmsgs_type`='0'"));

if ($userinfo['user_avatar']) {
		$content .= "<center>"._UMWELB."<br /><img src=\"modules/Forums/images/avatars/$userinfo[user_avatar]\" alt='' /><br />$uname\n</center><hr />";
	} else {
    $content .= "<center>"._BWEL."<br /><img src=\"images/blocks/icon_who.gif\" alt='' /><br />$uname\n</center><hr />";
}

    $content .= "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\"><tr><td valign=\"absmiddle\"><img src=\"images/blocks/icon_pm.gif\" border=\"0\" valign=\"absmiddle\" alt='' /></td><td><a href=\"modules.php?name=Private_Messages\"><b>"._UMPM."</b></a></tr></td></table>\n";
    $content .= "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">";
    $content .= "<tr><td width=\"22\"></td><td><img src=\"images/blocks/icon_dot.gif\" height=\"10\" width=\"9\" align=\"absmiddle\" alt='' /> "._UMNMSG.": </td><td width=\"35%\"><b>$newpms</b><br /></td></tr>\n";
    $content .= "<tr><td width=\"22\"></td><td><img src=\"images/blocks/icon_dot.gif\" height=\"10\" width=\"9\" align=\"absmiddle\" alt='' /> "._UMOMSG.": </td><td><b>$oldpms</b>\n</td></tr></table><hr>\n";


//$content .= "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\"><tr><td width=\"25\"><img src=\"images/blocks/icon_profile.gif\" border=\"0\" valign=\"absmiddle\" alt='' /></td><td><a href=\"album.html\"><b>My Book</b></a></tr></td></table>\n";
//$content .= "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">";
//$uname1=strtolower($uname);
//$content .= "<tr><td width=\"22\"></td><td><img src=\"images/blocks/icon_dot.gif\" height=\"10\" width=\"9\" alt='' /> <a href=\"albumku-edit.html\">"._CREATEALBUM."</a><br /></td></tr>\n";
//$content .= "<tr><td width=\"22\"></td><td><img src=\"images/blocks/icon_dot.gif\" height=\"10\" width=\"9\" alt='' /> <a href=\"album-$uname1.html\">"._VIEWALBUM."</a><br /></td></tr></table><hr>\n";


} else {
$content .= "<form action=\"modules.php?name=Your_Account\" method=\"post\">";
    $content .= "<center><b>"._BWEL."</b><br /><img src=\"images/blocks/icon_who.gif\" alt='' /><br />$anonymous\n</center><hr />";
    $content .= "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">";
    $content .= "<tr><td>"._UMNICK."</td><td align=\"right\"><input type=\"text\" name=\"username\" size=\"10\" maxlength=\"25\" />";
    $content .= "</tr></td><tr><td>"._UMPSW."</td><td align=\"right\"> <input type=\"password\" name=\"user_password\" size=\"10\" maxlength=\"20\" />";

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=\"mode\" value='$mode' />\n";
    $content .="<input type=\"hidden\" name=\"f\" value='$f' />\n";
    $content .="<input type=\"hidden\" name=\"t\" value='$t' />\n";
    $content .= "<input type=\"hidden\" name=\"op\" value=\"login\" />";
    $content .= "</td></tr><td><img src=\"images/blocks/icon_dot_ani.gif\" align=\"middle\" height=\"10\" width=\"9\" alt='' /> <a href=\"modules.php?name=Your_Account&amp;op=new_user\"><b>"._UMREG."</b></a></td><td align=\"right\"><input type=\"submit\" value=\""._UMLOGIN."\" /></form>\n</tr></td></table><hr />";

}
// Info IP/ISP
$ip = $_SERVER['REMOTE_ADDR'];
$client = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$str = preg_split("/\./", $client);
$i = count($str);
$x = $i - 1;
$n = $i - 2;
$isp = $str[$n] . "." . $str[$x];

$content .="<img src=\"images/blocks/icon_dot.gif\" align=\"middle\" alt='' />&nbsp;&nbsp;"._IP." : $ip";
$content .="<br /><img src=\"images/blocks/icon_dot.gif\" align=\"middle\" alt='' />&nbsp;&nbsp;"._ISP." : $isp";
$content .= "<br /><hr /><img src=\"images/blocks/group-1.gif\" width=\"18\" alt='' /> <a href=\"members.html\"><b>"._BMEMP.":</b></a><br />\n";

if(defined('ADMIN_ALLOW')){
$content .= "<img src=\"images/blocks/ur-moderator.gif\" height=\"15\" width=\"15\" alt='' /> " . _BLATEST . ": <a href=\"modules.php?name=Your_Account&amp;op=userinfo&amp;username=$lastuser\"><b>$lastuser</b></a><br />\n";
}else{
$content .= "<img src=\"images/blocks/ur-moderator.gif\" height=\"15\" width=\"15\" alt='' /> "._BLATEST.": <a href=\"modules.php?name=Forums&amp;file=profile&amp;mode=viewprofile&amp;u=$newid\"><b>$lastuser</b></a><br />\n";
}

global $prefix;
// How many in block
$memb = 10;
$query="SELECT `username`, `user_regdate` from `".TABLE_USERS."` ORDER BY `user_id` DESC LIMIT $memb";
$result=$GLOBALS['db']->sql_query($query);
	while(list($username, $user_regdate) = $GLOBALS['db']->sql_fetchrow($result)) {

if(defined('ADMIN_ALLOW')){
$DataMembers .="<font class=\"content\">&nbsp;<img src=\"images/blocks/icon_dot.gif\" border=\"0\" alt=\"\" title=\"\" align=\"middle\" alt='' />
<a href=\"modules.php?name=Your_Account&amp;op=userinfo&amp;username=$username\"> $username </a>";
}else{

$DataMembers .="<font class=\"content\">&nbsp;<img src=\"images/blocks/icon_dot.gif\" border=\"0\" alt=\"\" title=\"\" align=\"middle\" />
<a href=\"modules.php?name=Your_Account&amp;op=userinfo&amp;username=$username\"> $username </a>";
}
}
$result = $GLOBALS['db']->sql_query("SELECT `count` FROM `".TABLE_COUNTER."` WHERE `type`='total' AND `var`='hits'");
$result = $GLOBALS['db']->sql_fetchrow($result);
$content .= "<Marquee behavior=\"scroll\" Height=\"15\" ScrollAmount=\"1\" ScrollDelay=\"50\"  onMouseOver=\"this.stop()\" onMouseOut=\"this.start()\">&nbsp;$DataMembers</marquee>";

$content .= "<img src=\"images/blocks/ur-author.gif\" height=\"15\" width=\"15\" alt='' /> "._BTD.": <b>$userCount</b><br />\n";
$content .= "<img src=\"images/blocks/ur-admin.gif\" height=\"15\" width=\"15\" alt='' /> "._BYD.": <b>$userCount2</b><br />\n";
$content .= "<img src=\"images/blocks/ur-guest.gif\" height=\"15\" width=\"15\" alt='' /> "._BOVER.": <b>$numrows</b><br />\n<hr>\n";
$content .= "<img src=\"images/blocks/group-1.gif\" height=\"15\" width=\"15\" alt='' /> <b>"._UMONLINE."[$who_online_num]:</b>\n<br />\n";
$content .= "<img src=\"images/blocks/ur-anony.gif\" height=\"15\" width=\"15\" alt='' /> "._BVIS.": <b>$guest_online_num</b><br />\n";
$content .= "<img src=\"images/blocks/ur-member.gif\" height=\"15\" width=\"15\" alt='' /> "._BMEM.": <b>$member_online_num</b>\n";

if (defined('USER_ALLOW')) {
	$content .= "<hr />\n<img src=\"images/blocks/group-3.gif\" height=\"15\" width=\"15\" alt='' /> <b>"._BON.": </b><br />$who_online_now";
	$content .= "<hr /><img src=\"images/blocks/icon_logout.gif\" align=\"absmiddle\" alt='' /><a href=\"modules.php?name=Your_Account&amp;op=logout\"> <b>"._UMBEXIT."</b></a>";
}

else if (defined('ADMIN_ALLOW')) {
      $content .= "<hr />\n<img src=\"images/blocks/group-3.gif\" height=\"15\" width=\"15\" alt='' /> <b>"._BON.": </b><br />$who_online_now";
}

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