<?

if ($ku['status']>'0'){
//======в чат вошел(а)
$chat=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_chat` WHERE `id` = '".intval($_GET['chat'])."' AND `type` = 'room'"));
if (isset($_GET['go'])){
if (isset($ku))
{
if ($ku['status']=='1')$adm='[color=#F5F5F5][u]Тех. поддержка[/u][/color]';
if ($ku['status']=='2')$adm='[color=Turquoise][u]Модератор[/u][/color]';
if ($ku['id']=='1'){if ($ku['status']=='3')$adm='[color=#11AA55]Г[/color][color=#44CCAA]л[/color][color=#775566].[/color] [color=#5588DD]А[/color][color=#4466DD]д[/color][color=#EE4444]м[/color][color=#00BB88]и[/color][color=#11BBDD]н[/color][color=#AACC55]и[/color][color=#EECCAA]с[/color][color=#DD2266]т[/color][color=#55AAEE]р[/color][color=#FF8811]а[/color][color=#FF3388]т[/color][color=#BB5566]о[/color][color=#999900]р[/color]';}
else
if ($ku['status']=='3')$adm='[color=#398DFA][u]Администратор[/u][/color]';
if ($ku['status']=='4')$adm='[color=#EE9A00][u]Модератор форума[/u][/color]';
if ($ku['status']=='5')$adm='[color=#B3EE3A][u]Модератор чата[/u][/color]';
if ($ku['pol']==1)
{
mysql_query("INSERT INTO `kolhoz_chat` (`id_user`,`time`,`mother`,`type`,`msg`)VALUES('300','".time()."','".$chat['id']."','komm','[color=#66FF00]В чат вошел[/color] [b]$adm [url=?user=".$ku['id']."]".$ku['nick']."[/url][/b]')");
}
if ($ku['pol']==0)
{
mysql_query("INSERT INTO `kolhoz_chat` (`id_user`,`time`,`mother`,`type`,`msg`)VALUES('300','".time()."','".$chat['id']."','komm','[color=#66FF00]В чат вошла[/color] [b]$adm [url=?user=".$ku['id']."]".$ku['nick']."[/url][/b]')");
}
header ("Location: ?chat=$chat[id]");
}
}
//====вошли в чат
}



if(intval($_GET['chat'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_chat` WHERE `id` = '".intval($_GET['chat'])."' AND `type` = 'room'".($ku['status']<=0?" AND `admod` = '0'":null).""),0)!=0)
{
$chat=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_chat` WHERE `id` = '".intval($_GET['chat'])."' AND `type` = 'room'"));
if(isset($_GET['edit']) && $ku['status']>0)
{
if($_GET['edit']=='ok')
{
$name=$_POST['name'];
$opis=$_POST['opis'];
if($name==NULL)
{
echo err_game("Слишком короткое название");
$err=1;
}
if(!isset($err))
{
if($_POST['admod']==1)$admod=1;else $admod=0;
mysql_query("UPDATE `kolhoz_chat` SET `name` = '".my_esc($name)."', `opis` = '".my_esc($opis)."', `admod` = '$admod' WHERE `id` = '$chat[id]'");
header("Location:?chat=$chat[id]");
exit;
}
}
echo '<div class="content"><div class="block">';
echo "<form action='?chat=$chat[id]&edit=ok' method='post'><ul><li><label><div>Название:</div><div><input type='text' class='wide' value='".hsc($chat['name'])."' name='name'></div></label></li><li><label><div>Описание:</div><div><textarea class='wide' rows='5' name='opis'>".hsc($chat['opis'])."</textarea></div></label></li>";
echo "<input type='checkbox' name='admod' value='1'".($chat['admod']==1?" checked='checked'":null)."> <span>Давать доступ только администрации</span><br/>";
echo "<li><input type='submit' value='Создать'></li></ul></form></div>";
include_once 'inc/foot.php';
}
elseif(isset($_GET['clean']) && $ku['status']>0)
{
if($_GET['clean']=='ok')
{
mysql_query("delete from `kolhoz_chat` where `mother` = '$chat[id]' and `type` = 'komm'");
header("Location:?chat=$chat[id]");
}
else echo '<div class="event"><h1>Подтверждение</h1></div><div class="content"><div class="block"><ul class="block"><li><span class="title">Вы уверены?</span></li><li class="pt"><img alt="" width="16" height="16" src="img/icons/tick.png"> <a href="?chat='.$chat['id'].'&clean=ok"><span>
Да, подтверждаю</span></a></li><li><img alt="" width="16" height="16" src="img/icons/cross.png"> <a href="?chat='.$chat['id'].'"><span>
Нет, отказываюсь</span></a></li></ul></div>';
include_once 'inc/foot.php';
}
elseif(isset($_GET['del_komm']) && intval($_GET['del_komm'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_chat` WHERE `id` = '".intval($_GET['del_komm'])."' AND `type` = 'komm'"),0)!=0 && $ku['status']>0)
{
mysql_query("delete from `kolhoz_chat` where `mother` = '$chat[id]' and `type` = 'komm' and `id` = '".intval($_GET['del_komm'])."'");
header("Location:?chat=$chat[id]");
}
elseif(isset($_GET['del']) && $ku['status']>0)
{
if($_GET['del']=='ok')
{
mysql_query("delete from `kolhoz_chat` where `mother` = '$chat[id]' and `type` = 'komm'");
mysql_query("delete from `kolhoz_chat` where `id` = '$chat[id]' and `type` = 'room'");
header("Location:?chat");
}
else echo '<div class="event"><h1>Подтверждение</h1></div><div class="content"><div class="block"><ul class="block"><li><span class="title">Вы уверены?</span></li><li class="pt"><img alt="" width="16" height="16" src="img/icons/tick.png"> <a href="?chat='.$chat['id'].'&del=ok"><span>
Да, подтверждаю</span></a></li><li><img alt="" width="16" height="16" src="img/icons/cross.png"> <a href="?chat='.$chat['id'].'"><span>
Нет, отказываюсь</span></a></li></ul></div>';
include_once 'inc/foot.php';
}
else
{
if(isset($_GET['otv']) && intval($_GET['otv'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_user` WHERE `id` = '".intval($_GET['otv'])."'"),0)!=0 && intval($_GET['otv'])!=$ku['id'])
{
$otv=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '".intval($_GET['otv'])."'"));
$otvu=$otv;
}
//вызов модеров
if(isset($_GET['call'])){
echo "<center><div class='block'>";
echo "Вы уверены что хотите вызвать модератора? За ложный вызов модератора Вы можете  получить бан!<br/>";
echo "<a href='?chat=$chat[id]&call&da'><img src='img/icons/tick.png' alt='' class='*'/> Да</a> | ";
echo "<a href='?chat=$chat[id]'><img src='img/icons/cross.png' alt='' class='*'/> Нет</a>";
echo "</div></center>";
echo "<div class='hr'></div>";
if(isset($_GET['da'])){

$filter =  "AND `status`>'0'";
$q=mysql_query("SELECT `id` FROM `kolhoz_user` WHERE `id` != $ku[id] $filter");
$msg = "Вас вызывает игрок [u]$ku[nick][/u] в комнату [b][url=?chat=$chat[id]]$chat[name][/url][/b]!";
while($post = mysql_fetch_array($q))
{
mysql_query("INSERT INTO `kolhoz_mail` (`id_user` , `id_kont` ,`msg` , `time` )VALUES ('$post[id]', '300', '$msg', '$time')");
//mysql_query("INSERT INTO `kolhoz_mail` (`id_user` , `id_kont` ,`msg` , `time` )VALUES ('$post[id]', '$ku[id]', '$msg', '$time')");
}
header("Location:?chat=$chat[id]");
}
}



echo "<div class='event'><h1>".hsc($chat['name'])."</h1></div>";
echo '<div class="content"><div class="block">';

if($ku['status']>0){echo "<div class='block'><b><a href='?chat=$chat[id]&del'><font color='violet'>Удалить</font></a></b> | <b><a href='?chat=$chat[id]&clean'><font color='violet'>Очистить</font></a></b> | <b><a href='?chat=$chat[id]&edit'><font color='violet'>Изменить</font></a></b></div>";}

echo "<div class='content'><div class='block'>";
echo "<a href='?chat=$chat[id]&".rand(1000,9999)."'>Обновить</a> | ";
echo " <a href='?admin_list&modCHAT'>Модераторы</a> | <a href='?chat'>Комнаты</a> | ";
echo "<img width='16' height='16' src='img/icons/rules.png' alt='o'> <a href='?chat=$chat[id]&call'>Вызвать модератора</a>";
echo '</div></div>';

echo '<div class="content"><div class="block">';

if (isset($_GET['go'])){if (isset($ku)){if ($ku['pol']==1){mysql_query("INSERT INTO `kolhoz_chat` (`id_user`, `time`, `msg`, `room`, `privat`) values('251', '$time', '*В чат вошел [url=/chat/room/$room[id]/".rand(1000,9999)."/$ku[id]/]$ku[nick][/url]', '$room[id]', '0')");
}if ($ku['pol']==0){mysql_query("INSERT INTO `kolhoz_chat` (`id_user`, `time`, `msg`, `room`, `privat`) values('251', '$time', '*В чат вошла [url=/chat/room/$room[id]/".rand(1000,9999)."/$ku[id]/]$ku[nick][/url]', '$room[id]', '0')");}
header ("Location: /?chat=$chat[id]");}else{mysql_query("INSERT INTO `kolhoz_chat` (`id_user`, `time`, `msg`, `room`, `privat`) values('251', '$time', '[b]Гость[/b] вошел в комнату [b]$room[name][/b]', '$room[id]', '0')");}}
if(isset($_GET['add']) && $_GET['add']=='ok' && !isset($molchi))
{
$msg=$_POST['msg'];
$color=mysql_real_escape_string($_POST['color']);
if($msg==NULL)
{
echo err_game("Слишком короткое сообщение");
$err=1;
}
if($ku['level']<=15)
{
$err=1;
err_game("Писать в чате можно после того как достигните 15-го уровня!");
}
if($ku['time']<=3600*1)
{
$err=1;
err_game("Писать в чате можно после того как проведете в игре <b>1 час</b>");
}


if($ku['almaz']<=1)
{
$err=1;
err_game("У вас не хватает баксов");
}


if(!isset($err))
{

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

if($ban['id'])
{
echo "<ul class='pt'>
<div>
<li class='major'><span>".($ban['izg']==1?'Изгнание':"Обет Молчания до ".vremja($ban['time']))."</span>, выдал".($us_ban['pol']==0?'a':null)." <span>";
echo on_k($us_ban['id']);
echo "<a href='?user=$us_ban[id]'>".nc($us_ban['id'])."</a></span><span>, (".output_text($ban['msg']).")</span></li></div></ul>";
}


//if(isset($_GET['kto'])){

//".$ank['url']."
echo "Сейчас в комнате <b>".hsc($chat['name'])."</b>:<br/>";

//$num = 0;
$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_user` WHERE `date_last` > '".(time()-100)."' AND `url` like '?chat=$chat[id]%'"), 0);
$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_user` WHERE `date_last` > '".(time()-100)."' AND `url` like '?chat=$chat[id]%' ORDER BY `date_last` DESC LIMIT $start, $set[p_str]");
if ($k_post==0){echo "Нет никого";}
while ($post = mysql_fetch_array($q))
{
echo "<a class='' href='?user=$post[id]'><span>".nc($post['id'])."</span></a></span>, ";
}
//}


echo "<div><form action='?chat=$chat[id]&yes&add=ok".(isset($otv)?"&otv=$otv[id]":null)."' method='post'>";
echo "<label>Сообщение".(isset($otv)?" для $otvu[nick]":null).": 
[<a href='?smiles'>Смайлы</a>]<br>";
echo "<textarea class='wide' rows='2' name='msg'></textarea></label>";
//if ($ku['status']>0){
echo "<br/>Цвет: ";
echo '<select name="color">
<option value="">Стандартный</option>
<option value="red" style="background-color: red; color: white;">Красный</option>
<option value="darkred" style="background-color: darkred; color: white;">Тёмно-красный</option>
<option value="maroon" style="background-color: maroon; color: white;">Тёмно-бордовый</option>
<option value="brown" style="background-color: brown; color: white;">Коричневый</option>
<option value="pink" style="background-color: pink; color: white;">Розовый</option>
<option value="green" style="background-color: green; color: white;">Зеленый</option>
<option value="lime" style="background-color: lime; color: white;">Лайм</option>
<option value="lightgreen" style="background-color: lightgreen; color: white;">Светло-зеленый</option>
<option value="olive" style="background-color: olive; color: white;">Оливковый</option>
<option value="#669999" style="background-color: #669999; color: white;">Морская волна</option>
<option value="aquamarine" style="background-color: aquamarine; color: white;">Аквамарин</option>
<option value="blue" style="background-color: blue; color: white;">Синий</option>
<option value="navy" style="background-color: navy; color: white;">Тёмно-синий</option>
<option value="deepskyblue" style="background-color: deepskyblue; color: white;">Небесно-голубой</option>
<option value="blueviolet" style="background-color: blueviolet; color: white;">Фиолетовый</option>
<option value="purple" style="background-color: purple; color: white;">Пурпурный</option>
<option value="indigo" style="background-color: indigo; color: white;">Индиго</option>
<option value="yellow" style="background-color: yellow; color: black;">Жёлтый</option>
<option value="orange" style="background-color: orange; color: black;">Оранжевый</option>
<option value="goldenrod" style="background-color: goldenrod; color: black;">Золотой</option>
<option value="gray" style="background-color: gray; color: black;">Темно-серый</option>
<option value="#CCCCCC" style="background-color: #CCCCCC; color: black;">Светло-серый</option>
<option value="silver" style="background-color: silver; color: black;">Серебряный</option>
<option value="black" style="background-color: black; color: white;">Чёрный</option>
</select>';
//}
echo "<br><input type='submit' value='Отправить'></form></div>";

//echo "<div><form action='?chat=$chat[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'>+1<img src='img/icons/baks.png' alt='*'/></font></form></div></div>";

$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_chat` WHERE `type` = 'komm' AND `mother` = '$chat[id]'"),0);
if ($k_post==0)
{
echo "Нет сообщений..";
}
$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_chat` WHERE `type` = 'komm' AND `mother` = '$chat[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;
}*/

//===Новое
$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)
{
$ot=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '$post[otvet]'"));
}
//===END


echo "<div class='block'>";

$ban = mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_ban` WHERE `id_user` = '$topclan_row[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 med($ank['id']);
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>".($ank['id']!=$ku['id']?"<a class='small minor' href='?chat=$chat[id]&otv=$ank[id]'>[ответить]</a>":null)."";
//echo "<br/><span class='minor small'> <span class='minor small'> <span>".vremja($post['time'])."</span></span></div><div class='title'><p>".(!empty($post['otvet'])?"".($ku['id']==$ot['id']?"<span class='rare'>":null)."$ot[nick]".($ku['id']==$ot['id']?"</span>":null).", ":null)."".output_text($post['msg'], $ank['id'])."</p></div><div>".($ank['id']!=$ku['id']?"<a class='small minor' href='?chat=$chat[id]&otv=$ank[id]&write'>[ответить]</a>":null)."";
//echo "<br/><span class='minor small'> ".vremja($post['time'])."</span><br/>".(!empty($post['otvet'])?"".($ku['id']==$ot['id']?"<span class='rare'>":null)."$ot[nick]".($ku['id']==$ot['id']?"</span>":null).", ":null)."".output_text($post['msg'], $ank['id'])."</br>".($ank['id']!=$ku['id']?"<a class='small minor' href='?chat=$chat[id]&otv=$ank[id]&write'>[ответить]</a>":null)."";
echo "<br/><span class='minor small'> ".vremja($post['time'])."</span><br/>".(!empty($post['otvet'])?"".($ku['id']==$ot['id']?"<span class='rare'>":null)."$ot[nick]".($ku['id']==$ot['id']?"</span>":null).", ":null)."";
if ($post['color'])echo "<span style='color:".$post['color']."'>".output_text($post['msg'])."</span>";
else
if ($post['color']==null)echo "<span style='color:".$post['color']."'>".output_text($post['msg'], $ank['id'])."</span>";

echo "</br>".($ank['id']!=$ku['id']?"<a class='small minor' href='?chat=$chat[id]&otv=$ank[id]&write'>[ответить]</a>":null)."";



}
//====
if($ku['status']>0)echo " <a class='small minor' href='?chat=$chat[id]&del_komm=$post[id]'>[удалить]</a>";
echo "</div>";
}
echo "</div>";

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

//echo '<div class="content"><div class="block"><ul>';
//echo "<div><img width='16' height='16' src='img/icons/smiles.png' alt='o'> <a href='?smiles'>Смайлы</a></div>";
//if($ku['status']>0){echo "<div class='block'><b><a href='?chat=$chat[id]&del'>Удалить</a> | <a href='?chat=$chat[id]&clean'>Очистить</a> | <a href='?chat=$chat[id]&edit'>Изменить</a></b></div>";}
//echo "<li><img width='16' height='16' src='img/icons/chat.png' alt='o'> <a href='?chat'>Чаты</a></li>";
//echo "</ul></div>";
include_once 'inc/foot.php';
}
}
else
{
if(isset($_GET['add']) && $ku['status']>0)
{
echo '<div class="event"><h1>Создание комнаты</h1></div>';
if($_GET['add']=='ok')
{
$name=$_POST['name'];
$opis=$_POST['opis'];
if($name==NULL)
{
echo err_game("Слишком короткое название");
$err=1;
}
if(!isset($err))
{
if($_POST['admod']==1)$admod=1;else $admod=0;
$pos=mysql_result(mysql_query("SELECT MAX(`pos`) FROM `kolhoz_chat` WHERE `type` = 'room'"), 0)+1;
mysql_query("INSERT INTO `kolhoz_chat` SET `name` = '".my_esc($name)."', `id_user` = '$ku[id]', `type` = 'room', `mother` = '0', `time` = '$time', `admod` = '$admod', `pos` = '$pos', `opis` = '".my_esc($opis)."'");
header("Location:?chat");
exit;
}
}
echo '<div class="content"><div class="block">';
echo "<form action='?chat&add=ok' method='post'><ul><li><label><div>Название:</div><div><input type='text' class='wide' value='' name='name'></div></label></li><li><label><div>Описание:</div><div><textarea class='wide' rows='5' name='opis'></textarea></div></label></li>";
echo "<input type='checkbox' name='admod' value='1'> <span>Давать доступ только администрации</span><br/>";
echo "<li><input type='submit' value='Создать'></li></ul></form></div>";
include_once 'inc/foot.php';
}
else
{
if (isset($_GET['up']) && $ku['status']>0)
{
$up=mysql_fetch_assoc(mysql_query("SELECT * FROM `kolhoz_chat` WHERE `id` = '".intval($_GET['up'])."' AND `type` = 'room' LIMIT 1"));
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_chat` WHERE `pos` < '$up[pos]' AND `type` = 'room' LIMIT 1"),0)!=0)
{
mysql_query("UPDATE `kolhoz_chat` SET `pos` = '".($up['pos'])."' WHERE `pos` = '".($up['pos']-1)."' AND `type` = 'room' LIMIT 1");
mysql_query("UPDATE `kolhoz_chat` SET `pos` = '".($up['pos']-1)."' WHERE `id` = '".intval($_GET['up'])."' AND `type` = 'room' LIMIT 1");
}
}
elseif (isset($_GET['down']) && $ku['status']>0)
{
$down=mysql_fetch_assoc(mysql_query("SELECT * FROM `kolhoz_chat` WHERE `id` = '".intval($_GET['down'])."' AND `type` = 'room' LIMIT 1"));
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_chat` WHERE `pos` > '$down[pos]' AND `type` = 'room' LIMIT 1"),0)!=0)
{
mysql_query("UPDATE `kolhoz_chat` SET `pos` = '".($down['pos'])."' WHERE `pos` = '".($down['pos']+1)."' AND `type` = 'room' LIMIT 1");
mysql_query("UPDATE `kolhoz_chat` SET `pos` = '".($down['pos']+1)."' WHERE `id` = '".intval($_GET['down'])."' AND `type` = 'room' LIMIT 1");
}
}
echo "<div class='event'><h1>Онлайн чат</h1></div>";
echo '<div class="content"><div class="block"><ul>';












echo 'Игроков не в комнатах: (<span style="color: tomato">'. mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_user` WHERE `date_last` > '".(time()-600)."' AND `url` like '?chat'"), 0).'</span> <font color="green">чел</font>)';


$q=mysql_query("SELECT * FROM `kolhoz_chat` WHERE `type` = 'room'".($ku['status']<=0?" AND `admod` = '0'":null)." ORDER BY `pos` ASC");
while($post=mysql_fetch_array($q))
{











echo "<div class='block'><img width='16' height='16' src='img/icons/chat.png' alt='o'> <a href='?chat=$post[id]&go'><span>".hsc($post['name'])."</span></a> ";

echo '(<font color="tomato">'. mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_user` WHERE `date_last` > '".(time()-600)."' AND `url` like '?chat=$post[id]%'"), 0).'</font>|';
echo '<font color="orange">'.mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_chat` WHERE `id` >= $post[id] AND `mother` = $post[id]"),0).'</font>)';





if(isset($_GET['moderate']) && $ku['status']>0)echo " <a href='?chat&moderate&up=$post[id]'><img width='16' height='16' src='img/icons/up.png' alt='o'></a> <a href='?chat&moderate&down=$post[id]'><img width='16' height='16' src='img/icons/down.png' alt='o'></a>";
echo "<br/>".(strlen2($post['opis'])!=NULL?"<div class='minor small'>".hsc($post['opis'])."</div>":null)."";
echo "</div>";
}

echo "<b>*</b> <font color='tomato'>Кол. игроков в комнате</font><br/>";
echo "<b>*</b> <font color='orange'>Кол. сообщений в комнате</font>";

echo "</ul></div>";
if($ku['status']>0)echo "<div class='content'><div class='block'><li><img width='16' height='16' src='img/icons/moderate.png' alt='o'> <a href='?chat".(!isset($_GET['moderate'])?"&moderate":null)."'>Управление</a></li><li><img width='16' height='16' src='img/icons/chat.png' alt='*' title='*'> <a href='?chat&add'>Создать комнату</a></li></ul></div>";
include_once 'inc/foot.php';
}
}

?>