Файл: bdls.ru/news.php
Строк: 35
<?php
include ('./system/common.php');
include ('./system/functions.php');
include ('./system/user.php');
$title = 'Новости';
include ('./system/h.php');
if(!$user) {
header('location: /index.php');
exit;
}
if($_GET['news'] == add) {
if($user['id'] != 1) {
header('location: /news.php');
exit;
}
if($_POST['text']) {
$text = _string($_POST['text']);
mysql_query('INSERT INTO `news` (`text`,
`time`) VALUEs ("'.$text.'",
"'.time().'")');
header('location: /news.php');
exit();
}
echo "<div class='block center'>
<form action='' method='post'>
Текст новости: <textarea name='text' style='width: 97%'></textarea><br/>
<input type='submit' value='Создать'>
</form></div>";
include ('./system/f.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="block">'.bb(smiles($n['text'])).' <span style="float: right;">'.vremja(time() - $n['time']).'</span></div>';
}
if($k_post<1) {
echo '<div class="block center">Новостей нет!</div>';
}
if($k_page>1) echo str('?',$k_page,$page);
if($user['id'] == 1) {
echo '<a href="?news=add" class="link">Создать новость</a>';
}
require_once './system/f.php';
?>