<?php

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

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

$set['meta_keywords'] = meta_out_keywords(mb_substr($theme->description, 0, 160));
$_forum = $forum->name != null ? ',' . $forum->name : null;
$_razdel = $razdel->name != null ? ',' . $razdel->name : null;
$set['meta_description'] = meta_out_description($theme->name . '' . $_forum . '' . $_razdel);

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 `forum_reports` WHERE `id_theme` = ' . $theme->id . ' AND `id_user` = '$user[id]'");
    $my_report = (isset($user)) ? $q['count'] : 0;
    $q = $db->super_query("SELECT COUNT(*) as count FROM `forum_reports` WHERE `id_theme` = ' . $theme->id . '");
    $k_post = $q['count'];

    $vote_res = $db->super_query("SELECT COUNT(*) as count FROM `forum_votes` WHERE `id_theme` = '$theme->id'");
    if ($vote_res['count'] != 0) {
        $vote = mysqli_fetch_object($db->query('SELECT * FROM `forum_votes` WHERE `id_theme` = ' . $theme->id));
        $vars = $db->super_query("SELECT COUNT(*) as count FROM `forum_votes_var` WHERE `id_theme` = '$theme->id'");

        $vars = $vars['count'];
    }

    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 = mysqli_fetch_object($db->query('SELECT `id`, `id_post`, `name`, `count_downloads` FROM `forum_post_files` WHERE `id` = ' . intval($_GET['download'])));
        $this_post = mysqli_fetch_object($db->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'))) {
            $db->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=/id$user[id]]$user[nick][/url] " . ($user['sex'] ? 'открыл' : 'открыла') . " тему.";

        $db->query('INSERT INTO `forum_posts` SET `id_theme` = ' . $theme->id . ', `id_user` = "0", `id_admin` = "0", `text` = "' . $db->safesql($msg_sys) . '", `time` = ' . $time);
        $db->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 = $db->safesql(trim($_POST['text']));

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

                    while ($person = mysqli_fetch_object($persons)) {
                        $q = $db->super_query("SELECT COUNT(*) as count FROM `user_group_access` WHERE `id_group` = ' . $person->group_access . ' AND `id_access` = 'forum_them_edit'");

                        $access = $q['count'];
                        if ($access != 0) {
                            $msg = "[url=/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]";
                            $db->query('INSERT INTO `mail` SET `id_user` = "0", `id_kont` = ' . $person->id . ', `msg` = "' . $db->safesql($msg) . '", `time` = ' . $time);
                        }
                    }

                    $db->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;
        }
    }

    if (isset($vote) && isset($user)) {
        $q = $db->super_query("SELECT COUNT(*) as count FROM `forum_vote_voices` WHERE `id_user` = '$user[id]' AND `id_vote` = '$vote->id'");
        $my_voice = (isset($vote) && isset($user)) ? $q['count'] : NULL;
    } else {
        $my_voice = NULL;
    }

    if (isset($user)) {
        $q = $db->super_query("SELECT MAX(`id`) as id FROM `forum_posts` WHERE `id_theme` = '$theme->id'");

        $last_post = $q['id'];

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

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

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

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

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

            if ($k_post == 0) {
                $db->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('Комментарий успешно скрыт');

            $db->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('Комментарий успешно показан вновь');

            $db->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('Ваш голос успешно учтён');

            $db->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']) && (mysqli_fetch_object($db->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 = mysqli_fetch_object($db->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']]);

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

            $db->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 = $db->safesql($_POST['text']);
            $mat = antimat($text);

            $q = $db->super_query("SELECT COUNT(*) as count FROM `forum_posts` WHERE `id_user` = '$user[id]' AND `text` = '$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 ($q['count'] != 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;
                }

                $db->query('UPDATE `forum_themes` SET `time_post` = ' . $time . ' WHERE `id` = ' . $theme->id);
                $db->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 = $db->insert_id();

                $q = $db->super_query("SELECT COUNT(*) as count FROM `forum_posts` WHERE `id_theme` = '$theme->id' AND `id` < '" . ($post_id + 1) . "'");
                $count = $q['count'];
                $q = $db->super_query("SELECT COUNT(*) as count FROM `forum_posts` WHERE `id_theme` = '$theme->id'");
                $count_posts = $q['count'];

                $this_pages = k_page($count, $set['p_str']);
                $pages = ($this_pages > 0) ? '/page=' . $this_pages : '.html';
                $j_f = '[url=/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 = $db->query('SELECT `id_user` FROM `forum_journal` WHERE `id_theme` = ' . $theme->id);

                while ($forum_j = mysqli_fetch_object($forum_js)) {
                    $q = $db->super_query("SELECT COUNT(*) as count FROM `forum_posts` WHERE `id` = '$post_id' AND `id_user` = '$user[id]'");

                    if ($q['count'] == 0 && ((isset($_GET['answer']) && $_GET['answer'] != $forum_j->id_user) || !isset($_GET['answer']))) {
                        $db->query('INSERT INTO `f_journal` SET `id_user` = ' . $forum_j->id_user . ', `type` = "themes", `text` = "' . $db->safesql($j_f) . '", `time` = "' . $time . '"');
                    }
                }
                if (!isset($_GET['cit']) && !isset($_GET['privat']) && isset($_GET['answer'])) {
                    $j = '[url=/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=/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=/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=/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]';
                    $db->query('INSERT INTO `f_journal` SET `id_user` = ' . $theme->id_user . ', `type` = "my_themes", `text` = "' . $db->safesql($j_t) . '", `time` = "' . $time . '"');
                }

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

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

                $post = mysqli_fetch_object($db->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 = $db->safesql(trim($_POST['post']));
            $post_edit = mysqli_fetch_object($db->query('SELECT `count_edit` FROM `forum_posts` WHERE `id` = ' . intval($_POST['id_post'])));

            $db->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)) {
        $q = $db->super_query("SELECT COUNT(*) as count FROM `forum_votes_var` WHERE `variant` = '' AND `id_vote` = '$vote->id'");

        if ($q['count'] != 0) {
            $db->query('DELETE FROM `forum_votes_var` WHERE `id_vote` = ' . $vote->id);
            $db->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'])) {
        $q = $db->super_query("SELECT COUNT(*) as count FROM `forum_journal` WHERE `id_theme` = '$theme->id' AND `id_user` = '$user[id]'");

        if ($q['count'] == 0) {
            $db->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'])) {
        $q = $db->super_query("SELECT COUNT(*) as count FROM `forum_journal` WHERE `id_theme` = '$theme->id' AND `id_user` = '$user[id]'");

        if ($q['count'] != 0) {
            $db->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 = mysqli_fetch_object($db->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;' class='hint--top' data-hint='" . 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 />";
        }

        $q = $db->super_query("SELECT COUNT(*) as count FROM forum_journal WHERE id_theme = '$theme->id' AND `id_user` = '$user[id]'");
        $journal = $q['count'];
        $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-info'>";
        $q = $db->super_query("SELECT COUNT(*) as count FROM `forum_vote_voices` WHERE `id_vote` = '$vote->id'");
        $all_votes = $q['count'];
        $i = 0;

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

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

        while ($var = mysqli_fetch_object($vars)) {
            $i++;
            $q = $db->super_query("SELECT COUNT(*) as count FROM `forum_vote_voices` WHERE `id_vote` = '$vote->id' AND `id_variant` = '$var->id'");

            $vote_var = $q['count'];
            $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 "<small style='color: green;'><i class='fa fa-users fa-fw'></i> " . lang('Проголосовало') . ": $all_votes чел.</small>";
        echo "</div>";
    }

    if ($theme->time_edit != 0 && $theme->id_admin != 0) {
        $admin = mysqli_fetch_object($db->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 = mysqli_fetch_object($db->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 = mysqli_fetch_object($db->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 = mysqli_fetch_object($db->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 = mysqli_fetch_object($db->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 = $db->query('SELECT * FROM `forum_posts` WHERE `id_theme` = ' . $theme->id . ' ORDER BY `id` ' . $sort . $limit);

    while ($post = mysqli_fetch_object($posts)) {
        $man = ($post->id_user != 0) ? mysqli_fetch_object($db->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) ? mysqli_fetch_object($db->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 dop'><tr><td class='icon14' style='vertical-align: top;'>";
                } else {
                    echo "<table class='list-group-item-null list-group-item-grey dop'><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 dop'>";
                } else {
                    echo "<div class='list-group-item-null list-group-item-grey dop'>";
                }
            }

            echo "<div id='accordion'>";
            echo "<div 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 "<small style='color: #9197a3;'>" . user($man_id) . " " . date::times($post->time) . " $privat</small><br />";

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

                if (isset($user) && isset($_GET['like'])) {
                    $qs = $db->super_query("SELECT COUNT(*) as count FROM `forum_post_rating` WHERE `id_user` = '$user[id]' AND `id_post` = '" . intval($_GET['post']) . "' AND `type` = '0'");

                    if ($qs['count'] == 0) {


                        $q = $db->super_query("SELECT COUNT(*) as count FROM `forum_post_rating` WHERE `id_user` = '$user[id]' AND `id_post` = '" . intval($_GET['post']) . "' AND `type` = '1'");
                        $plus = ($q['count'] != 0) ? 2 : 1;

                        $q = $db->super_query("SELECT COUNT(*) as count FROM `forum_post_rating` WHERE `id_user` = '$user[id]' AND `id_post` = '" . intval($_GET['post']) . "'");

                        if ($q['count'] != 0) {
                            $db->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 {
                            $db->query('INSERT INTO `forum_post_rating` SET `id_theme` = ' . $theme->id . ', `id_user` = ' . $user['id'] . ', `type` = "0", `id_post` = ' . intval($_GET['post']));
                        }

                        $db->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']) : $db->safesql(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'])) {
                    $dis = $db->super_query("SELECT COUNT(*) as count FROM `forum_post_rating` WHERE `id_user` = '$user[id]' AND `id_post` = '" . intval($_GET['post']) . "' AND `type` = '1'");

                    if ($dis['count'] == 0) {
                        $q = $db->super_query("SELECT COUNT(*) as count FROM `forum_post_rating` WHERE `id_user` = '$user[id]' AND `id_post` = '" . intval($_GET['post']) . "' AND `type` = '0'");

                        $minus = ($q['count'] != 0) ? 2 : 1;

                        $q = $db->super_query("SELECT COUNT(*) as count FROM `forum_post_rating` WHERE `id_user` = '$user[id]' AND `id_post` = '" . intval($_GET['post']) . "'");

                        if ($q['count'] != 0) {
                            $db->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 {
                            $db->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 = $db->query('SELECT `id`, `group_access` FROM `user` WHERE `group_access` > "2"');

                            while ($person = mysqli_fetch_object($persons)) {
                                $q = $db->super_query("SELECT COUNT(*) as count FROM `user_group_access` WHERE `id_group` = '$person->group_access' AND `id_access` = 'forum_post_ed'");

                                $access = $q['count'];
                                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);
                                    $db->query('INSERT INTO `mail` SET `id_user` = "0", `id_kont` = ' . $person->id . ', `msg` = "' . $db->safesql($msg) . '", `time` = ' . $time);
                                }
                            }
                        }
                        $db->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']) : $db->safesql(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'>";

                $q = $db->super_query("SELECT COUNT(*) as count FROM `forum_post_rating` WHERE `id_user` = '$user[id]' AND `id_post` = '$post->id' AND `type` = '0'");

                if (isset($user) && $q['count'] == 0) {
                    echo "<a href='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/page=$page/$post->id/like' class='hint--left' data-hint='" . lang('Мне нравится') . "' style='color:#B2B2B2;'><small>$post->rating <i class='fa fa-heart-0'></i></small></a>";
                } else {
                    $q = $db->super_query("SELECT COUNT(*) as count FROM `forum_post_rating` WHERE `id_user` = '$user[id]' AND `id_post` = '$post->id' AND `type` = '1'");

                    if (isset($user) && $q['count'] == 0) {
                        echo "<a href='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/page=$page/$post->id/dislike' class='hint--left' data-hint='" . lang('Мне не нравится') . "' style='color:#EA5E5E;'><small>$post->rating <i class='fa fa-heart'></i></small></a>";
                    }
                }
                echo "</span>";
            } else {
                echo "<small style = 'float: right; padding-left: 5px; color:#B2B2B2;'>$post->rating <i class='fa fa-heart'></i></small>";
            }
            if (isset($_GET['edit']) && $_GET['edit'] == $post->id) {
                $edit_post = mysqli_fetch_object($db->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 "<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='/id=$admin->id'>$admin->nick</a></small><br />";

                    if (access('forum_post_ed')) {
                        echo '<s>' . toOutput($post->text) . '</s><br />';
                    }
                } else {
                    $q = $db->super_query("SELECT MAX(`rating`) as rating FROM `forum_posts` WHERE `rating` > '5' AND `id_theme` = '$theme->id'");

                    if ($q['rating'] == $post->rating) {
                        echo "<span style = 'float: right; padding-left: 10px; color: #ffff00;'>" . lang('Лучший ответ') . "</span>";
                    }

                    $q = $db->super_query("SELECT COUNT(*) as count FROM `forum_posts` WHERE `id` = '$post->cit'");

                    if ($post->cit != 0 && $q['count'] != 0) {
                        $cit_post = mysqli_fetch_object($db->query('SELECT `id_user`, `text`, `time` FROM `forum_posts` WHERE `id` = ' . $post->cit));
                        $user_cit = mysqli_fetch_object($db->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' 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 = $db->query('SELECT * FROM `forum_post_files` WHERE `id_post` = ' . $post->id);
                if ($db->num_rows($files) != 0) {
                    echo "<br />";
                    while ($file = mysqli_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' class='hint--left' data-hint='" . 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>";
            } else {
                echo "</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);
    }

    $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%'");
    $who = $q['count'];
    $q = $db->super_query("SELECT COUNT(*) as count FROM `forum_post_files` WHERE `id_theme` = '$theme->id'");
    $count_files = $q['count'];

    echo "<a href='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id/who.html' class='list-group-item-null list-group-item-grey dop'><i class='fa fa-user fa-fw'></i> " . lang('Сейчас в теме') . " <span class='tag tag-info right'>$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 dop'><i class='fa fa-file fa-fw'></i> " . lang('Файлы в теме') . " <span class='tag tag-info right'>$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>";

        $q = $db->super_query("SELECT COUNT(*) as count FROM `forum_votes` WHERE `id_theme` = '$theme->id'");

        if ($q['count'] == 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>";
        } else {
            $q = $db->super_query("SELECT COUNT(*) as count FROM `forum_votes` WHERE `id_theme` = '$theme->id'");

            if ($q['count'] != 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>";
}
