<?php

define('_CONSTANT_', 1);

require_once '../../core/start.php';

checkAuth();

head('Логи', 'Логи');

if ($user['access'] != 2) 
{
    header("Location: ".HOME."/game/");
    exit();
} 


switch ($do) 
{
    default : 
        break; 

        case 'banUser': 
            if (!isset($_GET['userId'])) 
            {
                error('Не получен идентификатор пользователя.', '/modules/administrative/index.php', 'Вернуться в панель управления');
            } 
            
            $data = $_GET;
            
            $data['userId'] = $Filter->clearInt($data['userId']);
            
            $all = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".BAN." WHERE `user_id` = ?", [$data['userId']]);
            $n = new Navigator($all,10,'do=banUser');
            $sql = DB::$dbs->query("SELECT * FROM ".BAN." WHERE `user_id` = ? ORDER BY `id` DESC LIMIT {$n->start()}, 10", [$data['userId']]);
            
            echo DIV_CONTENT;
            
            if (empty($all)) 
            {
                successNoExit('Нарушений не обнаружено.');
            } 
            else 
            {
                while ($ban = $sql -> fetch()) 
                {
                    echo 'ID: ' . $ban['id'] . '<br/> Модератор: ' . userLink($ban['moderator_id']) . '<br/>Окончание: ' . dataTime($ban['time_ban']).'<br/>Причина:' . $ban['text'] . '<br/>Статус: ' . ($ban['time_ban'] > time() ? '<span style="color: red;">[активен]</span>' : '<span style="color: green;">[не активен]</span>') . '<hr>';
                } 
                
                echo $n->navi();
            }
            
            echo CLOSE_DIV;
            
            $array = ['Панель Управления'];
            navPanel($array); 
            break;

            case 'administration': 
            
            if ($user['access'] == 2) 
            {
                $all = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM " . ADMIN_LOG . " ORDER BY `id`");
                $n = new Navigator($all,10,'do=administration');
                $sql = DB::$dbs->query("SELECT * FROM " . ADMIN_LOG . " ORDER BY `id` DESC LIMIT {$n->start()}, 10");

                echo DIV_CONTENT;

                if (empty($all)) 
                {
                    successNoExit('Пусто.');
                } 
                else 
                {
                    /* 
                     * Truncate log;
                     */ 
                     if (isset($_GET['deleteAll']) && $user['access'] == 2) 
                     {
                         DB::$dbs->query("TRUNCATE " . ADMIN_LOG . "");
                         $User->addLog($user['id'], 'Очистил логи');
                         success('Очищено.', '/modules/administrative/log.php?do=administration', 'Вернуться');
                     } 

                    //echo '<span style="font-weight: bold;color: #CECECE; margin: 8px;">';
                    while ($log = $sql -> fetch()) 
                    {
                        echo '<span style="font-weight: bold;color: #CECECE; margin: 8px;">' . $log['text'] . '</span><hr>';
                    }
                    //echo '</span>'; 

                    echo $n->navi();

                    echo '<a href="' . HOME . '/modules/administrative/log.php?do=administration&amp;deleteAll" class="link-touch"> Очистить логи</a>';
                } 

                echo CLOSE_DIV;

                

                $array = ['Панель Управления'];
                navPanel($array); 
                break;
            }
} 

require_once '../../core/foot.php';