<?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.16.6.2 $
 * $Author: tora60 $
 * $Date: 2009/04/06 17:58:03 $
 */

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 Hoehe des Blocks in Pixel. 0 um die Hoehe nicht zu beschränken */
$blockheigth = 100;

$mxblockcache = false;
/* Variablen initialisieren */
global $prefix, $user_prefix;
if (@file_exists("language/whoonline/lang-" . $GLOBALS['currentlang'] . ".php")) {
    include_once("language/whoonline/lang-" . $GLOBALS['currentlang'] . ".php");
} else {
    include_once("language/whoonline/lang-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)) {
            $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 .= '<li>' . mxCreateUserprofileLink($uname) . ': ';
    if ($dont) {
        $list .= $days . "&nbsp;Tage";
    } else {
        if ($days > 0) {
            $list .= $days . "T" . (($hours == 0 && $mins == 0)?(""):(", "));
        }
        if ($hours > 0) {
            $list .= $hours . "&nbsp;" . (($hours > 1)?("h"):("h")) . (($mins == 0)?(''):(', '));
        }
        if ($mins > 0) {
            $list .= $mins . "&nbsp;" . (($mins > 1)?("min"):("min"));
        } else { // less than a minute :)
            $list .= $realtime . "&nbsp;" . _LASTSEENSECONDS;
        }
    }
    $list .= " " . _LASTSEENAGO . "</li>";
    $days = 0;
    $hours = 0;
    $mins = 0;
    $dont = false;
}

if ($list) {
    $content = ($blockheigth == 0) ? $list : '<ul class="list" style="height: ' . $blockheigth . 'px; overflow: auto;">' . $list . '</ul>';
}

/* Blocktitel aus Sprachdatei auslesen */
$blockfiletitle = _LASTSEENTITLE;

?>