File size: 4.3Kb
<? $page_name="Коментарии"; include("include/1.php"); require "include/avto.php";
if(!isset($_GET['new']) and !isset($_POST['text']))echo error('Ничего не выбрано!', '');
if(isset($_GET['new'])){
$new=$_GET['new'];
if(mysql_num_rows(mysql_query("select * from `shurik_news` where id=$_GET[new]")) == 0)echo error('Новость не найдена!', '');
//////////////////////////////////////////
$num = $pstr['comment'];
@$page = $_GET['page'];
$result00 = mysql_query("SELECT COUNT(*) FROM `shurik_com` where new=$new");
$temp = mysql_fetch_array($result00);
$posts = $temp[0];
$total = (($posts - 1) / $num) + 1;
$total = intval($total);
$page = intval($page);
if(empty($page) or $page < 0) $page = 1;
if($page > $total) $page = $total;
$start = $page * $num - $num;
///////////////////////////////////////////
$comm_1=mysql_query("select * from `shurik_com` where new=$new order by date desc limit $start,$num");
$comm_3=mysql_query("select * from `shurik_com` where new=$new");
$comm_2=@mysql_fetch_array($comm_1);
echo "<a href=new.php?id=$new><<Назад</a><br/><br/>";
if(isset($_SESSION['user_id']))echo 'Оставить коментарий<br/><form action="comment.php?" method="post"><textarea name="text" cols="25" rows="4"></textarea><input name="id" type="hidden" value="'.$new.'"><br/><input name="" type="submit" value="Отправить"></form><br/>';
if(mysql_num_rows($comm_3) > 0){
do{$user_avtor=mysql_fetch_array(mysql_query("select * from `shurik_users` where login='$comm_2[avtor]'"));
$date=date("ndHis");
$time=$user_avtor['online'];
if ($time+45 > $date) $user_on = "<span style='color:green'>[ON]</span>";
else $user_on = "<span style='color:red'>[OFF]</span>";
echo "<a href=user/$user_avtor[id]>$user_avtor[echologin]</a> $user_on<br/><small>$comm_2[date]</small><br/>$comm_2[text]<hr color=white>";}
while ($comm_2=mysql_fetch_array($comm_1));
//////////////////////////
$url_for_pstr="comment.php?new=$new&page=";
if($page - 5 > 0) $page5left = ' <a href='.$url_for_pstr.($page - 5) .'>'. ($page - 5) .'</a> | ';
if($page - 4 > 0) $page4left = ' <a href='.$url_for_pstr.($page - 4) .'>'. ($page - 4) .'</a> | ';
if($page - 3 > 0) $page3left = ' <a href='.$url_for_pstr.($page - 3) .'>'. ($page - 3) .'</a> | ';
if($page - 2 > 0) $page2left = ' <a href='.$url_for_pstr.($page - 2) .'>'. ($page - 2) .'</a> | ';
if($page - 1 > 0) $page1left = ' <a href='.$url_for_pstr.($page - 1) .'>'. ($page - 1) .'</a> | ';
if($page + 5 <= $total) $page5right = ' | <a href='.$url_for_pstr.($page + 5) .'>'. ($page + 5) .'</a>';
if($page + 4 <= $total) $page4right = ' | <a href='.$url_for_pstr.($page + 4) .'>'. ($page + 4) .'</a>';
if($page + 3 <= $total) $page3right = ' | <a href='.$url_for_pstr.($page + 3) .'>'. ($page + 3) .'</a>';
if($page + 2 <= $total) $page2right = ' | <a href='.$url_for_pstr.($page + 2) .'>'. ($page + 2) .'</a>';
if($page + 1 <= $total) $page1right = ' | <a href='.$url_for_pstr.($page + 1) .'>'. ($page + 1) .'</a>';
if($page - 1 > 0) $nazad = '<a href='.$url_for_pstr.($page - 1) .'>Назад</a>';
if($page + 1 <= $total) $vpered = '<a href='.$url_for_pstr.($page + 1) .'>Далее</a>';
// Вывод меню если страниц больше одной
if ($total > 1)
{
Error_Reporting(E_ALL & ~E_NOTICE);
echo $pervpage.$page5left.$page4left.$page3left.$page2left.$page1left.'<b>'.$page.'</b>'.$page1right.$page2right.$page3right.$page4right.$page5right.$nextpage.'<br>'.$nazad.' | '.$vpered;
}
////////////////////////////
}
}
else {echo "";}
if(isset($_POST['text']) and isset($_SESSION['user_id']))
{$text=$_POST['text'];$text=code($text);$text=smile($text); $date=date("Y.m.d - H:i"); $id=$_POST['id']; $for=1;
$user_id=$_SESSION['user_id'];$avtor=mysql_fetch_array(mysql_query("select * from `shurik_users` where id=$user_id"));
@session_start();
$time_sec=60;
if (@$_SESSION['com_spam']<time ())
{
$_SESSION['com_spam']=time()+$time_sec;
$insert_post=mysql_query("insert into `shurik_com` set text='$text', date='$date', avtor='$avtor[login]', new='$id', `for`='$for'");
}
else echo 'Разрешается добавлять собщения раз в '.$time_sec.' секунд! Не части!<br>';
if(isset($insert_post) and $insert_post)echo "Коментарий успешно добавлено<br><a href=comment.php?new=$id>Назад</a><br/>";
else echo "<b>SHuRiK CMS error:</b> ошибка при добавлении сообщения<br>".mysql_error();
}
include("include/2.php"); ?>