<?php

include 'system/sys.php';
include 'system/funcs.php';

if (!isset ($us)) {
        header ('location: /');
        exit;
}

if (!isset ($_GET['id'])) {
        header ('location: /');
        exit;
}

$query = DB :: $dbs -> query ("SELECT * FROM `us` WHERE (`id`=?)", array ((int) $_GET['id']));
if ($query -> rowCount () == 0) {
        header ('location: /');
        exit;
}
$u = $query -> fetch ();

$items = DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `nar` WHERE (`us`='" . $u['id'] . "')");

H ('Пенализации ' . $u['nick'], 'Пенализации ' . uNick ($u['id']) . ' (' . $items . ')');

$items_per_page = 10;
$pages = ceil ( $items / $items_per_page );
$page = (int) $_GET['page'];

if ($page < 1)
        $page = 1;

if ($page > $pages)
        $page = $pages;
    
$start = $page * $items_per_page - $items_per_page;

if ($u['level'] < $us['level']) {

        echo '<div class="list1">';
        echo '<form action="/nar.php?id=' . $u['id'] . '&add" method="post">';
        echo 'Причина:<br/><textarea name="text"></textarea><br/>';
        echo '<input name="type" type="hidden" value="0" />';
        echo '<input name="type" type="radio" value="0" checked="checked"/> предупреждение<br/>';
        echo '<input name="type" type="radio" value="1" /> нарушение<br/>';
        echo '<input type="submit" value="Добавить"/>';
        echo '</form>';
        echo '</div>';
        
        if (isset ($_GET['add'])) {
        
                $_POST['text'] = htmlspecialchars (addslashes (trim ($_POST['text'])));
                if (empty ($_POST['text'])) {
                        echo '<div class="list1"><b style="color:red;">Вы не ввели причину..</b></div>';
                }
                else {
                                
                        DB :: $dbs -> query ("INSERT INTO `nar` (`us`,`kem`,`type`,`text`,`time`) VALUES ('" . $u['id'] . "', '" . $us['id'] . "', ?, ?, '" . time () . "')", array ((int) $_POST['type'], $_POST['text']));
                        DB :: $dbs -> query ("INSERT INTO `action` (`value`,`t`,`us`,`see`) VALUES ('us{" . $us['id'] . "} вписал вам [url=/nar" . $u['id'] . "]нарушение[/url]!', '" . time () . "', '" . $u['id'] . "', '1')");
             
                       header ('location: /nar.php?id=' . $u['id']);
                    
                }
            
        }

}
    
if ($items != 0) {
  
        $query = DB :: $dbs -> query ("SELECT * FROM `nar` WHERE (`us`='" . $u['id'] . "') ORDER BY `id` DESC LIMIT $start, $items_per_page");
        while ($nar = $query -> fetch ()) {
            
                $type = array (
                        'Предупреждение',
                        'Нарушение',
                        'Бан'
                );
                
                echo '<div class="lst">';
                echo uNick ($nar['kem']) . ' (' . datef ($nar['time']) . '):<br/>';
                echo 'Тип: ' . $type[ $nar['type'] ] . '<br/>';
                echo 'Причина: ' . bb ($nar['text']);
                echo '</div>';
            
        }

        echo '<div class="lst">' . pages ('/nar' . $u['id']) . '</div';
    
}
else {
        echo ' <div class="list1">Нет пенализаций!</div>';
}


F ();

?>