<?php

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

if(isset($_GET['id'])){
	$soo = intval($_GET['id']);
	}else{
		header("Location: index.php");
		}

$admin = mysql_fetch_array(mysql_query("SELECT * FROM `community_user_incomm` WHERE `cid` = '$soo' AND `uid` = '".$user['id']."'"));

$title = mysql_result(mysql_query("SELECT `name` FROM `community_comm` WHERE `id` = '".$soo."' LIMIT 1"),0);
$set['title'] = ' '.$title.' ' ;
include_once '../sys/inc/thead.php';

title();
aut();

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

$comm_id = mysql_fetch_array(mysql_query('SELECT * FROM `community_comm` WHERE `id` = '.$soo.' LIMIT 1'));
if($soo==0 || $soo<0){
	echo '<div class="err">Иди нахуй! Хакер недоношеный!</div>';
	}else if($soo!=$comm_id['id']){
		echo '<div class="err">Сообщество не найдено.</div>';
		}else if(mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_ban` WHERE `id_user` = '$user[id]' AND `id_comm` = '$soo' AND `time` > '$time'"), 0)!=0){
			header('Location: ban.php?id='.$soo);
			}else{

if(isset($_GET['ok_enter'])){
	msg('Ты принят в сообщество');
	}else if(isset($_GET['ok_enter_0'])){
		msg('Твою заявку рассмотрят администраторы сообщества.');
		}else if(isset($_GET['err_enter'])){
			msg('В сообщество можно вступить только один раз.');
			}else if(isset($_GET['ok_out'])){
				msg('Пока :(');
				}else if(isset($_GET['err_out'])){
					msg('Сообщество можно покинуть только один раз.');
					}else if(isset($_GET['err_admin'])){
						msg('Создатель не может покинуть свое сообщество');
						}else if(isset($_GET['ok_rules'])){
							msg('Записали правила) ');
							}

$comm = mysql_fetch_array(mysql_query("SELECT * FROM `community_comm` WHERE `id` = '".$soo."' LIMIT 1"));

echo '<span class="status"><b>'.$comm['name'].'</b></span> <span class="ank_n">('.vremja($comm['time_create']).')</span><br/>';

if($comm['status']==1){
	echo '<img src="1.gif" alt=""/> Открытое сообщество<br/>';
	}else if($comm['status']==2){
		echo '<img src="2.gif" alt=""/> Только для участников сообщества<br/>';
		}

echo '<b>ID сообщества</b>: '.$comm['id'].'<br/>';

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

if(is_file(H.'sys/comm/'.$soo.'.jpg')){
	echo '<img src="../../sys/comm/'.$soo.'.jpg" alt=""/><br/>';
echo '</div>';
	echo '&#187;&nbsp;<a href="../../sys/comm/'.$soo.'.jpg">Скачать логотип</a><br/>';
	}else if (isset($user) && $user['id']==$comm['id_author']){
		echo '<a href="upload.php?id='.$comm['id'].'">Загрузить логотип</a><br/>';
		}

echo '<div class="rowup">'.output_text($comm['about']).'</div>';
echo '&#187;&nbsp;<a href="pravila.php?id='.$comm['id'].'">Наши правила</a><br/>';

$list_user = '<b>'.mysql_result(mysql_query("SELECT COUNT(*) FROM `community_user_incomm` WHERE `cid` = '$comm[id]'"),0).'/+'.mysql_result(mysql_query("SELECT COUNT(*) FROM `community_user_incomm` WHERE `cid` = '$comm[id]' AND `time` > '".(time()-86400)."'"),0).'</b>';
echo '&#187;&nbsp;<a href="list_user.php?id='.$comm['id'].'">Участники</a> <span class="ank_n">('.$list_user.')</span><br/>';

$guest = '<b>'.mysql_result(mysql_query("SELECT COUNT(*) FROM `community_board` WHERE `id_comm` = '$comm[id]'"),0).'/+'.mysql_result(mysql_query("SELECT COUNT(*) FROM `community_board` WHERE `id_comm` = '$comm[id]' AND `time` > '".(time()-86400)."'"),0).'</b>';
echo '&#187;&nbsp;<a href="guest.php?id='.$comm['id'].'">Чат</a> <span class="ank_n">('.$guest.')</span><br/>';

$forum = '<b>'.mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_forum_p` WHERE `id_comm` = '$comm[id]'"),0).'/'.mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_forum_t` WHERE `id_comm` = '$comm[id]'"),0).'</b>';
echo '&#187;&nbsp;<a href="forum/index.php?id_comm='.$comm['id'].'">Форум</a> <span class="ank_n">('.$forum.')</span><br/>';

$k_p=mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_obmen_files` WHERE `id_comm` = '$comm[id]'"), 0);
$k_n= mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_obmen_files` WHERE `time` > '".(time()-86400)."' AND `id_comm` = '$comm[id]'"), 0);

if($k_n==0){
$k_n=NULL;
}else{
$k_n='/+'.$k_n;
}

echo '&#187;&nbsp;<a href="obmen/index.php?id_comm='.$comm['id'].'">Файлы</a> <span class="ank_n">(<b>'.$k_p.''.$k_n.'</b>)</span><br/>';

if(isset($user) && $admin['priv']==2){
	echo '[admin] <a href="setting.php?id='.$comm['id'].'">Панель управления сообществом</a><br/>';
	}

include_once 'inc/wall.php';

if(isset($user)){
	if(mysql_result(mysql_query("SELECT COUNT(uid) FROM `community_user_incomm` where `uid` = '$user[id]' AND `cid` = '$soo'"),0)){
		echo '[-] <a href="out.php?id='.$comm['id'].'">Покинуть сообщество</a><br/>';
		}else{
			echo '[+] <a href="enter.php?id='.$comm['id'].'">Вступить в сообщество</a><br/>';
			}
			}

echo '&#187;&nbsp;<a href="index.php">В разделы сообществ</a><br/>';


// Правила
if(isset($_GET['rules'])){
	$set['title'] = 'Правила ' ;
	include_once '../sys/inc/thead.php';

title();
aut();

$k_rules = mysql_num_rows(mysql_query("SELECT `rules` FROM `community_comm` WHERE `id` = '".$soo."'"));
$k_page = k_page($k_rules,$set['p_str']);
$page = page($k_page);
$start = $set['p_str']*$page-$set['p_str'];
$q4 = mysql_query("SELECT * FROM `community_comm` WHERE `id` = '".$soo."'");

while($rules = mysql_fetch_array($q4)){
echo output_text($rules['rules']).'<br/>';
}

if($k_page>1){
	str('comm.php?id='.$soo.'&amp;rules&amp;',$k_page,$page);
	}

echo '&#187;&nbsp;<a href="comm.php?id='.$soo.'">В сообщество</a><br/>';
}
}

echo '</div>';
include_once '../sys/inc/tfoot.php';
?>