File size: 1.57Kb
<?
require_once ('system/core.php');
require_once ('system/head.php');
if(!$user) {
header('location: /');
exit;
}
echo '<div class="title"><center> Новости </a></center></div>';
if($_GET['news'] == add) {
if($user['id'] != 1) {
header('location: /news.php');
exit;
}
if($_POST['text']) {
$text = guard($_POST['text']);
mysql_query('INSERT INTO `news` (`text`,`time`) VALUEs ("'.$text.'","'.time().'")');
header('location: /news.php');
$_SESSION['result'] = 'Новость создана!';
exit();
}
echo "<div class='link'>
<form action='' method='post'>
<textarea name='text' style='width: 100%'></textarea><br/>
<input type='submit' value='Создать'>
</form></div>";
require_once ('system/foot.php');
exit;
}
$max = 10;
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `news`"),0);
$k_page = k_page($k_post,$max);
$page = page($k_page);
$start = $max*$page-$max;
$news = mysql_query("SELECT * FROM `news` ORDER BY `time` DESC LIMIT $start, $max");
while($n = mysql_fetch_assoc($news))
{
echo '<div class="link">';
echo ' <b>'.text($n['text']).'</b> </br> <span style="float: right;"><img src="/style/icons/time.png" width="16px" alt="TheSom"> '.date("Y.m.d H:i", $n['time']).' </span> </br>';
echo '</div>';
}
if($k_post<1) {
echo '<div class="foot"> Новостей нет </div>';
}
if($k_page>1) echo str('?',$k_page,$page);
if($user['id'] == 1) {
echo '<div class="foot"><img src="/style/icons/news_n.png"><a href="?news=add"> Создать новость </a> </div>';
}
require_once ('system/foot.php');
?>