<?php

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

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

}

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


}

$query = DB :: $dbs -> query ("SELECT * FROM `zc_f` WHERE (`id`=?)", array ((int) $_GET['id']));
if ($query -> rowCount ()==0) {

    header ('location: /zc');
    
    exit;

}

$file = $query -> fetch ();

if (!isset ($file['dop']) || $file['dop']=='net') {
    
    header ('location: /zc');
    
    exit;
    
}

$kat = DB::$dbs->query ("SELECT * FROM `zc_kat` WHERE (`id`='" . $file['id_kat'] . "')");
if ($query -> rowCount ()==0) {

    header ('location:/zc');
    
    exit;

}

$kat = $query -> fetch ();

$query = DB :: $dbs -> query ("SELECT * FROM `zc_pk` WHERE (`id`='" . $file['id_pk'] . "')");
if ($query -> rowCount ()==0) {

    header ('location:/zc');
    
    exit;

}

$pk = $query -> fetch ();

H ($file['name'], '<a href="/zc" style="color:white;">ЗЦ</a> / <a href="/zc/pk' . $pk['id'] . '" style="color:white;">' . $pk['name'] . '</a> / ' . $file['name']);


$items = DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `zc_vote` WHERE (`id_file`='" . $file['id'] . "')");
$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 ($items==0) {
    echo '
    <div class="list1">
        Данный файл не оценивали!
    </div>
    ';
}
else {

    $query = DB :: $dbs -> query ("SELECT * FROM `zc_vote` WHERE (`id_file`='" . $file['id'] . "') ORDER BY `id` DESC LIMIT $start, $items_per_page");
    while ($vote = $query -> fetch()) {
        
        echo '
        <div class="list1">
            ' . uNick ($vote['kem']) . ' [' . datef ($vote['t']) . '] ' . ($vote['vot'] == 'za' ? '<b style="color:green;">+1</b>':'<b style="color:red;">-1</b>') . '<br/>
            Комментарий: ' . bb ($vote['komm']) . '<br/>
        </div>
        ';

    }
    
    echo '
    <div class="list1">
        ' . pages ('/zc/votes' . $file['id'] ) . '
    </div>
    ';

}

F ();


?>