<?php

define('PROFIWM_ENGINE', true);
define('PATH', $_SERVER['DOCUMENT_ROOT']);

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

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

$items = DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `news`");

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 '
        <div class="list1">
                Новостей нет!
        </div>
        ';

}
else {															 

        $query = DB :: $dbs -> query ("SELECT * FROM `news` ORDER BY `id` DESC LIMIT $start, $items_per_page");
        while ($news = $query -> fetch ()) {
        
                echo '
                <div class="list1">
                        ' . bb ($news['text']) . '<br/>
                        <span style="color: #6d6d6d;">Добавил: ' . uNick ($news['us']) . ' (' . datef ($news['t']) . ')</span><br/>
                        <a href="/komm' . $news['id'] . '">Комментарии</a> (' . DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `news_komm` WHERE (`id_news`='" . $news['id'] . "')") . ')
                </div>
                ';

        }

        echo '
        <div class="lst">
                ' . pages ('/news') . '
        </div>
        ';

}
								
F ();

?>