<?
if(isset($_GET['complaintchat2']) && ($ku['time']>=7200) && intval($_GET['complaintchat2'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_chat` WHERE `id` = '".intval($_GET['complaintchat2'])."'"),0)!=0)
{

echo "<div class='event'><h1>Вы уверены?</h1></div><div class='content'><div class='block'><a href='/?chat&complaintchat2=$_GET[complaintchat2]&ok'>Да, подтверждаю</a><br><a href='/?chat'>Нет, отказываюсь</a></div>";
if(isset($_GET['ok']))
{
$msg=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_chat` WHERE `id` = '".intval($_GET['complaintchat2'])."' LIMIT 1"));
  $complaint=mysql_result(mysql_query("SELECT Count(*) FROM `complaint` WHERE `id_user` = $ku[id] AND `infringer` = '$msg[id_user]' AND `check` = '0'"), 0);
if($complaint<1)
{
  mysql_query("INSERT INTO `complaint` SET `id_user` = '$ku[id]', `infringer` = '$msg[id_user]', `time` = '$time', `check` = '0', `msg` = '$msg[msg]'");
  header("Location:/?chat");
      $_SESSION['msg']='Спасибо! Администрация получит уведомление и примет меры.';
}else
{
    header("Location:/?chat");
      $_SESSION['msg']='У вас уже есть необработанная жалоба на этого игрока.';  
}
}

}
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `chat_see` WHERE `id_chat` = '0' AND `id_user` = '$ku[id]'"), 0)==0)mysql_query("INSERT INTO `chat_see` SET `id_user` = '$ku[id]', `id_chat` = '0'");
if(intval($_GET['chat'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_chat` WHERE `id` = '".intval($_GET['chat'])."' AND `type` = 'room'".($ku['status']<=1?" 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(mysql_result(mysql_query("SELECT COUNT(*) FROM `chat_see` WHERE `id_chat` = '$chat[id]' AND `id_user` = '$ku[id]'"), 0)==0)mysql_query("INSERT INTO `chat_see` SET `id_user` = '$ku[id]', `id_chat` = '$chat[id]'");
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="images/icons/tick.png"> <a href="?chat='.$chat['id'].'&clean=ok"><span>
Да, подтверждаю</span></a></li><li><img alt="" width="16" height="16" src="images/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)
{
$komm=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_chat` WHERE `id` = '".intval($_GET['del_komm'])."'"));
mysql_query("update `kolhoz_user` set  `TournoumentChat` = `TournoumentChat` - '2', `chat` = `chat` - '2' WHERE `id` = '$komm[id_user]'");
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')
{
$text="Игрок $ku[nick] удалил чат";
mysql_query("INSERT INTO `kolhoz_mail` SET `id_user` = '1', `id_kont` = '$ku[id]', `msg` = '$text', `time` = '".time()."', `type` = 'to'") or die (mysql_error());
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="images/icons/tick.png"> <a href="?chat='.$chat['id'].'&del=ok"><span>
Да, подтверждаю</span></a></li><li><img alt="" width="16" height="16" src="images/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;
}
echo "<div class='event'><h1><a href='/chat-$chat[id]/".(rand(100000000,900000000))."'><img alt='*' width='16' height='16' src='images/icons/refresh.png'></a>  ".hsc($chat['name'])." <span class='txt-md'><img src='/images/icons/chat.png'> <a href='/?information&medal'>$ku[chat]</a></span></h1></div>";
echo '<div class="content"><div class="block"><ul>';
echo "<div><div><span class='minor'> 
<img alt='' width='16' height='16' src='images/icons/pencil.png'> <a href='/chat-$chat[id]".(!isset($_GET['write'])?"/write":null)."'>Написать</a> 
| <img width='16' height='16' src='/images/icons/chat.png' alt='*'> <a href='/chat'>Чаты</a>

| <img width='16' height='16' src='http://www.iconsearch.ru/uploads/icons/officeicons/24x24/internet_link_02.png' alt='*'> <a href='/teg'>Теги</a> 

</div></span>";
if(isset($_GET['add']) && $_GET['add']=='ok' && isset($_GET['write']) && !isset($molchi))
{
if($ku['status']>0 || $ku['level']>=100 || $ku['time_vip']>time())
{
$msg=($_POST['msg']);
}else
{
$msg=antispam($_POST['msg']);
}
if($msg==NULL)
{
echo err_game("Слишком короткое сообщение");
$err=1;
}

if($ku['level']<=4)
{
echo err_game("Писать можно с 5 уровня");
$err=1;
}

if($ku['time']<=3600){
$err=1;
err_game("Данная функция доступна только после часа проведенного в игре");
}
if(!isset($err))
{
    $wowrandom=rand(0,10);
if($wowrandom>=8)
{
    $wow=rand(1,4);
    if($wow==1)
    {
        $text='золотой ваучер';
        $msql='gold';
    }
    if($wow==2)
        {
            $text='зеленый ваучер';
            $msql='green';
        }
    if($wow==3)
    {
        $text='синий ваучер';
        $msql='blue';
    }
    if($wow==4)
    {
        $text='фиолетовый ваучер';
        $msql='pink';
}
    mysql_query("UPDATE  `kolhoz_user` SET `$msql` = `$msql` + '1'  WHERE `id` = '$ku[id]'");
$_SESSION['msg']='Вы нашли: [color=yellow][img]/pavelgrey/img/talents/small/'.$msql.'.png[/img] '.$text.'[/color]';
}
   /*
    if($ku['post25']>=25)
    {
    mysql_query("UPDATE  `ivent_6farm` SET `cupon` =`cupon` + '2'  WHERE `id_user` = '$ku[id]'");

    mysql_query("UPDATE  `kolhoz_user` SET `post25` = '0'  WHERE `id` = '$ku[id]'");
$_SESSION['msg']='Вы нашли: [color=yellow]Купоны (2 шт.)[/color]';
}
*/
    if($ku['expbonus']<=50)
    {
$exprandom=rand(0,50);
if($exprandom>=47)
{
    $exp1=rand(1,3);
    mysql_query("UPDATE  `kolhoz_user` SET `expbonus` = `expbonus` + '$exp1'  WHERE `id` = '$ku[id]'");
$_SESSION['msg']='Вы нашли: [color=yellow][img]/images/icons/experience.png[/img] Бонус к опыту ('.$exp1.'%)[/color]';
}
}
    if($ku['expbonus']>50)
    {
$exprandom=rand(0,100);
if($exprandom>=95)
{
    $exp1=rand(1,3);
    mysql_query("UPDATE  `kolhoz_user` SET `expbonus` = `expbonus` + '$exp1'  WHERE `id` = '$ku[id]'");
$_SESSION['msg']='Вы нашли: [color=yellow][img]/images/icons/experience.png[/img] Бонус к опыту ('.$exp1.'%)[/color]';
}
}
/*
   if($ku['storona']==1)mysql_query("UPDATE `megabattle` SET `pauk_chat` = `pauk_chat` + '1' WHERE `id`='1'");
 if($ku['storona']==2)mysql_query("UPDATE `megabattle` SET `scorpion_chat` = `scorpion_chat` + '1' WHERE `id`='1'");    
        */
mysql_query("INSERT INTO `kolhoz_chat` SET `msg` = '".my_esc($msg)."', `id_user` = '$ku[id]', `type` = 'komm', `mother` = '$chat[id]', `time` = '$time'".(isset($otv)?", `otvet` = '$otv[id]'":null)."");
mysql_query("DELETE FROM `chat_see` WHERE `id_chat` = '$chat[id]'");
mysql_query("DELETE FROM `chat_see` WHERE `id_chat` = '0'");
mysql_query("UPDATE  `kolhoz_user` SET  `TournoumentChat` = `TournoumentChat` + '1', `chat_post` = `chat_post` + '1', `chat` = `chat` + '1'  WHERE `id` = '$ku[id]'");
header("Location:?chat=$chat[id]");
exit;
}
}
if(isset($_GET['write']))
{
if(!$ban['id']){$ban=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_ban` WHERE `id_user` = '$ku[id]' AND `time` > '$time' AND `izg` = '2' ORDER BY `id` DESC LIMIT 1"));
$us_ban=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '$ban[id_who]'"));
}
if($ban['id'])
{
echo "<ul class='pt'>
<div>
<li class='major'><span>".($ban['izg']==2?"Бан в чате до ".vremja($ban['time'])."":"Обет Молчания до ".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>";
}

elseif(isset($_GET['write']))echo "<div><form action='?chat=$chat[id]&write=yes&add=ok".(isset($otv)?"&otv=$otv[id]":null)."' method='post'><label><li class='pavelgrey'>Сообщение".(isset($otv)?" для $otvu[nick]":null).":<br><textarea class='wide' rows='2' name='msg'></textarea></label><br><input type='submit' value='Отправить'></form></div>";}

/*else echo "<div><form action='?chat=$chat[id]&write=yes&add=ok".(isset($otv)?"&otv=$otv[id]":null)."' method='post'><label>Сообщение".(isset($otv)?" для $otvu[nick]":null).":<br><textarea class='wide' rows='2' name='msg'></textarea></label><br><input type='submit' value='Отправить'></form></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 "пустo...";
}
$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;
}
echo "<li class='pt'><div><span>";
echo on_k($ank['id']);
echo " <span>".nc($ank['id'])."</span></span> <span class='minor small'> <span>
".($time-$post['time']<=2592000?"".time_left($time-$post['time'])."</span> назад</span>":"
".vremja($post['time'])."</span>")."
</div><div class='title'><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></div><div>".($ank['id']!=$ku['id']?"<a class='small minor' href='/chat-$chat[id]/otv-$ank[id]/write'>[ответить]</a> <a class='small minor' href='?chat=$chat[id]&complaintchat2=$post[id]'>[жалоба]</a>":null)."";
if($ku['status']>0)echo " <a class='small minor' href='?chat=$chat[id]&del_komm=$post[id]'>[x]</a> ";
echo "</div></li>";
unset($otvet);
}
if ($k_page>1){echo'<ul class="pt"></ul>'; new_str("chat-$chat[id]/",$k_page,$page);} // Вывод страниц
echo "</ul>";
echo "<ul class='pt'>";
echo "<li></li>";

if($ku['status']>2)echo "<li><img alt='*' width='16' height='16' src='images/icons/delete.png'> <a href='/chat-$chat[id]/del'>Удалить</a></li>";
if($ku['status']>0)echo "<li><img alt='*' width='16' height='16' src='images/icons/delete.png'> <a href='/chat-$chat[id]/clean'>Очистить комнату</a></li>";
echo"<img width='16' height='16' src='images/icons/smiles.png' alt='*'> <a href='/smiles'>Смайлы</a></div>";

echo "</ul></div>";
include_once 'inc/foot.php';
}
}
else
{
if(isset($_GET['add']) && $ku['status']>2)
{
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>';
$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 "<li><div><img width='16' height='16' src='images/icons/chat.png' alt='*'> <a href='/chat-$post[id]'><span>".hsc($post['name'])."</span></a></div>".(strlen2($post['opis'])!=NULL?"<div class='minor small'>".hsc($post['opis'])."</div>":null)."";
if(isset($_GET['moderate']) && $ku['status']>0)echo "<a href='/chat/moderate/up-$post[id]'><img width='16' height='16' src='images/icons/up.png' alt='*'></a> <a href='/chat/moderate/down-$post[id]'><img width='16' height='16' src='images/icons/down.png' alt='*'></a>";
echo "</li>";
}
echo "</ul>";
echo "<ul class='pt'>";
if($ku['status']>0)echo "<li><img width='16' height='16' src='images/icons/moderate.png' alt='*'> <a href='/chat".(!isset($_GET['moderate'])?"/moderate":null)."'>Управление</a></li><li><img width='16' height='16' src='images/icons/chat.png' alt='*' title='*'> <a href='/chat/add'>Создать комнату</a></li>";
echo "</ul></div>";
include_once 'inc/foot.php';
}
}
?>