<?php
/**
 * This file is part of
 * pragmaMx - Web Content Management System.
 * Copyright by pragmaMx Developer Team - http://www.pragmamx.org
 *
 * pragmaMx 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 3 of the License, or
 * (at your option) any later version.
 */

defined('mxMainFileLoaded') or die('access denied');

// Anzahl der User im Block
$numusers = 10;
// User, die nicht angezeigt werden sollen
// Namen mit Komma trennen!
$excludedusers = "Knalxler ,Dertzui";
// maximale Höhe des Blocks in Pixel. 0 um die Höhe nicht zu beschränken
$blockheigth = 100;
// #################################################################################################################
$mxblockcache = false;
// Variablen initialisieren
global $prefix, $user_prefix;
if (@file_exists("language/maaXoN/maaXoN-" . $GLOBALS['currentlang'] . ".php")) {
    include_once("language/maaXoN/maaXoN-" . $GLOBALS['currentlang'] . ".php");
} else {
    include_once("language/maaXoN/maaXoN-english.php");
}

$blockheigth = (int)$blockheigth;
// SQL-bedingung fuer excluded Users erstellen
$exusers = explode(",", $excludedusers);

if (!MX_IS_ADMIN) {
    while (list($key, $val) = each($exusers)) {
        $xexusers[] = trim($val);
    }
}
$xexusers[] = $GLOBALS['anonymous'];

if (MX_IS_USER) {
    $usersession = mxGetUserSession();
    $xexusers[] = $usersession[1];
}

$excludedusers = "'" . implode("','", mxAddSlashesForSQL($xexusers)) . "'";

$days = 0;
$hours = 0;
$mins = 0;
$result = sql_query("SELECT uname, user_lastvisit FROM ${user_prefix}_users where (uname not in(" . $excludedusers . ")) AND (user_stat=1) ORDER BY user_lastvisit DESC limit 0,$numusers");

$list = "";
while (list($uname, $date) = sql_fetch_row($result)) {
    $realtime = time() - $date;
    $dont = false;
    // how many days ago?
    if ($realtime >= (60 * 60 * 24 * 2)) { // if it's been more than 2 days
        $days = mxValueToString(floor($realtime / (60 * 60 * 24)), 0);
        $dont = true;
    } else if ($realtime >= (60 * 60 * 24)) { // if it's been less than 2 days
        $days = 1;
        $realtime -= (60 * 60 * 24);
    }
    if (!$dont) {
        // how many hours ago?
        if ($realtime >= (60 * 60)) {
            // $list .= " ($realtime) ";
            $hours = floor($realtime / (60 * 60));
            $realtime -= (60 * 60 * $hours);
        }
        // how many minutes ago?
        if ($realtime >= 60) {
            $mins = floor($realtime / 60);
            $realtime -= (60 * $mins);
        }
        // just a little precation, although I don't *think* mins will ever be 60...
        if ($mins == 60) {
            $mins = 0;
            $hours += 1;
        }
    }
    $list .= "<div><img src=\"images/menu/rarrow.gif\" width=\"14\" height=\"9\" alt=\"\" border=\"0\">&nbsp;&nbsp;<a href=\"modules.php?name=Userinfo&amp;uname=$uname\">" . urlencode($uname) . "</a>: ";
    if ($dont) {
        $list .= "" . $days . "&nbsp;" . _LASTSEENDAYS . "";
    } else {
        if ($days > 0) {
            $list .= "" . $days . "&nbsp;" . _LASTSEENDAY . "" . (($hours == 0 && $mins == 0)?(""):(","));
        }
        if ($hours > 0) {
            $list .= "" . $hours . "&nbsp;" . (($hours > 1)?("" . _LASTSEENHOURS . ""):("" . _LASTSEENHOUR . "")) . (($mins == 0)?(""):(","));
        }
        if ($mins > 0) {
            $list .= "" . $mins . "&nbsp;" . (($mins > 1)?("" . _LASTSEENMINUTES . ""):("" . _LASTSEENMINUTE . "")) . "";
        } else { // less than a minute :)
            $list .= "" . $realtime . "&nbsp;" . _LASTSEENSECONDS . "";
        }
    }
    $list .= " " . _LASTSEENAGO . "</div>";
    $days = 0;
    $hours = 0;
    $mins = 0;
    $dont = false;
} # end while
if ($list) {
    $contentlast = ($blockheigth == 0) ? $list : "<div style=\"overflow : auto;\">" . $list . "</div>";
}

//
$ucount = intval($ucount);
$qry="SELECT uname, user_regtime FROM ${user_prefix}_users WHERE user_stat=1 ORDER BY user_regtime DESC LIMIT ".$numusers.";";
$result = sql_query($qry);	# x neuste User ermitteln
while (list($uname, $user_regtime) = sql_fetch_row($result)) {
	$lasts[] = '<img src="images/menu/rarrow.gif" width="14" height="9" alt="" border="0">&nbsp;<a href="modules.php?name=Userinfo&amp;uname='.$uname.'">'.$uname.'</a>';
	}

if (isset($lasts)) {
	$contentuser = implode("<br>\n",$lasts);
	}

//

$numusers = 10;
// Hoehe des Scrollings, 0 um nicht zu scrollen
$hoehe = 70;
$scrolling = 0;
// #################################################################################################################
global $user_prefix, $prefix;
$thisfile = basename(__FILE__);

$mxblockcache = false;
// SQL-bedingung fuer excluded Users erstellen
if (!defined("mxYALoaded")) define("mxYALoaded", 1);
include("modules/Your_Account/config.php");
if (empty($useuserpoints) && !mxIsAdmin()) {
    $content = "";
    return;
}

$exusers = explode (",", $excludedusers);
if (!mxIsAdmin()) {
    foreach ($exusers as $key => $value) {
        $xexusers[] = trim($value);
    }
}
$xexusers[] = $GLOBALS['anonymous'];
$xexusers[] = "Anonymous";
$excludedusers = "'" . implode("','", mxAddSlashesForSQL($xexusers)) . "'";

$qry = "
SELECT ${prefix}_userpoints.punkte, ${user_prefix}_users.uname
FROM ${prefix}_userpoints LEFT JOIN ${user_prefix}_users ON ${prefix}_userpoints.uid = ${user_prefix}_users.uid
WHERE ${user_prefix}_users.user_stat=1 AND ${prefix}_userpoints.punkte>0 AND (${user_prefix}_users.uname not in($excludedusers))
ORDER BY ${prefix}_userpoints.punkte DESC, ${prefix}_userpoints.uid
LIMIT 0,$numusers;";
$result = sql_query($qry);

$content1 = "";
$i = 0;
if ($result) {
    while (list($punkte, $uname) = sql_fetch_row($result)) {
        $i++;
        $content1 .= "<div><img src=\"images/menu/rarrow.gif\" width=\"14\" height=\"9\" alt=\"\" border=\"0\">&nbsp;&nbsp;<a href=\"modules.php?name=Userinfo&amp;uname=" . urlencode($uname) . "\">$uname</a>: " . mxValueToString($punkte, 0) . "&nbsp;Puan</div>";
    }
}

if (!empty($content1)) { // && $i >= $numusers
    if ($scrolling) $content .= "<div >\n";
    $contentpoint .= $content1 . "\n";
    if ($scrolling) $contentpoint .= "</div>";
}



//Göster

$content='<table style="width:100%; padding:2px; border:1px solid #f2f2f2;" border="0" cellpadding="2" cellspacing="2">
<tr>
<td style="width:35%; padding:2px; ">&nbsp;&nbsp;&nbsp;<b>Puanlar</b></td>
<td style="width:30%; padding:2px; ">&nbsp;&nbsp;&nbsp;<b>Yeni Üyeler</b></td>
<td style="width:35%; padding:2px; ">&nbsp;&nbsp;&nbsp;<b>Kim Buradaydý</b></td>
</tr><tr>
<td style="width:35%; padding:5px; border:1px solid #f2f2f2;">'.$contentpoint.'</td>
<td style="width:30%; padding:5px; border:1px solid #f2f2f2;">'.$contentuser.'</td>
<td style="width:35%; padding:5px; border:1px solid #f2f2f2;">'.$contentlast.'</td>
</tr></table>
';
?>