View file vobog-wmzo_ru/top/index.php

File size: 5.25Kb
<?php
require_once '../system/core.php';
$title = 'Рейтинг Героев';
require_once '../system/thead.php';

$ligas_names = [
    0 => 'Бронзовая', 1 => 'Серебряная', 2 => 'Золотая', 
    3 => 'Платиновая', 4 => 'Алмазная', 5 => 'Элитная', 
    6 => 'Магическая', 7 => 'Тиданов', 8 => 'Властителей'
];

$sort = isset($_GET['sort']) ? $_GET['sort'] : 'exp';
switch ($sort) {
    case 'liga': $order_sql = "`liga` DESC, `liga_rating` DESC"; $sort_name = "Лигам"; break;
    case 'power': $order_sql = "(`str` * 1.5 + `def` * 0.5 + `level` * 10) DESC"; $sort_name = "Мощи"; break;
    case 'osada': $order_sql = "`osada` DESC"; $sort_name = "Осаде"; break;
    case 'shadow': $order_sql = "(SELECT points FROM shadow_tournament WHERE user_id = users.id) DESC"; $sort_name = "Теням"; break;
    default: $order_sql = "`exp` DESC, `level` DESC"; $sort_name = "Опыту"; break;
}

$per_page = 10;
$total_users = (int)db_query("SELECT COUNT(*) FROM `users`")->fetchColumn();
$total_pages = ceil($total_users / $per_page);
$page = isset($_GET['page']) ? max(1, (int)$_GET['page']) : 1;
$start = ($page - 1) * $per_page;

echo '<div style="text-align:center; margin-bottom:10px;"><div class="head-new"><div class="b-new" style="display:inline-block; width:90%;">РЕЙТИНГ ГЕРОЕВ</div></div></div>';

echo '<div style="display: flex; justify-content: center; gap: 4px; margin: 10px 5px; flex-wrap: wrap;">';
$menu = ['exp'=>'Опыт', 'liga'=>'Лиги', 'power'=>'Мощь', 'osada'=>'Осада', 'shadow'=>'Тени'];
foreach($menu as $k => $v) {
    $active = ($sort == $k);
    echo '<a href="?sort='.$k.'" style="flex: 1; min-width: 55px; text-decoration: none; margin-bottom:4px;">
        <div style="background: '.($active?'#1d3e4f':'rgba(0,0,0,0.3)').'; border: 1px solid '.($active?'#49acfc':'#183543').'; border-radius: 3px; padding: 6px 0; text-align: center;">
            <span style="color: '.($active?'#fff':'#477193').'; font-size: 9px; font-weight: bold; text-transform: uppercase;">'.$v.'</span>
        </div>
    </a>';
}
echo '</div>';

$q = db_query("SELECT *, (SELECT points FROM shadow_tournament WHERE user_id = users.id) as sh_pts FROM `users` ORDER BY $order_sql LIMIT $start, $per_page");
$rank = $start + 1;

while ($top = $q->fetch()) {
    $is_me = ($user['id'] == $top['id']);
    $side_icon = ($top['side'] == 1) ? '☀️' : '🌑';
    $side_color = ($top['side'] == 1) ? '#49acfc' : '#ff4444';
    
    if ($sort == 'liga') {
        $val = '<span style="color: #ffd70b; font-size: 10px;">' . ($ligas_names[(int)$top['liga']] ?? 'Легенда') . '</span>';
    } elseif ($sort == 'power') {
        $pwr = ($top['str'] * 1.5) + ($top['def'] * 0.5) + ($top['level'] * 10);
        $val = n_f($pwr) . ' <span style="color: #49fc72; font-size: 9px;">PWR</span>';
    } elseif ($sort == 'osada') {
        $val = n_f($top['osada']) . ' <span style="color: #ff4444; font-size: 9px;">УРОН</span>';
    } elseif ($sort == 'shadow') {
        $val = n_f($top['sh_pts'] ?? 0) . ' <span style="color: #666; font-size: 9px;">PTS</span>';
    } else {
        $val = n_f($top['exp']) . ' <span style="color: #ffd70b; font-size: 9px;">EXP</span>';
    }

    echo '<div class="msg-new" style="'.($is_me ? 'border: 1px solid #49acfc;' : '').'">
        <div class="wr4-new" style="padding:10px; display:flex; justify-content:space-between; align-items:center;">
            <div style="display:flex; align-items:center; gap:8px;">
                <div style="width:25px; color:'.($rank <= 3 ? '#ffd70b' : '#477193').'; font-weight:bold; font-size:12px;">#'.$rank.'</div>
                <div style="width:22px; height:22px; background:rgba(0,0,0,0.3); border-radius:3px; display:flex; align-items:center; justify-content:center;">
                    <img src="/style/icons/liga/'.((int)$top['liga']+1).'.png" style="width:16px;" onerror="this.src=\'/style/icons/liga.png\'">
                </div>
                <div>
                    <a href="/profile.php?id='.$top['id'].'" style="text-decoration:none; color:#fff; font-weight:bold; font-size:12px;">'.$top['login'].'</a>
                    <span style="color:#666; font-size:10px;">['.$top['level'].']</span>
                    <div style="font-size:9px; color:'.$side_color.'; margin-top:1px;">'.$side_icon.' '.($top['side'] == 1 ? 'СВЕТ' : 'ТЬМА').'</div>
                </div>
            </div>
            <div style="text-align:right; font-weight:bold; color:#fff; font-size:11px;">'.$val.'</div>
        </div>
    </div>';
    $rank++;
}

if ($total_pages > 1) {
    echo '<div style="margin:15px 0; text-align:center;">';
    if ($page > 1) echo '<a href="?sort='.$sort.'&page='.($page-1).'" class="bbtn-new" style="display:inline-block; width:75px; text-decoration:none; margin:0 4px;"><span class="lbl-new" style="font-size:10px;">НАЗАД</span></a>';
    echo '<span style="color:#666; font-size:11px;">'.$page.' / '.$total_pages.'</span>';
    if ($page < $total_pages) echo '<a href="?sort='.$sort.'&page='.($page+1).'" class="bbtn-new" style="display:inline-block; width:75px; text-decoration:none; margin:0 4px;"><span class="lbl-new" style="font-size:10px;">ДАЛЕЕ</span></a>';
    echo '</div>';
}

require_once '../system/tfoot.php';
?>