<?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';

$set['title']='Сообщества';
include_once '../sys/inc/thead.php';

title();
aut();


// Доступ только уровнем 4
if($user['level']==10){
	include_once 'inc/razd_act.php';
	}

/*
$k_razd = mysql_num_rows(mysql_query("SELECT `id` FROM `community_razd`"));
$k_page=k_page($k_razd,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];

// Вывод директорий
$q=mysql_query("SELECT * FROM `community_razd` ORDER BY `sort` LIMIT $start, $set[p_str]");
*/

$q=mysql_query("SELECT * FROM `community_razd` ORDER BY `sort`");
while($post = mysql_fetch_array($q)){

$k_f=0;
$k_n=0;

$q3=mysql_query("SELECT * FROM `community_comm` WHERE `id_razd` = '$post[id]'");
while($post2 = mysql_fetch_array($q3)){
	$k_f=$k_f+mysql_result(mysql_query("SELECT COUNT(*) FROM `community_user_incomm` WHERE `cid` = '$post2[id]'"),0);
	$k_n=$k_n+mysql_result(mysql_query("SELECT COUNT(*) FROM `community_user_incomm` WHERE `cid` = '$post2[id]' AND `time` > '".(time()-86400)."'"),0);
	}

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

echo "<table class='post'>";
echo "<tr>";
if($set['set_show_icon']==2){
echo "<td class='icon48' rowspan='2'>";
echo "<img src='/style/themes/$set[set_them]/lib/48/razdel.png'alt=''/>";
echo "</td>";
}
elseif($set['set_show_icon']==1)
{
echo "<td class='icon14'>";
echo "<img src='/style/themes/$set[set_them]/lib/14/razdel.png'alt=''/>";
echo "</td>";
}
echo "<td class='p_t'>";
echo '<a href="razd.php?id_razd='.$post['id'].'">'.$post['name'].'</a>';
echo '<span class="ank_n">('.mysql_result(mysql_query("SELECT COUNT(*) FROM `community_comm` WHERE `id_razd` = '$post[id]'"),0).'</span>/';
echo '<span class="ank_n">'.$k_f.''.$k_n.'</span>)<br/>';

echo "</td>";
echo "</tr>";
echo "<tr>";
if($set['set_show_icon']==1)echo "<td class='p_m' colspan='2'>"; else echo "<td class='p_m'>";
if($post['opis']!=NULL){
	echo output_text($post['opis']).'<br/>';
	}

// Доступ только уровнем 4
if($user['level']==10){
	echo '[<a href="index.php?razd=edit&amp;id_razd='.$post['id'].'">Ред.</a>|<a href="index.php?razd=delete&amp;id_razd='.$post['id'].'">Уд.</a>]';
echo "</td>";
echo "</tr>";
}
echo "</table>";
	}


/*
if($k_page>1){
	str('index.php?',$k_page,$page);
	}
*/

// Доступ только уровнем 4
if($user['level']==10){
	include_once 'inc/razd_form.php';
	}

include_once '../sys/inc/tfoot.php';
?>