<?php

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

#Путь к папки форума
define('DIR_FORUM', '/modules/forum/');

if (isset($user)) {
    $limit = $user['set_them_forum_num']; #Количество выводимых тем.
} else {
    $limit = 5;
}
$k_post = mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_themes`'), 0);
$k_page = k_page($k_post, $set['p_str']);
$page = page($k_page);
$start = $set['p_str'] * $page - $set['p_str'];

if ($k_post != 0) {
    $themes = mysql_query('SELECT * FROM `forum_themes` ORDER BY `time_post` DESC LIMIT ' . $limit);
    #Выводим тему
    while ($theme = mysql_fetch_object($themes)) {
echo "<div class='list-group-item-null list-group-item-grey'>";        
        $razdel = mysql_fetch_object(mysql_query('SELECT `id`, `id_forum` FROM `forum_razdels` WHERE `id` = ' . $theme->id_razdel));
        $forum = mysql_fetch_object(mysql_query('SELECT `id` FROM `forum` WHERE `id` = ' . $razdel->id_forum));
        $creater = mysql_fetch_object(mysql_query('SELECT `id`, `nick` FROM `user` WHERE `id` = ' . $theme->id_user));
        $count_posts = mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_posts` WHERE `id_theme` = ' . $theme->id), 0);
        $hide = (access('forum_post_ed')) ? NULL : '`hide` = "0" AND';
        $last_post = mysql_fetch_object(mysql_query('SELECT `id`, `hide`, `id_user`, `time` FROM `forum_posts` WHERE ' . $hide . ' `id_theme` = ' . $theme->id . ' ORDER BY `id` DESC'));
        $who = ($last_post && $last_post->id_user != 0) ? mysql_fetch_object(mysql_query('SELECT `id`, `nick` FROM `user` WHERE `id` = ' . $last_post->id_user)) : array();
        $who_id = ($last_post && $last_post->id_user != 0) ? $who->id : 0;
        $who_nick = ($last_post && $last_post->id_user != 0) ? $who->nick : 'Система';

                    if ($theme->reason_close != NULL) {
                        $type = "<i class='fa fa-file-text fa-fw'></i> " . toOutput($theme->name, 1, 1, 0, 0, 0) . " <i class='fa fa-lock fa-fw'></i>";
                    } elseif ($theme->type == 1) {
                        $type = "<i class='fa fa-file-text fa-fw'></i> " . toOutput($theme->name, 1, 1, 0, 0, 0) . " <i class='fa fa-thumb-tack fa-fw'></i>";
                    } else {
                        $type = "<i class='fa fa-file-text fa-fw'></i> " . toOutput($theme->name, 1, 1, 0, 0, 0) . "";
                    }

        echo "<a href='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id.html'>$type <span class='badge'>$count_posts</span></a>";
        echo "</div>";
    }
}

