<?php

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

foreach (array('start', 'compress', 'sess', 'settings', 'db_connect', 'ipua', 'fnc', 'user') as $inc) {
    require_once "../../sys/inc/$inc.php";
}
$news = $db->get_row($db->query("SELECT * FROM `news` WHERE `id` = '" . intval($_GET['news']) . "' LIMIT 1"));

require_once H . 'sys/inc/thead.php';

$q = $db->super_query("SELECT COUNT(*) as count FROM `news` WHERE `id` = '$news[id]' LIMIT 1");
if ($q['count'] == 0) {
    header("Location: ?" . SID);
    exit;
}
unset($q);

#Список тех, кому понравилась новость
if (isset($_GET['like_all'])) {
    $k_post = $db->super_query("SELECT COUNT(*) as count FROM `news_like` WHERE `id_news` = '" . intval($_GET['news']) . "'");
    $k_post = $k_post['count'];
    $k_page = k_page($k_post, $set['p_str']);
    $page = page($k_page);
    $start = $set['p_str'] * $page - $set['p_str'];
    $k_sisa = $k_post - 1;
    $q = $db->query("SELECT * FROM `news_like` WHERE `id_news` = '" . intval($_GET['news']) . "' ORDER BY `id` DESC LIMIT $start, $set[p_str]");

    #Навигация
    echo "<div class='list-group-item-null list-group-item-grey'><small>";
    echo "<a href='/' class='hint--right' data-hint='" . lang('На главную') . "'><i class='fa fa-home fa-lg'></i></a> <i class='fa fa-angle-right fa-fw'></i> ";
    echo "<a href='" . DIR_NEWS . "'>" . lang('Новости') . "</a> <i class='fa fa-angle-right fa-fw'></i> ";
    echo "<a href='" . DIR_NEWS . "?news=$news[id]'>" . cutStr($news['title'], 30) . "</a> <i class='fa fa-angle-right fa-fw'></i> ";
    echo lang('Им это нравится');
    echo "</div>";

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

    while ($post = $db->get_row($q)) {
        $ank = get_user($post['id_user']);
        echo "<table class='list-group-item-null list-group-item-grey dop'><tr><td class='icon14'>";
        avatar($ank['id'], '30', 'border-radius: 2px;');
        echo "</td><td class='null'>";
        user($ank['id']);
        echo "</td></tr></table>";
    }

    if ($k_page > 1) {
        echo $k_sisa;
    }

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

#Лайк на новость
if (isset($_GET['like']) && isset($user)) {
    $q = $db->super_query("SELECT COUNT(*) as count FROM `news_like` WHERE `id_news` = '" . intval($_GET['news']) . "' AND `id_user` = '$user[id]' LIMIT 1");

    if ($q['count'] != 0) {
        
    } else {
        $db->query("INSERT INTO `news_like` (`id_user`, `id_news`) values('$user[id]', '" . intval($_GET['news']) . "')");
    }

    #оповищаем друзей о том, что лайнули новость
    $q = $db->query("SELECT * FROM `friends` WHERE `user` = '$user[id]' AND `lenta_news` = '1' AND `i` = '1'");
    while ($f = $db->get_array($q)) {
        $a = $db->get_array($db->query("SELECT * FROM `user` WHERE `id` = '$f[friends]' LIMIT 1"));

        $not_msg = "$SexOcen новость [url=" . DIR_NEWS . "?news=$news[id]]" . htmlspecialchars($news['title']) . "[/url]";

        $db->query("INSERT INTO `notifications` (`id_user`, `id_kont`, `id_img`, `msg`, `time`) values('$user[id]', '$a[id]', '1', '$not_msg', '$time')");
    }

    header("Location: ?news=" . intval($_GET['news']) . "" . SID);
}
#Лайк на новость на главной
if (isset($_GET['likes']) && isset($user)) {
    $q = $db->super_query("SELECT COUNT(*) as count FROM `news_like` WHERE `id_news` = '" . intval($_GET['news']) . "' AND `id_user` = '$user[id]' LIMIT 1");

    if ($q['count'] != 0) {
        
    } else {
        $db->query("INSERT INTO `news_like` (`id_user`, `id_news`) values('$user[id]', '" . intval($_GET['news']) . "')");
    }

    #оповищаем друзей о том, что лайнули новость
    $q = $db->query("SELECT * FROM `friends` WHERE `user` = '$user[id]' AND `lenta_news` = '1' AND `i` = '1'");
    while ($f = $db->get_array($q)) {
        $a = $db->get_array($db->query("SELECT * FROM `user` WHERE `id` = '$f[friends]' LIMIT 1"));

        $not_msg = "$SexOcen новость [url=" . DIR_NEWS . "?news=$news[id]]" . htmlspecialchars($news['title']) . "[/url]";

        $db->query("INSERT INTO `notifications` (`id_user`, `id_kont`, `id_img`, `msg`, `time`) values('$user[id]', '$a[id]', '1', '$not_msg', '$time')");
    }

    header("Location: index.php?" . SID);
}
#дизлайк на новость
if (isset($_GET['unlike']) && isset($user)) {
    $db->query("DELETE FROM `news_like` WHERE `id_user` = '$user[id]' AND `id_news` = '" . intval($_GET['news']) . "' LIMIT 1");
    header("Location: ?news=" . intval($_GET['news']) . "" . SID);
}
#дизлайк на новость на главной
if (isset($_GET['unlikes']) && isset($user)) {
    $db->query("DELETE FROM `news_like` WHERE `id_user` = '$user[id]' AND `id_news` = '" . intval($_GET['news']) . "' LIMIT 1");
    header("Location: index.php?" . SID);
}

if (isset($_POST['msg']) && isset($user) && $news['close'] == 0) {

    $msg = $_POST['msg'];
    $mat = antimat($msg);

    if ($mat) {
        $err[] = lang("В тексте сообщения обнаружен мат") . ": $mat";
    }

    if (utf8_strlen($msg) > 10024) {
        $err = lang('Сообщение слишком длинное');
    } elseif (utf8_strlen($msg) < 2) {
        $err = lang('Короткое сообщение');
    }

    $q = $db->super_query("SELECT COUNT(*) as count FROM `news_komm` WHERE `id_news` = '" . intval($_GET['news']) . "' AND `id_user` = '$user[id]' AND `msg` = '" . $db->safesql($msg) . "' LIMIT 1");
    if ($q['count'] != 0) {
        $err = lang('Ваше сообщение повторяет предыдущее');
    }

    if (!isset($err)) {
        $db->query("INSERT INTO `news_komm` (`id_user`, `time`, `msg`, `id_news`) values('$user[id]', '$time', '" . $db->safesql($msg) . "', '" . intval($_GET['news']) . "')");
        #Добавляем рубли и активность
        $db->query("UPDATE `user` SET `money` = '" . ($user['money'] + 3) . "', `activity` = '" . ($user['activity'] + 2) . "' WHERE `id` = '$user[id]' LIMIT 1");

        #оповищаем друзей о том, что прокомментировали новость
        $q = $db->query("SELECT * FROM `friends` WHERE `user` = '$user[id]' AND `lenta_news` = '1' AND `i` = '1'");
        while ($f = $db->get_array($q)) {
            $a = $db->get_array($db->query("SELECT * FROM `user` WHERE `id` = '$f[friends]' LIMIT 1"));

            $not_msg = "$SexKomm новость [url=" . DIR_NEWS . "?news=$news[id]]" . htmlspecialchars($news['title']) . "[/url]";

            $db->query("INSERT INTO `notifications` (`id_user`, `id_kont`, `id_img`, `msg`, `time`) values('$user[id]', '$a[id]', '3', '$not_msg', '$time')");
        }

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

        header("Location: ?news=" . intval($_GET['news']) . "" . SID);
        exit;
    }
}
#Удаление комментария
if (isset($_GET['del'])) {
    $q = $db->super_query("SELECT COUNT(*) as count FROM `news_komm` WHERE `id` = '" . intval($_GET['del']) . "'");
    if ($q['count'] && isset($user) && access('adm_news_delete_comments')) {
        $db->query("DELETE FROM `news_komm` WHERE `id` = '" . intval($_GET['del']) . "'");
        $_SESSION['message'] = lang('Сообщение успешно удалено');
        header("Location: ?news=" . intval($_GET['news']) . "" . SID);
        exit;
    } else {
        $msg = "Совершил попытку удаления сообщения в новостях [url=/modules/news/?news=" . intval($_GET['news']) . "]здесь[/url]";
        $db->query("INSERT INTO `events` (`id_user`, `id_kont`, `msg`, `time`) values('$user[id]', '1', '" . $msg . "', '$time')");

        $_SESSION['message'] = lang('Администрация уведомлена');
        header("Location: ?news=" . intval($_GET['news']) . "" . SID);
        exit;
    }
}

err();

if (isset($user) && $user['id'] != $news['id']) {
    $db->query("UPDATE `news` SET `prosm` = '" . ($news['prosm'] + 1) . "' WHERE `id` = '$news[id]' LIMIT 1");
}

$like = $db->super_query("SELECT COUNT(*) as count FROM `news_like` WHERE `id_news` = '" . $news['id'] . "'");
$like = $like['count'];

#Навигация
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_NEWS . "'>" . lang('Новости') . "</a> <i class='fa fa-angle-right fa-fw'></i> ";
echo cutStr($news['title'], 30);
echo "</small></div><br />";

echo "<div class='list-group-item-null list-group-item-grey'>";

if (access('adm_news_edit') || access('adm_news_delete')) {
    echo "<span style='float:right;'>";
    echo "<div class='btn-group'>";
    echo "<a class='btn btn-sm' style='margin-right: -12px;' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false'><i class='fa fa-chevron-down'></i></a>";
    echo "<div class='dropdown-menu dropdown-menu-right'>";
    if (access('adm_news_edit')) {
        echo "<a class='dropdown-item' href='?edit=$news[id]'><i class='fa fa-edit fa-fw'></i> " . lang('Редактировать') . "</a>";
    }
    if (access('adm_news_delete')) {
        echo "<a class='dropdown-item' href='?delete=$news[id]'><i class='fa fa-trash-o fa-fw'></i> " . lang('Удалить') . "</a>";
    }
    echo "</div>";
    echo "</div>";
    echo "</span>";
}

echo "<h4><a href='?news=$news[id]'>" . toOutput($news['title']) . "</a></h4>";

#Текст новости
echo toOutput($news['msg']) . "<br />";

#Изображение, если есть
if ($user['set_news_images'] == 1) {
    if (is_file(H . 'modules/news/images/' . $news['id'] . '.png')) {
        echo "<br /><img src='" . DIR_NEWS . "images/$news[id].png' style='border: 1px solid #CCDDED; padding: 2px; border-radius: 5px; max-width: 200px;' /><br />";
    }
}

echo "<br /><small style='color: #9197a3;'>";
echo "<i class='fa fa-user fa-fw'></i> $news[avtor] &#183; <span class='hint--top' data-hint='" . date::time($news['time']) . "'>" . date::timek($news['time']) . "</span> ";

if ($news['time_edit'] != 0) {
    #Показываем последнее редактирование
    echo " &#183; " . lang('обновлено') . " $news[avtor_edit] (<span class='hint--top' data-hint='" . date::time($news['time_edit']) . "'>" . date::timek($news['time_edit']) . "</span>)";
}
echo "<br /> ";
echo "<i class='fa fa-tags fa-fw'></i> " . lang('Теги') . ": ";
if ($news['tags'] != NULL) {
    $tagss = explode(',', $news['tags']);
    for ($i = 0; $i < count($tagss); $i++) {
        echo "<a href='" . DIR_NEWS . "tags.php?tag=$tagss[$i]' class='hint--top' data-hint='" . lang('Искать метку') . " $tagss[$i]'>$tagss[$i]</a>, ";
    }
} else {
    echo lang('нет меток');
}
if ($news['link'] != NULL) {
    echo "<br /><i class='fa fa-link fa-fw'></i> " . lang('Источник') . ": <a href='" . htmlentities($news['link'], ENT_QUOTES, 'UTF-8') . "'>" . htmlentities($news['link'], ENT_QUOTES, 'UTF-8') . "</a> ";
}
echo "</small>";

if (isset($user)) {
    echo "<div class='hr'></div>";

    if ($like == 0) {
        $l = null;
    } else {
        $l = $db->super_query("SELECT COUNT(*) as count FROM `news_like` WHERE `id_news` = '$news[id]'");
        $l = $l['count'];
    }
    $news_like = $db->super_query("SELECT COUNT(*) as count FROM `news_like` WHERE `id_news` = '$news[id]' AND `id_user` = '$user[id]' LIMIT 1");

    if ($news_like['count'] == 0) {
        echo "<a href='?news=$news[id]&amp;like' class='btn btn-secondary btn-sm hint--right' data-hint='" . lang('Мне нравится') . "'><i class='fa fa-heart-o fa-fw'></i> $l</a> ";
    } else {
        echo "<a href='?news=$news[id]&amp;unlike' class='btn btn-secondary btn-sm hint--top-right' data-hint='" . lang('Вам понравилась новость') . "'><i class='fa fa-heart fa-fw'></i> $l</a> ";
    }
    #Просмотры
    echo "<span class='hint--top-left btn btn-secondary btn-sm' data-hint='" . lang('Просмотрели') . " " . sklon_text($news['prosm'], array(lang('раз'), lang('раза'), lang('раз'))) . "' style='float: right;'><i class='fa fa-eye fa-fw'></i> $news[prosm]</span>";

    if ($like > 0) {
        if (IS_WEB) {
            $q_like = $db->query("SELECT * FROM `news_like` WHERE `id_news` = '$news[id]' ORDER BY id DESC LIMIT 10");
        } else {
            $q_like = $db->query("SELECT * FROM `news_like` WHERE `id_news` = '$news[id]' ORDER BY id DESC LIMIT 5");
        }
        while ($post_like = $db->get_array($q_like)) {
            $ank = get_user($post_like['id_user']);
            echo "<a href='/id$ank[id]' class='hint--top' data-hint='$ank[nick]'>";
            echo avatar($ank['id'], '25', 'border-radius: 2px;');
            echo "</a> ";
        }
    }
}

echo "</div>";

if ($news['close'] == 1) {
    echo "<div class='list-group-item-null list-group-item-warning'>";
    echo "<i class='fa fa-lock fa-fw'></i> " . lang('Для Вас обсуждение ограничено');
    echo "</div>";
}

$k_post = $db->super_query("SELECT COUNT(*) as count FROM `news_komm` WHERE `id_news` = '" . intval($_GET['news']) . "'");
$k_post = $k_post['count'];
$k_page = k_page($k_post, $set['p_str']);
$page = page($k_page);
$start = $set['p_str'] * $page - $set['p_str'];
$q = $db->query("SELECT * FROM `news_komm` WHERE `id_news` = '" . intval($_GET['news']) . "' ORDER BY `id` $sort LIMIT $start, $set[p_str]");

if (isset($user)) {
    if (isset($user) && $news['close'] == 0) {
        echo "<form class='list-group-item-null' name='form' method='POST' action='?news=" . intval($_GET['news']) . "&amp;page=$page'>";
        echo auto_bb("form", "msg");
        echo "<textarea placeholder='" . lang('Напишите что-нибудь') . "...' name='msg' class='form-control'></textarea>";

        echo "<br />";
        $doc->Button('btn btn-primary btn-sm', 'ok', 'pencil', 'Опубликовать');

        echo "</form>";
    }
} else {
    echo "<div class='list-group-item-null list-group-item-grey-info'>";
    echo lang('Для того, чтобы комментировать - Вам необходимо авторизоваться или зарегистрироваться');
    echo "</div>";
}

if ($k_post == 0) {
    $doc->NoResult();
} else {
    if (isset($user)) {
        $li = "<li class='nav-item'><a class='nav-link' ";
        $lir = "<li class='nav-item'><a class='nav-link' ";

        echo "<div class='list-group-item-null'>";
        echo "<ul class='nav nav-tabs' style='margin-bottom: -11px;'>";

        if ($user['sort'] == 1) {
            $lir = "<li class='nav-item'><a class='nav-link active' ";
        } elseif ($user['sort'] == 0) {
            $li = "<li class='nav-item'><a class='nav-link active' ";
        } else {
            $li = "<li class='nav-item'><a class='nav-link' ";
        }

        echo "$li href='?news=" . intval($_GET['news']) . "&amp;page=$page&amp;sort=0'>" . lang('Вверху') . "</a></li>";
        echo "$lir href='?news=" . intval($_GET['news']) . "&amp;page=$page&amp;sort=1'>" . lang('Внизу') . "</a></li>";
        echo "</ul>";
        echo "</div>";
    }
}


while ($post = $db->get_row($q)) {
    $ank = get_user($post['id_user']);

    echo "<table class='list-group-item-null list-group-item-grey dop'><tr><td class='icon14'>";
    echo avatar($ank['id'], '40', 'border-radius: 1px;');
    echo "</td><td class='null'>";

    #лайки к постам
    if ($user['id'] != $post['id_user'] && $post['id_user'] != 0) {
        $_post = (isset($_GET['post'])) ? mysqli_fetch_object($db->query('SELECT `id`, `rating`, `msg` FROM `news_komm` WHERE `id` = ' . intval($_GET['post']))) : NULL;

        if (isset($user) && isset($_GET['like'])) {

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

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

                if ($news_komm_like['count'] != 0) {
                    $db->query('UPDATE `news_komm_like` SET `type` = "0" WHERE `id_post` = ' . intval($_GET['post']) . ' AND `id_news` = ' . $news['id'] . ' AND `id_user` = ' . $user['id']);
                } else {
                    $db->query('INSERT INTO `news_komm_like` SET `id_news` = ' . $news['id'] . ', `id_user` = ' . $user['id'] . ', `type` = "0", `id_post` = ' . intval($_GET['post']));
                }

                #Оповищаем друзей о лайке поста
                $not = $db->query("SELECT * FROM `friends` WHERE `user` = '$user[id]' AND `lenta_news` = '1' AND `i` = '1'");
                while ($f = $db->get_array($not)) {
                    $a = $db->get_array($db->query("SELECT * FROM `user` WHERE `id` = '$f[friends]' LIMIT 1"));

                    $not_msg = "$SexOcen пост [url=" . DIR_NEWS . "?news=$news[id]]" . htmlspecialchars($post['msg']) . "[/url]";

                    $db->query("INSERT INTO `notifications` (`id_user`, `id_kont`, `id_img`, `msg`, `time`) values('$user[id]', '$a[id]', '1', '$not_msg', '$time')");
                }
                #Оповищаем автора поста о лайке
                if (isset($user) && $user['id'] != $ank['id']) {
                    $not_msg = "$SexOcen Ваш пост [url=" . DIR_NEWS . "?news=$news[id]]" . htmlspecialchars($post['msg']) . "[/url]";

                    $db->query("INSERT INTO `notification` (`id_user`, `id_kont`, `id_img`, `msg`, `time`) values('$user[id]', '$ank[id]', '1', '$not_msg', '$time')");
                }
                #добавляем бал к посту
                $db->query('UPDATE `news_komm` 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: ?news=" . intval($_GET['news']) . "" . SID);
                } else {
                    header("Location: ?news=" . intval($_GET['news']) . "" . SID);
                }
                exit;
            }
        } elseif (isset($user) && isset($_GET['dislike'])) {
            $qw = $db->super_query("SELECT COUNT(*) as count FROM `news_komm_like` WHERE `id_user` = '$user[id]' AND `id_post` = '" . intval($_GET['post']) . "' AND type = '1'");
            if ($qw['count'] == 0) {

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

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

                if ($news_komm_like['count'] != 0) {
                    $db->query('UPDATE `news_komm_like` SET `type` = "1" WHERE `id_post` = ' . intval($_GET['post']) . ' AND `id_news` = ' . $news['id'] . ' AND `id_user` = ' . $user['id']);
                } else {
                    $db->query('INSERT INTO `news_komm_like` SET `id_news` = ' . $news['id'] . ', `id_user` = ' . $user['id'] . ', `type` = "1", `id_post` = ' . intval($_GET['post']));
                }

                $db->query('UPDATE `news_komm` 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: ?news=" . intval($_GET['news']) . "" . SID);
                } else {
                    header("Location: ?news=" . intval($_GET['news']) . "" . SID);
                }
                exit;
            }
        }

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

        if (isset($user)) {
            $nklike = $db->super_query("SELECT COUNT(*) as count FROM `news_komm_like` WHERE `id_user` = '$user[id]' AND `id_post` = '$post[id]' AND type = '0'");
            if ($nklike['count'] == 0) {
                echo "<small><a href='?news=$news[id]&amp;post=$post[id]&amp;like' title='" . lang('Мне нравится') . "' style='color:grey;'>$post[rating] <i class='fa fa-heart-o'></i></a></small>";
            } else {
                $nkunlike = $db->super_query("SELECT COUNT(*) as count FROM `news_komm_like` WHERE `id_user` = '$user[id]' AND `id_post` = '$post[id]' AND type = '1'");

                if ($nkunlike['count'] == 0) {
                    echo "<small><a href='?news=$news[id]&amp;post=$post[id]&amp;dislike' title='" . lang('Мне не нравится') . "' style='color:grey;'>$post[rating] <i class='fa fa-heart'></i></a></small>";
                }
            }
        }
        echo "</span>";
    } else {
        echo "<small style='float: right; color:#B2B2B2;'>$post[rating] <i class='fa fa-heart'></i></small>";
    }

    $qw = $db->super_query("SELECT COUNT(*) as count FROM `user` WHERE `id`='$post[otvet]'");

    if ($post['otvet'] != 0 && $qw['count'] != 0) {
        $otvet = $db->get_array($db->query("SELECT * FROM `user` WHERE `id` = '$post[otvet]'"));
    }

    echo user($ank['id']) . " <small class='hint--right' data-hint='" . date::time($post['time']) . "' style='color:grey;'>" . date::timek($post['time']) . "</small><br /> ";

    echo "<div id='accordion'>";
    echo "<div role='tab'>";
    echo "<span class='hint--left right' data-hint='" . lang('Действия') . "'><a class='collapsed' data-toggle='collapse' data-parent='#accordion' href='#post_$post[id]' aria-expanded='false'><i class='fa fa-ellipsis-v fa-fw'></i></a></span>";
    echo "</div>";
    if (isset($otvet)) {
        echo "$otvet[nick], ";
    }
    echo toOutput($post['msg']);

    if (isset($otvet)) {
        unset($otvet);
    }

    if ($post['time_edit'] != 0) {
        #Показываем последнее редактирование
        $admin = mysqli_fetch_object($db->query("SELECT `id`, `nick` FROM `user` WHERE `id` = $post[id_user_edit]"));

        echo "<br /> <small style='color: green;'>" . lang('обновлено') . " $admin->nick (<span class='hint--top' data-hint='" . date::time($post['time_edit']) . "'>" . date::timek($post['time_edit']) . "</span>)</small>";
    }
    if (isset($user)) {
        echo "<div id='post_$post[id]' class='panel-collapse collapse' aria-labelledby='post_$post[id]'><small>";
        if ($news['close'] == 0 && $user['id'] != $ank['id']) {
            echo "<a href='?new_komm=$post[id]'>" . lang('Ответить') . "</a> ";
        }
        if ($user['level'] > 2 || $user['id'] == $post['id_user'] && $post['time'] > time() - 600) {
            echo " &#183; <a href='?edit_komm=$post[id]'>" . lang('Редактировать') . "</a> ";
        }
        if (access('adm_news_delete_comments')) {
            echo " &#183; <a href='?news=$news[id]&amp;del=$post[id]'>" . lang('Удалить') . "</a> ";
        }
        echo "</small></div>";
    }

    echo "</div>";
    echo "</td></tr></table>";
}

if ($k_page > 1) {
    str("?news=" . intval($_GET['news']) . '&amp;', $k_page, $page);
}

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