<? include('header.php'); ?>
<div class="menucenter">
<?
$username=$nameus;
$newid=intval($_GET["id"]);
if($newid=="")
{
///переходы по страницам sfb

$num = 10;
$upag = "news.php?";
$page = (isset($_GET['n']))? intval($_GET['n']) : 1 ;
$numpag = mysql_num_rows(mysql_query("SELECT `id` FROM `tb_news`"));
$np =$numpag;
$obpag = intval(($np - 1) / $num) + 1;
if(empty($page) or $page < 0) $page = 1;
if($page > $obpag) $page = $obpag;
$nach = $page * $num - $num;

$sql="select * from tb_news order by id desc LIMIT $nach, $num";
$res=mysql_query($sql) or die(mysql_error());
include("navi.php");
while ($row=mysql_fetch_assoc($res))
{
$idnews=$row["id"];
	echo "
<table align='center' width='100%' border='0' cellpadding='0' cellspacing='0' style='pdding-top:4px;'>
          <thead style='background:#f5f5b5;'>
            <tr>
              <td colspan=5 align='left' style='color:red; border-bottom:solid 1px #F2C0A6; border-top:solid 1px #F2C0A6; font:12px Tahoma; padding:4px; padding-left:15px;'>".$row["data"]."</td>
            </tr>
          </thead>
<tr><td style='padding:10px;padding-top:2px;'>
<h2 align='center'>".$row["tema"]."</h2>
<span class='desctext4'>".$row["newstext"]."</span></td></tr>
<tr>
<td align='right'>
<a href='news.php?id=$idnews' class='bittorrenua' style='font-size:11px;'>Подробнее</a>
<div style='margin-bottom:5px;'></div>
</td>
</tr>
</table>
";
echo "<table width=100%><td align=left>";
echo "</td><td align=right></td></table>";
}
}
?>
<?
if($newid!="")
{
$neew=mysql_query("SELECT * FROM tb_news WHERE id='$newid'");$allsqls++;
if(mysql_num_rows($neew)==0)
{
echo "<div class='error'>Новости с Таким ID не существует! </div>";
include('footer.php'); exit;
}
$neew=mysql_fetch_assoc($neew);
echo "  <table class='reyt' align='center' width='100%' border='0' cellpadding='0' cellspacing='0'>
          <thead style='background:#f5f5b5;'>
            <tr>
              <td colspan=5 align='left' style='color:red; border-bottom:solid 1px #F2C0A6; border-top:solid 1px #F2C0A6; font:12px Tahoma; padding:4px; padding-left:15px;'>".$neew["data"]." ";
?>

<? echo "
</td>
            </tr>
          </thead>
<tr><td style='padding:10px;padding-top:2px;'>
<h2 align=center>".$neew["tema"]."</h2>
<span class='desctext4'>".$neew["newstext"]."</span></td></tr>
</table>
";
if(isset($_POST["delete"]))
{
$delid=intval($_POST["id"]);
$username=text($_SESSION["username"]);
$whois=mysql_query("SELECT * FROM tb_users WHERE username='$username'");
$whois=mysql_fetch_assoc($whois);
if($whois["user_status"]!='admin')
{
echo "<div class='error'>Вы не являетесь администратором проекта!</div>";
include('footer.php');
exit;
}
mysql_query("DELETE FROM afbcomments where id='$delid'");
echo "<div class='good'>Комментарий успешно удалён!</div>";
}
if(isset($_POST["comment"]))
{
if( strtolower($_POST['code'])!= strtolower($_SESSION['logcaptcha']) OR !isset($_SESSION["logcaptcha"]))
{
echo "<div class='error'>Неверно введён проверочный код!</div>";
include('footer.php');
exit;
}
unset($_SESSION["logcaptcha"]);
if(!isset($_SESSION["username"]))
{
echo "<div class='error'>Добавлять комментарии могут только зарегистрированные пользователи!</div>";
include('footer.php');
exit;
}

require_once('bbcode.php');
$comment = bbcod($_POST["comment"], true, true);

$date=time();
mysql_query("INSERT INTO afbcomments (idnew, date, user, text) VALUES ('$newid', '$date', '$username', '$comment')");
echo "<div class='good'>Ваш комментарий успешно добавлен </div>";
}
$res=mysql_query("select count(*) as kolvo from afbcomments where idnew='$newid'");
$res=mysql_fetch_assoc($res);
$allcomments=$res["kolvo"];

if($allcomments=='0')
{
	echo "<div class='wait'>Комментариев к данной новости нет!</div>";
}

$num = 10;
$upag = "news.php?id=".$newid."&amp;";
$page = (isset($_GET['n']))? intval($_GET['n']) : 1 ;
$numpag = $allcomments;$np =$numpag;
$obpag = intval(($np - 1) / $num) + 1;
if(empty($page) or $page < 0) $page = 1;
if($page > $obpag) $page = $obpag;
$nach = $page * $num - $num;

$result=mysql_query("SELECT * FROM afbcomments WHERE idnew='$newid'order by date ASC LIMIT $nach, $num");
include("navi.php");

if(!(isset($_SESSION["username"]) && isset($_SESSION["password"])))
{
echo "<div class='error'>Добавлять комментарии могут только зарегистрированные пользователи! </div>";
}else{ ?>
<script type="text/javascript" language="JavaScript">
function LoginClick() {
document.getElementById('logfrm').style.display = '';
document.getElementById('logbtn').style.display = 'none';
}
</script>
<form name="mailform" action="" id="logbtn" class="btnlogin" href="#login" >
<center><input type=submit class="ok_wm" onClick="javascript:LoginClick(); return false;" value="Оставить отзыв"></center>
</form>
</center>
<div id="logfrm" class="formlogin" style="display: none;">
<?
include("copilca/css.php");
include("form.php");
?>
</div>
<?
}

while ($rowe=mysql_fetch_assoc($result))
{
	$usernapisal=$rowe["user"];
	$sqlz=mysql_query("SELECT avatar,reyting FROM tb_users WHERE username='$usernapisal'");
        $res2=mysql_query("select user_status from tb_users where username='$usernapisal'");
        $res2=mysql_result($res2,0,0);
        if($res2=='user') { }
        if($res2=='admin') { $usernapisal='Администрация'; }
	$vivod=mysql_fetch_assoc($sqlz);
	$avabla=$vivod["avatar"];
        $rating=round($vivod["ball"],2);
	$yourcomment=$rowe["text"];
	$yourdata=$rowe["date"];
        $normdate=date("d.m.y H:i", $yourdata);


	echo "<table align='center' width='100%' border='0' cellpadding='0' cellspacing='0'  style=padding-top:1px;'>
          <thead style='background:#f5f5b5;'>
            <tr>
              <td colspan=4 align='left' style='color:red; font:11px Tahoma; border-bottom:solid 1px #F2C0A6; border-top:solid 1px #F2C0A6; padding:4px; padding-left:15px;'>".$usernapisal." ".$normdate." "; ?>

<? $username=text($_SESSION["username"]);
$whois=mysql_query("SELECT * FROM tb_users WHERE username='$username'");
$whois=mysql_fetch_assoc($whois);
if($whois["user_status"]=='admin')
{ ?>
<td align='right' style='color:red; font:12px Tahoma; border-bottom:solid 1px #F2C0A6; border-top:solid 1px #F2C0A6; '>
<form action="" method="POST">
<input type=hidden name="delete">
<input type=hidden name="id" value="<?=$rowe["id"];?>">
<input type="image" img src="images/delete.png" style="border:none;" alt="" title="Удалить"></form>
</td>
<?
} ?>
<? echo "
</td>
            </tr>
          </thead>";
echo "<td width='80px' valign='top' style='padding:5px;'>
<a href='avp/$avabla' onclick='return hs.expand(this)'>
<div align='center' style='background: url(../images/avbg.png) no-repeat; padding: 2px 0px 0px 0px; width: 78px; height:78px;'>
";?>
<a href='wall.php?user=<? echo $usernapisal; ?>'><? echo "<img src=avp/$avabla class='avatar' width='62px' height='62px' title='Перейти на стену пользователя'></a>
<div>
</a><b>

</td>"; ?>

<? echo "<td align='left' valign='top' colspan='3' style='padding:5px;font-size:11px;'>"; echo $yourcomment;
$username=text($_SESSION["username"]);
$whois=mysql_query("SELECT * FROM tb_users WHERE username='$username'");
$whois=mysql_fetch_assoc($whois);
if($whois["user_status"]=='admin')
{
?>
<td>
</td>
<?
}
echo "</td></table>";
}
}
include('footer.php'); ?>