<?php



define('_IN_JOHNCMS', 1);

echo '<div class="phdr"><a href="/shop/">Магазин '.str_replace('http://', '',$set['homeurl']).'</a> | Смена ника</div>';
// Узнаём цену
$price = mysql_fetch_assoc(mysql_query("SELECT `price` FROM `shop` WHERE `id` = 2"));
$a = $price['price'];

if (isset($_POST['submit'])) {
    // Принимаем дынные
    $kod = isset($_POST['kod']) ? trim($_POST['kod']) : '';
    $name = isset($_POST['name']) ? functions::check(mb_substr($_POST['name'], 0, 15)) : $datauser['name'];
    $error = false;

    // Проверка кода CAPTCHA
    if (empty($kod) || mb_strlen($kod) < 4)
        $error = $error . 'Tekshiruv kodi kiritilmadi!<br />';
    elseif ($kod != $_SESSION['code'])
        $error = $error . 'Tekshiruv kodi xato!<br />';
    unset($_SESSION['code']);

    if (empty($error)) {
        // Проверка монет
        if ($datauser['balans'] < $a) {
        $error = 'Sizda nikingizni almashtirish uchun yetarli mablag\' mavjud emas!<br/>';
        }

        // Проверка ника
        if (mb_strlen($name) < 2 || mb_strlen($name) > 15)
            $error = 'Nik uzunligi to\'g\'ri kelmaydi';
        $lat_nick = functions::rus_lat(mb_strtolower($name));
        if (preg_match("/[^0-9a-z\-\@\*\(\)\?\!\~\_\=\[\]]+/", $lat_nick))
            $error = 'Nikda ta\'qiqlangan belgilar!';
    }

    // Заносим данные в Базу
    if (empty($error)) {
        mysql_query("UPDATE `users` SET `balans` = '" . ($datauser['balans'] - $a) . "', `name` = '" . mysql_real_escape_string($name) . "' WHERE `id` = '$user_id'");
        echo '<div class="gmenu">Nik o\'zgartirildi!';
        echo '<br/><a href="/shop/">Do\'konga</a>';
        echo '</div>';
    } else {
        echo '<div class="rmenu"><p><b>XATO!</b><br />' . $error . '</p></div>';
    }

} else {
    // Форма ввода
    echo '<div class="list2"><b>'.$login.'</b>, Siz bu yerda nikingizni almashtirishingiz mumkin.<br/><span style="color:red">Muhim! Sizning nikingiz sayt bo\'ylab o\'zgaradi!<br/>Avval yozilgan psotlarda(forum, mehmonxona) va fikrlarda nik o\'zgarishsiz qoladi.<br/>Yangi Nik saylangandan so\'ng yozilgan postlarda sizning Yangi Nikingiz turadi<br/><b>Saytdagi profilingizga kirayotganda ro\'yxatdan o\'tish vaqtidagi nikingizdan foydalaning!!!</b></span><br/>Narxi: '.$a.' ball</div>';
    echo '<form action="/shop/index.php?act=nick" method="post"><div class="list1">';
    echo '<p><b>Nik:</b><br/><input type="text" name="name" maxlength="50" value="'.$datauser['name'].'" /><br/><small>Yangi nikingizni tanlang<br/>Minimal: 2belgi, maksimal: 15belgi</small></p></div>';
    echo '<div class="gmenu"><p><img src="/captcha.php?r=' . rand(1000, 9999) . '" alt="Проверочный код" border="1"/><br />';
    echo 'Tekshiruv kodi:<br/><input type="text" size="5" maxlength="5" name="kod"/></p></div>';
    echo '<div class="list2"><input type="submit" name="submit" value="O\'zgartirish"/></div></form>';
    }
?>