<?php

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

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

$items = DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `forum_podp` LEFT JOIN `forum_t` ON `forum_t`.`id`=`forum_podp`.`id_t` WHERE (`forum_podp`.`us`='" . $us['id'] . "') AND (`forum_t`.`type`!='2')");
H ('Наблюдаемые темы', 'Наблюдаемые темы (' . $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 'Тем нет..';
}
else {

        $query = DB :: $dbs -> query ("SELECT * FROM `forum_podp` LEFT JOIN `forum_t` ON `forum_t`.`id`=`forum_podp`.`id_t` WHERE (`forum_podp`.`us`='" . $us['id'] . "') AND (`forum_t`.`type`!='2') ORDER BY `forum_podp`.`id` DESC LIMIT $start, $items_per_page");
        while ($podp = $query -> fetch()) {
            
                $t   = DB :: $dbs -> queryFetch  ("SELECT * FROM `forum_t` WHERE (`id`='" . $podp['id_t'] . "')");
                // 
                $c_p = DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `forum_p` WHERE (`id_t`='" . $t['id'] . "') " . (isset ($us) ? ($us['level']>0 ? '' : 'AND (`del`=\'0\')') : 'AND (`del`=\'0\')'));
                
                echo '<div class="list1">';
                echo '<img src="/design/' . ($t['top']==1? 'prikrep' : ($t['type']==0 ? 'closed' : 'the')) . '.png" alt=""/> <a href="/forum/thema' . $t['id'] . '">' . $t['name'] . '</a> (' . $c_p.') <a href="/forum/thema' . $t['id'] . '/page' . ceil ( $c_p / 10 ) . '">>></a><br/>';
                echo uNick ($t['us']) . '/' . uNick ($t['last']) . ' (' . datef ($t['time']) . ')';
                echo '</div>';

        }
        
        echo '<div class="lst">' . pages ('/kab/pth') . '</div>';
   
}


F ();
