<?php
  
ECHO "<div class='list'>";

ECHO "<center><font size='+1'>".LG('Шаг')." 4 ".LG('из')." 5</font><br /><br />";

ECHO "<b><font size='+1'>".LG('Регистрация администратора')."</font></b></center><br />";

IF (POST('ok_login')){
  
  $login = CLEARSPECIALCHARS(ADSL(POST('login')));  
  $password = POST('password');
  $password2 = POST('password2');
  
  IF ($password != $password2){
    
    ECHO "<font color='red'>Пароли не совпадают</font><br /><br />";
  
  }ELSE{
    
    $ID = DB::GET_ADD("INSERT INTO `USERS` (`BROWSER`, `IP`, `DATE_CREATE`, `DATE_VISIT`, `LOGIN`, `PASSWORD`, `MANAGEMENT`, `ACCESS`) VALUES ('".USER_BROWSER."', '".IP."', '".TIME()."', '".TIME()."', '".$login."', '".SHIF($password)."', '1', '99')");
    
    $user = DB::GET_STRING("SELECT * FROM `USERS` WHERE `ID` = '".$ID."' AND `LOGIN` = '".$login."' AND `PASSWORD` = '".SHIF($password)."' LIMIT 1");
    
    $hash = USER_HASH($user['ID']);
    
    DB::GET_SET("UPDATE `USERS` SET `HASH` = '".$hash."' WHERE `ID` = '".$user['ID']."' LIMIT 1");
    
    SETCOOKIE('DOUBLE', 1, TIME() + 60 * 60 * 24 * 365);
    SETCOOKIE('USER_ID', $user['ID'], TIME() + 60 * 60 * 24 * 365);
    SETCOOKIE('PASSWORD', ENCRYPT($password, $user['ID']), TIME() + 60 * 60 * 24 * 365);
    
    $_SESSION['no_install'] = 1;
    
    $avatar_rand_param = ARRAY('#EB6156', '#FD8B2C', '#72C375', '#B970C5', '#31ACB8', '#5498CE', '#997445', '#4EA771', '#828D92', '#F55448');
    $avatar_rand = ARRAY_RAND($avatar_rand_param, 1);
    $avatar = $avatar_rand_param[$avatar_rand];
    
    DB::GET_ADD("INSERT INTO `USERS_SETTINGS` (`USER_ID`, `AVATAR_PHONE`) VALUES ('".$user['ID']."', '".$avatar."')");
    
    REDIRECT('?get=5');
  
  }
  
}

ECHO "<form method='post'>";

ECHO "<input type='text' class='form-control-100' name='login' placeholder='Логин'><br /><br />";

ECHO "<input type='password' class='form-control-100' name='password' placeholder='Придумайте пароль'><br /><br />";

ECHO "<input type='password' class='form-control-100' name='password2' placeholder='Повторите пароль'><br /><br />";
 
ECHO "<button class='btn2' name='ok_login' value='go'>".LG('Дальше')." ".ICONS('arrow-right', 15, 'fa-fw')."</button>";

IF (CONFIG('CSRF') == 1){
  
  ECHO '<input type="hidden" name="'.$token_id.'" value="'.$token_value.'">';

}

ECHO "</form>";

ECHO "</div>";
  
?>