<?
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';
$ID = intval($_GET['id']);
$cat = mysql_fetch_array(mysql_query("SELECT * FROM `comm` WHERE `id` = '$ID'"));	
$set['title']='Сообщества Lafac.Ru'; // заголовок страницы
include_once '../sys/inc/thead.php';
title();
aut();
err();

$order = "ORDER BY `rating` DESC";
$num = 0;
$sort = 'popular';
if(isset($_GET['sort']) && $_GET['sort']=='close'){
	$order = "AND `close` = '1' ORDER BY `rating` DESC";
	$num = 1;
	$sort = 'close';
}elseif(isset($_GET['sort']) && $_GET['sort']=='new'){
	$order = "ORDER BY `time` DESC";
	$num = 2;
	$sort = 'new';
}


echo "<div class='foot'>";
echo "<a href='?id=1' ".($num==0?" class='activ'":null).">Популярные</a> / ";

echo "<a href='?id=1&sort=close' ".($num==1?" class='activ'":null).">Закрытые</a> / ";

echo "<a href='?id=1&sort=new' ".($num==2?" class='activ'":null).">Новые</a>";
echo "</div>"; 


$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `comm` WHERE `id_category` = '$ID' $order"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
if ($k_post == 0)
{
	echo '<div class="mess">';
	echo 'Нет сообществ';
	echo '</div>';
}
$q=mysql_query("SELECT * FROM `comm` WHERE `id` = '$ID' AND `rating` $order LIMIT $start, $set[p_str]");
$nums = 0;
while($comm = mysql_fetch_assoc($q))
{	
	if ($nums==0){
		echo '<div class="nav1">';
		$nums=1;
	}elseif ($nums==1){
		echo '<div class="nav2">';
		$nums=0;
	}
	$idc = intval($comm['id']);
	echo avatar_comm($idc). ' '; 
	echo comm_name($idc);
	echo ' ('.vremja($comm['time']).')';
	if(isset($comm['opis']) && $comm['opis']!=NULL){
	echo " <br /> ".output_text($comm['opis'])."<br />";
	}
	$ret = $comm['rating'];
	$aqr = $comm['rating']/100;
	$aqr = floor($aqr);
	if($comm['rating']>100)$ret = $comm['rating']-(100*$aqr);
	echo "<b>Рейтинг:</b><br />";
	echo'<div style="display: inline-block; height: 14px; width: 140px; border: 1px solid DodgerBlue; position: relative; background-color: White;">
	 <div style="height: 14px; width: 329%; background: LightGray; position: absolute; max-width: 100%;"></div>
	 <div style="height: 14px; width: '.$ret.'%; background: #32CD32; position: absolute;  max-width: 100%;"></div>
	 <span style="position: absolute; text-align: center; width: 100%; display: block; font-size: 11px;">'.$comm['rating'].'%</span>
	</div>

	<br/>';
		

	
	echo'</div>';
}	
if ($k_page>1)str("?id=$ID&",$k_page,$page);


echo "<div class='foot'><img src='/style/icons/str2.gif' alt=''/> <a href='/comm/'>Категории</a> | <b>$cat[name]</b></div>";
include_once '../sys/inc/tfoot.php';
?>