<?
//
//
require_once($_SERVER['DOCUMENT_ROOT']."/jquery/inc/system.php"); 
//
//
if(!$user){
header('location:/login/');
exit();
}
//
//
if($user['news'] != 0){
DB::$dbs->query('UPDATE `users` SET `news` = ? WHERE `id` = ? LIMIT 1', array(0,$user['id']));
header('location:?');
exit();    
}
//
//
head([]);
//
//
$id = num($_GET['id']);
		$news = DB::$dbs->queryFetch('SELECT * FROM `news` WHERE `id` = ? LIMIT 1', [$id]);
		//
		//
		if($news){
		if(empty($news['id'])): header('location: /news'); exit; endif;
		//
		//
		?>
		<div class="poster -gas">
		    <div class="start">
		        <center>
		            <span class="title-wqi"><?=$news['name'];?></span>
		        </center>
		<div class="menu-us">
<?=user_info(1);?>
<span style="float: right;"><?=times($news['time']);?></span>
<div class="stats2"></div>
<font color="#999999">
<?=bbcode($news['text']);?>
</font>
<center>
<div class="stats2"></div>
<a href="?">Вернуться назад</a>
</center>
</div>
			</div>
						</div>
<?
		//
		//
		foot([]);
		exit();    
		}
		//
		//
//
//
                $coll = DB::$dbs->querySingle('SELECT COUNT(id) FROM `news`');
		$num = 10;
		$total = intval(($coll - 1) / $num) + 1;
		$page = isset($_GET['page'])?intval($_GET['page']):1;
		if(empty($page) or $page < 0) $page = 1;
		if($page > $total) $page = $total;
		$start = $page * $num - $num; 

$sql = DB::$dbs->query("SELECT `id`,`text`,`time`,`name` FROM `news` ORDER BY `id` DESC LIMIT $start, $num")->fetchAll(PDO::FETCH_BOTH);
		?>
<div class="poster -gas">
		    <div class="start">
		        <center>
		            <span class="title-wqi">Новости и обновления</span>
		        </center>

		<?
		if($coll < 1){
		 ?>
		 <div class="menu-not">
		     Новостей еще нет
		   </div>
		 <?   
		}
			foreach ($sql as $sqlls => $im): ?>

<a href="?id=<?=$im['id'];?>">
<div class="menu-us">
<img src="/css/img/news.png"> 
<font color="#999999">
<?=$im['name'];?>
</font>
</div>
</a>


			<?php endforeach;
			?>
			</div>
			<?
			echo page('?',$page,$total); ?>
			</div>
<?
//
//
foot([]);
//
//
?>