<?php
require_once('system/func.php');
auth(); //
$title = 'Арена';
require_once('system/header.php');


if(isset($_SESSION['relict'])){
echo msg($_SESSION['relict']);
unset($_SESSION['relict']);
}



$arena = mysql_fetch_assoc(mysql_query("SELECT * FROM `arena` WHERE `id_user` = '" . $myID . "'"));

$ability = mysql_query("SELECT * FROM `ability` WHERE `id_user` = '" . $myID . "' ORDER BY `id` LIMIT 1");
$ability = mysql_fetch_array($ability);

if($arena['rating'] >= 0){
    $rank_arena = "<font color='green'>Арена </font>";
} else if($arena['rating'] >= 4000){
    $rank_arena = "<font color='blue'>Арена</font>";
} else if($arena['rating'] >= 10000){
    $rank_arena = "<font color='violet'>Арена  </font>";
} else if($arena['rating'] >=25000){
    $rank_arena = "<font color ='yellow'>Арена   </font>";
} else if($arena['rating'] >= 70000){
    $rank_arena = "<font color='orange'> Арена   </font>";
}

//Если нету
if (!$arena) {
    mysql_query("INSERT INTO `arena` SET `id_user`='" . $myID . "' ");
    mysql_query("UPDATE `arena` SET `koll`=`koll` + '15' WHERE `id_user`='" . $myID . "' LIMIT 1");
    mysql_query("UPDATE `arena` SET  `UserName`='$user[login]'   WHERE `id_user`='" . $myID . "' LIMIT 1");
    header('location:/arena/');
    exit;
}

if (!isset($_GET['action']) && $arena['status'] == 1) {
    header('Location: /arena/fight/');
    exit();

}

//Идем в бой
if (isset($_GET['go']) && $arena['status'] == 0 && $arena['koll'] > 0) {
    $randTimeSeachOpponent = rand(5, 10);

    // Подбор противника
    $all_stats = array_sum(array($user['str'], $user['def'], $user['max_health']));
    $min_stats = $all_stats - (($all_stats/100)*10);
    $max_stats = $all_stats + (($all_stats/100)*10);

    $opp_user = mysql_query("SELECT `max_health`, `str`, `def`, `id` FROM `users` WHERE `id` != '" . $myID . "'");

    $user_array = array();
    while ($uid = mysql_fetch_assoc($opp_user)) {
        $opp_all = array_sum(array($uid['str'], $uid['def'], $uid['max_health']));
        if ($opp_all >= $min_stats && $opp_all <= $max_stats) {
            $user_array[$uid['id']] = $uid['id'];
        }
    }

    if (empty($user_array)) {
        $rand_opp = mysql_fetch_assoc(mysql_query("SELECT `id` FROM `users` WHERE `id` != '" . $myID . "' ORDER BY RAND() LIMIT 1"));
        $opp_id = $rand_opp['id'];
    } else {
        $opp_id = array_rand($user_array, 1);
    }

    $opp_user_arena = mysql_fetch_assoc(mysql_query("SELECT `max_health`, `str`, `def`, `login` FROM `users` WHERE `id` = '" . $opp_id . "'"));

    $ArenaOppHealth = $opp_user_arena['max_health'];
    $ArenaOppStr = $opp_user_arena['str'];
    $ArenaOppDef = $opp_user_arena['def'];
    $ArenaOppName = $opp_user_arena['login'];


    //Кампания
    if ($campaign['id_camp'] == 1) {
        mysql_query("UPDATE `campaign` SET `arena`='" . ($campaign['arena'] + 1) . "' WHERE `id_user`='" . $myID . "'");
    }

    //Кампания
    if ($campaign['id_camp'] == 3) {
        mysql_query("UPDATE `campaign` SET `arena`='" . ($campaign['arena'] + 1) . "' WHERE `id_user`='" . $myID . "'");
    }


    $hp = $user['max_health'];
    mysql_query("UPDATE `arena` SET `status` = '1' , `UserDmg` = '0'  , `time`='" . (time() + $randTimeSeachOpponent) . "', `koll` = `koll` - '1', `UserHp`='$hp'  ,  `EnemyHp`='$ArenaOppHealth' ,  `EnemyMaxHp`='$ArenaOppHealth', `EnemyDef`='$ArenaOppDef' , `EnemyStr`='$ArenaOppStr'  , `EnemyName`='$ArenaOppName'  WHERE `id_user`='" . $myID . "' LIMIT 1");
    header('Location: /arena/');

    exit();

}



if (isset($_GET['action']) && $_GET['action'] == 'fight' && $arena['status'] == 0) {
    header('Location: /arena/');
    exit();
}


switch (isset($_GET['action']) && $arena['status'] == 1) {
    case 'fight':
        $title = 'Бой';
        require_once('system/header.php');


        if ($arena['UserHp'] > $user['max_health']) {
            $arena['UserHp'] = $user['max_health'] + $ClassHp;
        }


        //Урон
        $crit = 10;
        $ChanseCrit = rand(1, 100);
        $dodje = 100;
        $dmg = 0;
        $dmg2 = 0;


        $dmg = ceil(($user['str'] / 4) - ($arena['EnemyDef'] / 8));

        $dmg2 = ceil(($arena['EnemyStr'] / 3) - ($user['def'] / 12));


        $dmg += rand(1, 10);
        $dmg2 += rand(1, 10);
        //Крит
        $log_crit = false;
        if ($ChanseCrit <= $crit) {
            $log_crit = true;
            $dmg *= 2;

        }
        if ($ability['statusDef'] == 1) {
            $dmg2 = ceil($dmg2 - ($ability['spellDefAbsorb'] + ($user['def'] / 20)));
        }
        $SpellStr = 0;
        if ($ability['statusStr'] == 1) {
            $SpellStr = ceil($dmg + ($ability['spellStrDmg'] + ($user['str'] / 15)));
        }

        $dmg += $SpellStr;


        if ($dmg2 < 0) {
            $dmg2 = rand(1, 10);
        }


        if ($dmg < 0) {
            $dmg = rand(1, 10);
        }


        //Умения  Сила жизни
        if (isset($_GET['UseSpellHp']) and $ability['statusHp'] == 0 and $ability['energy'] >= 1) {
            //Если юзали и меньше энергии
            if ($ability['statusHp'] == 1 and $ability['energy'] <= 1) {
                header('Location: /arena/fight/?attack');
                exit();

            }


            $SpellRespHp = ceil($ability['spellHpResp'] + ($user['max_health'] / 100 * 10));

            $logSpellHp = color('lime') . ' Вы полечились  на  ' . ico('ability', 'spell_health.png') . ' ' . $SpellRespHp . ' здоровья </font>';
            mysql_query("update `arena` set    `UserHp` = '" . ($arena['UserHp'] + $SpellRespHp) . "' where (`id_user` = '" . $myID . "')");
            mysql_query("update `ability` set    `energy` = '" . ($ability['energy'] - 1) . "'  ,  `statusHp` = '1'   where (`id_user` = '" . $myID . "')");
            mysql_query("INSERT INTO `arena_log` SET `time_log` = '" . time() . "', `id_user`='" . $myID . "', `text`='" . $logSpellHp . "'");
            header('Location: /arena/fight/');
            exit();


        }
        //Умения  Крепкая броня
        if (isset($_GET['UseSpellDef']) and $ability['statusDef'] == 0 and $ability['energy'] >= 1) {
            //Если юзали и меньше энергии
            if ($ability['statusDef'] == 1 and $ability['energy'] <= 1) {
                header('Location: /arena/fight/');
                exit();

            }
            $spellDef = ceil($ability['spellDefAbsorb'] + ($user['def'] / 20));

            $logSpellDef = color('lime') . ' Вы уменьшили урон   на  ' . ico('ability', 'spell_defence.png') . ' ' . $spellDef . ' урона </font>';
            mysql_query("update `ability` set    `energy` = '" . ($ability['energy'] - 1) . "'  ,  `statusDef` = '1'   where (`id_user` = '" . $myID . "')");
            mysql_query("INSERT INTO `arena_log` SET `time_log` = '" . time() . "', `id_user`='" . $myID . "', `text`='" . $logSpellDef . "'");
            header('Location: /arena/fight/');
            exit();
        }

        //Умения  Сила удара
        if (isset($_GET['UseSpellStr']) and $ability['statusStr'] == 0 and $ability['energy'] >= 1) {
            //Если юзали и меньше энергии
            if ($ability['statusStr'] == 1 and $ability['energy'] <= 1) {
                header('Location: /arena/fight/');
                exit();

            }
            $spellStr = ceil($ability['spellStrDmg'] + ($user['str'] / 15));

            $logSpellStr = color('orange') . ' Вы увеличили урон   на  ' . ico('ability', 'double_attack.jpg') . ' ' . $spellStr . '  </font>';
            mysql_query("update `ability` set    `energy` = '" . ($ability['energy'] - 1) . "'  ,  `statusStr` = '1'   where (`id_user` = '" . $myID . "')");
            mysql_query("INSERT INTO `arena_log` SET `time_log` = '" . time() . "', `id_user`='" . $myID . "', `text`='" . $logSpellStr . "'");


            header('Location: /arena/fight/');
            exit();

        }

        if ($arena['UserHp'] <= 0) {
            mysql_query("UPDATE  `arena` SET `status` = '2'   WHERE  `id_user`='" . $myID . "' LIMIT 1 ");


            header('Location: /arena/');
            exit();

        }

        if ($arena['EnemyHp'] <= 0) {
            mysql_query("UPDATE  `arena` SET `status` = '3'   WHERE  `id_user`='" . $myID . "' LIMIT 1 ");
            header('Location: /arena/');
            exit();

        }

        if (isset($_GET['attack'])) {


            if ($arena['timeAttack'] > time()) {

                $log = 'Вы промахнулись';

                mysql_query("INSERT INTO `arena_log` SET `time_log` = '" . time() . "', `id_user`='" . $myID . "', `text`='" . $log . "'");

                header('Location: /arena/');
                exit();
            } else {


                mysql_query("update `ability` set    `energy` = '" . ($ability['energy'] + 1) . "'     where (`id_user` = '" . $myID . "')");

                mysql_query("UPDATE `arena` SET `UserDmg`=`UserDmg`+'" . $dmg . "' WHERE `id_user`='" . $myID . "' LIMIT 1");
                mysql_query("UPDATE `arena` SET `timeAttack` = '" . (time() + 4) . "' WHERE `id_user`='" . $myID . "' LIMIT 1");

                mysql_query("UPDATE `arena` SET `EnemyHp`=`EnemyHp`-'" . $dmg . "' WHERE `id_user`='" . $myID . "' LIMIT 1");
                mysql_query("UPDATE `arena` SET `UserHp`=`UserHp`-'" . $dmg2 . "' WHERE `id_user`='" . $myID . "' LIMIT 1");
                $log = '<font color = green> Вы ударили ' . $arena['EnemyName'] . ' на  ' . $dmg . ' </font> ' . color('white') . '' . (isset($log_crit) ? '(крит)</font>' : '</font>') . '<br>
 <font color = red> ' . $arena['EnemyName'] . '  ударил Вас на  ' . $dmg2 . ' </font>';
                mysql_query("INSERT INTO `arena_log` SET `time_log` = '" . time() . "', `id_user`='" . $myID . "', `text`='" . $log . "'");

                if ($dmg2 >= $arena['UserHp']) {

                    mysql_query("UPDATE  `arena` SET `status` = '3'   WHERE  `id_user`='" . $myID . "' LIMIT 1 ");

                    // Выпадение сундука
                    $ChanseSunduk = 15;
                    $SundukQuatility = 1;
                    if (rand(1, 100) <= $ChanseSunduk) {
                        $r = rand(1, 100);
                        if ($r > 0 and $r <= 5) {
                            $SundukQuatility = 5;
                            $SundukLvl = 60;
                        } else if ($r >= 5 and $r <= 10) {
                            $SundukQuatility = 4;
                            $SundukLvl = 40;
                        } else if ($r >= 10 and $r <= 20) {
                            $SundukQuatility = 3;
                            $SundukLvl = 20;
                        } else if ($r >= 20 and $r <= 30) {
                            $SundukQuatility = 3;
                            $SundukLvl = 20;
                        } else if ($r >= 30 and $r <= 55) {
                            $SundukQuatility = 2;
                            $SundukLvl = 10;
                        } else if ($r >= 55 and $r <= 100) {
                            $SundukQuatility = 1;
                            $SundukLvl = 1;
                        }


                        switch ($SundukQuatility) {
                            case '1':
                                $color = '<font color="green">Обычный';
                                break;
                            case '2':
                                $color = '<font color="#1E90FF">Редкий';
                                break;
                            case '3':
                                $color = '<font color="violet">Эпический';
                                break;
                            case '4':
                                $color = '<font color="gold"> Уникальный';
                                break;
                            case '5':
                                $color = '<font color="Darkorange">Легендарный ';
                                break;
                        }
                        mysql_query("INSERT INTO `sunduk_user` SET `id_user` = '" . ($user['id']) . "' , `lvl` = '$SundukLvl', `quatility` = '$SundukQuatility', `status` = 'close'") or die(mysql_error());
                        $_SESSION['msg'] = div('header') . " Вы получили сундук $color </font><br><img src=' /images/other/chest.png' width='100px'> </div> ";
                    }

                    header('Location: /arena/');
                    exit();

                } else if ($dmg >= $arena['EnemyHp']) {
                    mysql_query("UPDATE  `arena` SET `status` = '2'   WHERE  `id_user`='" . $myID . "' LIMIT 1 ");

                    $quest = mysql_fetch_assoc(mysql_query("SELECT * FROM `quest` WHERE `id` = '20'"));
                    $q = mysql_fetch_assoc(mysql_query("SELECT * FROM `quest_user` WHERE `id_quest` = '$quest[id]' AND `id_user` = '$myID'"));
                    if ($q['last'] < time()) {
                        mysql_query("update `quest_user` set `koll` = `koll`+'1' where (`id` = '" . $q['id'] . "')");
                    }

                    // Выпадение сундука
                    $ChanseSunduk = 20;
                    $SundukQuatility = 1;
                    if (rand(1, 100) <= $ChanseSunduk) {
                        $r = rand(1, 100);
                        if ($r > 0 and $r <= 5) {
                            $SundukQuatility = 5;
                            $SundukLvl = 60;
                        } else if ($r >= 5 and $r <= 10) {
                            $SundukQuatility = 4;
                            $SundukLvl = 40;
                        } else if ($r >= 10 and $r <= 20) {
                            $SundukQuatility = 3;
                            $SundukLvl = 20;
                        } else if ($r >= 20 and $r <= 30) {
                            $SundukQuatility = 3;
                            $SundukLvl = 20;
                        } else if ($r >= 30 and $r <= 55) {
                            $SundukQuatility = 2;
                            $SundukLvl = 10;
                        } else if ($r >= 55 and $r <= 100) {
                            $SundukQuatility = 1;
                            $SundukLvl = 1;
                        }


                        switch ($SundukQuatility) {
                            case '1':
                                $color = '<font color="green">Обычный';
                                break;
                            case '2':
                                $color = '<font color="#1E90FF">Редкий';
                                break;
                            case '3':
                                $color = '<font color="violet">Эпический';
                                break;
                            case '4':
                                $color = '<font color="gold"> Уникальный';
                                break;
                            case '5':
                                $color = '<font color="Darkorange">Легендарный ';
                                break;
                        }
                        mysql_query("INSERT INTO `sunduk_user` SET `id_user` = '" . ($user['id']) . "' , `lvl` = '$SundukLvl', `quatility` = '$SundukQuatility', `status` = 'close'") or die(mysql_error());
                        $_SESSION['msg'] = div('header') . " Вы получили сундук $color </font><br><img src=' /images/other/chest.png' width='100px'> </div> ";
                    }


                    header('Location: /arena/');
                    exit();


                } else {


                    header('Location: /arena/fight/');

                    exit();

                }
            }

        }

        $ArenaEnemyHp = round($arena['EnemyHp'] / $arena['EnemyMaxHp'] * 100, 1);
        $ArenaUserHp = round($arena['UserHp'] / ($user['max_health']) * 100, 1);
echo div('wrapper');
echo div('center') . " " . $arena['EnemyName'] . " <br> " . ico('icons', 'str.png') . " " . $arena['EnemyStr'] . "
" . ico('icons', 'health.png') . "" . $arena['EnemyHp'] . "
" . ico('icons', 'def.png') . "" . $arena['EnemyDef'] . "";
        $user_avatar = mysql_fetch_assoc(mysql_query("SELECT `avatars` FROM `users` WHERE `login` = '" . text($arena['EnemyName']) . "'"));
        echo '<br>';
        if (!empty($user_avatar['avatars'])) {
            echo "<center><img src='/images/avatars/$user_avatar[avatars]'  width='180' height='180''></center>";
        } else {
            echo "<center><img src='/images/avatars/noavatar.png'  width='180' height='180''></center>";
        }
        echo '<br>';
     
        //echo "<div class='life_bar'><div class='life_bar-red' style='width:$ArenaEnemyHp%'></div></div></div>";

        if ($ability) {

            echo div('center');
            echo " <a href='?attack'>" . img('ability', 'spell_attack.png') . "</a>";
            if ($ability['statusHp'] == 1 or $ability['energy'] < 1) {
                echo " <a href='?'>" . spell('ability', 'spell_health.png ') . "</a>";
            } else {
                echo " <a href='?UseSpellHp'>" . img('ability', 'spell_health.png ') . "</a>";
            }


            if ($ability['statusDef'] == 1 or $ability['energy'] < 1) {
                echo " <a href='?'>" . spell('ability', 'spell_defence.png ') . "</a>";
            } else {
                echo " <a href='?UseSpellDef'>" . img('ability', 'spell_defence.png ') . "</a>";
            }


            if ($ability['statusStr'] == 1 or $ability['energy'] < 1) {
                echo " <a href='?'>" . spell('ability', 'double_attack.jpg ') . "</a>";
            } else {
                echo " <a href='?UseSpellStr'>" . img('ability', 'double_attack.jpg ') . "</a>";
            }

            echo "</div>";

        } else {
            echo "<a href='?attack'>" . img('ability', 'spell_attack.png') . "</a></br>";

        }

        echo "<br>" . ico('class', 'class.png') . "   $user[login]";

        echo '   <br> ' . ico('icons', 'str.png') . '' . $user['str'] . '
' . ico('icons', 'health.png') . '' . $arena['UserHp'] . '
' . ico('icons', 'def.png') . '' . $user['def'] . '';
        //echo "</div>";

       // echo "<div class='life_bar'><div class='life_bar-green' style='width:$ArenaUserHp%'></div></div></div>";

        $log = mysql_query("SELECT * FROM `arena_log` WHERE `id_user` = '" . $arena['id_user'] . "' ORDER BY(`id`) DESC LIMIT 15");
        //echo div('text_p1');

        while ($post = mysql_fetch_assoc($log)) {
            echo div('text_p1');
            echo  $post['text'] . "<br>";
            echo "</div>";
        }
        echo "</div>";
        require_once('system/footer.php');

        exit;

}
if (isset($_GET['end']) && $arena['status'] >= 2) {
    if ($arena['status'] == 2) {
        $RewardRating = ceil($arena['UserDmg'] / 250);
        $RewardGold = ceil($arena['UserDmg'] / 7);
        $RewardExp = ceil($arena['UserDmg'] / 10);

        mysql_query("UPDATE  `arena` SET `status` = '0'  WHERE  `id_user`='" . $myID . "'  ");
        mysql_query("UPDATE `arena` SET `rating`=`rating`+ '" . $RewardRating . "' WHERE `id_user`='" . $myID . "' LIMIT 1");

    }

    if ($arena['status'] == 3) {
        $RewardRating = ceil($arena['UserDmg'] / 300);
        $RewardGold = ceil($arena['UserDmg'] / 12);
        $RewardExp = ceil($arena['UserDmg'] / 10);
        mysql_query("UPDATE  `arena` SET `status` = '0'  WHERE  `id_user`='" . $myID . "'  ");
        mysql_query("UPDATE `arena` SET `rating`=`rating`- '" . $RewardRating . "' WHERE `id_user`='" . $myID . "' LIMIT 1");


    }
    if ($auction['name'] == 2) {
        $RewardExp = ceil($RewardExp * 2);
    }
    if ($auction['name'] == 2) {
        $RewardGold = ceil($RewardGold * 2);
    }

    mysql_query("UPDATE `users` SET `gold`=`gold`+ '" . $RewardGold . "' WHERE `id`='" . $myID . "' LIMIT 1");
    mysql_query("UPDATE `users` SET `exp`=`exp`+ '" . $RewardExp . "' WHERE `id`='" . $myID . "' LIMIT 1");
    $exp = $RewardExp;
    if ($user['clan_rang'] > 0) {

        mysql_query("UPDATE `users` SET `clan_exp` = '" . ($user['clan_exp'] + ceil($exp * $user['trust'] / 100)) . "' WHERE `id` = '" . $myID . "' LIMIT 1");
        mysql_query("UPDATE `clans` SET `exp` = `exp` + '" . ceil($exp * $user['trust'] / 100) . "' WHERE `id` = '" . $user['id_clan'] . "' LIMIT 1");
        mysql_query("UPDATE `users` SET `ResetClanExp` = `ResetClanExp` + '" . ceil($exp * $user['trust'] / 100) . "' WHERE `id` = '" . $myID . "' LIMIT 1");

    }

    $quest = mysql_fetch_assoc(mysql_query("SELECT * FROM `quest` WHERE `id` = '9'"));
    $q = mysql_fetch_assoc(mysql_query("SELECT * FROM `quest_user` WHERE `id_quest` = '$quest[id]' AND `id_user` = '$myID'"));
    if ($q['last'] < time()) {
        mysql_query("update `quest_user` set `koll` = `koll`+'1' where (`id` = '" . $q['id'] . "')");
    }

    mysql_query("update `ability` set    `energy` = '0'  ,  `statusHp` = '0'  ,  `statusDef` = '0' ,  `statusStr` = '0'  where (`id_user` = '" . $myID . "')");

    mysql_query("DELETE FROM `arena_log`  WHERE `id_user`='" . $myID . "'");

    $_SESSION['msg'] = 'Награда получена ';
    header('Location: /arena/?go');
    exit();

}


if ($arena['status'] == 2) {

    $RewardRating = ceil($arena['UserDmg'] / 250);
    $RewardGold = ceil($arena['UserDmg'] / 7);
    $RewardExp = ceil($arena['UserDmg'] / 10);
    if ($auction['name'] == 2) {
        $RewardExp = ceil($RewardExp * 2);
    }
    if ($auction['name'] == 2) {
        $RewardGold = ceil($RewardGold * 2);
    }
    echo div('header') . '   <span class="ribbon green  w75"><span class="r_end"><span class="r_cntr">Победa</span></span></span>';
    echo " Награда <br> <span class='gold'>" . ico('icons', 'gold.png') . " $RewardGold</span> <span class='white'> " . ico('icons', 'exp.png') . "$RewardExp </span> <br> <a href='/arena/?end'><div class='btn_grey'><span class='cb_end'><span class='cb_ttl'>Получить награду </div></span></span> </div>";
    require_once ('system/footer.php');

    exit;

}
if ($arena['status'] == 3) {

    $RewardRating = ceil($arena['UserDmg'] / 300);
    $RewardGold = ceil($arena['UserDmg'] / 12);
    $RewardExp = ceil($arena['UserDmg'] / 10);
    if ($auction['name'] == 2) {
        $RewardExp = ceil($RewardExp * 2);
    }
    if ($auction['name'] == 2) {
        $RewardGold = ceil($RewardGold * 2);
    }
    echo div('header') . '   <span class="ribbon red  w75"><span class="r_end"><span class="r_cntr">Поражение</span></span></span>';
    echo " Награда <br> <span class='gold'>" . ico('icons', 'gold.png') . " $RewardGold</span> <span class='white'> " . ico('icons', 'exp.png') . " $RewardExp</span><br> <a href='/arena/?end'><div class='btn_grey'><span class='cb_end'><span class='cb_ttl'>Получить награду </div></span></span> </div>";
    require_once ('system/footer.php');

    exit;

}
switch (isset($_GET['rating'])) {

    case 'arena':
        require_once('system/func.php');
        $title = 'Рейтинг арены';
        require_once('system/header.php');
        auth(); // Закроем от гостей
        $set['p_str'] = 20;
        $k_post = 1000;
        $k_page = k_page($k_post, $set['p_str']);
        $page = page($k_page);
        $start = $set['p_str'] * $page - $set['p_str'];
        echo '<span class="ribbon green  w75"><span class="r_end"><span class="r_cntr"> Рейтинг арены</span></span></span>';
        $q = mysql_query("SELECT * FROM `arena` ORDER BY `rating` DESC LIMIT 15");
        $i = 0;
        while ($post = mysql_fetch_assoc($q)) {

            $i ++;


            if ($i < 11) {
                if ($myID == $post['id']) {
                    echo div('wrapper');
                } else {
                    echo div('wrapper') . ' ';
                }
                echo  $i + $start .  "  <a href='/profile/$post[id_user]' data-ajax>$post[UserName] -</a>";
                echo " " . ico('icons', 'rating.png') . " <span class='white'>$post[rating] </span>";

                echo "</div>";


            }
        }

        $q = mysql_query("SELECT * FROM `arena` ORDER BY `rating`");
        $a = 0;
        while ($post = mysql_fetch_assoc($q)) {
            $a ++;
            if ($post['id'] == $myID) {
                if ($a <= 1000) {
                    echo "<div class='header'><span class='gold'>Вы находитесь на <b>$a</b> месте в рейтинге!</span></div>";
                } else {
                    echo "<div class='block'>Вы не участвуете в рейтинге...</div>";
                }

            }
        }

        echo div('wrapper header') . " <a href='/arena/'><div class='btn_grey'><span class='cb_end'><span class='cb_ttl'> Вернуться на арену</div></span></span></a></div>";

        require_once('system/footer.php');
        exit;
}

echo div('header');

echo div('title') . "   $rank_arena ";

echo "</div>";

echo " <img src='http://s47.radikal.ru/i117/1304/0f/199491a9eac7.jpg'></div>";


echo div('header');

if ($arena['koll'] > 0) {
    echo span('grey') . " </span> " . $arena['koll'];
}
echo " </div>";

echo div('wrapper header') . " <a href='?go'><div class='btn_grey'><span class='cb_end'><span class='cb_ttl'> Вступить в бой</div></span></span></a></div>";




//echo div('header') . "" . span('white') . " Ваш рейтинг:" . $arena['rating'] . "</span> </div>";
$tur = mysql_fetch_assoc(mysql_query("SELECT * FROM `arena` WHERE `id_user` = '1'"));
if (isset($_GET['on'])) {

    mysql_query("UPDATE  `arena` SET  `time`='" . (time() + 3600 * 24 * 7) . "'   WHERE  `id_user`='1' LIMIT 1 ");

}
//echo div('header') . "<a href='?rating=arena'><div class='btn_grey'><span class='cb_end'><span class='cb_ttl'> Рейтинг арены </div></span></span></a> <br>
//</span></small></div>";
echo div('wrapper gold') . "Каждый час вы  получаете 50 боев  арены <br></div>";


require_once('system/footer.php');
