<?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>100</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 "<div class='foot'>\n";
echo "<a href='razd.php?id_razd=".$id_razd."&amp;page=".$page."&amp;sort=name'>Имя</a> \n";
echo "<a href='razd.php?id_razd=".$id_razd."&amp;page=".$page."&amp;sort=time_create'>Дата Соз.</a> \n";
echo "<a href='razd.php?id_razd=".$id_razd."&amp;page=".$page."&amp;sort=status'>Статусу</a> \n";
echo "<a href='razd.php?id_razd=".$id_razd."&amp;page=".$page."&amp;sort=new'>Новые</a> \n";

echo "</div>\n";


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(is_file(H.'sys/comm/'.$post['id'].'.jpg')){
	echo '<img src="../../../sys/comm/'.$post['id'].'.jpg" align="left" width="40" height="45" alt=""/>';
	}else{
		echo 'no logo';
		}

echo '</td>';

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]'")).') ';

if($post['status']==1){
	echo '<img src="1.gif" alt="" class="icon"/><br/>';
	}else{
		echo '<img src="2.gif" alt="" class="icon"/><br/>';
		}

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

if($user['balls']>100 && mysql_result(mysql_query("SELECT COUNT(id) FROM `community_comm` where `id_author` = '$user[id]' LIMIT 1"),0)<51){
	echo '&#187;&nbsp;<b><a href="create_comm.php?id_razd='.$razd['id'].'">Создать сообщество</a></b><br/>';
	}
	}

echo '&#187;&nbsp;<a href="index.php">К разделам</a></div>';
include_once '../sys/inc/tfoot.php';
?>