<?
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `comm` WHERE `id` = '".intval($_GET['id'])."'"),0)!=0)
{
$comm=mysql_query("SELECT * FROM `comm` WHERE `id` = '".intval($_GET['id'])."'");
$comm=mysql_fetch_array($comm);

$cat=mysql_query("SELECT * FROM `comm_cat` WHERE `id` = '$comm[id_cat]'");
$cat=mysql_fetch_array($cat);
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_users` WHERE `id_comm` = '$comm[id]' AND `activate` = '1' AND `invite` = '0'"),0)==0)$comm['id_user']=0;
$ank=get_user($comm['id_user']); // sozdak



$set['title'] = 'Сообщество - '.htmlspecialchars($comm['name']); // Заголовок страницы
include_once '../sys/inc/thead.php';
title();
aut();


//if (mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_ban` WHERE `id_comm` = '$comm[id]' AND `type` = '3' AND `time` > '$time'"), 0)!=0)
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_ban` WHERE `id_comm` = '$comm[id]' AND `time` > '$time'"), 0)!=0 || mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_ban` WHERE `id_comm` = '$comm[id]' AND `type` = '3'"), 0)!=0)
{
echo "<div class='err'>";
echo "Сообщество $comm[name] заблокировано.</div><div class='main'>";

echo "<a href='?act=comm_ban&amp;id=$comm[id]'>Подробнее &rarr;</a>";

echo "</div>";
echo "<div class='foot'><img src='/style/icons/str2.gif'> <a href='/comm/?act=cat&id=$cat[id]'>".htmlspecialchars($cat['name'])."</a> | <a href='/comm/'>Категории</a></div>";
}else{



if($comm['id_user']!=0 && isset($user))
{
if(isset($_GET['in']))
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_users` WHERE `id_comm` = '$comm[id]' AND `id_user` = '$user[id]' AND `activate` = '1'"),0)==0)
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_blist` WHERE `id_comm` = '$comm[id]' AND `id_user` = '$user[id]'"),0)!=0)$err[]="Вы не можете вступить в данное сообщество, так как находитесь в черном списке сообщества!";
else
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_users` WHERE `id_comm` = '$comm[id]' AND `id_user` = '$user[id]' AND `invite` = '1'"),0)!=0)
{
mysql_query("INSERT INTO `comm_journal` SET `id_comm` = '$comm[id]', `id_user` = '$user[id]', `type` = 'in_comm', `time` = '$time'");
mysql_query("UPDATE `comm_users` SET `activate` = '1', `invite` = '0', `time` = '$time' WHERE `id_comm` = '$comm[id]' AND `id_user` = '$user[id]' AND `invite` = '1'");
msg("Приглашение принято");
}
elseif($comm['join_rule']!=3)
{
if($comm['join_rule']==2)
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_users` WHERE `id_comm` = '$comm[id]' AND `id_user` = '$user[id]' AND `invite` = '0' AND `activate` = '0'"),0)==0)
{
mysql_query("INSERT INTO `comm_users` (`id_comm`, `id_user`, `time`, `activate`) VALUES ('$comm[id]', '$user[id]', '".time()."', '0')");
mysql_query("INSERT INTO `mail` (`id_user`, `id_kont`, `msg`, `time`) VALUES ('0', '$ank[id]', '$user[nick] хочет вступить в сообщество [url=/comm/?act=comm&id=$comm[id]]".htmlspecialchars($comm['name'])."[/url].', '$time')");
msg("Вы успешно подали заявку. Дождитесь пока создатель ее рассмотрит");
}
else
{
$err[]="Вы уже подали заявку";
}
}
else
{
mysql_query("INSERT INTO `comm_journal` SET `id_comm` = '$comm[id]', `id_user` = '$user[id]', `type` = 'in_comm', `time` = '$time'");
mysql_query("INSERT INTO `comm_users` (`id_comm`, `id_user`, `time`, `activate`) VALUES ('$comm[id]', '$user[id]', '$time', '1')");
msg("Вы успешно вступили в сообщество");
}
}
else $err[]="Сообщество закрытого типа";
}
}
else $err[]="Вы уже являетесь участником сообщества";
}
elseif(isset($_GET['out']))
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_users` WHERE `id_comm` = '$comm[id]' AND `id_user` = '$user[id]' AND `activate` = '1'"),0)!=0)
{
if($ank['id']==$user['id'] && isset($user) && mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_users` WHERE `id_comm` = '$comm[id]' AND `activate` = '1'"),0)>1)$err[]="Вы создатель сообщества! Для начала удалите всех участников сообщества";
else
{
if($ank['id']==$user['id'] && isset($user))
{
$comm['id_user']=0;
$ank=get_user($comm['id_user']); // sozdak
}

mysql_query("INSERT INTO `comm_journal` SET `id_comm` = '$comm[id]', `id_user` = '$user[id]', `type` = 'out_comm', `time` = '$time'");
mysql_query("DELETE FROM `comm_users` WHERE `id_comm` = '$comm[id]' AND `id_user` = '$user[id]' AND `activate` = '1'");
msg("Вы успешно покинули сообщество");
}
}
else $err[]="Вы не являетесь участником сообщества";
}
}
elseif(isset($user) && isset($_GET['creator']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_users` WHERE `id_comm` = '$comm[id]' AND `activate` = '1' AND `invite` = '0'"),0)==0)
{
mysql_query("INSERT INTO `comm_journal` SET `id_comm` = '$comm[id]', `id_user` = '$user[id]', `id_ank` = '".mysql_result(mysql_query("SELECT `id_user` FROM `comm` WHERE `id` = '$comm[id]'"),0)."', `type` = 'access', `time` = '$time', `access` = 'creator'");
mysql_query("UPDATE `comm` SET `id_user` = '$user[id]' WHERE `id` = '$comm[id]'");
mysql_query("INSERT INTO `comm_users` (`id_comm`, `id_user`, `time`, `activate`, `access`) VALUES ('$comm[id]', '$user[id]', '".time()."', '1', 'creator')");
msg("Теперь вы создатель сообщества");
$ank=get_user($user['id']);
}

err();





echo "<div class='nav2'>\n";
echo "<img src='/comm/img/comm_".($comm['read_rule']==1?"open":"closed").".png' /> ".($comm['read_rule']==1?"Открыто":"Закрыто")." для чтения\n";
echo " ".($comm['adult']==1?" <span style='color: red;'>(+18)</span>":NULL)."<br/>\n";
echo "</div>\n";
echo "<div class='main'>\n";
$cn=mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_ban` WHERE `id_comm` = '$comm[id]'"), 0);
echo "<img src='/comm/img/violation.png' /> <a href='?act=comm_ban&id=$comm[id]'>Нарушения</a> ($cn)";
echo "</div>";
echo "<div class='nav2'>\n";
if (is_file(H."comm/img/avatar/comm.".$comm['id'].".".$comm['mdi'].".img.png"))echo "<img src='/comm/img/avatar/comm.".$comm['id'].".".$comm['mdi'].".img.png' style='border: 1px solid #CCCACA;'/><br/>\n";
else echo "<img src='/comm/screen_tmp/48-48_0screen.png' style='border: 1px solid #CCCACA;'/><br/>\n";
if($comm['id_user']!=0)
{
//echo "Создатель: ";
//echo "<a href='/info.php?id=$ank[id]'>$ank[nick]</a> ".online($ank['id'])."<br />;
echo "<img src='/comm/img/information.png'/> <a href='/comm/?act=comm_info&id=$comm[id]'>Информация</a><br />\n";
}
echo "</div>\n";
if ($comm['forum']==1 || $comm['chat']==1 || $comm['files']==1)echo "<div class='main'>\n";
if ($comm['forum']==1)
{
$count_topics=mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_forum` WHERE `id_comm` = '$comm[id]' AND `type` = 'topic'"),0);
$count_topics_new=mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_forum` WHERE `id_comm` = '$comm[id]' AND `type` = 'topic' AND `time` > '".($time-(3600*24))."'"),0);
$count_topics_show=$count_topics.($count_topics_new>0?"/+$count_topics_new":NULL);
echo "<img src='/comm/img/forum.png' /> <a href='/comm/?act=forum&id=$comm[id]'>Форум ($count_topics_show)</a><br />\n";
}
if ($comm['chat']==1)
{
$times = $time-20;
$chat=mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_chat` WHERE `id_comm` = '$comm[id]' AND (`private` = '1' AND (`id_user` = '$user[id]' OR `reply` = '$user[id]') OR `private` = '0')"),0);
echo "<img src='/comm/img/message.png' /> <a href='/comm/?act=chat&id=$comm[id]'>Чат ($chat)</a><br />\n";
}
if ($comm['files']==1)
{
$count_files=mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_files` WHERE `id_comm` = '$comm[id]' AND `type` = 'file'"),0);
$count_files_new=mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_files` WHERE `id_comm` = '$comm[id]' AND `type` = 'file' AND `time` > '".($time-(3600*24))."'"),0);
$count_files_show=$count_files.($count_files_new>0?"/+$count_files_new":NULL);
echo "<img src='/comm/img/download.png' /> <a href='/comm/?act=files&id=$comm[id]'>Файлы ($count_files_show)</a><br />\n";
}
if ($comm['forum']==1 || $comm['chat']==1 || $comm['files']==1)echo "</div>\n";
echo "<div class='nav2'>\n";
echo "<img src='/comm/img/users.png'/> <a href='/comm/?act=comm_users&id=$comm[id]'> Участники (".mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_users` WHERE `id_comm` = '$comm[id]' AND `activate` = '1' AND `invite` = '0'"),0).")</a><br />\n";
echo "<img src='/comm/img/users_ban.png'/> <a href='/comm/?act=comm_users_ban&id=$comm[id]'>Нарушители</a><br />\n";
echo "<img src='/comm/img/journal_comm.png'/> <a href='/comm/?act=comm_journal&id=$comm[id]'>Журнал сообщества</a><br />\n";
if($ank['id']==$user['id'] && isset($user) || $uinc['access']=='adm')echo "<img src='/comm/img/blocked.png'/> <a href='/comm/?act=blist&id=$comm[id]'>Черный список</a><br />\n";
if($ank['id']==$user['id'] && isset($user))echo "<img src='/comm/img/settings.png'/> <a href='/comm/?act=comm_settings&id=$comm[id]'>Настройки</a><br />\n";
echo "</div>\n";
if(isset($user))
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_users` WHERE `id_comm` = '$comm[id]' AND `id_user` = '$user[id]' AND `activate` = '1'"),0)!=0)
{
echo "<div class='main'>\n";
echo "<img src='/comm/img/add.png'/> <a href='/comm/?act=invite&id=$comm[id]'>Пригласить в сообщество</a><br />\n";
echo "<img src='/comm/img/out.png'/> <a href='/comm/?act=comm&id=$comm[id]&out=1'>Покинуть сообщество</a><br />\n";
echo "</div>\n";
}
else
{
if($comm['id_user']==0)
{
echo "<div class='main'>\n";
echo "Сообщество без создателя!<br/><img src='/comm/img/okey.png'/> <a href='/comm/?act=comm&id=$comm[id]&creator=1'>Стать создателем</a><br />\n";
echo "</div>\n";
}
else
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_users` WHERE `id_comm` = '$comm[id]' AND `id_user` = '$user[id]' AND `invite` = '1'"),0)!=0)echo "<div class='main'><img src='/comm/img/okey.png'/> <a href='/comm/?act=comm&id=$comm[id]&in=1'>Принять приглашение</a></div>\n";
elseif($comm['join_rule']!=3)echo "<div class='main'><img src='/comm/img/okey.png'/> <a href='/comm/?act=comm&id=$comm[id]&in=1'>Вступить в сообщество</a></div>\n";
}
}
}
	echo '<div class="main"><img src="/style/icons/fav.gif" alt="*" /> ';

if ( mysql_result(mysql_query("SELECT COUNT(*) FROM `mark_comm` WHERE `id_user` = '" . $user['id'] . "' AND `id_comm` = '" . $comm['id'] . "' LIMIT 1"),0) == 0)echo '<a href="?act=comm&id=' . $comm['id'] . '&amp;fav=1">В закладки</a></div>';
else
echo '<a href="?act=comm&id=' . $comm['id'] . '&amp;fav=0">Удалить из закладок</a></div>'; 





if (isset($_GET['fav']) && isset($user)){
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `mark_comm` WHERE `id_user` = '".$user['id']."' AND `id_comm` = '".$comm['id']."' LIMIT 1"),0) == 0 && $_GET['fav'] == 1){
mysql_query("INSERT INTO `mark_comm` (`id_comm`, `id_user`, `time`) VALUES ('$comm[id]', '$user[id]', '$time')");
$_SESSION['message'] = $comm['name'] . ' добавлено в закладки';
}
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `mark_comm` WHERE `id_user` = '".$user['id']."' AND `id_comm` = '".$comm['id']."' LIMIT 1"),0) == 1 && $_GET['fav'] == 0){
mysql_query("DELETE FROM `mark_comm` WHERE `id_user` = '$user[id]' AND  `id_comm` = '$comm[id]'");
$_SESSION['message'] = $comm['name'] . ' удалено из закладок';
}

header("Location: ?act=comm&id=$comm[id]");
exit;
}


echo'<div class="foot">';
echo'Ссылка на сообщество :<br />';
echo'<a href="http://'.$_SERVER['HTTP_HOST'].'/comm/'.$comm['id'].'/"><span>http://'.$_SERVER['HTTP_HOST'].'/comm/'.$comm['id'].'/</span></a>';
echo'</div>';
	
	
	
    


echo "<div class='foot'><img src='/style/icons/str2.gif'> <a href='/comm/?act=cat&id=$cat[id]'>".htmlspecialchars($cat['name'])."</a> | <a href='/comm/'>Категории</a></div>";
}
}
?>
