<?php

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

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

H ('Почта ' . $u['nick'], uNick ($u['id']));
echo '<div class="panell"><table width="100%" cellpadding="0" cellspacing="0"><tr>';
                                echo '<td width="25%" align="center"><a href="/kab"><img src="/images/menu/upanel.png"></a></td>';
                                echo '<td width="25%" align="center"><a href="/mail.php"><img src="/images/menu/message.png"> ' . ($n_m != 0 ? '<span class="coun">+' . $n_m . '</span>' : '') . '</a></td>';
                                echo '<td width="25%" align="center"><a href="/action.php"><img src="/images/menu/lenta.png"> ' . ($n_a != 0 ? '<span class="coun">+' . $n_a . '</span>' : '') . '</a></td>';
                                echo '<td width="25%" align="center"><a href="/?exit"><img src="/images/menu/logout.png"></a></td>';
                                echo '</tr></table></div>';
          
echo '<div class="menu">Почта ' . $us['nick'], '</div>';
$items = DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `poch` WHERE (`us`='" . $us['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 `poch` WHERE (`us`='" . $us['id'] . "') ORDER BY `last` DESC LIMIT $start, $items_per_page");
        while ($mail = $query -> fetch ()) {
     
                echo '<div class="lst">';
                echo uNick ($mail['kem']) . ' [<a href="/msg' . $mail['kem'] . '">диалог</a>] [<b>' . DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `msg` WHERE (`us`='" . $us['id'] . "') AND (`kem`='" . $mail['kem'] . "') AND (`see`='1')") . '</b>/' . DB :: $dbs -> querySingle ("SELECT COUNT(id) FROM `msg` WHERE (`us`='" . $us['id'] . "') AND (`kem`='" . $mail['kem'] . "') OR (`kem`='" . $us['id'] . "') AND (`us`='" . $mail['kem'] . "')") . '] [' . datef ($mail['last']) . ']';
                echo '</div>';
        
        }
        
        echo '<div class="list1">' . pages ('/mail') . '</div>';
        echo '<div class="list1"><a href="/search.php">Поиск контакта</a></div>';
        echo '<div class="list1"><a href="/favorit.php">Избранные</a></div>';
        echo '<div class="list1"><a href="/ignor.php">Игнор-лист</a></div>';
     
}

F ();

?>