<?php

require_once '../incfiles/core.php';
require_once '../incfiles/func.php';
require_once '../incfiles/auth.php';
require_once '../incfiles/user.php';

$title = lang('Сообщества-категории','Спільноти-категорії');
require_once '../incfiles/head.php';

echo '<div class="title">'.$title.'</div>';


if (!empty($_GET['r']) && is_numeric($_GET['r']) && mysql_result(mysql_query("SELECT COUNT(`id`) FROM `groups_category` WHERE `id` = '".abs(intval($_GET['r']))."' LIMIT 1"),0) == true) $arr = mysql_fetch_array(mysql_query("SELECT * FROM `groups_category` WHERE `id` = '".abs(intval($_GET['r']))."' LIMIT 1"));

if (!empty($arr))
{
	$all = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `groups`"),0);	
	echo '<div class="title"><div class="right">'.$all.'</div>'.lang($arr['ru_name'],$arr['ua_name']).'</div>';

	if ($all > 0)
	{
		$cp = ceil($all/10);
		$p = (isset($_GET['p']) and is_numeric($_GET['p']) and $_GET['p']>1 and $_GET['p']<=$cp) ? $_GET['p'] : 1;
		$start = $p*10-10;

		$res = mysql_query("SELECT * FROM `groups` WHERE `category` = '".$arr['id']."' DESC LIMIT $start,10");
		
		while ($array = mysql_fetch_array($res)) echo '<div class="block">'.group_name($array['id']).'</div>';
		navi($p,$cp,'/people/?act=search&r='.$arr['id'].'&');
	}
}
else
{
	$res = mysql_query("SELECT * FROM `groups_category` ORDER by `id`");
	while ($array = mysql_fetch_array($res))
	{
		$all_r = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `groups` WHERE `groups_category` = '".$array['id'].""),1);
		echo '<div class="block"><a href="'.URL.'/people/?act=search&r='.$array['id'].'" onclick="Page.Go(this.href); return false"><b>'.lang($array['ru_name'],$array['ua_name']).'</b></a> '.($all_r>0?'('.people($all_r).')':'').'</div>';
	}
}