<?php
include ('core/system.php');

head('Новости');


reg();
$dbc->query("update `users` set `anekdot` = 0 where `id`='".$user['id']."' ");

if(isset($_GET['dele']) AND !empty($_GET['news']) AND $user['admins']>1){
$news_id = int($_GET['news']);
$test_news = $dbc->query("SELECT * FROM `news` WHERE `id`='".$news_id."'")->fetch_assoc();




if(!$test_news){
header("Location: index.php");
exit;
}
header("Location: news.php");
$dbc->query("DELETE FROM `news` WHERE `id`='".$news_id."'");

foot();
exit;
}
if(isset($_GET['new']) AND $user['admins']>1){
if(empty($_POST['text'])){
echo '

<div class="main">

<div class="block_zero center">

<a href="admins.php">

<div class="head">

<font color="cyan">

Админ - панель

</font>

</div>

</a>

</div>

<div class="mini-line"></div>

<div class="block_zero center">

Добавить весть

<br/>

<form action="news.php?new" method="post">

<textarea class="text" name="text"></textarea>

<br>

<span class="btn">

<span class="end">

<input class="label" type="submit" value="Добавить">

</span>

</span>

</form>

</div>

</div>



';
}
else{
$text = protect($_POST['text']);
$dbc->query("INSERT INTO `news` SET

`text`='".$text."',
`time`='".time()."',
`user_id`='".$user['id']."'");
$dbc->query("update `users` set `anekdot` = 1 where `level`>4 ");


header('Location: news.php');
}
foot();
exit;
}
//echo '<center><span class="info">Новости<br></span></center>';




if($user['admins']>0){
echo '<a href="news.php?new">Новая весть</a>';
}
echo '</div>';
$total = $dbc->query("SELECT `id` FROM `news`"); $total = $total->num_rows;

	if($total==0){
	echo '<div class="row">Новостей еще нет.</div>';
	foot();
	exit;
	}
$news_q = $dbc->query("SELECT * FROM `news` ORDER BY `time` DESC LIMIT 1");


while($news = $news_q->fetch_assoc()){


$ank = $dbc->query("SELECT `id`,`login` FROM `users` WHERE `id`='".$news['user_id']."' LIMIT 1")->fetch_assoc();

echo '<div class="b-panel-new dblue-panel bordered mt2">
<div class="panel-inner-2">[<b>'.clock($news['time']).'</b>]';

	if($user['admins']>0){
echo '<a href="news.php?dele&amp;news='.$news['id'].'"> [удалить]</a>';
	}
?><b><span class="info"><?=$news['text']?></span></b></br><?




echo' Опубликовал: <a href="pers.php?ank='.$ank['id'].'">'.$ank['login'].' </a></div></div></div>';






?></div></div><?











}
/*
if($total > $set['str'])	{
		pages($page, $total, 'news.php?', $set['str']);
	}
*/
foot();
?>