<?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 `podp` WHERE (`" . (isset($_GET['na']) ? 'us' : 'na') . "`='" . $u['id'] . "')");

H ((isset ($_GET['na']) ? $u['nick'] . ' подписан на..' : 'Подписчики ' . $u['nick']), (isset ($_GET['na']) ? uNick ($u['id']) . ' подписан на..' : 'Подписчики ' . 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;

echo '<div class="list1"><a href="/podp.php?id=' . $u['id'] . '">Подписчики</a> | <a href="/podp.php?id=' . $u['id'] . '&na">Подписан на..</a></div>';
if ($items != 0) {
        
        echo '<div class="list1">';
        
        $query = DB :: $dbs -> query ("SELECT * FROM `podp` WHERE (`" . (isset($_GET['na']) ? 'us' : 'na') . "`='" . $u['id'] . "') ORDER BY `id` DESC limit $start, $items_per_page");
        while ($podp = $query -> fetch ()) {
                echo uNick ($podp[ (isset($_GET['na']) ? 'na' : 'us') ]) . '<br/>';
        }
        
        echo '</div>';
        
        echo '<div class="lst">' . pages ('/podp' . $u['id']) . '</div>';

}
else {
        echo '<div class="list1">' . (isset ($_GET['na']) ? uNick ($u['id']) . ' ни на кого не подписан..' : 'У ' . uNick ($u['id']) . ' нет подписчиков!') . '</div>';
}


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

F ();

?>