<?php

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

if (!access('forum_them_edit')) {
    header('Location: ' . DIR_FORUM);
    exit;
} else {
    $set['title'] = lang('Жалобы на темы');

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

    aut();

    if (isset($_GET['delete'])) {
        $this_report = intval($_GET['delete']);
        $q = $db->super_query("SELECT COUNT(*) as count FROM forum_reports WHERE `id` = '$this_report'");
        if ($q['count'] != 0) {
            $db->query('DELETE FROM `forum_reports` WHERE `id` = ' . $this_report);
        }
        unset($q);
        header('Location: ' . DIR_FORUM . 'reports.html');
        exit;
    }

    $q = $db->super_query("SELECT COUNT(*) as count FROM forum_reports");
    $k_post = $q['count'];
    $k_page = k_page($k_post, $set['p_str']);
    $page = page($k_page);
    $start = $set['p_str'] * $page - $set['p_str'];

    #Навигация
    echo "<div class='list-group-item-null list-group-item-grey'><small>";
    echo "<a href='/' class='hint--right' data-hint='" . lang('На главную') . "'><i class='fa fa-home fa-lg'></i></a> <i class='fa fa-angle-right fa-fw'></i> ";
    echo "<a href='" . DIR_FORUM . "'>" . lang('Форум') . "</a> <i class='fa fa-angle-right fa-fw'></i> ";
    echo lang('Жалобы на темы');
    echo "</small></div><br />";

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

    $reports = $db->query('SELECT * FROM `forum_reports` ORDER BY `id` ASC LIMIT ' . $start . ', ' . $set['p_str']);
    while ($report = mysqli_fetch_object($reports)) {
        $who = mysqli_fetch_object($db->query('SELECT `id`,`nick` FROM `user` WHERE `id` = ' . $report->id_user));
        $theme = mysqli_fetch_object($db->query('SELECT `id`, `id_razdel`, `name` FROM `forum_themes` WHERE `id` = ' . $report->id_theme));
        $razdel = mysqli_fetch_object($db->query('SELECT `id`, `id_forum` FROM `forum_razdels` WHERE `id` = ' . $theme->id_razdel));
        $forum = mysqli_fetch_object($db->query('SELECT `id` FROM `forum` WHERE `id` = ' . $razdel->id_forum));

        echo "<div class='list-group-item-null' style='margin-top: 2px;margin-bottom: 2px;'>\n";
        echo "<a href='" . DIR_FORUM . "reports/delete_$report->id' style='float: right;'><i class='fa fa-trash-o'></i></a>";
        echo lang('Тема') . ": <a href='" . DIR_FORUM . "$forum->id/$razdel->id/$theme->id.html'>" . toOutput($theme->name, 1, 1, 0, 0, 0) . "</a> ";
        echo "<b><a href='/info.php?id=$who->id'>$who->nick</a></b><br />";
        echo toOutput($report->text);
        echo "</div>";
    }

    if ($k_page > 1) {
        str(DIR_FORUM . 'reports/', $k_page, $page);
    }
}
