<?Error_Reporting (E_ALL & ~E_NOTICE);
header('refresh: 180');
if($mc['id']==$ct['id'])
{
if(isset($_GET['leave_ct']))
{
if($mcu['status']==1)echo err_game("Председатель не может покинуть свой колхоз.");
else
{
if(isset($_GET['ok']))
{
mysql_querll("DELETE FROM `kolhoz_collective_rating_gos` WHERE `id_user` = '$ku[id]'");
mysql_querll("DELETE FROM `kolhoz_collective_rubies` WHERE `id_user` = '$ku[id]'");
mysql_querll("DELETE FROM `kolhoz_collective_user` WHERE `id_user` = '$ku[id]'");
mysql_querll("INSERT INTO `kolhoz_collective_history` SET `id_user` = '$ku[id]', `id_collective` = '$ct[id]', `time` = '$time', `type` = 'out', `dei` = 'user'");
mysql_querll("UPDATE `kolhoz_user` SET `time_shmel` = '0', `time_yastreb` = '0', `time_drakon` = '0' WHERE `id` = '$ku[id]'");
header("Location:?collective=$ct[id]");
exit;
}
else
{
echo podtv("?collective=$ct[id]&selsovet&leave_ct&ok","?collective=$ct[id]&selsovet");
include_once 'inc/foot.php';
}
}
}
}

if(isset($_GET['cleans']) && $mcu['status']==1)
{
if($_GET['cleans']=='ok')
{
mysql_query("delete from `kolhoz_collective_chat` where `id_collective` = '$ct[id]'");
header("Location:?collective=$ct[id]&selsovet");
}
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="?collective='.$ct['id'].'&selsovet&cleans=ok"><span>
Да, подтверждаю</span></a></li><li><img alt="" width="16" height="16" src="img/icons/cross.png"> <a href="?collective='.$ct['id'].'&selsovet"><span>
Нет, отказываюсь</span></a></li></ul></div>';
include_once 'inc/foot.php';
}

echo "<div class='event'><h1><a
href='?collective=$ct[id]'>".hsc($ct['name'])."</a> / Сельсовет</h1></div>
<div class='content'>
<div class='block'>";
if($mc['id']==$ct['id'])
{
if(isset($_GET['del_komm']) && intval($_GET['del_komm'])!=NULL && mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_collective_chat` WHERE `id` = '".intval($_GET['del_komm'])."' AND `id_collective` = '$ct[id]'"),0)!=0 && $mcu['status']<=3)
{
mysql_querll("delete from `kolhoz_collective_chat` where `id` = '".intval($_GET['del_komm'])."'");
}
if(isset($_GET['otv']) && intval($_GET['otv'])!=NULL && mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_collective_user` WHERE `id_user` = '".intval($_GET['otv'])."'"),0)!=0 && intval($_GET['otv'])!=$ku['id'])
{
$otv=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_user` WHERE `id` = '".intval($_GET['otv'])."'"));
$otvu=$otv;
}

echo "<div><img alt='' width='16' height='16' src='img/icons/refresh.png'> <a href='?collective=$ct[id]&selsovet&reflesh=".rand(99999,99999999)."'>Обновить</a>";
if ($mcu['status']==1)echo " | <img alt='' width='16' height='16' src='img/icons/cross.png'> <a href='?collective=$ct[id]&selsovet&cleans'>Очистить сельсоват</a></div>";
if(isset($_POST['msg']) && isset($_GET['add']) && $_GET['add']=='ok' && !isset($molchi))
{
$msg=$_POST['msg'];
if($msg==NULL)
{
echo err_game("Слишком короткое сообщение");
$err=1;
}
if(!isset($err))
{
mysql_querll("INSERT INTO `kolhoz_collective_chat` SET `msg` = '".my_esc($msg)."', `id_user` = '$ku[id]', `time` = '$time', `id_collective` = '$ct[id]'".(isset($otv)?", `otvet` = '$otv[id]'":null)."");
header("Location:?collective=$ct[id]&selsovet");
}
}

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>";
}
else echo "<div><form action='?collective=$ct[id]&selsovet=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_querll("SELECT COUNT(*) FROM `kolhoz_collective_chat` WHERE `id_collective` = '$ct[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_querll("SELECT * FROM `kolhoz_collective_chat` WHERE `id_collective` = '$ct[id]' ORDER BY `time` DESC LIMIT $start, 10");
while($post=mysql_fetch_array($q))
{
$ank=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_user` WHERE `id` = '$post[id_user]'"));
if($post['otvet']!=0 && mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_user` WHERE `id` = '$post[otvet]'"),0)!=0)
{
$otvet=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_user` WHERE `id` = '$post[otvet]'"));
$otvetu=$otvet;
}
echo "<li class='pt'><div><span>";
//======
$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 " ".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 "".($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></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='?collective=$ct[id]&selsovet&otv=$ank[id]&write'>[ответить]</a>":null)."";
}





if($mcu['status']<=3)echo " <a class='small minor' href='?collective=$ct[id]&selsovet&del_komm=$post[id]'>[удалить]</a>";
echo "</div></li>";
}
if ($k_page>1)str("?collective=$ct[id]&selsovet&",$k_page,$page); // Вывод страниц
echo "</ul>";




echo "<div><img width='16' height='16' src='img/icons/smiles.png' alt='o'> <a href='?smiles'>Смайлы</a></div>";
echo "<div><img width='16' height='16' src='img/icons/forum.png' alt='o'>
<a href='?collective=$ct[id]&club'>Дом культуры</a></div>";
}

if(isset($_GET['onl'])){
echo "<h3><a href='?collective=".$ct['id']."&selsovet'>Все участники</a> | <b>Онлайн</b></h3>";

$k_post = mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_collective_user` WHERE `id_collective` = '$ct[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'];
$num=($page-1)*$set['p_str'];
$q=mysql_querll("SELECT * FROM `kolhoz_collective_user` WHERE `id_collective` = '$ct[id]' ORDER BY `status` ASC LIMIT $start, 10");

echo "<ul>";
while($post=mysql_fetch_array($q))
{
$num++;
$uk=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_user` WHERE `id` = '$post[id_user]'"));
$uuk=$uk;
if($uuk['pol']==1)$post['status_name']='колхозник';else $post['status_name']='колхозница';
if($post['status']==1)$post['status_name']='председатель';
elseif($post['status']==2)$post['status_name']='зампред';
elseif($post['status']==3)$post['status_name']='агроном';
elseif($post['status']==4)$post['status_name']=($uuk['pol']==1?'бригадир':'хозяйка');
elseif($post['status']==5)$post['status_name']='староста';
elseif($post['status']==6)$post['status_name']=($uuk['pol']==1?'механизатор':'товаровёд');

if (mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_user` WHERE `id` = '$uk[id]' AND `date_last` > '".(time()-600)."' LIMIT 1"),0)==1){
echo "<div class='block'>";
echo on_k($uk['id']);
echo " <a class='' href='?user=$uk[id]'>".nc($uk['id'])."</a>";//вывод игроков
echo " ".med($uk['id'])."";
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_user` WHERE `id` = '$uk[id]' AND `date_last` > '".(time()-600)."' LIMIT 1"),0)==1)
echo " <img src='img/icons/online.gif' alt='' class='*'/>";
echo "<br/><span class='minor'><span>$post[status_name]</span>, <span>$uk[level]</span>, <span>$uk[tehnika]</span></span></div>";
}
}
if ($k_page>1)str("?collective=$ct[id]&selsovet&",$k_page,$page); // Вывод страниц

echo "<div class='small minor ptm'>Рядом с именем - должность, уровень, механизация.</div>
<ul class='ptm'>
<li><img width='16' height='16' src='img/icons/rating.png' alt='o'> <a href='?collective=".$ct['id']."&selsovet&rating'>Рейтинг</a></li>
<li><img width='16' height='16' src='img/icons/work_log.png' alt='o'> <a href='?collective=".$ct['id']."&selsovet&history'>История</a></li>";

if(isset($mc) && $ct['id']==$mc['id'])echo "<li><img width='16' height='16' src='img/icons/favorite.png' alt='o'> <a href='?collective=$ct[id]&selsovet&enlarge'>Расширить</a></li>";
if(isset($mc) && $mc['id']==$ct['id'] && $mcu['status']==1)echo "<li><img width='16' height='16' src='img/icons/rename.png' alt='o'> <a href='?collective=$ct[id]&selsovet&rename'>Переименовать</a></li>";

if($mc['id']==$ct['id'])
{
echo "<div class='pt'><img alt='o' width='16' height='16' src='img/icons/leave.png'> <a href='?collective=$ct[id]&selsovet&leave_ct'>Покинуть колхоз</a><br/></div>
<div class='pt'><span class='minor'>Внимание! Все бонусы вертолетов исчезнут при выходе из колхоза.</span></div>";
}
echo "</div>";
include_once 'inc/foot.php';
}

echo "<h3><b>Все участники</b> | <a href='?collective=".$ct['id']."&selsovet&onl'>Онлайн</a></h3>";

$k_post = mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_collective_user` WHERE `id_collective` = '$ct[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'];
$num=($page-1)*$set['p_str'];
$q=mysql_querll("SELECT * FROM `kolhoz_collective_user` WHERE `id_collective` = '$ct[id]' ORDER BY `status` ASC LIMIT $start, 10");

echo "<ul>";
while($post=mysql_fetch_array($q))
{
$num++;
$uk=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_user` WHERE `id` = '$post[id_user]'"));
$uuk=$uk;
if($uuk['pol']==1)$post['status_name']='колхозник';else $post['status_name']='колхозница';
if($post['status']==1)$post['status_name']='председатель';
elseif($post['status']==2)$post['status_name']='зампред';
elseif($post['status']==3)$post['status_name']='агроном';
elseif($post['status']==4)$post['status_name']=($uuk['pol']==1?'бригадир':'хозяйка');
elseif($post['status']==5)$post['status_name']='староста';
elseif($post['status']==6)$post['status_name']=($uuk['pol']==1?'механизатор':'товаровёд');

echo "<div class='block'>";
echo on_k($uk['id']);
echo " <a class='' href='?user=$uk[id]'>".nc($uk['id'])."</a>";//вывод игроков
echo " ".med($uk['id'])."";
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_user` WHERE `id` = '$uk[id]' AND `date_last` > '".(time()-600)."' LIMIT 1"),0)==1)
echo " <img src='img/icons/online.gif' alt='' class='*'/>";
echo "<br/><span class='minor'><span>$post[status_name]</span>, <span>$uk[level]</span>, <span>$uk[tehnika]</span></span></div>";
}
if ($k_page>1)str("?collective=$ct[id]&selsovet&",$k_page,$page); // Вывод страниц










?>


<div class='small minor ptm'>Рядом с именем - должность, уровень, механизация.</div>
<ul class='ptm'>
<li><img width='16' height='16' src='img/icons/rating.png' alt='o'> <a href='?collective=<? echo $ct['id'];?>&selsovet&rating'>Рейтинг</a></li>
<li><img width='16' height='16' src='img/icons/work_log.png' alt='o'> <a href='?collective=<? echo $ct['id'];?>&selsovet&history'>История</a></li>
<?
if(isset($mc) && $ct['id']==$mc['id'])echo "<li><img width='16' height='16' src='img/icons/favorite.png' alt='o'> <a href='?collective=$ct[id]&selsovet&enlarge'>Расширить</a></li>";
if(isset($mc) && $mc['id']==$ct['id'] && $mcu['status']==1)echo "<li><img width='16' height='16' src='img/icons/rename.png' alt='o'> <a href='?collective=$ct[id]&selsovet&rename'>Переименовать</a></li>";
?>
</ul>
<?
if($mc['id']==$ct['id'])
{
echo "<div class='pt'><img alt='o' width='16' height='16' src='img/icons/leave.png'> <a href='?collective=$ct[id]&selsovet&leave_ct'>Покинуть колхоз</a><br/></div>
<div class='pt'><span class='minor'>Внимание! Все бонусы вертолетов исчезнут при выходе из колхоза.</span></div>";
}
?>
</div>
<? include_once 'inc/foot.php';?>