<?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");
		}

$set['title'] = 'Вступаем в сообщество &amp; '.$_SERVER['HTTP_HOST'];
include_once '../sys/inc/thead.php';

title();
aut();

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

$comm = mysql_fetch_array(mysql_query('SELECT * FROM `community_comm` WHERE `id` = '.$soo.' LIMIT 1'));
$q = mysql_fetch_array(mysql_query('SELECT * FROM `user` WHERE `id` = '.$user['id'].' LIMIT 1'));
$user_comm = mysql_fetch_array(mysql_query('SELECT * FROM `community_user_incomm` WHERE `cid` = '.$soo.' AND `uid` = '.$user['id'].' LIMIT 1'));
$status_comm = mysql_fetch_array(mysql_query("SELECT * FROM `community_comm` WHERE `id` = '$soo' LIMIT 1"));

if(!isset($user)){
	echo '<div class="err">Доступ закрыт.</div>';
	}else if($soo==0 || $soo<0){
		echo '<div class="err">Иди нахуй! Хакер недоношеный!</div>';
		}else if($soo!=$comm['id']){
			echo '<div class="err">Сообщество не найдено.</div>';
			}else if($user_comm['uid']==$user['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($status_comm['status']==2){
	mysql_query("INSERT INTO `community_user_incomm` (`uid`, `cid`, `time`, `priv`, `postov`, `them`, `files`) VALUES ('$user[id]', '$soo', '$time', '0', '0', '0', '0')");
	$msg = 'Обитатель '.$q['nick'].', хочет вступить в Ваше сообщество. Вы можете ему разрешить или отказать в вступлении. Для этого зайдите на страницу [url=http://'.$_SERVER['HTTP_HOST'].'/comm/activate.php?id='.$soo.']активации[/url]';
	mysql_query("INSERT INTO `jurnal` (`id_user`, `id_kont`, `time`, `msg`, `read`) VALUES ('0', '$comm[id_author]', '$time', '$msg', '0')");
	header("Location: comm.php?id=$soo&ok_enter_0");
	}else{
		mysql_query("INSERT INTO `community_user_incomm` (`uid`, `cid`, `time`, `priv`, `postov`, `them`, `files`) VALUES ('$user[id]', '$soo', '$time', '0', '0', '0', '0')");
		header("Location: comm.php?id=$soo&ok_enter");
		}
		}

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