<?php

include 'system/sys.php';
include 'system/funcs.php';

if(!isset ($us)) {
        header ('location: /');
        exit;
}

$items = DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `us` WHERE (`last`>'" . ( time () - 3600 ) . "')");
H ('Онлайн '.$items, 'Онлайн ' . $items . ' человек');

$items_per_page = 10;
$pages = ceil ( $items / $items_per_page );
$page = (int) $_GET['page'];

if ($page < 1)
        $page = 1;

if ($page > $pages)
        $page = $pages;
    
$start = $page * $items_per_page - $items_per_page;

if ($items == 0) {
        echo '<div class="lst">Список пуст..</div>';
}
else {

        $query = DB :: $dbs -> query ("SELECT `id`, `last` FROM `us` WHERE `last`>'" . ( time () - 3600 ) . "' ORDER BY `last` DESC LIMIT $start, $items_per_page");
        while ($u = $query -> fetch()) {
                echo '<div class="lst">' . uNick ($u['id']) . ' (' . datef ($u['last']) . ')</div>';
        }
    
    
        echo '<div class="list1">';
        echo 'Онлайн:             ' . DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `us` WHERE `last` > '" . ( time () - 3600 ) . "'") . '<br/>';
        echo 'Онлайн за 5 минут:  ' . DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `us` WHERE `last` > '" . ( time () - 300 ) . "'") . ' <br/>';
        echo 'Онлайн за 10 минут: ' . DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `us` WHERE `last` > '" . ( time () - 600 ) . "'") . ' <br/>';
        echo 'Онлайн за 20 минут: ' . DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `us` WHERE `last` > '" . ( time () - 1200 ) . "'") . '<br/>';
        echo '</div>';
        echo '<div class="lst">' . pages ("/online") . '</div>';

}

F ();
