View file news.php

File size: 5.52Kb
<?php
include_once("incs/conf.php");
include_once("incs/fmysql.php");
include_once("incs/fnc.php");
include_once("incs/head.php");

$a = intval(fil($_GET['a']));
$p = fil($_GET['p']);
$n = fil($_GET['n']);

if($settings[news]==1){
head("Новости",$meuser,$auth);
echo "<div class='rowup'>";
include_once("incs/title.php");
echo "Новости</div>";
echo "Раздел закрыт<br>";
include_once("incs/down.php");
}

$ban_ok=$user[ban]-$time;
if($ban_ok>0){
head("Новости",$meuser,$auth);
echo "<div class='rowup'>";
include_once("incs/title.php");
echo "Новости</div>";

echo "Вы забанены по причине:<br>";
echo "<b>$user[ban_prich]</b><br>";
echo "До окончания бана осталось: $ban_ok сек.<br>";
echo "Старайтесь больше не нарушать <a href=\"rules.php\">правила</a> сайта!<br>";
include_once("incs/down.php");
}

$news_id=mysql_fetch_array(mysql_query("SELECT * FROM `news` WHERE `id` = '$a'"));
if($news_id[name]=="" && $a!=""){
head("Ошибка",$meuser,$auth);
echo "<div class='rowup'>";
include_once("incs/title.php");
echo "<a href=\"\">Новости</a> - Ошибка</div>";
echo"Такой новости не существует!<br>";
include_once("incs/down.php");
}

switch($a){
case '':
head("Новости",$meuser,$auth);
echo "<div class='rowup'>";
include_once("incs/title.php");
echo "Новости</div>";

$k_post = mysql_num_rows(mysql_query("SELECT id FROM `news`"));
if ($k_post==0)
{
echo "Нет новостей<br/>\n";
}

if($on==1){
$end=$user[msg_for_page];
}else{
$end=10;}
$skok_pages=ceil($k_post/$end);
if(!isset($_GET['page'])){
$page=1;
}else{
$page=intval($_GET['page']);
if($page<1){$page=1;}
if($page>$skok_pages){$page=1;}
}
if($page==1 OR $page<1){
$start=0;
}else{
$start=($page-1)*$end;
}

$q=mysql_query("SELECT * FROM `news` WHERE `id` != '0' ORDER BY id DESC LIMIT $start,$end");
while ($postt = mysql_fetch_array($q))
{
echo "<div class='rowap'>$postt[name] ($postt[data])";
$kom_post = mysql_num_rows(mysql_query("SELECT id FROM `news_kom` WHERE `id_news` = '$postt[id]'"));
$news_user=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `nick` = '$postt[sozdal]'"));
$rest = substr("$postt[msg]", 0, 100);
echo "<br>$rest...<br>";
echo "<div class='news'>";
echo "Просмотров: <b>$postt[skok]</b><br>";
echo "Коментариев: <b>$kom_post</b><br>";
echo "Добавил: <b><a href=\"my.php?id=$news_user[id]\">$postt[sozdal]</a></b></div>";
echo "[<a href=\"news.php?a=$postt[id]\">Читать полностью</a>]<br></div>";
}
if($skok_pages>1){
for($i=1;$i<=$skok_pages;$i++){
if($i==$page){
echo "<span class=\"str_t\">$i</span>";
}else{
echo "<span class=\"str_l\"><a href='?page=$i'>$i</a></span>";
}}}
include_once("incs/down.php");
break;
}
switch($p){
case'add_com':
$povtor=mysql_fetch_array(mysql_query("SELECT * FROM `news_kom` WHERE `id` != '0' ORDER BY id DESC LIMIT 1"));
if($_POST['msg_kom']!=""){
$msg_kom=$_POST['msg_kom'];
$msg_kom=filtr($msg_kom);
$msg_kom=bbcode(smiles($msg_kom));
if($povtor[msg]!=$msg_kom){
mysql_query("INSERT INTO `news_kom` (`id_news`, `id_user`, `msg`, `time`) values('$a', '$user[id]', '$msg_kom', '".date('Y.m.d/H:i')."')");
mysql_query("UPDATE `user` SET `money` = '".($user['money']+1)."' WHERE `id` = '$user[id]'");
}else{
$sis_msg="Коментарий повторяетса<br>";
}
}else{
$sis_msg="Коментарий пуст<br>";
}
break;

case'del':

if($user[level]>=2 && $n!="" && $n!=0){
mysql_query("DELETE FROM `news_kom` WHERE `id` = '$n'");
}
break;
}

head("Новости - $news_id[name]",$meuser,$auth);
echo "<div class='rowup'>";
include_once("incs/title.php");
echo "<a href=\"?\">Новости</a> - $news_id[name]</div>";

echo "<b>$news_id[name]</b><br>";
echo "$news_id[msg]<br>";
$new_skok=$news_id[skok]+1;
mysql_query("UPDATE `news` SET `skok` = '$new_skok' WHERE `id` = '$news_id[id]'");
$news_user=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `nick` = '$news_id[sozdal]'"));
echo "<div class='news'>";
echo "Дата: $news_id[data]<br>";
echo "Просмотров: <b>$news_id[skok]</b><br>";
echo "Добавил: <b><a href=\"my.php?id=$news_user[id]\">$news_id[sozdal]</a></b></div>";
echo "<div class='rowup'>Коментарии:</div>";

if($on==1){
echo "$sis_msg";
echo "<form method=\"post\" action=\"?a=$a&p=add_com\">";
echo 'Сообщение:<br/><textarea name="msg_kom"></textarea><br>';
echo '<input value="Написать" type="submit"/></form>';
}

$kom_post = mysql_num_rows(mysql_query("SELECT id FROM `news_kom` WHERE `id_news` = '$a'"));
if ($kom_post==0){
echo "Нет коментариев<br/>\n";
}

if($on==1){
$end=$user[msg_for_page];
}else{
$end=10;}
$skok_pages=ceil($kom_post/$end);
if(!isset($_GET['page'])){
$page=1;
}else{
$page=intval($_GET['page']);
if($page<1){$page=1;}
if($page>$skok_pages){$page=1;}
}
if($page==1 OR $page<1){
$start=0;
}else{
$start=($page-1)*$end;
}

$qf=mysql_query("SELECT * FROM `news_kom` WHERE `id` != '0' AND `id_news` = '$a' ORDER BY id DESC LIMIT $start,$end");
while ($news_kom_id = mysql_fetch_array($qf))
{
$v=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '$news_kom_id[id_user]'"));
if($num==1){ 
echo "<div class='reki'>"; 
$num=0;
}else{ 
echo "<div class='rek'>"; 
$num=1;}
echo "<a href=\"my.php?id=$news_kom_id[id_user]\">$v[nick]</a> ($news_kom_id[time])<br>";
echo "$news_kom_id[msg]";
if($user[level]>=2){
echo "<br><a href=\"?a=$a&p=del&n=$news_kom_id[id]\">Удалить</a>";
}
echo "</div>";
}
if($skok_pages>1){
for($i=1;$i<=$skok_pages;$i++){
if($i==$page){
echo "<span class=\"str_t\">$i</span>";
}else{
echo "<span class=\"str_l\"><a href='?a=$a&page=$i'>$i</a></span>";
}}}
include_once("incs/down.php");
?>