<?
    
    include './system/common.php';
    
 include './system/functions.php';
        
      include './system/user.php';
    
if(!$user) {

  header('location: /');
    
exit;

}

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

  header('location: /');
  exit;

}

$title = 'Сохранение';    

include './system/head.php';  
echo '<div class="main">';

$login = _string($_POST['login']);
$password = _string($_POST['password']);


if($login && $password){
$_SESSION['login'] = $login;
$_SESSION['password'] = $password;
$_SESSION['s'] = 1;
}
if(isset($_GET['save'])) {
  
  if(!preg_match('/[a-z0-9а-я]{2,20}/i', $login)) $errors[] = 'Имя персонажа введено не верно';
  if(!preg_match('/[a-z0-9]{2,20}/i', $password)) $errors[] = 'Пароль введен неверно';

  if(mysql_result(mysql_query('SELECT COUNT(*) FROM `users` WHERE `login` = \''.$login.'\''),0) != 0) $errors[] = 'Выбранное имя персонажа уже занято';  
  
  if($errors) {

        echo '<div class=\'block\' align=\'center\'>';
        
        foreach($errors as $error) {
          
          echo $error.'<br/>';
          
        }
      
        echo '</div>
<div class=\'mini-line\'></div>';

  }
  else
  {
  
    mysql_query('UPDATE `users` SET `login` = \''.$login.'\', 
                                 `password` = \''.$password.'\',
                                     `save` = \'1\',
                                     `g` = `g` + 100 WHERE `id` = \''.$user['id'].'\'');

    setCookie('password', $password, time() + 86400, '/');
  
    header('location: /s/?s1');
  
  }
  
}
if($_SESSION['s'] == 1){
if(isset($_GET['set'])){
$_SESSION['s']=0;
header('location:/save');
}
?>
<div class="center">
<div class="block_zero"><h1>Проверьте данные</h1>
<div class="separ"></div>
Имя персонажа: <img src="/images/icon/race/<?=$user['r']?>.png" alt=""> <?=$_SESSION['login'];?><br>
Ваш пароль: <?=$_SESSION['password']?><br>
<form action="/save?save" method="post">
<input type="hidden" name="login" value="<?=$_SESSION['login'];?>"><input type="hidden" name="password" value="<?=$_SESSION['password'];?>">
<input type="hidden" name="repass" value="none">
<input type="hidden" name="email" value="none">
<input type="hidden" name="ready" value="1"><br>
<span class="btn"><span class="end"><input class="label" type="submit" value="Всё верно">Всё верно</span></span></form>
</div><div class="dot-line"></div><div class="block_zero"><a class="grey medium" href="?set">Изменить данные</a></div></div>



<?php
echo'</div>';
}else{
?>
<div class="center">
<div class="block_zero">
<div class="mb5 dgreen">За регистрацию вы получите <img src="/images/icon/gold.png" alt=""> <b>100</b> золота!</div>
<div class="mb5">Откроете акцию на <img src="https://tiwar.ru/images/icon/grade/3.png" alt=""> <span class="quality-3">Редкий комплект</span></div>
<div class=""><span class="green">+1600</span> к параметрам!</div></div>
<div class="mini-line"></div>
<div class="block_zero">
<form action="/save/" method="post">
<div><input type="hidden" name="email" value="none">
Имя персонажа:<br><input class="text medium-text" type="text" name="login" maxlength="16" value="<?=$_SESSION['login'];?>"><br>
Введите пароль:<br><input class="text medium-text" name="password" value="<?=$_SESSION['password'];?>" maxlength="16">
<br><input type="hidden" name="repass" value="none"><span class="btn"><span class="end">
<input class="label" type="submit" value="Сохранить">Сохранить</span></span></div>
</form>
</div>
</div>
  
  
  
  
  </div>
  <?
  }
include './system/foot.php';

?>