<?php

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

$forum = mysql_fetch_object(mysql_query('SELECT * FROM `forum` WHERE `id` = ' . intval($_GET['forum'])));
$razdel = mysql_fetch_object(mysql_query('SELECT * FROM `forum_razdels` WHERE `id_forum` = ' . $forum->id . ' AND `id` = ' . intval($_GET['razdel'])));
$theme = mysql_fetch_object(mysql_query('SELECT * 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();

    $my_report = (isset($user)) ? mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_reports` WHERE `id_theme` = ' . $theme->id . ' AND `id_user` = ' . $user['id']), 0) : 0;
    $k_post = mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_posts` WHERE `id_theme` = ' . $theme->id), 0);

    if (mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_votes` WHERE `id_theme` = ' . $theme->id), 0) != 0) {
        $vote = mysql_fetch_object(mysql_query('SELECT * FROM `forum_votes` WHERE `id_theme` = ' . $theme->id));
        $vars = mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_votes_var` WHERE `id_theme` = ' . $theme->id), 0);
    } else {
        $vars = NULL;
    }

    if (isset($_GET['sort_0'])) {
        unset($_SESSION['sort_' . $user['id']]);

        header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '.html');
        exit;
    } elseif (isset($_GET['sort_1'])) {
        $_SESSION['sort_' . $user['id']] = 1;

        header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '.html');
        exit;
    } elseif (isset($_GET['download'])) {
        $file = mysql_fetch_object(mysql_query('SELECT `id`, `id_post`, `name`, `count_downloads` FROM `forum_post_files` WHERE `id` = ' . intval($_GET['download'])));
        $this_post = mysql_fetch_object(mysql_query('SELECT `hide`, `privat` FROM `forum_posts` WHERE `id` = ' . $file->id_post));

        if ($this_post->privat == 0 || ($this_post->privat == $user['id'] || $this_post->id_user == $user['id']) || ($this_post->hide != 0 && access('forum_post_ed'))) {
            mysql_query('UPDATE `forum_post_files` SET `count_downloads` = ' . ($file->count_downloads + 1) . ' WHERE `id` = ' . $file->id);
            header('Location: ' . DIR_FORUM_FILES . $file->name);
        } else {
            header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '.html');
        }
        exit;
    } elseif (isset($user) && isset($_GET['cleare_theme']) && access('forum_them_edit')) {
        require_once 'action/clear_theme.php'; #Очистка темы.
    } elseif (isset($user) && isset($_GET['edit_theme'])) {
        require_once 'action/edit_theme.php'; #Редактирование темы.
    } elseif (isset($user) && isset($_GET['close_theme']) && $theme->reason_close == NULL && access('forum_them_edit')) {
        require_once 'action/close_theme.php'; #Закрытие темы.
    } elseif (isset($user) && isset($_GET['open_theme']) && $theme->reason_close != NULL && access('forum_them_edit')) {

        $_SESSION['message'] = lang('Тема успешно открыта');

        $msg_sys = "Проблема решена. [url=/info.php?id=$user[id]]$user[nick][/url] " . ($user['sex'] ? 'открыл' : 'открыла') . " тему.";

        mysql_query('INSERT INTO `forum_posts` SET `id_theme` = ' . $theme->id . ', `id_user` = "0", `id_admin` = "0", `text` = "' . mysql_real_escape_string($msg_sys) . '", `time` = ' . $time);
        mysql_query('UPDATE `forum_themes` SET `reason_close` = "" WHERE `id` = ' . $theme->id);

        header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '.html');
        exit;
    } elseif (isset($user) && isset($_GET['create_vote']) && ($theme->reason_close == NULL || ($theme->reason_close != NULL && access('forum_post_close'))) && $user['id'] == $theme->id_user) {
        require_once 'action/create_vote.php'; #Создание голосования.
    } elseif (isset($user) && isset($_GET['edit_vote']) && $theme->reason_close == NULL && $user['id'] == $theme->id_user) {
        require_once 'action/edit_vote.php'; #Редактирование голосования.
    } elseif (isset($user) && isset($_GET['report'])) {
        if ($my_report != 0 || access('forum_them_edit') || $user['id'] == $theme->id_user || $theme->reason_close != NULL) {
            header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '.html');
            exit;
        } else {
            if (isset($_POST['send'])) {
                $text = mysql_real_escape_string(trim($_POST['text']));

                if (mb_strlen($text) < 5) {
                    echo "<div class='alert alert-danger'>" . lang('Слишком короткая причина. Указывайте нормальную причину, если не хотите быть забаненым администрацией') . ".</div>";
                } else {
                    $persons = mysql_query('SELECT `id`, `group_access` FROM `user` WHERE `group_access` > "2"');

                    while ($person = mysql_fetch_object($persons)) {
                        $access = mysql_result(mysql_query('SELECT COUNT(*) FROM `user_group_access` WHERE `id_group` = ' . $person->group_access . ' AND `id_access` = "forum_them_edit"'), 0);
                        if ($access != 0) {
                            $msg = "[url=/info.php?id=$user[id]]$user[nick][/url] " . ($user['sex'] ? 'подал' : 'подала') . " жалобу на тему [url=" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id.html]$theme->name[/url].
                                    Причина указана [url=" . DIR_FORUM . "reports.html]здесь[/url]";
                            mysql_query('INSERT INTO `mail` SET `id_user` = "0", `id_kont` = ' . $person->id . ', `msg` = "' . mysql_real_escape_string($msg) . '", `time` = ' . $time);
                        }
                    }

                    mysql_query('INSERT INTO `forum_reports` SET `id_theme` = ' . $theme->id . ', `id_user` = ' . $user['id'] . ', `text` = "' . $text . '"');

                    $_SESSION['message'] = lang('Жалоба успешно отправлена на рассмотрение администрацией');

                    header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '.html');
                    exit;
                }
            }

            #Навигация
            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(cutStr($forum->name, 30)) . "</a> <i class='fa fa-angle-right fa-fw'></i> ";
            echo "<a href='" . DIR_FORUM . "$forum->id/$razdel->id/'>" . toOutput(cutStr($razdel->name, 30)) . "</a> <i class='fa fa-angle-right fa-fw'></i> ";
            echo "<a href='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id.html'>" . toOutput(cutStr($theme->name, 30)) . "</a> <i class='fa fa-angle-right fa-fw'></i> ";
            echo lang('Жалоба');
            echo "</small></div><br />";

            echo "<form method='post' class='list-group-item-null' action='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/report.html'>";
            $doc->Textarea('text', 'Укажите причину');
            echo "<br />";
            $doc->Button('btn btn-primary btn-sm', 'send', null, 'Отправить');
            echo "</form>";

            require_once H . 'sys/inc/tfoot.php';
            exit;
        }
    }

    $my_voice = (isset($vote) && isset($user)) ? mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_vote_voices` WHERE `id_user` = ' . $user['id'] . ' AND `id_vote` = ' . $vote->id), 0) : NULL;

    if (isset($user)) {
        $last_post = mysql_result(mysql_query('SELECT MAX(`id`) FROM `forum_posts` WHERE `id_theme` = ' . $theme->id), 0);

        if (isset($_GET['delete_post']) && access('forum_post_ed')) {

            $_SESSION['message'] = lang('Комментарий успешно удалён');

            $files = mysql_query('SELECT `name` FROM `forum_post_files` WHERE `id_post` = ' . intval($_GET['delete_post']));

            while ($file = mysql_fetch_object($files)) {
                unlink(DIR_FORUM_FILES . $file->name);
            }

            mysql_query('DELETE FROM `forum_post_rating` WHERE `id_post` = ' . intval($_GET['delete_post']));
            mysql_query('DELETE FROM `forum_posts` WHERE `id` = ' . intval($_GET['delete_post']));

            if ($k_post == 0) {
                mysql_query('UPDATE `forum_themes` SET `time_post` = ' . $theme->time . ' WHERE `id` = ' . $theme->id);
            }

            header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '.html');
            exit;
        } elseif (isset($_GET['hide']) && access('forum_post_ed')) {

            $_SESSION['message'] = lang('Комментарий успешно скрыт');

            mysql_query('UPDATE `forum_posts` SET `id_admin` = ' . $user['id'] . ', `hide` = "1" WHERE `id` = ' . intval($_GET['hide']));

            header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '.html');
            exit;
        } elseif (isset($_GET['display']) && access('forum_post_ed')) {

            $_SESSION['message'] = lang('Комментарий успешно показан вновь');

            mysql_query('UPDATE `forum_posts` SET `id_admin` = "0", `hide` = "0" WHERE `id` = ' . intval($_GET['display']));

            header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '.html');
            exit;
        } elseif (isset($_GET['vote']) && $my_voice == 0) {

            $_SESSION['message'] = lang('Ваш голос успешно учтён');

            mysql_query('INSERT INTO `forum_vote_voices` SET `id_vote` = ' . $vote->id . ', `id_variant` = ' . intval($_GET['vote']) . ', `id_user` = ' . $user['id']);

            header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '.html');
            exit;
        } elseif (isset($_GET['del_file']) && (mysql_fetch_object(mysql_query('SELECT `id_user` FROM `forum_post_files` WHERE `id` = ' . intval($_GET['del_file'])))->id_user == $user['id'] || access('forum_post_ed'))) {

            $_SESSION['message'] = lang('Файл успешно удалён');

            $file = mysql_fetch_object(mysql_query('SELECT `id`, `id_post`,  `name` FROM `forum_post_files` WHERE `id` = ' . intval($_GET['del_file'])));

            unlink(DIR_FORUM_FILES . $file->name);

            $id_post = $file->id_post;

            unset($_SESSION['sort_' . $user['id']]);

            $count = mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_posts` WHERE `id_theme` = ' . $theme->id . ' AND `id` < ' . ($id_post + 1)), 0);
            $count_posts = mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_posts` WHERE `id_theme` = ' . $theme->id), 0);
            $this_pages = k_page($count, $set['p_str']);
            $pages = ($this_pages > 0) ? '/page=' . $this_pages : '.html';

            mysql_query('DELETE FROM `forum_post_files` WHERE `id` = ' . $file->id);

            header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . $pages . '#' . $id_post);
            exit;
        }
        if (isset($_POST['comment']) && ($theme->reason_close == NULL || ($theme->reason_close != NULL && access('forum_post_close')))) {
            $text = mysql_real_escape_string($_POST['text']);
            $mat = antimat($text);

            if ($mat) {
                echo "<div class='alert alert-danger'>" . lang('В тексте сообщения обнаружен мат') . ": $mat.</div>";
            } elseif (mb_strlen($text) < 2) {
                echo "<div class='alert alert-danger'>" . lang('Комментарий слишком короткий') . ".</div>";
            } elseif (mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_posts` WHERE `id_user` = ' . $user['id'] . ' AND `text` = "' . $text . '"'), 0) != 0) {
                echo "<div class='alert alert-danger'>" . lang('Вы уже писали это в данной теме. Будьте оригинальнее') . ".</div>";
            } else {
                if (isset($_GET['cit']) && is_numeric($_GET['cit'])) {
                    $cit = intval($_GET['cit']);
                    $privat = 0;
                } elseif (isset($_GET['privat']) && is_numeric($_GET['privat'])) {
                    $privat = intval($_GET['privat']);
                    $cit = 0;
                } else {
                    $cit = 0;
                    $privat = 0;
                }

                mysql_query('UPDATE `forum_themes` SET `time_post` = ' . $time . ' WHERE `id` = ' . $theme->id);
                mysql_query('INSERT INTO `forum_posts` SET `id_theme` = ' . $theme->id . ', `id_user` = ' . $user['id'] . ', `id_admin` = "0", `text` = "' . $text . '", `cit` = ' . $cit . ', `privat` = ' . $privat . ', `time` = "' . $time . '", `hide` = "0"');

                $post_id = mysql_insert_id();
                $count = mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_posts` WHERE `id_theme` = ' . $theme->id . ' AND `id` < ' . ($post_id + 1)), 0);
                $count_posts = mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_posts` WHERE `id_theme` = ' . $theme->id), 0);
                $this_pages = k_page($count, $set['p_str']);
                $pages = ($this_pages > 0) ? '/page=' . $this_pages : '.html';
                $j_f = '[url=/info.php?id=' . $user['id'] . ']' . $user['nick'] . '[/url] ' . ($user['sex'] ? "написал" : "написала") . ' в теме "[url=' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . $pages . '#' . $post_id . ']' . $theme->name . '[/url]", на которую Вы подписаны.
                Комментарий: [b]' . $text . '[/b]';
                $forum_js = mysql_query('SELECT `id_user` FROM `forum_journal` WHERE `id_theme` = ' . $theme->id);

                while ($forum_j = mysql_fetch_object($forum_js)) {
                    if (mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_posts` WHERE `id` = ' . $post_id . ' AND `id_user` = ' . $user['id']), 0) == 0 && ((isset($_GET['answer']) && $_GET['answer'] != $forum_j->id_user) || !isset($_GET['answer']))) {
                        mysql_query('INSERT INTO `f_journal` SET `id_user` = ' . $forum_j->id_user . ', `type` = "themes", `text` = "' . mysql_real_escape_string($j_f) . '", `time` = "' . $time . '"');
                    }
                }
                if (!isset($_GET['cit']) && !isset($_GET['privat']) && isset($_GET['answer'])) {
                    $j = '[url=/info.php?id=' . $user['id'] . ']' . $user['nick'] . '[/url] ' . ($user['sex'] ? "ответил" : "ответила") . ' Вам в теме "[url=' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . $pages . '#' . $post_id . ']' . $theme->name . '[/url]".
                    Ответ: [b]' . $text . '[/b]';
                    $type = 'answers';
                } elseif (isset($_GET['cit']) && isset($_GET['answer'])) {
                    $j = '[url=/info.php?id=' . $user['id'] . ']' . $user['nick'] . '[/url] ' . ($user['sex'] ? "процитировал" : "процитировала") . ' Ваш комментарий в теме [url=' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . $pages . '#' . $post_id . ']' . $theme->name . '[/url].
                    Цитата: [b]' . $text . '[/b]';
                    $type = 'quotes';
                } elseif (isset($_GET['privat'])) {
                    $j = '[url=/info.php?id=' . $user['id'] . ']' . $user['nick'] . '[/url] ' . ($user['sex'] ? "оставил" : "оставила") . ' Вам приватное сообщение в теме [url=' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . $pages . '#' . $post_id . ']' . $theme->name . '[/url].
                    Сообщение: [b]' . $text . '[/b]';
                    $type = 'privat';
                }

                if (isset($user) && $user['id'] != $theme->id_user && !isset($_GET['answer']) && !isset($_GET['cit']) && !isset($_GET['privat'])) {
                    $j_t = '[url=/info.php?id=' . $user['id'] . ']' . $user['nick'] . '[/url] ' . ($user['sex'] ? "написал" : "написала") . ' комментарий в Вашей теме "[url=' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . $pages . '#' . $post_id . ']' . $theme->name . '[/url]".
                    Комментарий: [b]' . $text . '[/b]';
                    mysql_query('INSERT INTO `f_journal` SET `id_user` = ' . $theme->id_user . ', `type` = "my_themes", `text` = "' . mysql_real_escape_string($j_t) . '", `time` = "' . $time . '"');
                }

                if (isset($_GET['answer'])) {
                    mysql_query('INSERT INTO `f_journal` SET `id_user` = ' . intval($_GET['answer']) . ', `type` = "' . mysql_real_escape_string($type) . '", `text` = "' . mysql_real_escape_string($j) . '", `time` = "' . $time . '"');
                } elseif (isset($_GET['privat'])) {
                    mysql_query('INSERT INTO `f_journal` SET `id_user` = ' . intval($_GET['privat']) . ', `type` = "' . mysql_real_escape_string($type) . '", `text` = "' . mysql_real_escape_string($j) . '", `time` = "' . $time . '"');
                }

                $_SESSION['message'] = lang('Сообщение добавлено');

                $post = mysql_fetch_object(mysql_query('SELECT `id` FROM `forum_posts` WHERE `id` = ' . $post_id));

                if (isset($_POST['add_file']) && $post) {
                    header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '/' . $post->id . '/add_file');
                } else {
                    header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '.html');
                }

                exit;
            }
        } elseif (isset($user) && isset($_POST['edit_post'])) {
            $edit_post = mysql_real_escape_string(trim($_POST['post']));
            $post_edit = mysql_fetch_object(mysql_query('SELECT `count_edit` FROM `forum_posts` WHERE `id` = ' . intval($_POST['id_post'])));

            mysql_query('UPDATE `forum_posts` SET `text` = "' . $edit_post . '", `last_edit` = ' . $time . ', `who_edit` = "' . $user['nick'] . '", `count_edit` = ' . ($post_edit->count_edit + 1) . ' WHERE `id` = ' . intval($_POST['id_post']));

            header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '.html#' . intval($_POST['id_post']));
            exit;
        } elseif (isset($_POST['cancel_edit'])) {
            header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '.html');

            exit;
        } elseif (isset($user) && isset($_GET['act_posts']) && (isset($_POST['delete_posts']) || isset($_POST['hide_posts']) || isset($_POST['display_posts']))) {
            include_once 'action/actions_posts.php'; #Действия над постами.
        }
    }
    if (isset($user) && isset($vote) && mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_votes_var` WHERE `variant` = "" AND `id_vote` = ' . $vote->id), 0) != 0) {
        mysql_query('DELETE FROM `forum_votes_var` WHERE `id_vote` = ' . $vote->id);
        mysql_query('DELETE FROM `forum_votes` WHERE `id` = ' . $vote->id);

        header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '.html');
        exit;
    }
    if (isset($user) && isset($_GET['journal_yes'])) {
        if (mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_journal` WHERE `id_theme` = ' . $theme->id . ' AND `id_user` = ' . $user['id']), 0) == 0) {
            mysql_query('INSERT INTO `forum_journal` SET `id_theme` = ' . $theme->id . ', `id_user` = ' . $user['id']);

            $_SESSION['message'] = lang('Вы успешно подписались на эту тему');
        }
        header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '.html');
        exit;
    } elseif (isset($user) && isset($_GET['journal_no'])) {
        if (mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_journal` WHERE `id_theme` = ' . $theme->id . ' AND `id_user` = ' . $user['id']), 0) != 0) {
            mysql_query('DELETE FROM `forum_journal` WHERE `id_theme` = ' . $theme->id . ' AND `id_user` = ' . $user['id']);

            $_SESSION['message'] = lang('Вы успешно отписались от этой темы');
        }
        header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '.html');
        exit;
    }
    if (isset($_SESSION['success'])) {
        echo $_SESSION['message'];
        unset($_SESSION['success']);
    }

    #Навигация
    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 toOutput(utf8_substr($theme->name, 10));
    echo "</small></div><br />";

    if ($theme->reason_close != NULL) {
        echo "<div class='list-group-item-null list-group-item-warning'>$theme->reason_close</div>";
    }

    $person = mysql_fetch_object(mysql_query('SELECT `id`, `nick`, `sex` FROM `user` WHERE `id` = ' . $theme->id_user));
    $k_page = k_page($k_post, $set['p_str']);
    $page = page($k_page);
    $start = $set['p_str'] * $page - $set['p_str'];

    echo "<table class='list-group-item-null list-group-item-grey'><tr><td class='icon14'>";
    echo avatar("$person->id", '50', 'border-radius: 2px;');
    echo "</td><td class='null'>";
    echo user($person->id) . " <span style='color: #9197a3;' data-toggle='tooltip' data-placement='top' title='" . date::time($theme->time) . "'>" . date::times($theme->time) . "</span><br />";
    echo "<b>" . toOutput($theme->name) . "</b>";
    echo "</td></tr><tr><td class='null' colspan='2'>";
    echo toOutput($theme->description);

    if (isset($user) && $my_report == 0 && !access('forum_them_edit') && $user['id'] != $theme->id_user && $theme->reason_close == NULL) {
        echo "<br /><a href='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/report.html'><span class='fa fa-flag fa-fw'></span> " . lang('Пожаловаться') . "</a> &nbsp; ";
    }
    if (isset($user) && $user['id'] != $theme->id_user) {
        if (isset($user) && $my_report == 0 && !access('forum_them_edit') && $user['id'] != $theme->id_user && $theme->reason_close == NULL) {
            
        } else {
            echo "<br />";
        }
        $journal = mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_journal` WHERE `id_theme` = "' . $theme->id . '" AND `id_user` = ' . $user['id']), 0);
        $theme_journal = ($journal == 0) ? "<a href='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/journal_yes'><span class='fa fa-rss fa-fw'></span> " . lang('Подписаться') . "</a>" : "<a href='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/journal_no'><span class='fa fa-rss fa-fw'></span> Вы подписаны</a>";

        echo " $theme_journal";
    }
    echo "</td></tr></table>";


    if (isset($vote)) {
        echo "<div class='list-group-item-null list-group-item-warning'>";

        $all_votes = mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_vote_voices` WHERE `id_vote` = ' . $vote->id), 0);
        $i = 0;

        echo "<b>" . toOutput($vote->name) . "</b><br />";

        $vars = mysql_query('SELECT `id`, `variant` FROM `forum_votes_var` WHERE `id_vote` = ' . $vote->id . ' ORDER BY `id` ASC');

        while ($var = mysql_fetch_object($vars)) {
            $i++;
            $vote_var = mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_vote_voices` WHERE `id_vote` = ' . $vote->id . ' AND `id_variant` = ' . $var->id), 0);
            $procent = ($all_votes == 0) ? 0 : $vote_var / $all_votes * 100;
            $procent = sprintf("%u", $procent);

            echo toOutput($var->variant) . ' (' . $procent . '%) - ' . $vote_var . ' чел.';

            if (isset($user) && $my_voice == 0) {
                echo "<a href = '" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/vote=$var->id'>";
            }

            echo "<progress class='progress progress-info' value='$procent' max='100'>$procent%</progress>";

            if (isset($user) && $my_voice == 0) {
                echo '</a>';
            }
        }
        echo "<span style='color: grey;'>" . lang('Начало голосования') . ": <span title='" . date::time($vote->time) . "' data-toggle='tooltip' data-placement='top'>" . date::times($vote->time) . "</span></span><br />";

        if ($vote->time_end > time()) {
            echo "<span style='color: grey;'>" . lang('До завершения голосования') . ":<br /> <b>" . date::time($vote->time_end) . "</b></span><br />";
        } elseif ($vote->time_end < time() && $vote->time_end != 0) {
            echo "<span style='color: green;'>" . lang('Голосование завершено') . ".</span><br />";
        }

        echo "<span style='color: #4FC3F7;'><i class='fa fa-users fa-fw'></i> " . lang('Проголосовало') . ": $all_votes чел.</span>";
        echo "</div>";
    }

    if ($theme->time_edit != 0 && $theme->id_admin != 0) {
        $admin = mysql_fetch_object(mysql_query('SELECT `id`, `nick` FROM `user` WHERE `id` = ' . $theme->id_admin));
        #Показываем последнее редактирование
        echo "<div class='list-group-item-null' style='border-bottom: 1px solid #dcdee3;color: #9197a3;'><small><i class='fa fa-pencil fa-fw'></i> " . lang('Посл. раз редактировалось') . " <a href='/info.php?id=$admin->id'>$admin->nick</a> (<span title='" . date::time($theme->time_edit) . "' data-toggle='tooltip' data-placement='top'>" . date::timek($theme->time_edit) . "</span>)</small></div>";
    }

    echo "<div class='list-group-item-null'>";
    echo "<i class='fa fa-comments fa-fw'></i> <b>" . sklon_text($k_post, array(lang('комментарий'), lang('комментария'), lang('комментариев'))) . "</b><br />";
    echo "</div>";

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

    if (isset($user)) {
        echo "<div class='list-group-item-null list-group-item-grey'>";
        $li = "<li class='nav-item'><a class='nav-link' ";
        $lir = "<li class='nav-item'><a class='nav-link' ";

        echo "<ul class='nav nav-tabs' style='margin-bottom: -11px;'>";

        if (!isset($_SESSION['sort_' . $user['id']])) {
            $lir = "<li class='nav-item'><a class='nav-link active'>" . lang('Вверху') . "</a></li> <li class='nav-item'><a class='nav-link' href='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/sort_1'>" . lang('Внизу') . "</a></li>";
        } else {
            $lir = "<li class='nav-item'><a class='nav-link' href='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/sort_0'>" . lang('Вверху') . "</a></li> <li class='nav-item'><a class='nav-link active'>" . lang('Внизу') . "</a></li>";
        }

        echo "$lir";
        echo "</ul>";
        echo "</div>";
    }

    if (isset($user) && ($theme->reason_close == NULL || ($theme->reason_close != NULL && access('forum_post_close')))) {
        $cit = 0;
        $privat = 0;
        $text = '';

        if (isset($_GET['cit'])) {
            $cit = intval($_GET['cit']);
            $answer = intval($_GET['answer']);
            $text = mysql_fetch_object(mysql_query('SELECT `id`, `nick` FROM `user` WHERE `id` = ' . $answer))->nick . ', ';

            echo "<form method='post' class='list-group-item-null' name='form' action='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/cit=$cit/answer=$answer'>";
        } elseif (isset($_GET['privat'])) {
            $privat = intval($_GET['privat']);
            $text = mysql_fetch_object(mysql_query('SELECT `id`, `nick` FROM `user` WHERE `id` = ' . $privat))->nick . ', ';

            echo "<form method='post' class='list-group-item-null' name='form' action='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/privat=$privat'>";
        } elseif (isset($_GET['answer'])) {
            $answer = intval($_GET['answer']);
            $text = mysql_fetch_object(mysql_query('SELECT `id`, `nick` FROM `user` WHERE `id` = ' . $answer))->nick . ', ';

            echo "<form class='list-group-item-null' method='post' name='form' action='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/answer=$answer'>";
        } else {
            echo "<form method='post' class='list-group-item-null' name='form' action='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id.html'>";
        }
        $cit = mysql_fetch_object(mysql_query('SELECT `text` FROM `forum_posts` WHERE `id` = ' . $cit));
        if (isset($_GET['cit']) && isset($_GET['answer'])) {
            echo "<div class='cit'>Цитата: " . toOutput($cit->text) . "</div>";
        }

        echo auto_bb("form", "text");
        echo "<textarea name='text' class='form-control'>$text</textarea>";
        $doc->Checkbox('add_file', 'Прикрепить файл', 1);
        $doc->Button('btn btn-primary btn-sm', 'comment', null, 'Отправить');

        echo "</form>";
    }
    if (isset($_GET['act_posts'])) {
        echo "<form class='list-group-item-null list-group-item-grey' action='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/act_posts' method='post' style='padding: 0px'>";
    }

    $post_count = $start;
    $sort = (!isset($_SESSION['sort_' . $user['id']])) ? 'DESC' : 'ASC';
    $limit = (isset($_GET['act_posts'])) ? NULL : ' LIMIT ' . $start . ', ' . $set['p_str'];
    $posts = mysql_query('SELECT * FROM `forum_posts` WHERE `id_theme` = ' . $theme->id . ' ORDER BY `id` ' . $sort . $limit);

    while ($post = mysql_fetch_object($posts)) {
        $man = ($post->id_user != 0) ? mysql_fetch_object(mysql_query('SELECT `id`, `nick`, `sex` FROM `user` WHERE `id` = ' . $post->id_user)) : array();
        $man_id = ($post->id_user != 0) ? $man->id : 0;
        $man_pol = ($post->id_user != 0) ? $man->sex : 0;
        $man_nick = ($post->id_user != 0) ? $man->nick : 'Система';
        $privat = ($post->privat == $user['id'] || ($post->id_user == $user['id'] && $post->privat != 0)) ? '<font color="red"><i class="fa fa-lock"></i></font>' : NULL;
        $admin = ($post->hide == 1) ? mysql_fetch_object(mysql_query('SELECT `id`, `nick`, `sex` FROM `user` WHERE `id` = ' . $post->id_admin)) : NULL;

        if ($post->privat == 0 || ($post->privat == $user['id'] || $post->id_user == $user['id']) || $user['group_access'] > 14) {
            $post_count++;
            echo "<a id='$post->id'></a>";

            if (IS_WEB) {
                #Меняем цвет сообщения, если скрытое
                if ($post->hide == 1) {
                    echo "<table class='list-group-item-null list-group-item-warning'><tr><td class='icon14' style='vertical-align: top;'>";
                } else {
                    echo "<table class='list-group-item-null'><tr><td class='icon14' style='vertical-align: top;'>";
                }
                avatar($man_id, '40', 'border-radius: 2px;');
                echo "</td><td class='null'>";
            } else {
                #Меняем цвет сообщения, если скрытое
                if ($post->hide == 1) {
                    echo "<div class='list-group-item-null list-group-item-warning'>";
                } else {
                    echo "<div class='list-group-item-null'>";
                }
            }

            echo "<div id='accordion' role='tablist' aria-multiselectable='true'>";
            echo "<div role='tab' id='headingTwo'>";
            echo "<span style='float: right;'><a class='collapsed' data-toggle='collapse' data-parent='#accordion' href='#post_$post->id' aria-expanded='false' aria-controls='collapseTwo'><i class='fa fa-ellipsis-v fa-fw'></i></a></span>";
            echo "</div>";

            if (isset($_GET['act_posts'])) {
                echo "<input type='checkbox' name='act[]' value='$post->id' /> ";
            }
            echo user_one($man_id) . " <small style='color: #9197a3;'>" . date::times($post->time) . " $privat</small><br />";

            if ($user['id'] != $post->id_user && $post->id_user != 0) {
                $_post = (isset($_GET['post'])) ? mysql_fetch_object(mysql_query('SELECT `id`, `rating`, `text` FROM `forum_posts` WHERE `id` = ' . intval($_GET['post']))) : NULL;

                if (isset($user) && isset($_GET['like']) && mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_post_rating` WHERE `id_user` = ' . $user['id'] . ' AND `id_post` = ' . intval($_GET['post']) . ' AND `type` = "0"'), 0) == 0) {
                    $plus = (mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_post_rating` WHERE `id_user` = ' . $user['id'] . ' AND `id_post` = ' . intval($_GET['post']) . ' AND `type` = "1"'), 0) != 0) ? 2 : 1;

                    if (mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_post_rating` WHERE `id_user` = ' . $user['id'] . ' AND `id_post` = ' . intval($_GET['post'])), 0) != 0) {
                        mysql_query('UPDATE `forum_post_rating` SET `type` = "0" WHERE `id_post` = ' . intval($_GET['post']) . ' AND `id_theme` = ' . $theme->id . ' AND `id_user` = ' . $user['id']);
                    } else {
                        mysql_query('INSERT INTO `forum_post_rating` SET `id_theme` = ' . $theme->id . ', `id_user` = ' . $user['id'] . ', `type` = "0", `id_post` = ' . intval($_GET['post']));
                    }

                    mysql_query('UPDATE `forum_posts` SET `rating` = ' . ($_post->rating + $plus) . ' WHERE `id` = ' . intval($_GET['post']));

                    $_SESSION['message'] = lang('Вы успешно проголосовали за пост');

                    $page = (is_numeric($_GET['page'])) ? intval($_GET['page']) : mysql_real_escape_string(trim($_GET['page']));

                    if ($page != 'end' && !is_numeric($page)) {
                        header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '.html');
                    } else {
                        header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '/page=' . $page . '#' . intval($_GET['post']));
                    }
                    exit;
                } elseif (isset($user) && isset($_GET['dislike']) && mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_post_rating` WHERE `id_user` = ' . $user['id'] . ' AND `id_post` = ' . intval($_GET['post']) . ' AND `type` = "1"'), 0) == 0) {
                    $minus = (mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_post_rating` WHERE `id_user` = ' . $user['id'] . ' AND `id_post` = ' . intval($_GET['post']) . ' AND `type` = "0"'), 0) != 0) ? 2 : 1;

                    if (mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_post_rating` WHERE `id_user` = ' . $user['id'] . ' AND `id_post` = ' . intval($_GET['post'])), 0) != 0) {
                        mysql_query('UPDATE `forum_post_rating` SET `type` = "1" WHERE `id_post` = ' . intval($_GET['post']) . ' AND `id_theme` = ' . $theme->id . ' AND `id_user` = ' . $user['id']);
                    } else {
                        mysql_query('INSERT INTO `forum_post_rating` SET `id_theme` = ' . $theme->id . ', `id_user` = ' . $user['id'] . ', `type` = "1", `id_post` = ' . intval($_GET['post']));
                    }

                    if (($_post->rating - $minus) < -5) {
                        $persons = mysql_query('SELECT `id`, `group_access` FROM `user` WHERE `group_access` > "2"');

                        while ($person = mysql_fetch_object($persons)) {
                            $access = mysql_result(mysql_query('SELECT COUNT(*) FROM `user_group_access` WHERE `id_group` = ' . $person->group_access . ' AND `id_access` = "forum_post_ed"'), 0);
                            if ($access != 0) {
                                $msg = 'Комментарий в теме [url=' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '/page=' . $page . '#' . $_post->id . ']' . $theme->name . '[/url] набрал много отрицательных отзывов. Есть подозрение, что он нарушает правила форума.
                    [b]Сам комментарий:[/b]
                    ' . toOutput($_post->text);
                                mysql_query('INSERT INTO `mail` SET `id_user` = "0", `id_kont` = ' . $person->id . ', `msg` = "' . mysql_real_escape_string($msg) . '", `time` = ' . $time);
                            }
                        }
                    }
                    mysql_query('UPDATE `forum_posts` SET `rating` = ' . ($_post->rating - $minus) . ' WHERE `id` = ' . intval($_GET['post']));

                    $_SESSION['message'] = lang('Вы успешно проголосовали за пост');

                    $page = (is_numeric($_GET['page'])) ? intval($_GET['page']) : mysql_real_escape_string(trim($_GET['page']));
                    if ($page != 'end' && !is_numeric($page)) {
                        header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '.html');
                    } else {
                        header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '/page=' . $page . '#' . intval($_GET['post']));
                    }
                    exit;
                }

                echo "<span style='float: right; padding-left: 5px'>";

                if (isset($user) && mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_post_rating` WHERE `id_user` = ' . $user['id'] . ' AND `id_post` = ' . $post->id . ' AND `type` = "0"'), 0) == 0) {
                    echo "<a href='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/page=$page/$post->id/like' data-toggle='tooltip' data-placement='left' title='" . lang('Мне нравится') . "' style='color:#B2B2B2;'>$post->rating <i class='fa fa-heart'></i></a>";
                } else {
                    if (isset($user) && mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_post_rating` WHERE `id_user` = ' . $user['id'] . ' AND `id_post` = ' . $post->id . ' AND `type` = "1"'), 0) == 0) {
                        echo "<a href='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/page=$page/$post->id/dislike' data-toggle='tooltip' data-placement='left' title='" . lang('Мне не нравится') . "' style='color:#EA5E5E;'>$post->rating <i class='fa fa-heart'></i></a>";
                    }
                }
                echo "</span>";
            } else {
                echo "<span style = 'float: right; padding-left: 5px; color:#B2B2B2;'>$post->rating <i class='fa fa-heart'></i></span>";
            }
            if (isset($_GET['edit']) && $_GET['edit'] == $post->id) {
                $edit_post = mysql_fetch_object(mysql_query('SELECT `id`, `id_user`, `text` FROM `forum_posts` WHERE `id` = ' . intval($_GET['edit'])));
                if (isset($user) && (access('forum_post_ed') || ($theme->reason_close == NULL && $user['id'] == $edit_post->id_user && $last_post == $edit_post->id))) {
                    echo "<form action='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id.html' method='post'>";
                    echo "<input type='hidden' name='id_post' value='" . intval($_GET['edit']) . "' />";
                    echo lang('Редактируем сообщение') . "<br />";
                    echo "<textarea name='post' class='form-control'>$edit_post->text</textarea><br />";

                    $doc->Button('btn btn-success btn-sm', 'edit_post', 'save', 'Сохранить');
                    $doc->Button('btn btn-secondary btn-sm', 'cancel_edit', null, 'Отменить');
                    echo "</form>";
                } else {
                    header('Location: ' . DIR_FORUM . $forum->id . '/' . $razdel->id . '/' . $theme->id . '.html');
                    exit;
                }
            } else {
                if ($post->hide == 1) {
                    echo "<small style='color: #9197a3;'>" . lang('Комментарий скрыл') . " " . (($admin->sex == 0) ? 'а' : NULL) . " <a href='/info.php?id=$admin->id'>$admin->nick</a></small><br />";

                    if (access('forum_post_ed')) {
                        echo '<s>' . toOutput($post->text) . '</s><br />';
                    }
                } else {
                    if (mysql_result(mysql_query('SELECT MAX(`rating`) FROM `forum_posts` WHERE `rating` > "5" AND `id_theme` = ' . $theme->id), 0) == $post->rating) {
                        echo "<span style = 'float: right; padding-left: 10px; color: #ffff00;'>" . lang('Лучший ответ') . "</span>";
                    }
                    if ($post->cit != 0 && mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_posts` WHERE `id` = ' . $post->cit), 0) != 0) {
                        $cit_post = mysql_fetch_object(mysql_query('SELECT `id_user`, `text`, `time` FROM `forum_posts` WHERE `id` = ' . $post->cit));
                        $user_cit = mysql_fetch_object(mysql_query('SELECT `id`, `nick` FROM `user` WHERE `id` = ' . $cit_post->id_user));

                        echo "<div class='cit'>";
                        echo "<b>$user_cit->nick : " . date::times($cit_post->time) . "</b><br />";
                        echo toOutput($cit_post->text, 1, 0, 0, 0, 0, 0) . '<br />';
                        echo "</div>";
                    }
                    echo toOutput($post->text) . '<br />';
                }
            }

            if (isset($user) && ((isset($_GET['edit']) && $post->id != $_GET['edit']) || !isset($_GET['edit']))) {
                echo "<div id='post_$post->id' class='panel-collapse collapse' role='tabpanel' aria-labelledby='post_$post->id'><small>";
                if ($user['id'] != $post->id_user && $post->id_user != 0 && $post->hide == 0 && ($theme->reason_close == NULL || ($theme->reason_close != NULL && access('forum_post_close')))) {
                    $doc->Link(null, "" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/answer=$man_id", null, 'Ответить');
                    $doc->Link(null, "" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/cit=$post->id/answer=$man_id", null, 'Цитировать');
                    $doc->Link(null, "" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/privat=$man_id", null, 'Приватно');
                }
                if ($post->id_user != 0 && (access('forum_post_ed') || ($theme->reason_close == NULL && $user['id'] == $post->id_user && $last_post == $post->id))) {
                    $razd = (access('forum_post_ed') && $post->hide == 0 && $post->id_user != $user['id']) ? ' ' : NULL;
                    echo $razd . "" . $doc->Link(null, "" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/edit_$post->id#$post->id", null, 'Редактировать');
                }
                if (access('forum_post_ed')) {
                    $razd = ($post->id_user == 0) ? NULL : ' ';
                    echo $razd;
                    if ($post->hide == 0) {
                        $doc->Link(null, "" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/hide=$post->id", null, 'Скрыть');
                    } else {
                        $doc->Link(null, "" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/display=$post->id", null, 'Показать');
                    }

                    $doc->Link(null, "" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/delete_post=$post->id", null, 'Удалить');
                }
                echo "</small></div>";
            }
            echo "</div>";

            if ($post->hide == 0 || ($post->hide == 1 && access('forum_post_ed'))) {
                $files = mysql_query('SELECT * FROM `forum_post_files` WHERE `id_post` = ' . $post->id);
                if (mysql_num_rows($files) != 0) {
                    echo "<br />";
                    while ($file = mysql_fetch_object($files)) {
                        $ras = strtolower(preg_replace('#^.*\.#', NULL, $file->name));
                        if ($ras == 'jpg' || $ras == 'jpeg' || $ras == 'gif' || $ras == 'png' || $ras == 'bmp' || $ras == 'ico') {
                            $icons = "<i class='fa fa-file-image-o fa-fw'></i>";
                        } elseif ($ras == '3gp' || $ras == 'mp4' || $ras == 'avi' || $ras == 'mpeg' || $ras == 'flv' || $ras == 'wmv' || $ras == 'mkv') {
                            $icons = "<i class='fa fa-file-video-o fa-fw'></i>";
                        } elseif ($ras == 'docx' || $ras == 'doc' || $ras == 'docm' || $ras == 'dotx' || $ras == 'dot' || $ras == 'dotm') {
                            $icons = "<i class='fa fa-file-text-o fa-fw'></i>";
                        } elseif ($ras == 'mp1' || $ras == 'mp2' || $ras == 'mp3' || $ras == 'wav' || $ras == 'aif' || $ras == 'ape' || $ras == 'flac' || $ras == 'ogg' || $ras == 'asf' || $ras == 'wma') {
                            $icons = "<i class='fa fa-file-audio-o fa-fw'></i>";
                        } elseif ($ras == 'zip' || $ras == 'rar' || $ras == 'tar' || $ras == '7-zip' || $ras == 'gzip' || $ras == 'jar' || $ras == 'jad' || $ras == 'war' || $ras == 'xar') {
                            $icons = "<i class='fa fa-file-archive-o fa-fw'></i>";
                        } elseif ($ras == 'txt' || $ras == 'xml') {
                            $icons = "<i class='fa fa-file-text-o fa-fw'></i>";
                        } elseif ($ras == 'pdf') {
                            $icons = "<i class='fa fa-file-text-o fa-fw'></i>";
                        } elseif ($ras == 'psd') {
                            $icons = "<i class='fa fa-file-image-o fa-fw'></i>";
                        } else {
                            $icons = "<i class='fa fa-file-o fa-fw'></i>";
                        }

                        $icon = DIR_FORUM_FILES . $file->name;

                        echo "<div>";
                        if ($user['id'] == $post->id_user || access('forum_post_ed')) {
                            echo "<span style = 'float:right;'>";
                            echo "<a href = '" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/del_file=$file->id' data-toggle='tooltip' data-placement='left' title='" . lang('Удалить файл') . "'><i class='fa fa-trash-o'></i></a>";
                            echo "</span>";
                        }
                        echo "<a href='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/download_$file->id'>$icons " . toOutput($file->real_name, 1, 1, 0, 0, 0) . "</a> (" . size_file($file->size) . " ";
                        echo "<span style='color: #88C057;'><i class='fa fa-download fa-fw'></i> $file->count_downloads чел.</span>)";
                        echo "</div>";
                    }
                }
            }
            if ($post->count_edit != 0) {
                echo "<div class='hr'></div>";
                echo "<small style='color: #9197a3;'><i class='fa fa-pencil fa-fw'></i> " . lang('Посл. ред') . " " . date::timek($post->last_edit) . " - $post->who_edit</small>";
            }

            if (IS_WEB) {
                echo "</td></tr></table>";
                echo "<div class='hr'></div>";
            } else {
                echo "</div>";
                echo "<div class='hr'></div>";
            }
        }
    }

    if (isset($_GET['act_posts'])) {
        echo "<div class='list-group-item-null'>";
        echo "<button name='delete_posts' class='btn btn-success btn-sm'>" . lang('Удалить') . "</button> ";
        echo "<button name='hide_posts' class='btn btn-success btn-sm'>" . lang('Скрыть') . "</button> ";
        echo "<button name='display_posts' class='btn btn-success btn-sm'>" . lang('Показать') . "</button>";
        echo "</div>";
        echo "</form>";
    }

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

    $who = mysql_result(mysql_query('SELECT COUNT(*) FROM `user` WHERE `date_last` > "' . (time() - 600) . '" AND `forum_url` LIKE "/modules/forum/' . $forum->id . '/' . $razdel->id . '/' . $theme->id . '%"'), 0);
    $count_files = mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_post_files` WHERE `id_theme` = ' . $theme->id), 0);

    echo "<a href='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/who.html' class='list-group-item-null list-group-item-grey'><i class='fa fa-user fa-fw'></i> " . lang('Сейчас в теме') . " <span class='badge'>$who</span></a>";
    echo "<a href='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/files.html' class='list-group-item-null list-group-item-grey'><i class='fa fa-file fa-fw'></i> " . lang('Файлы в теме') . " <span class='badge'>$count_files</span></a>";

    if ((access('forum_them_edit') || $user['id'] == $theme->id_user) && ($theme->reason_close == NULL || ($theme->reason_close != NULL && access('forum_post_close')))) {
        echo "<a href = '" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/edit_theme.html' class = 'list-group-item-null list-group-item-grey'><i class='fa fa-pencil-square-o fa-fw'></i> " . lang('Редактировать') . "</a>";

        if (mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_votes` WHERE `id_theme` = ' . $theme->id), 0) == 0 && ($theme->reason_close == NULL || ($theme->reason_close != NULL && access('forum_post_close'))) && $user['id'] == $theme->id_user) {
            echo "<a href = '" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/create_vote.html' class = 'list-group-item-null list-group-item-grey'><i class='fa fa-pie-chart fa-fw'></i> " . lang('Создать голосование') . "</a>";
        } elseif (mysql_result(mysql_query('SELECT COUNT(*) FROM `forum_votes` WHERE `id_theme` = ' . $theme->id), 0) != 0 && ($theme->reason_close == NULL || ($theme->reason_close != NULL && access('forum_post_close'))) && $user['id'] == $theme->id_user) {
            echo "<a href = '" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/edit_vote.html' class = 'list-group-item-null list-group-item-grey'><i class='fa fa-pie-chart fa-fw'></i> " . lang('Ред. голосование') . "</a>";
        }
        if (access('forum_them_edit')) {
            if ($theme->reason_close == NULL && access('forum_post_close')) {
                echo "<a href = '" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/close_theme.html' class = 'list-group-item-null list-group-item-grey'><i class='fa fa-lock fa-fw'></i> " . lang('Закрыть тему') . "</a>";
            } elseif ($theme->reason_close != NULL && access('forum_post_close')) {
                echo "<a href = '" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/open_theme.html' class = 'list-group-item-null list-group-item-grey'><i class='fa fa-unlock fa-fw'></i> " . lang('Открыть тему') . "</a>";
            }
            if (access('forum_post_ed')) {
                echo "<a href = '" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/cleare_theme.html' class = 'list-group-item-null list-group-item-grey'><i class='fa fa-trash fa-fw'></i> " . lang('Очистить тему') . "</a>";
            }
        }
        if (access('forum_post_ed') && access('forum_them_edit')) {
            if (!isset($_GET['act_posts'])) {
                echo "<a href = '" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/act_posts' class = 'list-group-item-null list-group-item-grey'><i class='fa fa-location-arrow fa-fw'></i> " . lang('Действия над постами') . "</a>";
            } else {
                echo "<a href = '" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id.html' class = 'list-group-item-null list-group-item-grey'><i class='fa fa-ban fa-fw'></i> " . lang('Отменить действие') . "</a>";
            }
        }
    }
    echo "<a class='list-group-item-null list-group-item-info' href='" . DIR_FORUM . "$forum->id/$razdel->id/'><i class='fa fa-arrow-left fa-fw'></i> " . toOutput($razdel->name, 1, 0, 0, 0, 0) . "</a>";
    echo "<a class='list-group-item-null list-group-item-info' href='" . DIR_FORUM . "$forum->id/'><i class='fa fa-arrow-left fa-fw'></i> " . toOutput($forum->name, 1, 1, 0, 0, 0) . "</a>";
    echo "<a class='list-group-item-null list-group-item-info' href='" . DIR_FORUM . "'><i class='fa fa-arrow-left fa-fw'></i> " . lang('Форум') . "</a>";
}
