<?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.
 *
 * $Revision: 1.14.2.1 $
 * $Author: tora60 $
 * $Date: 2008/05/13 22:06:43 $
 */

defined('mxMainFileLoaded') or die('access denied');

// Anzahl der User im Block
$numusers = 20;
// 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 style="text-indent: -8px; margin-left: 8px;"><strong><big>&middot;</big></strong>&nbsp;<a href="modules.php?name=Userinfo&amp;uname=' . urlencode($uname) . '">' . $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) {
    $content = ($blockheigth == 0) ? $list : '<div style="height: ' . $blockheigth . 'px; overflow: auto;">' . $list . '</div>';
}
// Blocktitel aus Sprachdatei auslesen
$blockfiletitle = _LASTSEENTITLE;

?>