<?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 `zc_f` WHERE (`us`='" . $u['id'] . "') AND (`dop`='da')");

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 ($items==0) {
        echo '<div class="list1"><b>' . uNick ($u['id']) . '</b> не загружал файлов!</div>';
}
else {

        $query = DB :: $dbs -> query ("SELECT * FROM `zc_f` WHERE (`us`='" . $u['id'] . "') AND (`dop`='da') ORDER BY `id` DESC LIMIT $start, $items_per_page");
        while ($f = $query -> fetch()) {
                
                $kat = DB :: $dbs -> queryFetch ("SELECT * FROM `zc_kat` WHERE (`id`='" . $f['id_kat'] . "')");
                $pk = DB :: $dbs -> queryFetch ("SELECT * FROM `zc_pk` WHERE (`id`='" . $f['id_pk'] . "')");
                
                echo '<div class="lst">';
                echo 'Файл: <a href="/zc/file' . $f['id'] . '">' . $f['name'] . '</a> (' . datef ($f['time']) . ')<br/>';
                echo 'Категория: <a href="/zc/kat' . $kat['id'] . '">' . $kat['name'] . '</a> / <a href="/zc/pk' . $pk['id'] . '">' . $pk['name'] . '</a>';
                echo '</div>';
                
        }
        
        echo '<div class="lst">' . pages ('/files' . $u['id']) . '</div>';

}

echo '<div class="list1"><a href="/us' . $u['id'] . '">В анкету ' . $u['nick'] . '</a></div>';

F ();
