<?php
require_once '../core/system.php';
require_once 'sys.php';
echo only_reg();
$id = (int) $_GET['id'];
if($user['clan_id'] == $id) {
    header("Location: /clan");
    exit();
}

$k_post = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `user` WHERE `clan_id` = '$id'"), 0);
$k_page = k_page($k_post,$set['p_str']);
$page = page($k_page);
$start = $set['p_str']*$page-$set['p_str'];

$row = mysql_fetch_assoc(mysql_query("SELECT *, DATE_FORMAT(date, '%d.%m.%Y') AS `date1` FROM `clans` WHERE `id` = '$id'"));
if(empty($row['id'])) {
    header("Location: /clan/clanrating.php");
    exit();
}

$header = 'Клан "'.htmlspecialchars($row['name']).'"';
$name = htmlspecialchars($row['name']);
$nexp = show_exp($row['exp']);
$clvl = clan_lvl($row['exp']);
$next_lvl = clan_lvl($row['exp']) + 1;
$nextl = show_exp($clan_lvl[$next_lvl]);
$bar = round(($row['exp'] / $clan_lvl[$next_lvl]) * 100);
$date = $row['date1'];
$storona = $row['storona'];
require_once '../core/head.php';
echo '<div class="block_zero">
<img class="float-left" src="/images/icon/clan/gerb/'.(int) $row['gerb'].'.png" alt="" style="margin-right:3px;"/>
<img src="/images/icon/clan/'.$storona.'.png" alt=""/> <b>'.$name.'</b><br/>
<img src="/images/icon/level.png" alt=""/> Уровень: <b>'.$clvl.'</b><br/>
<img src="/images/icon/exp.png" alt=""/> Опыт: '.$nexp.' / '.$nextl.'<br/>
<div style="clear:both;"></div>
<div class="stat_bar"><div class="progress" style="width:'.$bar.'%"></div></div>
</div>
<div class="mini-line"></div>
<div class="menuList">
</div>
<div class="mini-line"></div>
<div class="block_zero">
<b>Состав клана: ('.$k_post.')</b>
</div>
<div class="dot-line"></div>
<div class="menuList">';
$q = mysql_query("SELECT `id`, `nick`, `storona`, `clan_prava` FROM `user` WHERE `clan_id` = '$id' ORDER BY `clan_prava` DESC LIMIT $start, $set[p_str]");
while($rowu = mysql_fetch_assoc($q)) {
    $exp = mysql_result(mysql_query("SELECT SUM(`exp`) FROM `jr_clan` WHERE `user_id` = '".$rowu['id']."' AND `clan_id` = '$id'"), 0);
    echo '<li><a href="/user/'.$rowu['id'].'/">
    <img src="/images/icon/'.$rowu['storona'].'.png" width="12" height="12" /> 
    '.$rowu['nick'].'<span class="white">, '.(int) $exp.' - '.clan_prava($rowu['clan_prava']).'</span></a></li>';
}

echo '</div>';

if(!empty($row['about'])) {
    echo '<div class="dot-line"></div><div class="block_zero">
    <img src="/images/icon/clan.png" alt=""/> О клане: '.htmlspecialchars($row['about']).'
    </div>';
}
echo '<div class="dot-line"></div><div class="block_zero">
<img src="/images/icon/clan.png" alt=""/> Клан создан: '.$date.'</div>';
  
if ($k_page>1){
    echo "<div class='dot-line'></div>";
    str('?id='.$id.'&',$k_page,$page);
}

require_once '../core/foot.php';