<?php
error_reporting(0);
include 'conf/dbc.php';
include 'conf/session_start.php';

$usid=abs(intval($_SESSION['id']));
$usst=$dbc->query("SELECT * FROM `users` WHERE`id`='$usid' LIMIT 1")->fetch_assoc();

$count=mysqli_num_rows(mysqli_query($dbc,"SELECT COUNT(*) FROM`news`"));



include_once 'nav_class.php';
//Эх подстраничная навигация нелезть:)
$nstr='1'; //Сообщений на страницу
$countQ=$dbc->query("SELECT * FROM`news`"); #запрос в бд
$count=mysqli_num_rows($countQ); //Подсчёт строк
$pages = new Navigator($count,$nstr); #Вызов класса подстраничной навигации и расчёт страниц
$str = $pages -> start; //Сам хз что))
//----------//
$news="SELECT * FROM news ";

$rw=$dbc->query("SELECT * FROM `news` ORDER BY`id` DESC LIMIT $str,$nstr"); //Запрос в бд 
while($rn = mysqli_fetch_assoc($rw)) {
$page_title = ''.$rn[name];
include 'conf/head.php';
include 'conf/top.php';

$user_id = abs(intval($_SESSION['id']));

$dbc->query("UPDATE `users` SET new_news=0 WHERE `id` ='".$user_id."' LIMIT 1");

echo '<br/><center><p class="name">Новости</p></center>';
$adm= $dbc->query("SELECT * FROM users WHERE id ='".$rn['id_admin']."' LIMIT 1")->fetch_assoc();
$gruppa = $adm['gruppa'];
		$last_active = $adm['last_active'];
        $last_active = strtotime("$last_active");
        $razn_last_act = ($now - $last_active);
echo '<div class="r6">';
if ($gruppa == 'svoboda') {if ($razn_last_act < 300 ) {?><img src="img/ico/on.png" width="12" height="12" alt="н"/><img src="img/ico/svobodaon.png" width="12" height="12" alt="н"/><?php } else {?><img src="img/ico/off.png" width="12" height="12" alt="н"/><img src="img/ico/svobodaon.png" width="12" height="12" alt="н"/><?php }}
	  if ($gruppa == 'dolg') {if ($razn_last_act < 300 ) {?><img src="img/ico/on.png" width="12" height="12" alt="н"/><img src="img/ico/dolgon.png" width="12" height="12" alt="н"/><?php } else {?><img src="img/ico/off.png" width="12" height="12" alt="н"/><img src="img/ico/dolgon.png" width="12" height="12" alt="н"/><?php }}
	  if ($gruppa == 'naemniki') {if ($razn_last_act < 300 ) {?><img src="img/ico/on.png" width="12" height="12" alt="н"/><img src="img/ico/naemniki.png" width="12" height="12" alt="н"/><?php } else {?><img src="img/ico/off.png" width="12" height="12" alt="н"/><img src="img/ico/naemniki.png" width="12" height="12" alt="н"/><?php }}
 if ($gruppa == 'chistoenebo') {if ($razn_last_act < 300 ) {?><img src="img/ico/on.png" width="12" height="12" alt="н"/><img src="img/ico/chistoenebo.png" width="12" height="12" alt="н"/><?php } else {?><img src="img/ico/off.png" width="12" height="12" alt="н"/><img src="img/ico/chistoenebo.png" width="12" height="12" alt="н"/><?php }}
	  if ($gruppa == 'renegat') {if ($razn_last_act < 300 ) {?><img src="img/ico/on.png" width="12" height="12" alt="н"/><img src="img/ico/renegat.png" width="12" height="12" alt="н"/><?php } else {?><img src="img/ico/off.png" width="12" height="12" alt="н"/><img src="img/ico/renegat.png" width="12" height="12" alt="н"/><?php }}
echo'<a style="text-decoration:none"  href="user.php?id='.$rn['id_admin'].'">'.$rn['user'].'</a> <span class="bonus">('.vremja($rn['time']).')</span></div>';
echo '<p><div class="r6"><font color=#6DC2FF>'.$rn[text].'</font></div>';
$top=$dbc->query("SELECT * FROM `topics` WHERE `news`='".$rn[name]."' LIMIT 1")->fetch_assoc();
  $query_avt = "Select * from  comments where id_top = '".$top[id_top]."'";
  $result_avt = mysqli_query($dbc, $query_avt) or die ('Ошибка передачи запроса к БД');
  $kom= mysqli_num_rows($result_avt);
echo'<p><span class="menu"><a href="topic.php?topic='.$top[id_top].'">Обсудить в форуме</a> ('.$kom.')</p></span>
<p class="podmenu" style="border-top:1px solid #444e4f; background-color:#1c252f;"></p>';
}
if($count==0){echo'<p style="border-top: dashed #444e4f 1px;"></p>Новостей нет!<p style="border-top: dashed #444e4f 1px;"></p>';}
if($count>0){$pages->print_nav('');} //Навигация гг

$msg=filter($_POST['msg']);
$usid=intval($_SESSION['id']);


require_once('conf/navig.php');
require_once('conf/foot.php');
mysqli_close($dbc);
?>