<?php

	$title = 'Клан';
	$limit = 10;
	$paginate = TRUE;
    $load = array('f_time', 'user');

	require_once '../protected/sys.php';

	$id = isset($_GET['id']) ? intval($_GET['id']) : NULL;

	if(empty($id) || !$clan = $db->fetch("SELECT * FROM clans WHERE id = ?", array($_GET['id']))) {

		$_SESSION['error'] = 'Такого клана не существует!';
		header('Location: /clans');
		exit;

	}

	$count = $db->rows("SELECT id FROM users WHERE clan_id = '". $clan['id'] ."'");

	$db->offEmulate();

	$cusers = $db->fetchAll("SELECT id, login, sex, online FROM users WHERE clan_id = '". $clan['id'] ."' AND id != '". $clan['admin_id'] ."' ORDER BY id DESC");
	$admin = $db->fetch("SELECT id, login, sex, online FROM users WHERE id = '". $clan['admin_id'] ."'", array());
	$us = new user($db);




		

?>
<div class="menu">
Имя клана: <?=$clan['name']?>
</div>
<div class="menu">
	Основан: <?= data_v($clan['time'])?>
</div>
<div class="menu">
Опыт клана: <?=$clan['exp']?>/<?=$expClan[$clan['level']]?>
</div>
<div class="menu">
Уровень клана: <?=$clan['level']?>
</div>

	<a class="menu" href="/clans/chat?id=<?= $clan['id'] ?>">Чат клана</a>

<div class="menu">
	<center>Пользователи клана <?= $count ?> из <?= $limit ?></center>
</div>


<a class="menu" href ="/user?id=<?= $admin['id'] ?>">
<img src="/imgData/static/<?= $admin['sex'] ?>.png">
<?= $us->login($admin['id']) ?> <?= $admin['online'] > ($config['time'] - 600) ? '<img src="/imgData/static/online.png">' : NULL ?> (Основатель)
</a>

<?php foreach($cusers as $cuser): ?>

<a class="menu" href ="/user?id=<?= $cuser['id'] ?>">
<img src="/imgData/static/<?= $cuser['sex'] ?>.png">
<?= $us->login($cuser['id']) ?> <?= $cuser['online'] > ($config['time'] - 600) ? '<img src="/imgData/static/online.png">' : NULL ?> 
</a>
<?php if($clan['admin_id'] == $user['id']): ?>
<a href="/clans/user?delete=<?= $cuser['id'] ?>">Исключить</a>
<?php endif; ?>


<?php endforeach; ?>
</div>

<?php

	require_once $config['root'] .'/protected/footermain.php';

?>