<?php

define('_IN_JOHNCMS', 1);
$headmod = 'color';
$textl = 'Nik fonini o\'zgartirish';
require ("../incfiles/core.php");
require ("../incfiles/head.php");
echo '<div class="phdr">Onlay do`kon | Nik Foni</div>';
// Narxi
$a = '500';

if (isset($_POST['submit'])) {
    $kod = isset($_POST['kod']) ? trim($_POST['kod']) : '';
    $clr = isset($_POST['color']) ? functions::check(mb_substr($_POST['color'], 0, 25)) : '';
    $error = false;

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

    if (empty($clr) || mb_strlen($clr) < 3)
$error = $error . 'Rangni kiritmadingiz!<br />';
    if (preg_match("/[^0-9a-zA-Z] /", $clr))
$error = 'Rang nomi xato!<br/>';

    if (empty($error)) {
        if ($datauser['balans'] < $a) {
$error = 'Ball yetarli emas!<br/>';
        }
    }

    if (empty($error)) {
        mysql_query("UPDATE `users` SET `balans` = '" . ($datauser['balans'] - $a) . "', `cfon` = '" . mysql_real_escape_string($clr) . "' WHERE `id` = '$user_id'");
echo '<div class="gmenu">Tabriklaymiz Nikingizning foni o\'zgartirildi!<br/>';
echo 'Nikingiz: <span style="background:'.$clr.';border-radius:8px 0px 8px 0px;padding:3px 5px 2px 5px;">'.$datauser['name'].'</span>';
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>, Bu yerda siz Nikingizning fonini o\'zgartirasiz.<br/>Narxi: '.$a.' ball</div>';
    echo '<form action="/shop/cfon.php" method="post"><div class="list1">';
echo '<p>'.(strlen($datauser['cfon']) == 1 ? '<b>Rang:</b>' : '<font color="'.$datauser['cfon'].'"><b>Rang:</b></font>').'<br/><input type="text" name="color" maxlength="25" value="'.$datauser['cfon'].'" /><br/><small>Masalan #000000 qilib yozasiz. Bunda nikingiz foni qora rangda bo`ladi.<br/><font color="red">Kod yozishning turlari bor masalan НЕ va RGB yana HTML kodlari! Agar boshqa ranglarding yozilishini bilmasangiz pasdagi Ranglar javdaliga kiring va har xil ranglarning yozilishini bilib oling</font></small><br/><a href="colortable.php"><font color="0000ff">Ranglar javdali</font></a></p></div>';
echo '<div class="gmenu"><p><img src="/captcha.php?r=' . rand(1000, 9999) . '" alt="TEST kodi" border="1"/><br />';
echo 'Rasmdagi kodni kiriting:<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>';
    }
require ("../incfiles/end.php");
?>