<?php
require_once('../wu_init.php');
if (!wu_token()) { exit('wu-error'); }

//Проверка капчи
if(!isset($_SESSION['qaptcha_key']) || empty($_SESSION['qaptcha_key'])) { exit('captcha'); }

//Регистрация
if(isset($_POST['login']) && isset($_POST['pass']) && isset($_POST['mail'])){
if ($_POST['oferta'] == 'true') {
$login = mysqli_real_escape_string($connect_db, preg_replace('#[^a-zA-Z\-\@\_\.\-0-9]+#','',$_POST['login']));
if(strlen($login) < '3') { exit('lsmall'); }
$ulq = mysqli_query($connect_db, "SELECT uid FROM ".DB_PREFIX."_users WHERE log = '$login' LIMIT 1");
if(mysqli_num_rows($ulq)>0){ exit('regged'); }
$mail = mysqli_real_escape_string($connect_db, trim($_POST['mail']));
$ism = mysqli_query($connect_db, "SELECT uid FROM ".DB_PREFIX."_users WHERE mail = '$mail' LIMIT 1");
if(mysqli_num_rows($ism)>0){ exit('mailreg'); }
$pass = mysqli_real_escape_string($connect_db, $_POST['pass']);
if(strlen($pass) < '3'){ exit('psmall'); }
function is_email($email) {
return preg_match("/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)*\.([a-zA-Z]{2,6})$/", $email);
}
if (!is_email($mail)) { exit('mail'); }
if (isset($_COOKIE['referer'])) { $ref = intval($_COOKIE['referer']); $referer = mysqli_fetch_assoc(mysqli_query($connect_db, "SELECT uid,log FROM ".DB_PREFIX."_users WHERE uid = '$ref' LIMIT 1")); $adm_plus = ", Реферер: $referer[log]"; } else { $ref = 0; $adm_plus = ''; }
$pas = md5(md5(trim($dt.'_'.$pass)));

//Информация для админа
$adm_info = '';

//Откуда пришёл пользователь
if (isset($_COOKIE['fromsite'])) { $adm_info .= 'Пришёл с '.$_COOKIE['fromsite']."\r\n"; }

//Проверка мультиаккаунта
if(!isset($_COOKIE['wu_i'])) {
wu_log_auth(2,"Зарегистрирован новый пользователь $login, IP: $ip$adm_plus");
$multi = '';
} else {
$multi = wu_decode($_COOKIE['wu_i']);
$multi = mysqli_real_escape_string($connect_db, $multi);
$nusr = mysqli_fetch_assoc(mysqli_query($connect_db, "SELECT uid,log FROM `".DB_PREFIX."_users` WHERE uid = '$multi' LIMIT 1"));
if (empty($nusr['uid'])) { $multi_code = $_COOKIE['wu_i']; wu_log_auth(1,"Зарегистрирован новый пользователь $login, IP: $ip$adm_plus, мультиаккаунт с неверной меткой. Оригинальный текст метки: $multi, код метки: $multi_code"); $multi = ''; } else {
wu_log_auth(1,"Зарегистрирован новый пользователь $login, IP: $ip$adm_plus, мультиаккаунт с пользователем $nusr[log]");
$adm_info .= "Мультиаккаунт с пользователем $nusr[log]";
}
}

$adm_info = mysqli_real_escape_string($connect_db, $adm_info);

mysqli_query($connect_db, "INSERT INTO ".DB_PREFIX."_users (log,pas,ref,regdate,regip,lastip,mail,admin_text,multi) VALUES ('$login','$pas','$ref','$dt','$ip','$dt','$mail','$adm_info','$multi')");

if (!empty($ref)) { mysqli_query($connect_db, "UPDATE ".DB_PREFIX."_users SET `rat`=`rat`+'0.05' WHERE uid='$ref' LIMIT 1"); }
unset($_SESSION['qaptcha_key']);
echo '1';
} else { echo 'offer'; }
} else { echo 'error'; }
?>