<?
require '../sys/inc/start.php';
require '../sys/inc/compress.php';
require '../sys/inc/sess.php';
require '../sys/inc/home.php';
require '../sys/inc/settings.php';
require '../sys/inc/db_connect.php';
require '../sys/inc/ipua.php';
require '../sys/inc/fnc.php';
require '../sys/inc/user.php';

if(isset($_GET['s']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `soo` WHERE `id` = '".intval($_GET['s'])."' LIMIT 1"),0)==1)
{
$s=intval($_GET['s']);
$soo=mysql_fetch_assoc(mysql_query("SELECT * FROM `soo` WHERE `id` = '$s' LIMIT 1"));
if (isset($_GET['block'])&&$user['group_access']>8){
if ($soo['block']=='yes')mysql_query("update `soo` set `block`='no' where `id`='$s';");
else mysql_query("update `soo` set `block`='yes', `who_block`='$user[nick]' where `id`='$s';");
$soo=mysql_fetch_assoc(mysql_query("SELECT * FROM `soo` WHERE `id` = '$s' LIMIT 1"));
}
require 'inc/ban.php';
if(isset($_GET['rules']))
{
$set['title']=$soo['name'].' - Правила сообщества'; // заголовок страницы
require '../sys/inc/thead.php';
title();
if ($soo['block']=='yes'){
echo '<div class="err">Сообщество было заблокировано администратором '.$soo['who_block'].'</div>';
echo "<div class='navi'>\n";
echo'<img src="img/back.png" alt=""/> <a href="/soo/">Сообщества</a>/<a href="/soo/?r='.$soo['id_cat'].'">'.mysql_result(mysql_query("SELECT `name` FROM `soo_cat` WHERE `id` = '$soo[id_cat]' LIMIT 1"),0).'</a><br />';
if ($user['group_access']>8)echo '&raquo; <a href="./?s='.$soo['id'].'&amp;block">Разблокировать</a><br />';
echo "</div>\n";
require '../sys/inc/tfootphp';
exit;
}
echo'<div class="menu">', output_text($soo['rules']),'</div>';
echo "<div class='navi'>\n";
echo '<img src="img/back.png" alt="" class="icon"/> <a href="?s='.$soo['id'].'">В сообщество</a><br/>';
echo "</div>\n";
}else{
$set['title']=$soo['name'];
require '../sys/inc/thead.php';
title();
if ($soo['block']=='yes'){
echo '<div class="err">Сообщество было заблокировано администратором '.$soo['who_block'].'</div>';
echo "<div class='navi'>\n";
echo'<img src="img/back.png" alt=""/> <a href="/soo/">Сообщества</a>/<a href="/soo/?r='.$soo['id_cat'].'">'.mysql_result(mysql_query("SELECT `name` FROM `soo_cat` WHERE `id` = '$soo[id_cat]' LIMIT 1"),0).'</a><br />';
if ($user['group_access']>8)echo '&raquo; <a href="./?s='.$soo['id'].'&amp;block">Разблокировать</a><br />';
echo "</div>\n";
require '../sys/inc/tfoot.php';
exit;
}
require 'inc/user_act.php';
################################################################################
echo "<div class='fyt'>\n";
echo "<input type='text' value='http://$_SERVER[SERVER_NAME]/soo/$soo[id]'><br />\n";
echo "</div>\n";
################################################################################
if(!isset($user) || isset($user) && mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_users` WHERE `id_user` = '$user[id]' AND `id_soo`='$soo[id]' AND `activate`='0' AND `invit`='0' LIMIT 1"),0)==0 && $user['id']!=$soo['admid'])
{
echo "<div class='fyt'>\n";
if($soo['konf_soo']==0 || $soo['konf_soo']==1)echo'<img src="img/open.png" alt=""/> Открыто для вступления'; elseif($soo['konf_soo']==2)echo'<img src="img/money.png" alt=""/> Вступление платное'; elseif($soo['konf_soo']==3)echo'<img src="img/close.png" alt=""/> Закрыто для вступления';
if($soo['konf_soo']==0)echo'<br/><img src="img/open.png" alt=""/> Открыто для чтения'; else echo'<br/><img src="img/close.png" alt=""/> Закрыто для чтения';
echo "</div>\n";
}
################################################################################
echo'<table class="post">';
echo '<tr>';
echo'<td class="icon_enk" rowspan="2">';
if (is_file(H."soo/logo/$soo[id].gif"))
echo '<img src="logo/'.$soo['id'].'.gif" alt="" />';
elseif (is_file(H."soo/logo/$soo[id].jpg"))
echo '<img src="logo/'.$soo['id'].'.jpg" alt="" />';
elseif (is_file(H."soo/logo/$soo[id].png"))
echo '<img src="logo/'.$soo['id'].'.png" alt="" />';
else
echo '<img src="/sys/avatar/0.png" alt="" />';
echo'</td>';
echo '<td class="p_enk">';
echo "<u>$soo[name]</u> (".vremja($soo['time']).")<br />\n";

echo "".output_text($soo['desc'])."";
echo'</td>';
echo'</tr>';
echo'</table>';
################################################################################
$count_news = mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_news` WHERE `id_soo` = '$soo[id]'"),0);
$count_chat = mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_chat` WHERE `id_soo` = '$soo[id]'"),0);
echo mysql_error();
$count_votes_open = mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_votes` WHERE `id_soo` = '$soo[id]' AND `time_close`>'$time'"),0);
$count_votes_all = mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_votes` WHERE `id_soo` = '$soo[id]'"),0);
$count_users = $soo['users']+1;
$count_banned = mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_users` WHERE `id_soo` = '$soo[id]' AND `activate`='0' AND `invit`='0' AND `ban`>'$time'"),0);
$count_friends = mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_friends` WHERE `id_soo` = '$soo[id]'"),0);
echo '<div class="fyt"><center>Меню сообщества</center></div>';
################################################################################
if($soo['rules']!=NULL)
echo "<a href='index.php?s=$soo[id]&rules'><div class='enk2_div'><img src='img/rules.png'> Правила сообщества</div></a>\n";
echo "<a href='news.php?s=$soo[id]'><div class='enk_div'><img src='img/rss.png'> Новости ($count_news)</div></a>";
echo "<a href='chat.php?s=$soo[id]'><div class='enk2_div'><img src='img/chat.png'> Мини-чат ($count_chat)</div></a>\n";
echo "<a href='votes.php?s=$soo[id]'><div class='enk_div'><img src='img/votes.png'> Опросы ($count_votes_open/$count_votes_all)</div></a>\n";
echo "<a href='users.php?s=$soo[id]'><div class='enk2_div'><img src='img/users.png'> Участники ($count_users)</div></a>\n";
echo "<a href='banned.php?s=$soo[id]'><div class='enk_div'><img src='img/banned.png'> Забаненные ($count_banned)</div></a>\n";
echo "<a href='friends.php?s=$soo[id]'><div class='enk2_div'><img src='img/cat.png'> Друзья соо ($count_friends)</div></a>\n";
################################################################################
if(isset($user))
{


if($user['id']==$soo['admid'])echo "<a href='admin.php?s=$soo[id]'><div class='enk_div'><img src='img/admin.png'> Управление</div></a>\n";
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_users` WHERE `id_soo` = '$soo[id]' AND `id_user`='$user[id]' LIMIT 1"),0)==0 && $user['id']!=$soo['admid'])
{
if($soo['konf_soo']==0 || $soo['konf_soo']==1 || $soo['konf_soo']==3)
{
echo "<a href='index.php?s=$soo[id]&amp;enter'><div class='enk2_div'><img src='img/open.png'> Вступить в соо</div></a>\n";
}
elseif($soo['konf_soo']==2 && $user['balls']>=$soo['plata'])
{
echo "<a href='index.php?s=$soo[id]&amp;enter'><div class='enk2_div'><img src='img/open.png'> Вступить в соо (<b>$soo[plata] баллов</b>)</div></a>\n";
}
elseif($soo['konf_soo']==2 && $user['balls']<$soo['plata'])
{
echo "<div class='enk2_div'><img src='img/close.png'> Для вступления необходимо <b>$soo[plata]</b> баллов</div>";
}
}
elseif(mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_users` WHERE `id_soo` = '$soo[id]' AND `id_user`='$user[id]' AND `invit`='1' LIMIT 1"),0)==1)
{
echo "<div class='fyt'>";
echo'<img src="img/open.png" alt=""/> <a href="index.php?s='.$soo['id'].'&yes">Принять приглавшение</a><br />';
echo'<img src="img/close.png" alt=""/> <a href="index.php?s='.$soo['id'].'&no">Отклонить приглашение</a><br />';
echo "</div>";
}
elseif(mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_users` WHERE `id_soo` = '$soo[id]' AND `id_user`='$user[id]' AND `invit`='0' AND `activate`='0' LIMIT 1"),0)==1 || $user['id']==$soo['admid'])
{
echo "<div class='fyt'>";
echo'<img src="img/invite.png" alt=""/> <a href="users.php?s='.$soo['id'].'&invite">Пригласить в соо</a><br/>';
if($user['id']!=$soo['admid'])echo'<img src="img/close.png" alt=""/> <a href="index.php?s='.$soo['id'].'&exit">Покинуть соо</a><br/>';
echo "</div>";
}
}
echo "</div>\n";
echo "<div class='fyt'>\n";
echo'<img src="img/back.png" alt=""/> <a href="/soo/">Сообщества</a>/<a href="/soo/?r='.$soo['id_cat'].'">'.mysql_result(mysql_query("SELECT `name` FROM `soo_cat` WHERE `id` = '$soo[id_cat]' LIMIT 1"),0).'</a><br/>';
echo "</div>\n";
}
echo "</div>\n";
}
elseif(isset($_GET['r']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_cat` WHERE `id` = '".intval($_GET['r'])."' LIMIT 1"),0)==1)
{
$r=intval($_GET['r']);
$razdel=mysql_fetch_assoc(mysql_query("SELECT * FROM `soo_cat` WHERE `id` = '$r' LIMIT 1"));

if(isset($_GET['new']) && isset($user))
{
$set['title']='Сообщества - '.$razdel['name'].' - Новое сообщество'; // заголовок страницы
require '../sys/inc/thead.php';
title();
$limit = 3;
$time_create = 60*60*24*30;
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `soo` WHERE `admid` = '$user[id]' LIMIT 1"),0)>=$limit && $user['level']<3)
{
echo'<div class="err">Максимальное количество сообществ на одного человека <b>'.$limit.'</b>, у Вас уже столько имеется</div>';
}
elseif(mysql_result(mysql_query("SELECT COUNT(*) FROM `soo` WHERE `admid` = '$user[id]' LIMIT 1"),0)!=0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `soo` WHERE `admid` = '$user[id]' LIMIT 1"),0)<$limit && $user['level']<3)
{
$last_soo = mysql_fetch_assoc(mysql_query("SELECT * FROM `soo` WHERE `admid` = '$user[id]' ORDER BY `time` DESC LIMIT 1"));
$time_new = $last_soo['time']+$time_create;
if($time<$time_new)
{
echo'<div class="err">Нельзя так часто создавать сообщества. Следующая возможность у Вас будет '.vremja($time_new).'</div>';
}else{
require 'inc/new_act.php';
require 'inc/new_form.php';
}
}
elseif(mysql_result(mysql_query("SELECT COUNT(*) FROM `soo` WHERE `admid` = '$user[id]' LIMIT 1"),0)==0 || $user['level']>=3)
{
require 'inc/new_act.php';
require 'inc/new_form.php';
}
err();
echo "<div class='fyt'>\n";
echo'<img src="img/back.png" alt=""/> <a href="/soo/">Сообщества</a>/<a href="/soo/?r='.$r.'">'.mysql_result(mysql_query("SELECT `name` FROM `soo_cat` WHERE `id` = '$r' LIMIT 1"),0).'</a><br/>';
echo "</div>\n";
}else{
$set['title']='Сообщества - '.$razdel['name'];
require '../sys/inc/thead.php';
title();
if(isset($_GET['sort']))
{
if($_GET['sort']=='users'){$sort='users'; $por='DESC';}
elseif($_GET['sort']=='open'){$sort='konf_soo'; $por='ASC';}
else{$sort='time'; $por='DESC';}
}
else
{
$sort='time'; $por='DESC';
}
################################################################################
if(isset($user) && $user['level']>3 && isset($_GET['del']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `soo` WHERE `id` = '".intval($_GET['del'])."' LIMIT 1"),0)==1)
{
$delid=intval($_GET['del']);
$del=mysql_fetch_assoc(mysql_query("SELECT * FROM `soo` WHERE `id` = '$delid' LIMIT 1"));
$deladm=get_user($del['admid']);
if($user['id']!=$deladm['id'] && $user['level']>$deladm['level'] || $user['id']==$deladm['id'])
{
if(isset($_GET['ok']))
{
mysql_query("DELETE FROM `soo_users` WHERE `id_soo`='$delid'");
mysql_query("DELETE FROM `soo_chat` WHERE `id_soo`='$delid'");
mysql_query("DELETE FROM `soo_news` WHERE `id_soo`='$delid'");
mysql_query("DELETE FROM `soo_bl` WHERE `id_soo`='$delid'");
mysql_query("DELETE FROM `soo_friends` WHERE `id_soo`='$delid'");
mysql_query("DELETE FROM `soo_friends` WHERE `id_friend`='$delid'");
mysql_query("DELETE FROM `soo_votes` WHERE `id_soo`='$delid'");
mysql_query("DELETE FROM `soo_votes_otvet` WHERE `id_soo`='$delid'");
mysql_query("DELETE FROM `soo` WHERE `id`='$delid'");
while ($delete = mysql_fetch_assoc($q))
{
unlink(H.'sys/soo/obmen/files/'.$delete['id'].'.dat');
}
mysql_query("DELETE FROM `soo_obmen_files` WHERE `id_soo`='$delid'");
mysql_query("DELETE FROM `soo_obmen_komm` WHERE `id_soo`='$delid'");
msg('Сообщество успешно удалено');
}else{
echo'<div class="err">Вы уверены, что хотите удалить данное сообщество?<br/>';
echo "[<a href='?r=$r&del=$delid&ok'>Да</a>] | [<a href='?r=$r'>Нет</a>]</div>\n";
}
}
}
################################################################################
$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `soo` WHERE `id_cat`='$r'"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];

echo "<div class='fyt'>\n";
echo "Сортировать:<br />\n";
echo '<a href="?r='.$r.'&sort=users&page='.$page.'">Популярные</a> | <a href="?r='.$r.'&sort=time&page='.$page.'">Новые</a> | <a href="?r='.$r.'&sort=open&page='.$page.'">Открытые</a>';
echo "</div>\n";
echo "<div class='fyt'>\n";
echo '<img src="img/open.png" alt="open"/> - Открытые для вступления<br/>';
echo'<img src="img/close.png" alt="close"/> - Закрытые для вступления<br/>';
echo'<img src="img/money.png" alt="money"/> - Вступление платное (за баллы)<br/>';
echo "</div>\n";
if ($k_post==0)
{
?>
<div class='noy'>Нет сообществ в данной категории</div>
<?
}
$q=mysql_query("SELECT * FROM `soo` WHERE `id_cat`='$r' ORDER BY $sort $por LIMIT $start, $set[p_str]");
while ($comm = mysql_fetch_assoc($q))
{
if($num==1){
echo "<div class='enk_div'>\n";
$num=0;
}else{
echo "<div class='enk2_div'>\n";
$num=1;}
################################################################################
if($comm['konf_soo']==0 || $comm['konf_soo']==1)echo'<img src="img/open.png" alt="open"/> '; elseif($comm['konf_soo']==2)echo'<img src="img/money.png" alt="money"/> '; else echo'<img src="img/close.png" alt="close"/> ';
echo "<a href='/soo/$comm[id]'>$comm[name]</a>";
if($comm['ban']!=NULL && $comm['ban']>$time)echo "[BAN]";
$count=$comm['users']+1;
if(isset($_GET['sort']) && $_GET['sort']=='users')echo " (Участников: $count)"; else echo " (".vremja($comm['time']).")\n";
echo "<br />\n";
echo "".output_text($comm['desc'])."<br />\n";
################################################################################
$admid=get_user($comm['admid']);
if(isset($user) && $user['level']>=3 && $user['id']!=$comm['admid'] && $user['level']>$admid['level'])
{
echo'[<a href="ban.php?s='.$comm['id'].'">Нарушения</a>]';
}
if(isset($user) && $user['level']>3 && ($user['id']!=$comm['admid'] && $user['level']>$admid['level'] || $user['id']==$comm['admid']))
{
echo "[<a href='?r=$r&amp;del=$comm[id]'>Удалить соо</a>]<br/>\n";
}
echo "</div>\n";
}
################################################################################
if ($k_page>1)str("?r=$r&sort=$sort&$por&",$k_page,$page);
echo "<div class='fyt'>\n";
if (isset($user))echo "»<a href='?r=$r&new'><u>Создать сообщесто</u></a><br />\n";
echo "«<a href='/soo/'>Сообщества</a><br/>\n";
echo "</div>\n";
}
}else{
$set['title']='Сообщества - Категории';
require '../sys/inc/thead.php';
title();
if(isset($user) && $user['level']>2)
{
include_once 'inc/admin_soo_act.php';
}
echo '<div class="fyt"><img src="img/top.gif" alt="" class="icon"/> <a href="top.php">Топ сообществ</a><br/>';
$soo = mysql_num_rows(mysql_query("SELECT `id` FROM `soo` WHERE `admid` = '$user[id]'"));
{
echo '<img src="img/soo.gif" alt="" class="icon"/> <a href="user.php">Мои сообщества</a> ('.$soo.')<br/>';
}
echo "</div>\n";
$q=mysql_query("SELECT * FROM `soo_cat` ORDER BY `name` ASC");
if (mysql_num_rows($q)==0){
?>
<div class='noy'>Нет категорий</div>
<?
}
while ($cat = mysql_fetch_assoc($q))
{
$count = mysql_result(mysql_query("SELECT COUNT(*) FROM `soo` WHERE `id_cat`='$cat[id]'"),0);
if($num==1){
echo "<div class='enk_div'>\n";
$num=0;
}else{
echo "<div class='enk2_div'>\n";
$num=1;}
###########
echo "<img src='/style/comm/$cat[id].gif' alt='enk' /> ";
echo "<a href='?r=$cat[id]'>$cat[name]</a> ($count)<br />\n";
echo "</div>\n";
}
}
require '../sys/inc/tfoot.php';
?>