<?
require_once '../core/system.php';
require_once 'sys.php';
echo only_reg();
if($user['clan_id'] == 0) {
    header("Location: /clan/clanrating.php");
    exit();
} else {
    $clan = mysql_fetch_assoc(mysql_query("SELECT * FROM `clans` WHERE `id` = '".$user['clan_id']."' LIMIT 1"));
    $in_clan = TRUE;
    $header = 'Клан "'.$clan['name'].'"';
}
require_once '../core/head.php';

echo '<div class="player menuList">';
if(!$in_clan) {
    echo '<li><a href="/clan/create.php"><img src="/images/icon/clan.png">Создать клан</a></li>';
} else {
    $k_post = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `user` WHERE `clan_id` = '".$user['clan_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` = '".$user['clan_id']."'"));
    $header = 'Клан "'.htmlspecialchars($row['name']).'"';
    require_once '../core/head.php';
    $next_lvl = clan_lvl($row['exp']) + 1;
    $bar = round(($row['exp'] / $clan_lvl[$next_lvl]) * 100);
    echo '<div class="block_zero">
    <img class="float-left" src="/images/icon/clan/gerb/'.$row['gerb'].'.png" alt="" style="margin-right:3px;"/>
    <img src="/images/icon/clan/'.$row['storona'].'.png" alt=""/> <b>'.htmlspecialchars($row['name']).'</b><br/>
    <img src="/images/icon/level.png" alt=""/> Уровень: <b>'.clan_lvl($row['exp']).'</b><br/>
    <img src="/images/icon/exp.png" alt=""/> Опыт: '.show_exp($row['exp']).' / '.show_exp($clan_lvl[$next_lvl]).'<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">
    <li class="original">
    <a class="white" href="built.php">
    <img src="/images/icon/clan/building.png" height="30px" width="30px" style="float:left;margin-top:3px;"/>
    <img src="/images/icon/clan.png" />Клановые постройки<br/>
    <span class="medium">+ к параметрам и опыту</span></a>
    </li>
    </div>
    <div class="mini-line"></div>
    <div class="menuList">
    <li class="original">
    <a class="white" href="kazna.php">
    <img src="/images/icon/clan/19.png" height="30px" width="30px" style="float:left;margin-top:3px;"/>
    <img src="/images/icon/gold.png" />Казна клана<br/>
    <span class="medium"><img src="/images/icon/kamni.png">'.$row['kamni'].' 
    <img src="/images/icon/gold.png">'.$row['gold'].'</span></a>
    </li>
    </div>
    <div class="mini-line"></div>
    <div class="menuList">
    <li><a href="journal.php"><img src="/images/icon/arrow.png" alt=""/>Журнал клана</a></li>
<li><a href="quest.php"><img src="/images/icon/arrow.png" alt=""/>Клановые задания</a></li>
    <li><a href="chat.php"><img src="/images/icon/arrow.png" alt=""/>Чат клана</a></li>';
    if($row[$user['clan_prava'].'_invite'] == 1 || $user['clan_prava'] == 4) {
        echo '<li><a href="rekrut.php"><img src="/images/icon/clan.png" alt=""/> Рекрутинг</a></li>';
    }
    if( $user['clan_prava'] > 1) {
        echo '<li><a href="users.php"><img src="/images/icon/clan.png" alt=""/> Управление соклановцами</a></li>';
    }
    if($user['clan_prava'] >= 3) {
    echo '<li><a href="gerb.php"><img src="/images/icon/user.png" alt=""/>Герб клана</a></li>';
    }
    if($user['clan_prava'] >= 2) {
    echo '<li><a href="message.php"><img src="/images/icon/arrow.png" alt=""/>Объявление клану</a></li>';  
    }
    if($user['clan_prava'] == 4) {
    echo '<li><a href="settings.php"><img src="/images/icon/arrow.png" alt=""/>Настройки</a></li>';  
    }
    echo '</div>
    <div class="mini-line"></div>
    <div class="block_zero">
    <b>Состав клана: ('.(int) $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` = '".$user['clan_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` = '".$user['clan_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><div class="dot-line"></div>
    <li><a href="/clan/leave.php">Покинуть клан</a></li>
    </div>';
        
    if ($k_page>1){
        echo "<div class='dot-line'></div>";
        str('?',$k_page,$page);
    }
    
    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=""/> Клан создан: '.$row['date1'].'
    </div>';
}

echo '</div>';

include '../core/foot.php';