Файл: public_html/element_town_create.php
Строк: 156
<?php
require_once './element_options/element_options.php';
if (!$user) { header('Location: /'); exit; }
$create_level = element_settings_game('lost_town_create_lvl');
    if ($create_level > $user['lost_level']) {
        $title = 'Доступ закрыт';
        $error1 = '<span class="small">Чтобы создать город, нужен минимум '.$create_level.' уровень</span>';
        require_once 'element_error_page.php';
        exit;
    }
    
    if ($user['lost_town'] > 0) {
        $title = 'Доступ закрыт';
        $error1 = '<span class="small">Чтобы создать собственный город, для начала покиньте текущий город!</span>';
        require_once 'element_error_page.php';
        exit;
    }
    
    $create_gold = element_settings_game('lost_town_create_gold');
    $title = 'Создание города'; 
    if (readcache('element_user_mesto'.$user['lost_id']) != $title) writecache('element_user_mesto'.$user['lost_id'], $title);
    require_once './element_include/element_head.php';
    require_once './element_include/element_header_user_true.php';
    
    if ($go == 'add') {
        $name_town = (isset($_POST['name_town']) AND !empty($_POST['name_town'])) ? mysql_real_escape_string(htmlspecialchars(addslashes(trim($_POST['name_town'])))) : false;
    
        if ($user['lost_money_gold'] < $create_gold) $error = '<span class="red">Вам не хватает <img src="/images/icons/gold.png"><span class="bold">'.($create_gold - $user['lost_money_gold']).'</span> золота</span><br/><a class="button mt5 w40" href="#">Купить золото</a>';
        if (!$name_town) $error = '<span class="red">Название клана обязательно для ввода</span>';
    
        if (!isset($error) AND $name_town) {
            if (!preg_match("/^[a-z]|[а-яё]+$/ui", $name_town) OR preg_match("/[0-9]/", $name_town) OR substr_count($name_town,' ') > 1 OR mb_strlen($name_town, 'utf-8') < 4 OR mb_strlen($name_town, 'utf-8') > 20) $error = '<span class="red">В имени вы можете использовать от 4-х до 20-и символов и 1 пробел. Нельзя использовать цифры и чередовать латиницу с кириллицей.</span>';
            if (mysql_num_rows(mysql_query("SELECT `lost_id` FROM `element_town` WHERE `lost_name` = '$name_town' LIMIT 1")) > 0) $error = '<span class="red">Название '<span class="ccc">'.$name_town.'</span>' уже занято. Выберите пожалуйста другое название</span><br/>';
        }
        
        if (!isset($error)) {
            require_once './element_function/element_function_rating.php';
            
            mysql_query("INSERT INTO `element_town` SET  `lost_name` = '$name_town',
                                                         `lost_level` = '1',
                                                         `lost_exp` = '0',
                                                         `lost_race` = '$user[lost_race]',
                                                         `lost_create_time` = '".time()."',
                                                         `lost_create_user` = '$user[lost_id]',
                                                         `lost_max_users` = '20',
                                                         `lost_altar` = '1'");
            $insert = mysql_insert_id();
            mysql_query("INSERT INTO `element_town_journal` SET `lost_town` = '$insert',
                                                                `lost_value` = '<span class="yellow1">[user]$user[lost_id][/user] основал город "$name_town"!</span>',
                                                                `lost_time` = '".time()."'");
            $rating = update_rating_user('town', 1);    
            if (!in_array($insert, $rating)) {
                array_push($rating, $insert);
                writecache('element_ratingtown', $rating);
            }
                
            $lost_exp[2] = 0;    
            $user['lost_exp'] = implode(' ', $lost_exp);
            $user['lost_town'] = $insert;
            $user['lost_town_other'] = '0:'.time();
            mysql_query("UPDATE `element_user` SET `lost_exp` = '$user[lost_exp]', 
                                                   `lost_town` = '$user[lost_town]', 
                                                   `lost_town_other` = '$user[lost_town_other]' 
                                                   WHERE `lost_id` = '$user[lost_id]' 
                                                   LIMIT 1");
                                                                                       
                                                   
            update_money_exp($user, 0, 0, 0, -$create_gold);
            header('Location: /town');
            exit;
        } else echo '<div class="nfl cntr p5 mt5 mlra small">'.$error.'</div>';
    }
    
    echo '<div class="nfl p5 mb5 mt5 cntr small mlra">';
    
        echo '<div><form method="post" action="/town/create?go=add">
              <label class="bl mb5 ccc">Введите название города:<br>
              <input class="fdark w70" type="text" name="name_town" value="'.((isset($name_town) AND $name_town) ? $name_town : '').'" size="20" maxlength="20">
              </label>
              <input type="submit" class="button blue w40" name="submit" value="Создать"/>
            
              </form>
              </div>';
        echo '<div class="mt5 yellow1">Стоимость создания города <img src="/images/icons/gold.png">'.$create_gold.' золота!</div>';
    
    echo '</div>';
    require_once './element_include/element_foot_user_true.php';
?>