<?

$row=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_news` WHERE `id` = ".intval($_GET['id'])." LIMIT 1"));
if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id']!=NULL)
{
echo "<div class='event'><h1><a href='?news'>Новости</a>/".$row['name']."</h1></div>";
echo "<div class='content'>";
echo "<div class='block'>";
echo "<b>Название:</b> <font color='violet'>".$row['name']."</font><br/>";
echo '<b>Полное описание:</b><br/>'.output_text($row['opis'], $row['id_user']).'</br>';



if($row['ssylka']!=NULL)echo "<b>Ссылка:</b> <a href='http://$row[ssylka]'>Перейти</a><br>";
if($row['dostup']==1)$dostup='Всем';else $dostup='Администрации';
if($ku['status']>0)echo "<b>Кому:</b> $dostup<br>";
echo "<b>Добавил:</b> ";
echo '<b>'.on_k($row['id_user']).' <a href="?user='.$row[id_user].'">'.nc($row['id_user']).'</a></b>';
echo " ".med($row['id_user'])."";
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_user` WHERE `id` = '$row[id_user]' AND `date_last` > '".(time()-600)."' LIMIT 1"),0)==1)
echo " <img src='img/icons/online.gif' alt='' class='*'/> ";
echo "</div>";

if(isset($_GET['del_komm']) && intval($_GET['del_komm'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_kom` WHERE `id` = '".intval($_GET['del_komm'])."' AND `type` = 'komm'"),0)!=0 && $ku['status']>0)
{
mysql_query("delete from `kolhoz_kom` where `mother` = '$row[id]' and `type` = 'komm' and `id` = '".intval($_GET['del_komm'])."'");
header("Location:?news&id=$row[id]");
}
elseif(isset($_GET['del']) && $ku['status']>0)
{
if($_GET['del']=='ok')
{
mysql_query("delete from `kolhoz_kom` where `mother` = '$row[id]' and `type` = 'komm'");
mysql_query("delete from `kolhoz_kom` where `id` = '$row[id]' and `type` = 'room'");
header("Location:?news&id=$row[id]");
}
include_once 'inc/foot.php';
}




if(isset($_GET['add']) && $_GET['add']=='ok' && !isset($molchi))
{
$msg=$_POST['msg'];
if($msg==NULL)
{
echo err_game("Слишком короткое сообщение");
$err=1;
}
if($ku['level']<=1)
{
$err=1;
err_game("Комментировать новости можно после того как достигните 15-го уровня!");
}
if($ku['time']<=3600*1)
{
$err=1;
err_game("Комментировать новости можно после того как проведете в игре <b>1 час</b>");
}




if(!isset($err))
{

mysql_query("UPDATE `kolhoz_user` SET `almaz` = '".($ku['almaz']+10)."' WHERE `id` = '$ku[id]' LIMIT 1");
mysql_query("INSERT INTO `kolhoz_kom` SET `msg` = '".my_esc($msg)."', `id_user` = '$ku[id]', `type` = 'komm', `mother` = '$row[id]', `time` = '$time'".(isset($otv)?", `otvet` = '$otv[id]'":null)."");
header("Location:?news&id=$row[id]&yes");
exit;
}
}



echo "<div class='block'><form action='?news&id=$row[id]&yes&add=ok".(isset($otv)?"&otv=$otv[id]":null)."' method='post'><label>Комментарий".(isset($otv)?" для $otvu[nick]":null).": [<a href='?smiles'>Смайлы</a>]<br><textarea class='wide' rows='2' name='msg'></textarea></label><br><input type='submit' value='Отправить'> <font color='#33FFCC'>+ <img src='img/icons/baks.png' alt='*'/>10</font></form></div>";

$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_kom` WHERE `type` = 'komm' AND `mother` = '$row[id]'"),0);
if ($k_post==0)
{
echo "<div class='block'>Нет сообщений..</div>";
}
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
$q=mysql_query("SELECT * FROM `kolhoz_kom` WHERE `type` = 'komm' AND `mother` = '$row[id]' ORDER BY `time` DESC LIMIT $start, $set[p_str]");
while($post=mysql_fetch_array($q))
{
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '$post[id_user]'"));
if($post['otvet']!=0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_user` WHERE `id` = '$post[otvet]'"),0)!=0)
{
$otvet=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '$post[otvet]'"));
$otvetu=$otvet;
}
echo "<div class='block'>";



$ban = mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_ban` WHERE `id_user` = '$ank[id]' AND (`time` > '$time' OR `izg` = '1') ORDER BY `id` DESC LIMIT 1"));
$us_ban = mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_user` WHERE `id` = '$ban[id_who]'"));

if($ban['id']){
echo on_k($ank['id']);
echo " <a class='' href='?user=$ank[id]'><span>".nc($ank['id'])."</span></a></span>";
echo "".($ban['izg']==1?'<br/><font color="tomato">Сообщение заблокировано</font>':"<br/><font color='tomato'>Сообщение заблокировано до:</font> <b>".vremja($ban['time']))."</b><br/>";
}
else
if($ank['id']){
echo on_k($ank['id']);
echo " <a class='' href='?user=$ank[id]'><span>".nc($ank['id'])."</span></a></span>";
echo " ".med($ank['id'])."";
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_user` WHERE `id` = '$ank[id]' AND `date_last` > '".(time()-600)."' LIMIT 1"),0)==1)
echo " <img src='img/icons/online.gif' alt='' class='*'/> ";
echo "<br/><span class='minor small'> <span>".vremja($post['time'])."</span></span><p>".(isset($otvet)?"".($ku['id']==$otvet['id']?"<span class='rare'>":null)."$otvetu[nick]".($ku['id']==$otvet['id']?"</span>":null).", ":null)."".output_text($post['msg'], $ank['id'])."</p>";
}
//====


//====================
if($ku['status']>0)echo "<div style='text-align:right;'>[<a href='?news&id=$row[id]&del_komm=$post[id]'><font color='violet'>удалить</font></a>]</div>";
echo "</div>";
}

if ($k_page>1)str("?news&id=$row[id]&",$k_page,$page); // Вывод страниц













include_once 'inc/foot.php';
echo "</div></div>";
}

echo "<div class='event'><h1>Новости</h1></div>";
$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_news`"),0);

if ($k_post==0)
{
echo "<div class='block'>Нет новостей..</div>";
}

$x=mysql_querll("SELECT * FROM `kolhoz_news` ORDER BY `id` DESC");
while($row=mysql_fetch_assoc($x)){
if(isset($_GET['read_news']))
{
mysql_querll("UPDATE `kolhoz_user` SET `read_news` = '1' WHERE `id` = '$ku[id]'");
}



echo "<div class='block'><img src='img/icons/news.png' alt='' class='*'/> ";


echo "<a href='?news&id=$row[id]'>$row[name]</a><br/>";
if ($row['opis']!=NULL){$string = htmlspecialchars(mb_substr($row['opis'],0,50,'utf-8')); echo'<span class="small minor">'.$string.'..</span><br/>';}

echo "Добавил: ";
echo '<b>'.on_k($row['id_user']).' <a href="?user='.$row[id_user].'">'.nc($row['id_user']).'</a></b>';
echo " ".med($row['id_user'])."</div>";
}
include_once 'inc/foot.php';
?>