<?php
define('ROOT','../');
define('GCMS',true);
require_once (ROOT.'system/power.php');
if ($id) {
$type = $db -> query("SELECT `id` FROM `news`");
if ($type -> num_rows > 0) $the = $type -> fetch_assoc(); else $the = false;
} else $the = false;
$diz -> head('Новости');
$diz -> title('Новости');
$count = $db -> dbcount('COUNT(`id`)','news');
$num = isset($ya['num']) ? $ya['num'] : 10;
$total = intval(($count - 1) / $num) + 1; 
if (!isset($_GET['page']) || !is_numeric($_GET['page']) || $_GET['page'] < 1 )
{
$page = 1;
} elseif($_GET['page'] > $total)
{ $page = $total;
} else $page = (int)$_GET['page'];
$start = $page * $num - $num;
$posts = $db -> query("SELECT `id` FROM `news`");
if ($posts -> num_rows > 0) {
$for = $db -> query("SELECT * FROM `news` ORDER BY `id` DESC LIMIT ".$start.",".$num);
while ($assoc = $for -> fetch_assoc()) {
$msg .= '<div class="top"><a href="./new'.$assoc['id'].'">'.$assoc['name'].'</a><br/>'.$func->user($assoc['user']).' ('.$func -> vremja($assoc['time']).') </br>';
if ($assoc['temaonf'] > 0){
$pob = $db -> dbcount('COUNT(*)','forum_posts','`tema` = '.$assoc['temaonf'].'');
if ($pob==0)$pob=NULL;
else $pob=''.$pob;
$msg .= '<a href="../forum/tema'.$assoc['temaonf'].'">Обсудить на форуме</a> ('.$pob.')';
}elseif($assoc['onf']==2){
$pob = $db -> dbcount('COUNT(*)','comes','`where`="news" and `idwh` = '.$assoc['id'].'');
$msg .= '<a href="com'.$assoc['id'].'">Комментарии</a> ('.$pob.')';
}
$msg.='</div>';
}
}else{$msg .= '<div class="fon">Новостей пока нет!</div>';}
$act = './?id='.$id;
$msg .= ''.$func -> pagenav($act,$page,$total).'';

$msg .= '<div class="levo">'.$diz -> img('home.png').'<a href="/index.php">На главную</a></div>';
#####Копирайт#######
require_once (ROOT.'system/kopy.php');
$diz -> out($msg);
?>