<?
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']);
if (isset($_GET['id']) && $_GET['id']!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `comm` WHERE `id` = '".intval($_GET['id'])."'"),0)!=0){	
$comm = get_comm($ID);
$set['title']='Участники сообщества '.text($comm['name']).''; // заголовок страницы
include_once '../sys/inc/thead.php';
title();
err();
aut();
//======================Начало приватности сообщества===============================//
	if(isset($user) && mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_blacklist` WHERE `id_user` = '$user[id]' AND `id_comm` = '$comm[id]' && (`time_ban` > '$time' OR `navsegda` = '1')"),0)!=0){
	echo'<div class="mess">Вы были забанены ';
	$banned = mysql_fetch_array(mysql_query("SELECT * FROM `comm_blacklist` WHERE `id_user` = '$user[id]' AND `id_comm` = '$comm[id]'"));
	$bancon = mysql_fetch_array(mysql_query("SELECT * FROM `comm_user` WHERE `id_user` = '$banned[id_ban]' AND `id_comm` = '$comm[id]'"));
	if($bancon['level']==1){
		echo 'модератором ';
	}elseif($bancon['level']==2){
		echo 'администратором ';
	}elseif($bancon['level']==3){
		echo 'создателем ';
	}
	echo group($bancon['id_user']);
	echo user::nick($bancon['id_user'],1,1,1);
	if($banned['navsegda']==1){
		echo' навсегда!';
	}else{
		$timefe = $banned['time_ban']-$banned['time'];
		echo ' на ';
		if($timefe>3600){
			$timef = $timefe/3600;
			$timefe = floor($timef);
			
			$timem = $timef-$timefe;
			if($timem==0){
			echo''.$timefe.' часов!';
			}else{
				$timem = round($timem*60);
				echo''.$timefe.' часов '.$timem.' минут!';
			}
		}elseif($timefe<3600){
			$timef = $timefe/60;
			$timefe = round($timef);
			echo''.$timefe.' минут!';
		}
		echo ' <small>';
		echo vremja($banned['time']);
		echo '</small>';
	}
		echo "</div><div class='foot'><img src='/style/icons/str2.gif' alt=''/> <a href='/comm/cat.php?id=$comm[id_category]'>Назад в категорию</a></div>"; 
		include_once '../sys/inc/tfoot.php';
		exit;
	}
	//===========================================//
	if($comm['close']==1 && mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_user` WHERE `id_comm` = '".intval($comm['id'])."' AND `id_user` = '$user[id]'"),0)==0){
		echo'<div class="mess">Сообщество закрыто для чтения!</div>';
		echo "<div class='foot'><img src='/style/icons/str2.gif' alt=''/> <a href='/comm/$comm[id]/'>В сообщество</a></div>";
		include_once '../sys/inc/tfoot.php';
		exit;
	}
	//================Конец приватности сообщества=====================//
$admin = mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_user` WHERE `id_user` = '".intval($user['id'])."' AND `id_comm` = '$ID' AND `level` > '1'"),0);
if ($admin!=0 && isset($user) && isset($_GET['edit']) && $_GET['edit']=='user' && isset($_GET['us']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_user` WHERE `id_user` = '".intval($_GET['us'])."' AND `id_comm` = '$ID' AND `level` = '3'"),0)==0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_user` WHERE `id_user` = '".intval($_GET['us'])."' AND `id_comm` = '$ID'"),0)!=0 && $_GET['us']!=$user['id']){
	$us = intval($_GET['us']);
	$nick = get_user($us);
	$use = mysql_fetch_array(mysql_query("SELECT * FROM `comm_user` WHERE `id_comm` = '$comm[id]' AND `id_user` = '$us'"));
	if (isset($_POST['level']) && isset($_POST['save']) &&($_POST['level']==0 || $_POST['level']==1 || $_POST['level']==2))
	{
		$level = intval($_POST['level']);
		mysql_query("UPDATE `comm_user` SET `level` = '$level' WHERE `id_comm` = '$ID' AND `id_user` = '$us'LIMIT 1");
		$_SESSION['message'] = 'Статус пользователя '.$nick['nick'].' успешно изменен!';
		header("Location: ?");
		exit;
	}
	echo "<form method=\"post\" name='create_comm' action=\"?edit=user&us=$us\" class=\"mess\">";
	echo "Статус пользователя ";echo user::nick($us,0,0,0);echo" в сообществе:<br />\n";
	echo "<input name='level' ".($use['level']==0?" checked='checked'":null)."  type='radio' value='0' />Пользователь<br />";
	echo "<input name='level'  ".($use['level']==1?" checked='checked'":null)." type='radio' value='1' />Модератор<br />";
	echo "<input name='level'  ".($use['level']==2?" checked='checked'":null)." type='radio' value='2' />Администратор<br />";
	
	echo "<input name=\"save\" value=\"Сохранить\" type=\"submit\" /><br />\n";
	echo "</form>\n";
	echo "<div class='foot'><img src='/style/icons/str2.gif' alt=''/> <a href='?'>Назад</a></div>";
	include_once '../sys/inc/tfoot.php';
	exit;
}
$order = "ORDER BY `id` DESC";
$num = 0;
$sort = 'all';
if(isset($_GET['sort']) && $_GET['sort']=='admin'){
	$order = "AND `level` > '0' ORDER BY `level` DESC";
	$num = 1;
	$sort = 'admin';
}
echo "<div id='comments' class='menus'>";

echo "<div class='webmenu'>";
echo "<a href='?' ".($num==0?" class='activ'":null).">Все</a>";
echo "</div>"; 

echo "<div class='webmenu last'>";
echo "<a href='?sort=admin' ".($num==1?" class='activ'":null).">Администрация</a>";
echo "</div>"; 
echo "</div>";
$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_user` WHERE `id_comm` = '$ID' $order"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
$q=mysql_query("SELECT * FROM `comm_user` WHERE `id_comm` = '$ID' $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_user']);
	$status = intval($comm['level']);
	echo status($idc); echo group($idc); echo user::nick($idc,1,1,1); 
	echo comm_user_group($status); 
	if ($admin!=0 && isset($user) && mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_user` WHERE `id_user` = '".intval($idc)."' AND `id_comm` = '$ID' AND `level` = '3'"),0)==0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_user` WHERE `id_user` = '".intval($idc)."' AND `id_comm` = '$ID'"),0)!=0 && $idc!=$user['id']){
	echo' <a href="?edit=user&us='.$idc.'"><img src="/style/icons/edit.gif" alt="edit"/></a>';
	}
	echo'</div>';
}	
if ($k_post == 0)
{
	echo '<div class="mess">';
	echo 'Нет участников';
	echo '</div>';
}
if($sort=='admin'){
	if ($k_page>1)str("?sort=admin&",$k_page,$page);
}else{
	if ($k_page>1)str("?",$k_page,$page);
}
echo "<div class='foot'><img src='/style/icons/str2.gif' alt=''/> <a href='/comm/$ID/'>В сообщество</a></div>";
}else{
	header("Location: /");
}
include_once '../sys/inc/tfoot.php';
?>