Просмотр файла news/index.php

Размер файла: 5.75Kb
<?
include('../core/core.php');
include(BASEDIR.INC.'func.php');
include(BASEDIR.INC.'session.php');
include(BASEDIR.INC.'session_user.php');
$mode = htmlspecialchars($_GET['mode']);
include(BASEDIR.INC.'head.php');
show_title('Новости');
 echo '<div class="razdel">Новости сайта</div>';
switch ($mode):
case 'index':
define('TOPAGE',10);
$page=(int)$_GET['page'];  
     
   $q=mysql_result(mysql_query("SELECT COUNT(*) FROM `news`"),0);  
      
    $total = intval(($q - 1) / TOPAGE) + 1;  
      
    if(empty($page) or $page < 0) $page = 1;  
      
    if($page > $total) $page = $total;  
      
    $start = $page * TOPAGE -TOPAGE;  

    $g=mysql_query("SELECT * FROM `news` ORDER BY `id` DESC LIMIT $start,".TOPAGE."");  
while($u=mysql_fetch_array($g)){ 
echo'<div class="menu">';
$o= mysql_query("SELECT count(*) FROM `news_kom` WHERE `id_news` = '".$u['id']."'");
$r = mysql_fetch_row($o);
$t = $r[0];
$com=mysql_result(mysql_query("SELECT COUNT(*) FROM `news_kom` WHERE `id_news` = '".$u['id']."'"),0);  
$tot = intval(($com - 1) / 10) + 1; 
echo'<img src="/'.IMG.'news.png"> '.$u['title'].' <small>('.$u['data'].')</small><hr>'.$u['news'].'<hr>
Добавил: <a href="/users/profile.php?user='.$u['login'].'">'.$u['login'].'</a><br />
<a href="?mode=read&id='.$u['id'].'">Комментарии</a> ('.$t.') <a href="?mode=read&id='.$u['id'].'&page='.$tot.'">»</a>';
echo'</div>';}

if($q == 0){ echo'<div class="menu">Новостей пока что нету!</div>'; } 
       if ($page != $total) $nextpage = ' <a href="?mode=index&page='. ($page + 1) .'">Далее</a>';  
      if($page - 1 > 0) $pageback = '<a href="?mode=index&page='. ($page - 1) .'">Назад</a> ';  
echo''.$pageback.' '.$nextpage.'';
break;
case 'read':
# ---------------------- #
if(is_user()){
$users = mysql_query('SELECT * FROM users WHERE login = "'.$_COOKIE['login'].'"');
$users = mysql_fetch_assoc($users);
$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);
$page=(int)$_GET['page'];  
     
   $q=mysql_result(mysql_query("SELECT COUNT(*) FROM `news_kom` WHERE `id_news` = '".$id."'"),0);  
      
    $total = intval(($q - 1) / TOPAGE) + 1;  
      
    if(empty($page) or $page < 0) $page = 1;  
      
    if($page > $total) $page = $total;  
      
    $start = $page * TOPAGE -TOPAGE;  

    $g=mysql_query("SELECT * FROM `news_kom` WHERE `id_news` = '".$id."' ORDER BY `id` DESC LIMIT $start,".TOPAGE."");  
while($u=mysql_fetch_array($g)){ 
echo'<div class="menu">';
$login = $u['login'];
$li =mysql_query("SELECT * FROM users WHERE `login`='$login';");
$li = mysql_fetch_assoc($li);
if($li['status'] == 101){$st ='Администратор';}
if($li['status'] == 102){$st ='Помощник Администратора';}
if($li['status'] == 103){$st ='Модератор';}
if($li['status'] == 104){$st ='Помощник Модератора';}
if($li['status'] == 105){$st ='Пользователь';}
$p = mysql_query('SELECT * FROM session_user WHERE user = "'.$login.'"');
if(mysql_num_rows($p) != 0){ $on ='[<font color="green">On</font>]'; } else { $on ='[<font color="red">Off</font>]'; }
if($li['avatar_mini'] == NULL){ $avatar ='/images/noavatar.gif'; } else {$avatar = ''.$li['avatar_mini'].'';}
echo'<div style="overflow: hidden"><div style="float: left"><img src="'.$avatar.'"></div> <a href="/users/profile.php?user='.$login.'">'.$login.'</a> ('.$u['data'].')<br />
 '.$st.' '.$on.'</div><hr>'.$u['msg'].'';
if($_COOKIE['login'] == !NULL && $admin == 101 || $admin == 102 || $admin == 103 || $admin == 104){ 
if($_COOKIE['login'] == !NULL && $_COOKIE['pass'] == !NULL){
$us = mysql_query('SELECT * FROM users WHERE login = "'.$u['login'].'"');
$us = mysql_fetch_assoc($us);
$ad = $us['status'];
}
# ---------------------- #
if($admin == 104 && $ad == 101 || $ad == 102 || $ad == 103){} else {
if($admin == 103 && $ad == 101 || $ad == 102){} else {
if($admin == 102 && $ad == 101){} else {
echo'<hr><a href="?mode=delet_com&id='.$u['id'].'" onclick="return confirm(\'Вы подтверждаете удаление?\')">[удл]</a>'; }}}}
echo'</div>';}

if($q == 0){ echo'<div class="menu">Комментарьев пока что нету!</div>'; } 
       if ($page != $total) $nextpage = ' <a href="?mode=index&page='. ($page + 1) .'">Далее</a>';  
      if($page - 1 > 0) $pageback = '<a href="?mode=index&page='. ($page - 1) .'">Назад</a> ';  
echo''.$pageback.' '.$nextpage.'';
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 = date("d.m.Y / H:i:s");
$i = $_COOKIE['login'];
$msg = no_br($msg);
$msg = antimat($msg);
$msg = smiles($msg);
mysql_query("INSERT INTO `news_kom`(`id_news`, `login`, `msg`, `data`) VALUES ('$id','$i','$msg','$data')");
$_SESSION['antiflood'] = time() + 30;
$q=mysql_result(mysql_query("SELECT COUNT(*) FROM `news_kom` WHERE `id_news` = '".$id."'"),0);  
$total = intval(($q - 1) / 10) + 1;  
header("Location: ?mode=read&id=".$id."&page=".$total."");
}
break;
default: 
header ('location: ?mode=index'); 
endswitch;
echo'<a href="/">На главную</a>';
include(BASEDIR.INC.'foot.php');
?>