<?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` WHERE `category` = '".$arr['id']."' AND `ban` = 0"),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']."' AND `ban` = 0  DESC LIMIT $start,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($arr['id'],0,1).'</div>';
		//while ($array = mysql_fetch_array($res)) echo '<div class="block">'.group_name$array['id'].'</div>';
		navi($p,$cp,'/groups/?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 `category` = '".$array['id']."' AND `ban` = 0"),0);
		echo '<div class="block"><a href="'.URL.'/groups/category.php?&r='.$array['id'].'" onclick="Page.Go(this.href); return false"><b>'.lang($array['ru_name'],$array['ua_name']).' обл.</b></a> '.($all_r>0?'('.group_name($all_r).')':'').'</div>';
	}
}

require_once '../incfiles/foot.php';