<?session_start();?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251"/>
<meta forua="true" http-equiv="Cache-Control" content="no-cache,no-store,must-revalidate"/>
<link rel="shortcut icon" href="../ico1.ico" type="image/x-icon" />
<title>Новости</title>
</head>
<link rel="stylesheet" href="../styleN.css" type="text/css" />
<link rel="stylesheet" href="../msg.css" type="text/css" />
<b>
<?php
echo"<title>Новости</title>";
?>

<div class='main' style='word-wrap:break-word;'>
<div class="center"><div class='top'>
<b><font color="white">«Новости»</font></b>
</div></div>

<div class="line"></div>
<div class="main" style="padding:5px">
<?
$p=@intval($_GET['p']);
$pa=@intval($_GET['pa']);
$reg = $_GET['reg'];
$com = $_GET['com'];
$cm = $_GET['cm'];
$cmname = $_GET['cmname'];
$cmcon = $_GET['cmcon'];
$like = $_GET['like'];
$nid = $_GET['nid'];
include("../db.php");
$db->openDB();
$sql=mysql_query("SET NAMES 'cp1251'");
$sql = mysql_query("SELECT * FROM news ORDER by date DESC LIMIT $p,10");


if(mysql_affected_rows() == 0)
{
echo("Новостей нет.<br/>");
}?>

<?
if(isset($like)){
if(!$_SESSION[s]){
echo"<div class=\"menu\"><li></li><center><li style=\"background:lime\">Для того чтобы поставить лайк или прокомментировать,авторизуйтесь</li></center><li></li><li></li></div>";
}
if($_SESSION[s]){
$prli = mysql_query("SELECT * FROM news_like WHERE NEWS_ID=\"$nid\" AND NICK=\"$_SESSION[s]\"");
if(mysql_num_rows($prli)>0){echo"<div class=\"menu\"><li></li><center><li style=\"background:lime\">Вы уже голосовали за эту новость</li></center><li></li><li></li></div>";
}
if(mysql_num_rows($prli)<1){
if($like == 1){$inl = mysql_query("INSERT INTO news_like (NICK,NEWS_ID,NEWS_LIKE,NEWS_DISLIKE) values ('$_SESSION[s]','$nid','1','') ");
print('<script>location.href="news.php?reg=4&p='."$p".'";</script>');
}
if($like == 2){$inl = mysql_query("INSERT INTO news_like (NICK,NEWS_ID,NEWS_LIKE,NEWS_DISLIKE) values ('$_SESSION[s]','$nid','','1') ");
print('<script>location.href="news.php?reg=4&p='."$p".'";</script>');

}
}
}}
echo "";
$i=0;
$count=mysql_num_rows($sql);
while($news = mysql_fetch_array($sql))
{
$commen = mysql_query("SELECT * FROM news_comments WHERE ID_NEWS=\"$news[id_news]\" ORDER BY N_DATE DESC LIMIT $pa,10");

$comcou = mysql_query("SELECT * FROM news_comments WHERE ID_NEWS=\"$news[id_news]\"");
$comco2 = mysql_num_rows($comcou);//считаем кол-во комментариев
$lkcou = mysql_query("SELECT * FROM news_like WHERE NEWS_ID=\"$news[id_news]\" AND NEWS_LIKE");
$likco2 = mysql_num_rows($lkcou);//считаем кол-во лайков
$discou = mysql_query("SELECT * FROM news_like WHERE NEWS_ID=\"$news[id_news]\" AND NEWS_DISLIKE");
$disco2 = mysql_num_rows($discou);//считаем кол-во дизлайков
    $i++;
echo "$i.<b><font color=\"red\">&#187;</font> ".$news['date']."</b><br/>";
echo "$news[content]<br/>разместил:<font color=\"red\"><u>$news[author]</u></font><br/>($likco2) <a href=\"?reg=4&p=$p&like=1&nid=$news[id_news]\"><img src=\"../img/like.png\" width=\"24\" height=\"24\"></a>  <a href=\"?reg=4&p=$p&like=2&nid=$news[id_news]\"><img src=\"../img/dislike.png\" width=\"24\" height=\"24\"></a> ($disco2)
<br/><a href=\"?reg=4&p=$p&com=1&nid=$news[id_news]\">комментарии</a> ($comco2)";
$i=0;
if(mysql_num_rows($comcou)<1){
$nws1 = mysql_query("SELECT * FROM news WHERE id_news=\"$news[id_news]\"");
while($nws2 = mysql_fetch_assoc($nws1)){
if($com == '1' AND $nid == $nws2[id_news] AND mysql_num_rows($commen)<1 AND !isset($cm)){
echo"<div style=\"background-color:#A23232;color:white\"><center>Комментариев нет, вы можете: <a href=\"news.php?reg=4&p=$p&com=1&nid=$nid&pa=$pa&cm=1\"><font color=\"gold\">оставить комментарий</font></a></center></div>";
}if($com == '1' AND $nid == $nws2[id_news] AND mysql_num_rows($commen)<1 AND isset($cm)){
if($cm==1){echo"
<form action=\"news.php?reg=4&p=$p&com=1&nid=$nid&pa=$pa&cm=1&cmname=1\" method=\"GET\">
<input name=\"reg\" value=\"4\" type=\"hidden\">
<input name=\"p\" value=\"$p\" type=\"hidden\">
<input name=\"com\" value=\"1\" type=\"hidden\">
<input name=\"nid\" value=\"$nid\" type=\"hidden\">
<input name=\"pa\" value=\"$pa\" type=\"hidden\">
<input name=\"cm\" value=\"1\" type=\"hidden\">
<input name=\"cmname\" value=\"1\" type=\"hidden\">
<input name=\"cmcon\" maxlength=\"2500\" class=\"ll3\"><br/>
<input type=\"submit\" value=\"написать\" class=\"buttonb\">
</form>

";
if($cmname == 1){
if(!$_SESSION[s]){
echo"<div class=\"menu\"><li></li><center><li style=\"background:lime\">Для того чтобы поставить лайк или прокомментировать,авторизуйтесь</li></center><li></li><li></li></div>";
}
if($_SESSION[s]){
echo"<div class=\"menu\"><li></li><center><li style=\"background:lime\">Для того чтобы поставить лайк или прокомментировать,авторизуйтесь</li></center><li></li><li></li></div>";

$date = date("Y-m-d");
$inscomm = mysql_query("INSERT INTO news_comments (NICK,N_DATE,CONTENT,ID_NEWS) VALUES ('$_SESSION[s]','$date','$cmcon','$nid')");
print('<script>location.href="news.php?reg=4&p='."$p".'";</script>');
}
}
}
}
}
}
while($commen2 = mysql_fetch_assoc($commen)){
if($com == '1' AND $nid == $commen2[ID_NEWS] AND mysql_num_rows($commen)>0){
$i++;
echo "<br/>$commen2[N_DATE]:$commen2[NICK] ".$commen2[CONTENT]."";
}

}




?>
<div class="menu">
<?
if(mysql_num_rows($comcou)>0){
$nws1 = mysql_query("SELECT * FROM news WHERE id_news=\"$news[id_news]\"");
while($nws2 = mysql_fetch_assoc($nws1)){
if($com == '1' AND $nid == $nws2[id_news] AND mysql_num_rows($commen)>0 AND !isset($cm)){
echo"<a href=\"news.php?reg=4&p=$p&com=1&nid=$nid&pa=$pa&cm=1\">оставить комментарий</a>";}if($com == '1' AND $nid == $nws2[id_news] AND mysql_num_rows($commen)>0 AND isset($cm)){
if($cm==1){echo"
<form action=\"news.php?reg=4&p=$p&com=1&nid=$nid&pa=$pa&cm=1&cmname=1\" method=\"GET\">
<input name=\"reg\" value=\"4\" type=\"hidden\">
<input name=\"p\" value=\"$p\" type=\"hidden\">
<input name=\"com\" value=\"1\" type=\"hidden\">
<input name=\"nid\" value=\"$nid\" type=\"hidden\">
<input name=\"pa\" value=\"$pa\" type=\"hidden\">
<input name=\"cm\" value=\"1\" type=\"hidden\">
<input name=\"cmname\" value=\"1\" type=\"hidden\">
<input name=\"cmcon\" maxlength=\"2500\" class=\"ll3\"><br/>
<input type=\"submit\" value=\"написать\" class=\"buttonb\">
</form>

";
if($cmname == 1){
	if(!$_SESSION[s]){
echo"<div class=\"menu\"><li></li><center><li style=\"background:lime\">Для того чтобы поставить лайк или прокомментировать,авторизуйтесь</li></center><li></li><li></li></div>";
}
if($_SESSION[s]){
echo"<div class=\"menu\"><li></li><center><li style=\"background:lime\">Для того чтобы поставить лайк или прокомментировать,авторизуйтесь</li></center><li></li><li></li></div>";

$date = date("Y-m-d");
$inscomm = mysql_query("INSERT INTO news_comments (NICK,N_DATE,CONTENT,ID_NEWS) VALUES ('$_SESSION[s]','$date','$cmcon','$nid')");
print('<script>location.href="news.php?reg=4&p='."$p".'";</script>');
}}
}

}
$ne = $pa+10;
$pr = $pa-10;
if($com == '1' AND $nid == $nws2[id_news] AND mysql_num_rows($commen)>0){
if ($pa>0) {
echo "<li><li></li><a href=\"news.php?reg=4&p=$p&com=1&nid=$nid&pa=$pr\">Назад</a><li></li></li>";
}
list($ca)=mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM news_comments WHERE id_news"));
if ($pa+10<$ca) {
echo "<li><li></li><a href=\"news.php?reg=4&p=$p&com=1&nid=$nid&pa=$ne\">Далее</a><li></li></li>";
}}
}

}

?>
</div>
<?





echo"<div class=\"point-line\"></div>";
echo "";

}

?>
<div class="menu">
<?
$next = $p+10;
$prev = $p-10;
if ($p>0) {
echo "<li><a href=\"news.php?reg=4&amp;p=$prev\">Назад</a><li>";
}
list($c)=mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM news WHERE id_news"));
if ($p+10<$c) {
echo "<li> <a href=\"news.php?reg=4&amp;p=$next\">Далее</a></li><br/>";
}
echo "</b>
</div></div>";
include("../footer.php");

?>

