<?php
require_once('system/func.php');

require_once('system/header.php');
auth();
if ($user['access'] == 3 || $user['id'] == 2) {

    echo "<h1>Список забаненных</h1>";
    echo "<div class='block'>";
    $set['p_str'] = 10;
    $k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `ban`"), 0);
    $k_page = k_page($k_post, $set['p_str']);
    $page = page($k_page);
    $start = $set['p_str'] * $page - $set['p_str'];
    $q = mysql_query("SELECT * FROM `ban` ORDER BY `id` DESC LIMIT $start, $set[p_str]");
    if ($k_post == 0) {
        echo '<div>Список пуст</div>';
    }
    while ($post = mysql_fetch_assoc($q)) {
        $ank = mysql_fetch_assoc(mysql_query("SELECT `id`, `login` FROM `users` WHERE `id` = '" . $post['id_user'] . "' LIMIT 1"));

        echo " <a href='/profile/$ank[id]'>$ank[login]</a>, причина: " . text_msg($post['text']) . "<br>";
        echo '<div>';
        if ($post['last'] > time()) {
            echo "Конец: " . tl($post['last'] - time());
        } else {
            echo "Разбанен: " . vremja($post['last']);
        }
        $adm_nick = mysql_fetch_assoc(mysql_query("SELECT `login` FROM `users` WHERE `id` = '" . $post['id_admin'] . "' ORDER BY `id` DESC LIMIT 1"));
        echo 'Кто забанил: <a href="/profile/' . $post['id_admin'] . '">' . $adm_nick['login'] . '</a></div>';
        echo "<hr>";
    }
    str('?', $k_page, $page); // Вывод страниц
    echo "</div>";

} else {
    header('Location: /main');
    exit;
}
require_once ('system/footer.php');