<?php

/* DCMS Special
 * Дата последнего редактирования 09.10.2016
 * Модифицировал densnet
 * Автор yadalay
 */

$forum = mysqli_fetch_object($db->query('SELECT `id`, `access`, `name` FROM `forum` WHERE `id` = ' . intval($_GET['forum'])));
$razdel = mysqli_fetch_object($db->query('SELECT `id`, `id_forum`, `name` FROM `forum_razdels` WHERE `id_forum` = ' . $forum->id . ' AND `id` = ' . intval($_GET['razdel'])));
$theme = mysqli_fetch_object($db->query('SELECT `id`, `id_razdel`, `name` FROM `forum_themes` WHERE `id_razdel` = ' . $razdel->id . ' AND `id` = ' . intval($_GET['theme'])));

if (!$theme || !$razdel || !$forum || ($forum->access == 1 && $user['group_access'] < 8) || ($forum->access == 2 && $user['group_access'] < 3)) {
    header('Location: ' . DIR_FORUM);
    exit;
} else {
    $set['title'] = lang('Сейчас в теме') . ' - ' . toOutput($theme->name, 1, 1, 0, 0, 0);
    require_once H . 'sys/inc/thead.php';

    aut();

    $q = $db->super_query("SELECT COUNT(*) as count FROM user WHERE date_last > '" . (time() - 600) . "' AND url LIKE '/modules/forum/$forum->id/$razdel->id/$theme->id%'");

    $k_post = $q['count'];
    $k_page = k_page($k_post, $set['p_str']);
    $page = page($k_page);
    $start = $set['p_str'] * $page - $set['p_str'];

    #Навигация
    echo "<div class='list-group-item-null list-group-item-grey'><small>";
    echo "<a href='/' class='hint--right' data-hint='" . lang('На главную') . "'><i class='fa fa-home fa-lg'></i></a> <i class='fa fa-angle-right fa-fw'></i> ";
    echo "<a href='" . DIR_FORUM . "'>" . lang('Форум') . "</a> <i class='fa fa-angle-right fa-fw'></i> ";
    echo "<a href='" . DIR_FORUM . "$forum->id/'>" . toOutput(utf8_substr($forum->name, 10)) . "</a> <i class='fa fa-angle-right fa-fw'></i> ";
    echo "<a href='" . DIR_FORUM . "$forum->id/$razdel->id/'>" . toOutput(utf8_substr($razdel->name, 10)) . "</a> <i class='fa fa-angle-right fa-fw'></i> ";
    echo "<a href='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id.html'>" . toOutput(utf8_substr($theme->name, 10)) . "</a> <i class='fa fa-angle-right fa-fw'></i> ";
    echo lang('Сейчас в теме');
    echo "</small></div><br />";

    if ($k_post == 0) {
        $doc->NoResult();
    }

    $persons = $db->query('SELECT `id`, `sex`, `nick` FROM `user` WHERE `date_last` > "' . (time() - 600) . '" AND `url` LIKE "/modules/forum/' . $forum->id . '/' . $razdel->id . '/' . $theme->id . '%" ORDER BY `date_last` LIMIT ' . $start . ', ' . $set['p_str']);

    while ($person = mysqli_fetch_object($persons)) {
        echo "<table class='list-group-item-null list-group-item-grey dop'><tr><td class='icon14'>";
        echo avatar("$person->id", '40', 'border-radius: 2px;');
        echo "</td><td class='null'>";
        echo user($person->id);
        echo "</td></tr></table>";
    }

    if ($k_page > 1) {
        str(DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '/who/', $k_page, $page);
    }
}
