<?php



define('_IN_JOHNCMS', 1);

echo '<div class="phdr"><a href="/shop/">'.str_replace('http://', '',$set['homeurl']).' do\'koni</a> | Sistema xabari yuborish</div>';

// Узнаём цену
$price = mysql_fetch_assoc(mysql_query("SELECT `price` FROM `shop` WHERE `id` = 10"));
$a = $price['price'];

// Проверка на спам
$flood = functions::antiflood();
if ($flood) {
echo functions::display_error($lng['error_flood'] . ' ' . $flood . '&#160;' . $lng['seconds'], '<a href="/shop/index.php">Orqaga</a>');
require_once('../incfiles/end.php');
exit;
}

if (isset($_POST['submit'])) {
    if (isset($ban['1']) || isset($ban['3'])) {
    require_once('../incfiles/end.php');
    exit;
    }

    // Принимаем дынные
    $kod = isset($_POST['kod']) ? trim($_POST['kod']) : '';
	$name = isset($_POST['usr']) ? functions::check($_POST['usr']) : '';
    $text = isset($_POST['msg']) ? functions::check($_POST['msg']) : '';
	$tema = isset($_POST['tema']) ? functions::check(mb_substr($_POST['tema'], 0, 50)) : '';
    $error = false;

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

    if (empty($name))
        $error = $error . 'Qabul qiluvchi ID yoki logini kiritilmadi!<br />';
	if (empty($tema))
        $error = $error . 'Anonim xabar mavzusi kiritilmadi!<br />';
    if (empty($text))
        $error = $error . 'Anonim xabar matni kiritilmadi!<br />';

    if (empty($error)) {
        // Проверка монет
        if ($datauser['balans'] < $a) {
        $error = 'Anonim xabar yuborish uchun mablag\' yetarli emas!<br/>';
        }
    }
        // Проверка на кривые данные Ник или АйДи
        if (is_numeric($name) != false) {
        $req = mysql_query("select * from `users` where `id`='$name'");
        if (mysql_num_rows($req) == 0) {
        $error = 'Bunday foydalanuvchi yo\'q!<br/>';
        }
        $fusr = $name;
        } else {
        $req = mysql_query("select * from `users` where `name`='$name'");
        if (mysql_num_rows($req) == 0) {
        $error = 'Bunday foydalanuvchi yo\'q!<br/>';
        }
        $uid = mysql_fetch_assoc(mysql_query("SELECT `id` FROM `users` WHERE `name`='$name'"));
        $fusr = $uid['id'];
        }

    if (empty($error)) {
        // Заносим данные в Базу
        mysql_query("UPDATE `users` SET `balans` = '" . ($datauser['balans'] - $a) . "', `lastpost` = '" . time() . "' WHERE `id` = '$user_id'");
        mysql_query("INSERT INTO `cms_mail` SET `user_id` = '0',`from_id` = '" . $fusr . "',`text` = '" . $text . "

[b]Xabar sayt do\'koni orqali yuborildi!
Unga javob qaytarish shart emas!!![/b]',`time` = '" . time() . "',`sys` = '1',`them` = '" . $tema . "'");
        echo '<div class="gmenu">Anonim xabar yuborildi!';
        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 xohlagan foydalanuvchiga anonim xabar yubora olasiz!<br/>Narxi: '.$a.' ball</div>';
    echo '<form action="/shop/index.php?act=amail" method="post"><div class="list1">';
    echo '<p><b>Nik:</b><br/><input type="text" name="usr" maxlength="30" value="" /><br/><small>Siz sh.x yuborishni xohlagan foydalanuvchining ID yoki loginini kiriting.</small></p>';
	echo '<p><b>Mavzu:</b><br/><input type="text" name="tema" maxlength="50" value="" /><br/><small>Anonim xabar mavzusini kiriting.</small></p>';
    echo '<p><b>Xabar:</b><br/><textarea rows="' . $set_user['field_h'] . '" name="msg"></textarea><br/><small>Anonim xabar matnini kiriting. BB kodlardan foydalansangiz bo\'ladi</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="Yuborish"/></div></form>';
    }

?>