<?php
require_once('system/func.php');
$title = 'Главная';
require_once('system/header.php');

auth(); // Закроем от не авторизованных


$boss_user = mysql_query("SELECT * FROM `boss_user` WHERE `id_user` = '" . $myID . "' ORDER BY `id` LIMIT 1");
$boss_user = mysql_fetch_array($boss_user);
$boss = mysql_query("SELECT * FROM `boss` WHERE `id` = '" . $user['adventure_id'] . "' ORDER BY `id` LIMIT 1");
$boss = mysql_fetch_array($boss);
//Если нету игрока в приключениях
if ($user['adventure_id'] == 0) {
    mysql_query("UPDATE  `users` SET `adventure_id`  = '1' WHERE `id` = '" . $myID . "' ");
    mysql_query("INSERT INTO `boss_user` SET `id_user` = '$myID', `id_boss` = '1'");

}


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

//Если нету
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]', `avatars`='$user[avatars]'  ,  `UserSex`='$user[sex]'  WHERE `id_user`='" . $myID . "' LIMIT 1");

}


$clan_memb = mysql_fetch_array(mysql_query("SELECT * FROM `clan_memb` WHERE `id_user` = '$myID' ORDER BY `id` DESC LIMIT 1"));
$clan = mysql_fetch_array(mysql_query("SELECT * FROM `clans` WHERE `id` = '" . $clan_memb['id_clan'] . "' ORDER BY `id` DESC LIMIT 1"));
if ($clan_memb) {
    if (isset($_GET['clan_memb_net'])) {
        mysql_query("DELETE FROM `clan_memb` WHERE `id` = '" . $clan_memb['id'] . "'");
        header('Location:/');
        exit();
    }
    if (isset($_GET['clan_memb_ok']) and $user['side'] == $clan[side]) {
        mysql_query("update `users` set `id_clan` = '" . $clan[id] . "', `str` = `str` + '" . ($clan['str_plus']) . "', `def` = `def` + '" . ($clan['def_plus']) . "', `max_health` = `max_health` + '" . ($clan['max_health_plus']) . "', `clan_rang` = '1' , `trust` = '10'
 , `clan_exp` = '0' , `clan_gold` = '0' , `clan_almaz` = '0' , `ResetClanExp` = '0' where (`id` = '" . $myID . "')");
        mysql_query("DELETE FROM `clan_memb` WHERE `id_user` = '" . $myID . "'");
        $log = ' <a href="/profile/' . $user['id'] . '"> <a> ' . text($user['login']) . ' </a></a> вступил в клан';

        mysql_query("INSERT INTO `clan_journal` SET `clan` = '$clan[id]', `time` = '" . time() . "', `text` = '$log' ");

        header('Location: /clan/');
        exit();
    }
    echo '<div class="header"><span class="violet">Вас приглашают в клан</span>';
    echo ico('icons', 'clan.png') . "<a class='medium'><a href='/clan/$clan[id]/'><b>" . text($clan['name']) . "</b></a><br>";
    //echo  ico('icons', 'level.png')."<span class='white'>Уровень клана: $clan[level]<br> $clan[stat] к параметрам</span>";
    echo "<table style='width:100%;'>";
    echo "<td class='center'><div class='btn_grey'><li><a href='?clan_memb_ok'><font color='white'>Принять заявку</font></a></li></td>";
    echo "<td class='center'><li><div class='btn_grey'><a href='?clan_memb_net'><font color='orange'>Отклонить</font></a></li></td>";

    echo "</table></div>";
}
$news = mysql_query("SELECT * FROM `topic` WHERE `id_forum` = '1' ORDER BY `id` DESC LIMIT 1");
$news = mysql_fetch_array($news);
if ($news) {
    if (isset($_GET['view_news'])) {
        mysql_query("update `users` set `news_read` = '0' where (`id` = '" . $myID . "')");
        header("Location: /forum/sub/$news[id]?page=end");
        exit();
    }
    if ($user['news_read'] == 1 && $news['time'] > time() - 86400) {
        echo "<div class='block_l'>";
        echo "<center><a href='?view_news'> " . ico('icons', 'topic.png') . "" . color('lime') . "  Новая новость</center> </a></font>";
        echo "</div>";
    }

}


if ($user['id_partner'] == true) {
    $text = false;
    if ($user['level'] >= 20 && $user['check_ref'] == 0) {
        $text = 'Ваш реферал ' . htmlspecialchars($user['login']) . ', получил <img src="/images/icons/level.png" width="20" /> 20 уровень и Вы получаете награду: ' . getCountDiamondRef(0) . ' <img src="/images/icons/almaz.png" width="20" /> алмазов!';
        $arrayPrize = ['diamond' => 100, 'check' => 1];
    } else if ($user['level'] >= 40 && $user['check_ref'] == 1) {
        $text = 'Ваш реферал ' . htmlspecialchars($user['login']) . ', получил <img src="/images/icons/level.png" width="20" /> 40 уровень и Вы получаете награду: ' . getCountDiamondRef(1) . ' <img src="/images/icons/almaz.png" width="20" /> алмазов!';
        $arrayPrize = ['diamond' => 200, 'check' => 2];
    } else if ($user['level'] >= 60 && $user['check_ref'] == 2) {
        $text = 'Ваш реферал ' . htmlspecialchars($user['login']) . ', получил <img src="/images/icons/level.png" width="20" /> 60 уровень и Вы получаете награду: ' . getCountDiamondRef(2) . ' <img src="/images/icons/almaz.png" width="20" /> алмазов!';
        $arrayPrize = ['diamond' => 500, 'check' => 3];
    }

    if ($text == true) {
        mysql_query("INSERT INTO `mail` SET `in` = '1', `out` = '" . $user['id_partner'] . "', `text` = '$text' , `time` = '" . time() . "'");
        mysql_query("update `users` set `almaz` = `almaz` + '" . $arrayPrize['diamond'] . "' where (`id` = '" . $user['id_partner'] . "')");
        mysql_query("update `users` set `check_ref` = '" . $arrayPrize['check'] . "' where (`id` = '" . $user['id'] . "')");
    }
}


$q = mysql_query("SELECT * FROM `quest` ORDER BY `id` ASC");
while ($post = mysql_fetch_assoc($q)) {
    $quest = mysql_fetch_assoc(mysql_query("SELECT * FROM `quest_user` WHERE `id_quest` = '" . $post['id'] . "' AND `id_user` = '$myID'"));
    if (!$quest) {
        mysql_query("INSERT INTO `quest_user` SET `id_user` = '$myID', `id_quest` = '$post[id]', `max_koll` = '$post[koll]'");
    }
}


if ($user['save'] == 1) {
    if (isset($_GET['w']) and $user['save'] == 1) {
        mysql_query("update `users` set `sex` = 'w' , `save` = '2' where (`id` = '" . $myID . "')");

    }
    if (isset($_GET['m']) and $user['save'] == 1) {
        mysql_query("update `users` set `sex` = 'm' , `save` = '2' where (`id` = '" . $myID . "')");

    }

    echo div('block_c') . "Выберите пол персонажа<br>";


    echo "<div class='btn_grey'><span class='cb_end'><span class='cb_ttl'> <a href='?w'>Женский</div></span></span></a>";
    echo "<div class='btn_grey'><span class='cb_end'><span class='cb_ttl'> <a href='?m'>Мужской</div></span></span></a>";

    exit();

}

if ($user['save'] == 2) {
    $err = false;
    if (isset($_REQUEST['add'])) {
        $login = text($_POST['login']);
        $sql = mysql_query("SELECT COUNT(`id`) FROM `users` WHERE `login` = '" . mysql_real_escape_string($login) . "'"); // Доступность логина
        if (empty($login)) {
            $err = 'Введите логин';
        }
        if (mysql_result($sql, 0) > 0) {
            $err = 'Такой логин уже занят';
        }
        if (mb_strlen($login) > 20 or mb_strlen($login) < 3) {
            $err = 'Логин не может быть короче 3 и длиннее 20 символов';
        }
        if (!$err) {
            mysql_query("UPDATE `users` SET `login` = '" . mysql_real_escape_string($login) . "' , `save` = '3' where (`id` = '" . $myID . "')");
            setcookie('login', $login, time() + 86400 * 365, '/');
            header('Location: ?');
            exit();
        } else {
            $_SESSION['msg'] = $err;
            header('Location: ?login');
            exit();
        }
    }

    echo "<div class='block_c'>";
    echo '<form action="" method="post">';
    echo 'Введите имя персонажа<br><input type="text" name="login" maxlength="50" value="" /><br/>';
    echo '<input type="submit" name="add" class="btn_grey="Сохранить">';
    echo '</form></div>';
    exit();
}

if ($user['save'] == 3) {
    $err = false;
    if (isset($_REQUEST['e'])) {
        $email = text($_POST['email']);
        $sql = mysql_query("SELECT COUNT(`id`) FROM `users` WHERE `email` = '" . mysql_real_escape_string($email) . "'"); // Доступность логина
        if (empty($email)) {
            $err = 'Введите email';
        }
        if (mysql_result($sql, 0) > 0) {
            $err = 'Такой емайл зарегистрован';
        }
        if (mb_strlen($email) > 40 or mb_strlen($email) < 3) {
            $err = 'Email не может быть короче 3 и длиннее 40 символов';
        }
        if (!$err) {
            mysql_query("UPDATE `users` SET `email` = '" . mysql_real_escape_string($email) . "' , `save` = '4' where (`id` = '" . $myID . "')");
            $_SESSION['msg'] = "Email <b>$email</b>";
            header('Location: ?');
            exit();
        } else {
            $_SESSION['msg'] = $err;
            header('Location: ?');
            exit();
        }
    }
    echo "<div class='block_c'>";
    echo '<form action="" method="post">';
    echo 'Ввведите email<br><input type="text" name="email" maxlength="50" value="" /><br/>';
    echo '<input type="submit" name="e" class="btn_grey" value="Сохранить">';
    echo '</form><br>Email нужен для восстановление пароля </div>';
    exit();
}

if ($user['save'] == 4) {

    if (isset($_REQUEST['add'])) {
        $err = false;
        $pass = text($_POST['pass']);
        $repass = text($_POST['repass']);
        if (empty($pass)) {
            $err = 'Введите пароль';
        } elseif (empty($repass)) {
            $err = 'Введите пароль еще раз';
        } elseif (!preg_match('|^[a-z0-9\-]+$|i', $pass)) {
            $err = 'Кириллица в пароле запрещена';
        } elseif (mb_strlen($pass) > 20 or mb_strlen($pass) < 3) {
            $err = 'Пароль не может быть короче 3 и длиннее 20 символов';
        } elseif ($pass != $repass) {
            $err = 'Пароли не совпадают';
        }
        if (!$err) {
            mysql_query("UPDATE `users` SET `password` = '" . md5($pass) . "' , `save` = '5' WHERE `id` = '" . $myID . "'");
            setcookie('password', md5($pass), time() + 86400 * 365, '/');
            $_SESSION['msg'] = "Ваш пароль <b>$pass</b><br>Вам выдано 180 алмазов.<br>Пройдите в магазин и купите несколько вещей, для того, что бы начать сражаться на арене.";
            header('Location: ?');
            exit();
        } else {
            $_SESSION['msg'] = $err;
            header('Location: ?');
            exit();
        }
    }

    echo "<div class='block_c'>" . span('almaz') . " Придумайте сложный пароль что бы защитить своего героя</span><br><br>";

    echo '<form action="" method="post">';
    echo 'Пароль:<br><input type="password" name="pass" maxlength="50" value="" /><br/>';
    echo 'Повторите  пароль:<br><input type="password" name="repass" maxlength="50" value="" /><br/>';
    echo color('white') . '<center><input type="submit" name="add" class="btn_grey" value="Продолжить ">';
    echo '</form>';
    echo "</div>";
    exit;
}

if (isset($_GET['complete']) and $user['action_fight'] == 0 and $user['action_koll'] >= ($user['level'] * 4)) {
    mysql_query("INSERT INTO `sunduk_user` SET `id_user` = '$myID', `status` = 'close'  , `lvl` = '20'  , `quatility` = '5' ");
    mysql_query("update `users` set `action_fight` = '1'  where (`id` = '" . $myID . "')");

    $_SESSION['msg'] = "Сундук получен ";
    header('Location: ?');
    exit();
}
//if($user['action_fight'] == 0  ){

//    echo div('block_c')." Победи  ".(($user['level'] * 4) -  $user['action_koll']  )." врагов в сражение и получи <font color='orange'>Легендарный сундук

//    </font><br>";
//   if($user['action_koll']  >= $user['level'] * 4 )
//   echo " <div class='cbtn green mt2 w50'><span class='cb_end'><span class='cb_ttl'> <a href='?complete' > Завершить </div></span></span></a></div> ";
//   else
// echo " <div class='cbtn blue mt2 w50'><span class='cb_end'><span class='cb_ttl'> <a href='/fights/' > К выполнению  </div></span></span></a></div> ";

//}

//if($user['access'] >=1 and $_SERVER['PHP_SELF'] == '/main.php')echo '<div class="block_c"><a href="/settGame/adm_chat/"data-ajax> Админ-чат</center> </div></a>';


//Adminka


if (date('j') != $user['present_day']) {
    getDay($user['id']);
}
$batle_orc = mysql_query("SELECT `resp_boss` FROM `bashna` WHERE `id` = '1' ORDER BY `id` LIMIT 1");
$batle_orc = mysql_fetch_assoc($batle_orc);

if (($batle_orc['resp_boss'] - time()) <= 600 && ($batle_orc['resp_boss'] - time()) > 0) {
    //echo '<div class="bbtn mb5"><img src="/images/icons/fight.png" width="22px"> <span class="white">До боя с Орком:</span> ' . tl($batle['resp_boss'] - time()) . '</div>';
    //} else {
    //echo '<div class="bbtn mb5"><a class="llb" href="/battle_ork"><img src="/images/icons/fight.png" width="22px"><span class="white">Идёт бой с орком</span></a></div>';
}


//$timeOrk = null;
//if ($batle['resp_boss'] < time()) {
//  $timeOrk = "На нас напал орк!  <br><div class='btn_grey'><span class='cb_end'><span class='cb_ttl'><a href='/battle_ork/' > Сразиться с орком</div></span></span> </a>";

//} else {
//$timeOrk = " <br><span style ='float:right;'>" . isTimer($batle['resp_boss']) . "</span>";
//}


//echo "<center><img src='/images/pims.png'> </a></center></div>";
echo "<center><img src='/images/1111.jpg'> </a></center></div>";


if ($user['access'] == 2 and $_SERVER['PHP_SELF'] == '/main.php') {
    echo '<div class="wrapper center"><a href="/65468465465464646556"data-ajax> Админ-Панель</center></div> </a>';
}
//Статус приключеий
$camp = mysql_fetch_assoc(mysql_query("SELECT * FROM `campaign` WHERE `id_user`='" . $myID . "' LIMIT 1"));

if ($boss_user['last'] < time()) {
    $status = color('lime') . " К бою готовы <br></font>";
    $plus = color('lime') . " (+) </font>";
} else {
    $status = color('grey') . " Доступно через:   " . span('white') . "" . tl($boss_user['last'] - time()) . " </span><br>";
}
$boss_stat = $boss['str'] + $boss['def'] + $boss['max_health'];
$user_stat = $user['str'] + $user['def'] + $user['max_health'];
if ($boss_stat > $user_stat) {
    $complexity = color('red') . "тяжело</font>";
} else {
    $complexity = color('lime') . "легко</font>";
}

if ($camp['limit'] < time()) {

    $camp_plus = color('lime') . " (+) </font><br><br>";
} else {
    $camp_status = color('grey') . " <br>Доступно через:   " . span('white') . "" . tl($camp['limit'] - time()) . " </span><br>";

}


if ($arena['koll'] > 0) {
    $Arenastatus = color('lime') ." " . $arena['koll'] . "";
    $arenap = color('lime') . " (+) </font>";
} else {
    $Arenastatus = color('grey') . " Доступно через: " . span('white') . "" . isTimer($arena['last']) . " </span>";
}
echo "<div class='header'>";

//echo "<table style='width:100%;'>";
//echo div('wrapper');
//echo "  <a href='/mor.php'><div class='oh'><img src='/images/icons/adventure.png' width='50px'></div> <span class='white'>Приключение $plus </a></span><br>$status<br></div>";
//echo "<div class ='bbtn mb5'>";

//echo "<td class='center'><li> <div class='bbtn mb5'> <div class='ssilki_dop p_0'><a href='/arena/?'>" . img('icons', 'arena.png') . "<br> Арена  $arenap</a></li></td>";
//if ($arena['koll'] > 0) {
echo "<div class ='main_link'>";

echo "<a class='llb'  href='/arena/?go'><div class='ssilki_dop p_0'><img src='/images/icons/arena.png' width ='28px'>    Арена  $arenap</span></div></div>";
//}
//echo "  <td class='center'><li><a href='/arena/?'><div class='llb'><div class='ssilki_dop p_0'><img src='/images/icons/arena.png' width='22px'> Арена  $arenap </div></div></li></td>";
//echo "  <a href='/arena/?'><div class='oh'><img src='/images/icons/arena.png' width='45px'></div> Арена $arenap </a></span><br> $Arenastatus <br><br></div>";

//echo "<td class='center'><li> <div class='bbtn mb5'> <div class='ssilki_dop p_0'><a href='/main'>" . img('other', 'home.png') . "<br> Главная</a></li></td>";

//echo "</div>";


//echo "<div class ='bbtn mb5'>";
//echo "<a class='llb' href='/action/'><img src='/images/icons/fight.png' width ='22px'><span class='white'> Акции ".color('red')." - </font> </span></div>";


//if ($user['level'] >= 5) {
echo "<div class ='main_link'>";

echo "<a class='llb' href='/fights'><div class='ssilki_dop p_0'><img src='/images/icons/fight.png' width ='28px'> Сражение</span></div></div>";

//echo "<div class ='bbtn mb5'>";
//echo "<a class='mbtn mb_lblue mt2 mb_gray'><span class='mb_end'><span class='ico portal_d'><span class='ttl minor'> href='/fights/'><span class='small fr pr10'><img src='/images/icons/fight.png' width ='22px'> Сражение  </span></span></span></span>";
//echo "</table></div>";
//}
//echo "<div class ='bbtn mb5'>";
//echo "<a class='llb' href='/battleclans/index.php'><div class='ssilki_dop p_0'><img src='/images/icons/sum_stat.png' width ='22px'><span class='white'> Клановые битвы  </span></div></div>";
//echo "<div class='header'>";

echo "<div class ='main_link'>";
echo "<a class='llb' href='/team_war.php'><div class='ssilki_dop p_0'><img src='/images/icons/ten.png' width ='28px'> Выживание </span></div></div>";

if ($user['level'] >= 5) {
    $battleGoPlus = null;
    if (mysql_result(mysql_query("SELECT COUNT(*) FROM `demons_battles` WHERE `status` = 'battle' "), 0) == true) {
        $battleGoPlus = '<span style="color: lime"> (+)</span>';
    }

























    echo "<div class ='main_link'>";
    echo "<a class='llb' href='/invasion'><div class='ssilki_dop p_0'><img src='/images/icons/st.png' width ='28px'> Вторжение</span>" . $battleGoPlus . "</div></div>";
}


$battleGo = null;
if ($user['id_clan'] == true) {
    $clan_monsters_fight_clan = mysql_fetch_assoc(mysql_query("SELECT `time` FROM `clan_monsters_fight` WHERE `id_clan` = '$user[id_clan]' "));
    if ($clan_monsters_fight_clan['time'] > time()) {
        $battleGo = '<span style="color: lime"> (+)</span>';
    }
    echo "<div class ='main_link'>";
    echo "<a class='llb' href='/monsters/'><div class='ssilki_dop p_0'><img src='/images/icons/ork.png' width ='28px'> Монстры" . $battleGo . "</div></div>";

}
echo "<div class ='main_link'>";
    echo "<a class='llb' href='/battle/basement/'><div class='ssilki_dop p_0'><img src='/images/icons/equip_weapon_frozen_6.png' width ='28px'> Логово" . $battleGo . "</div></div>";
//if($user['level']>=7){
//echo "<div class ='bbtn mb5'>";
//echo "<a class='llb' href='/coliseum/'><img src='/images/icons/ten.png' width ='22px'><span class='white'>Колизей</span></div>";
//}
$statusCamp = null;
//if ($campaign['arena'] >= 10 and $campaign['item'] >= 5 and $user['str'] >= 100 and $user['def'] >= 100 and $campaign['quest'] >= 3 and $campaign['farm'] >= 2 and $campaign['id_camp'] == 1) {
// $statusCamp = color('lime') . "+</font>";
//}

//if ($user['level'] >= 10 and $campaign['fight'] >= 50 and $campaign['adventure'] >= 10 and $user['id_clan'] >= 1 and $campaign['sunduk'] >= 4 and $campaign['skull'] >= 100 and $campaign['id_camp'] == 2) {
// $statusCamp = color('lime') . "+</font>";
//}

//if ($campaign['ork'] >= 15000 and $campaign['arena'] >= 75 and $user['str'] >= 650 and $user['def'] >= 650 and $user['max_health'] >= 700 and $campaign['farm'] >= 35 and $campaign['id_camp'] == 3) {
// $statusCamp = color('lime') . "+</font>";
//}

//if ($campaign['fight'] >= 250 and $campaign['quest'] >= 15 and $campaign['sunduk'] >= 25 and $user['level'] >= 20 and $user['clan_exp'] >= 75000 and $campaign['itemLvl'] >= 15 and $campaign['id_camp'] == 4) {
//$statusCamp = color('lime') . "+</font>";
//}





echo "<div class ='main_link'>";
echo "<a class='llb' href='/campaign'><div class='ssilki_dop p_0'><img src='/images/icons/jour.png' width ='28px'> Кампания $statusCamp  </span></div></div>";
$quest = mysql_fetch_assoc(mysql_query("SELECT * FROM `quest` WHERE `id` = '$q[id_quest]'"));

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

$statusQuest = null;
if ($q['koll'] >= $q['max_koll']) {
    $statusQuest = color('lime') . "+</font>";
}

echo "<div class ='main_link'>";
echo "<a class='llb' href='/quest'><div class='ssilki_dop p_0'><img src='/images/icons/quest.png' width ='28px'> Задания $statusQuest  </span></div></div>";
echo "<div class ='main_link'>";
echo "<a class='llb' href='/shop'><div class='ssilki_dop p_0'><img src='/images/icons/ItemShop.png' width ='28px'> Рыночная площадь  </span></div></div>";
//echo "<div class ='bbtn mb5'>";



echo "<div class ='main_link'>";
echo "<a class='llb' href='/fish.php'><div class='ssilki_dop p_0'> <img src='/images/icons/pit.png' width ='28px'> Охота</div></div>";


echo "<div class ='main_link'>";
echo "<a class='llb' href='/farm.php'><div class='ssilki_dop p_0'> <img src='/images/icons/farm.png' width ='28px'> Поход</span></div></div>";


echo "<div class ='main_link'>";
echo "<a class='llb' href='/cel.php'> <div class='ssilki_dop p_0'><img src='/images/icons/heart.png' width ='28px'> Целитильница</div></div>";
//echo "<div class ='bbtn mb5'>";

//echo "<a class='llb' href='/xsolla/index.php'> <img src='/images/icons/almaz.png' width ='22px'><span class='almaz'> Купить алмазы  </span></div></font></span></div>";

/*
if (isset($_GET['almaz'])) {
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, 'https://api.xsolla.com/merchant/merchants/23775/token');
    $h = array("Content-Type: application/json");
    curl_setopt($curl, CURLOPT_HTTPHEADER, $h);
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($curl, CURLOPT_USERPWD, '23775:KhlODRtQ93mvkAzm');
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_POST, true);
    $json = array(
        "user" => array("id" => array("value" => $user['id'], "hidden" => true)),
        "settings" => array("project_id" => 16248)
    );
    $json = json_encode($json);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
    $token = json_decode(curl_exec($curl))->token;
    curl_close($curl);
    if (isset($token)) {
        header("Location:https://secure.xsolla.com/paystation2/?access_token=$token");
        exit;
    } else {
        $_SESSION['msg'] = 'Ошибка платежной системы - обратитесь к администратору';
        header("Location:/xsolla/");
        exit;
    }
}*/
//$title = 'Покупка Алмазов';
//require_once ('../system/header.php');
//echo "<div class='block'>";
//echo ico('icons','arrow.png')." Купить золото | <a href='/pay'>Обменник</a> ";
if ($user['koll_gold'] > 0) {
    echo "<font color='green'>(+)</font>";
}
//echo "</div>";
echo "<div class ='main_link'>";

$getSale = mysql_fetch_assoc(mysql_query("SELECT * FROM `avenax_admin` WHERE `id` = '1'"));
$bonusXsolla = null;
if (!empty($getSale) && $getSale['sale_xsolla_time'] > time()) {
    $bonusXsolla = '<span style="color: red">+' . $getSale['sale_xsolla'] . '%</span>';
}

echo "<a class='llb' href='/diamond'> <div class='ssilki_dop p_0'><img src='/images/icons/alm.png' width ='28px'><span class='almaz'> Купить алмазы  " . $bonusXsolla . "</font></span></div></div>";


echo "<div class ='main_link'>";
echo "<a class='llb' href='/rating'><div class='ssilki_dop p_0'> <img src='/images/icons/rating.png' width ='28px'> Зал славы  </div></font></span></div>";


echo "<div class ='main_link'>";
echo "<a class='llb' href='/clans'><div class='ssilki_dop p_0'> <img src='/images/icons/clan.png' width ='28px'> Рейтинг кланов</span></div></font></span></div>";

//echo "<div class ='bbtn mb5'>";
//echo "<a class='llb' href='/contest.php'> <div class='ssilki_dop p_0'><img src='/images/icons/adventure.png' width ='22px'> Рейтинг рефералов</span></div></font></span></div>";

require_once('system/footer.php');

