Файл: news/index.php
Строк: 129
<?
include('../core/core.php');
include(MAINDIR.'style/head.php');
title('Новости');
echo '<div class="title">Новости сайта</div>';
switch ($mode):
case 'index':
define('TOPAGE',10); $num = TOPAGE;
$links = '?mode=index&page=';
$page = intval($_GET['page']);
$posts = DB::run() -> query("SELECT * FROM `news`") -> rowCount();
$total = intval(($posts - 1) / $num) + 1;
if(empty($page) or $page < 0) $page = 1;
if($page > $total) $page = $total;
$start = $page * $num - $num;
$ucv = DB::run()->query("SELECT * FROM `news` ORDER BY `id` DESC LIMIT $start,".TOPAGE."");
$ucv = $ucv -> fetchAll();
foreach($ucv AS $u){
echo'<div class="menu">';
$com = DB::run() -> query("SELECT * FROM `news_com` WHERE `id_news` =?",array($u['id'])) -> rowCount();
$tot = intval(($com - 1) / 10) + 1;
echo'<img src="/images/news.png"> '.$u['title'].' <small>('.$u['data'].')</small><hr>'.$u['msg'].'<hr>
Добавил: <a href="/profile/'.$u['login'].'">'.$u['login'].'</a><br />
<a href="?mode=read&id='.$u['id'].'">Комментарии</a> ('.count_all('news_com','id_news',$u['id']).') <a href="?mode=read&id='.$u['id'].'&page='.$tot.'">»</a>';
echo'</div>';
}
if ($page != 1) $pervpage = '<a href= '.$links.'1><<</a> <a href= '.$links.''. ($page - 1) .'><</a> ';
if ($page != $total) $nextpage = ' <a href= '.$links.''. ($page + 1) .'>></a> <a href= '.$links.'' .$total. '>>></a>';
if($page - 2 > 0) $page2left = ' <a href= '.$links.''. ($page - 2) .'>'. ($page - 2) .'</a> | ';
if($page - 1 > 0) $page1left = '<a href= '.$links.''. ($page - 1) .'>'. ($page - 1) .'</a> | ';
if($page + 2 <= $total) $page2right = ' | <a href= '.$links.''. ($page + 2) .'>'. ($page + 2) .'</a>';
if($page + 1 <= $total) $page1right = ' | <a href= '.$links.''. ($page + 1) .'>'. ($page + 1) .'</a>';
if($posts == 0){ echo'<div class="menu">Новости не добавлены!</div>'; } else {echo '<div class="menu_2">'.$pervpage.$page2left.$page1left.'<b>'.$page.'</b>'.$page1right.$page2right.$nextpage.'</div>'; }
break;
case 'read':
# ---------------------- #
if(is_user()){
$my = DB::run() -> queryFetch("SELECT * FROM `users` WHERE `login`=? LIMIT 1",array(check($_COOKIE['login'])));
$admin = $users['status'];
}
# ---------------------- #
$id = abs($_GET['id']);
if($id == NULL){ $id = 1;} else {$id = $id; }
if(is_user()){
echo'<div class="menu">';
echo'<form action="?mode=add&id='.$id.'" method="post">
<textarea name="msg" cols="40" rows="4"></textarea><br />
<input name="" type="submit" value="Написать" />
</form>';
echo'</div>';
}
define('TOPAGE',10); $num = TOPAGE;
$links = '?mode=read&id='.$id.'&page=';
$page = intval($_GET['page']);
$posts = DB::run() -> query("SELECT * FROM `news_com` WHERE `id_news`=?",array($id)) -> rowCount();
$total = intval(($posts - 1) / $num) + 1;
if(empty($page) or $page < 0) $page = 1;
if($page > $total) $page = $total;
$start = $page * $num - $num;
$themes = DB::run()->query("SELECT * FROM `news_com` WHERE `id_news`=? ORDER BY `id` DESC LIMIT $start,".TOPAGE."",array($id));
$themes = $themes -> fetchAll();
foreach($themes AS $u){
if($u['login'] == 'Гость'){echo'<div class="menu"><img src="/images/0.png"> '.$u['login'].' ('.$u['data'].')</div>';} else {
# Определяем иконку
$query = DB::run() -> queryFetch("SELECT * FROM `users` WHERE `login`=?",array($u['login']));
# если он из админ состава
if($query['status'] == 101 || $query['status'] == 102 || $query['status'] == 103 || $query['status'] == 104){
# определяем его пол и выводим иконку
if($query['pol'] == 1){$img = '<img src="/images/1.png">';}
if($query['pol'] == 0){$img = '<img src="/images/2.png">';}
}
# Если он обычный юзер
if($query['status'] == 105){
if($query['pol'] == 1){$img = '<img src="/images/4.png">';}
if($query['pol'] == 0){$img = '<img src="/images/3.png">';}
}
echo'<div class="menu">'.$img.' <a href="/profile/'.$u['login'].'">'.$u['login'].'</a> '.online($u['login']).' ('.$u['data'].')</div>';}
echo'<div class="menu_2">'.$u['msg'].'';
if(is_admin()){echo'<hr><a href="?mode=delet_com&id='.$u['id'].'" onclick="return confirm('Вы подтверждаете удаление?')">[удл]</a>'; }
}
if ($page != 1) $pervpage = '<a href= '.$links.'1><<</a> <a href= '.$links.''. ($page - 1) .'><</a> ';
if ($page != $total) $nextpage = ' <a href= '.$links.''. ($page + 1) .'>></a> <a href= '.$links.'' .$total. '>>></a>';
if($page - 2 > 0) $page2left = ' <a href= '.$links.''. ($page - 2) .'>'. ($page - 2) .'</a> | ';
if($page - 1 > 0) $page1left = '<a href= '.$links.''. ($page - 1) .'>'. ($page - 1) .'</a> | ';
if($page + 2 <= $total) $page2right = ' | <a href= '.$links.''. ($page + 2) .'>'. ($page + 2) .'</a>';
if($page + 1 <= $total) $page1right = ' | <a href= '.$links.''. ($page + 1) .'>'. ($page + 1) .'</a>';
if($posts == 0){ echo'<div class="menu">Пусто!</div>'; } else {echo '<div class="menu_2">'.$pervpage.$page2left.$page1left.'<b>'.$page.'</b>'.$page1right.$page2right.$nextpage.'</div>'; }
break;
case 'delet_com':
$id = abs(intval($_GET['id']));
DB::run()->query("DELETE FROM `news_com` WHERE `id` =?",array($id));
header ('location: '.$_SERVER['HTTP_REFERER'].'');
break;
case 'add':
$id = abs($_GET['id']);
if($id == NULL){ $id = 1;} else {$id = $id; }
$s = $_SESSION['antiflood'] - time();
if($_SESSION['antiflood'] >= time()){echo'Антифлуд! Разрешается отправлять сообщения раз в 30 секунд!<br />
Осталось: >'.formattime($s).'</div>';
}else{
$msg = check($_POST['msg']);
$data = times();
$i = check($_COOKIE['login']);
$msg = no_br($msg);
$msg = antimat($msg);
$msg = smiles($msg);
DB::run()->query("INSERT INTO `news_com`(`id_news`, `login`, `msg`, `data`) VALUES (?,?,?,?)",array($id,$i,$msg,$data));
$set = DB::run() -> queryFetch("SELECT * FROM `setting` WHERE `id`=? LIMIT 1",array(1));
$_SESSION['antiflood'] = time() + $set['antiflood'];
$com = DB::run() -> query("SELECT * FROM `news_com` WHERE `id_news` =?",array($id)) -> rowCount();
$total = intval(($q - 1) / 10) + 1;
header("Location: ?mode=read&id=".$id."&page=".$total."");
}
break;
default:
header ('location: ?mode=index');
endswitch;
echo'<div class="menu_2"><a href="/">На главную</a></div>';
include(MAINDIR.'style/foot.php');
?>