<?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_razd'])){
	$id_razd = intval($_GET['id_razd']);
	}else{
		header("Location: index.php");
		}

$set['title']='Список сообществ &amp; '.$_SERVER['HTTP_HOST'];
include_once '../sys/inc/thead.php';

title();
aut();

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

$razd = mysql_fetch_array(mysql_query('SELECT * FROM `community_razd` WHERE `id` = '.$id_razd.' LIMIT 1'));
if($id_razd==0 || $id_razd<0){
	echo '<div class="err">Иди нахуй! Хакер недоношеный!</div>';
	}else if($id_razd!=$razd['id']){
		echo '<div class="err">Раздел не найден.</div>';
		}else{

if(isset($user) && $user['balls']<50){
	echo '<div class="err">Для создания сообщества Вам нужно набрать как минимум <b>50</b> баллов.</div>';
	}

if(isset($user) && $user['level']==10){


if(isset($_GET['act']) && $_GET['act']=='delete'){
	$id = $_GET['id'];
	mysql_query("DELETE FROM `community_board` WHERE `id_comm` = '$id'"); //мини чат
	mysql_query("DELETE FROM `community_comm` WHERE `id` = '$id'"); //сообщества
	mysql_query("DELETE FROM `community_user_incomm` WHERE `cid` = '$id'"); //пользователи
	mysql_query("DELETE FROM `comm_ban` WHERE `id_comm` = '$id'"); //баны
	mysql_query("DELETE FROM `comm_forum_f` WHERE `id_comm` = '$id'"); //форум
	mysql_query("DELETE FROM `comm_forum_p` WHERE `id_comm` = '$id'");
	mysql_query("DELETE FROM `comm_forum_r` WHERE `id_comm` = '$id'");
	mysql_query("DELETE FROM `comm_forum_t` WHERE `id_comm` = '$id'");
	mysql_query("DELETE FROM `comm_forum_zakl` WHERE `id_comm` = '$id'");
mysql_query("DELETE FROM `comm_forum_files_rating` WHERE `id_comm` = '$id'");
mysql_query("DELETE FROM `comm_obmen_dir` WHERE `id_comm` = '$id'");
mysql_query("DELETE FROM `comm_obmen_files` WHERE `id_comm` = '$id'");
mysql_query("DELETE FROM `comm_obmen_komm` WHERE `id_comm` = '$id'");
mysql_query("DELETE FROM `comm_wall` WHERE `id_comm` = '$id'");
	mysql_query("OPTIMIZE TABLE `community_board` , `community_comm` , `community_user_incomm` , `comm_ban` , `comm_forum_f` , `comm_forum_files` , `comm_forum_files_rating` , `comm_forum_p` , `comm_forum_r` , `comm_forum_t` , `comm_forum_zakl`");
	msg("Сообщество успешно удалено ");

	}
	}

$razd = mysql_fetch_array(mysql_query("SELECT * FROM `community_razd` WHERE `id` = '".$id_razd."'"));
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `community_comm` WHERE `id_razd` = '$razd[id]'"),0);
$k_page = k_page($k_post,$set['p_str']);
$page = page($k_page);
$start = $set['p_str']*$page-$set['p_str'];
echo '<form action="razd.php?id_razd='.$id_razd.'&amp;page='.$page.'" method="post">';
echo '<div class="str"><b>Сорт</b>:&nbsp;<select name="sort"><option value="name">имя</option><option value="time_create">дата создания</option><option value="status">статус</option><option value="new">новые</option></select>';
echo '<input type="submit" value="ok"></div></form>';

echo '<table class="post">';

if($k_post==0){
	echo '<tr><td class="p_t">Нет сообществ</td></tr>';
	}

$asc='DESC';
$order='id';

if(isset($_GET['sort']) && $_GET['sort']=='name'){
	$order='`name`';
	}else if(isset($_GET['sort']) && $_GET['sort']=='time_create'){
		$order='`time_create`';
		}else if(isset($_GET['sort']) && $_GET['sort']=='status'){
			$order='`status`';
			}else if(isset($_GET['sort']) && $_GET['sort']=='new'){
				$order='`id`';
				$asc='DESC';
				}

$q = mysql_query("SELECT * FROM `community_comm` WHERE `id_razd` = '$razd[id]' ORDER BY $order $asc LIMIT $start, $set[p_str]");
while($post = mysql_fetch_array($q)){
	echo '<tr><td class="icon14">';
if($post['status']==1){
	echo '<img src="1.gif" alt="" class="icon"/>';
	}else{
		echo '<img src="2.gif" alt="" class="icon"/>';
		}
echo '<td class="p_m"><a href="comm.php?id='.$post['id'].'">'.esc(trim(smiles(stripcslashes(htmlspecialchars($post['name']))))).'</a> ('.mysql_num_rows(mysql_query("SELECT `id` FROM `community_user_incomm` WHERE `cid` = '$post[id]'")).') ';
$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 "<br/>\n";


echo output_text($post['about']);

if(isset($user) && $user['level']>3){
	echo '<br/>&#187;&nbsp;<a href="razd.php?id_razd='.$id_razd.'&amp;id='.$post['id'].'&amp;act=delete">Удалить</a>';
	}

echo '</td></tr>';
}

echo '</table>';

if($k_page>1){
	str('razd.php?id_razd='.$razd['id'].'&amp;',$k_page,$page);
	}
echo "<div style='background-color:#FFFF33 ;border-top:1px solid #FF9900 ;border-bottom:1px solid #FF9900 ;padding:2px'>\n";
if($user['balls']>50 && mysql_result(mysql_query("SELECT COUNT(id) FROM `community_comm` where `id_author` = '$user[id]' LIMIT 1"),0)<51){
	echo '(+) <b><a href="create_comm.php?id_razd='.$razd['id'].'">Создать сообщество</a></b><br/>';
	}
	}
echo "</div>\n";
echo "<img src='/img/Back.gif' alt='' class=''/>\n"; 
echo" <a href='index.php'>К разделам</a>"; 
include_once '../sys/inc/tfoot.php';
?>