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

if(isset($_POST['mail'])){
if(!empty($_POST['mail'])){
$mail = mysqli_real_escape_string($connect_db, trim($_POST['mail']));
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('0'); }
$nm = mysqli_fetch_assoc(mysqli_query($connect_db, "SELECT uid,mail,mailver FROM ".DB_PREFIX."_users WHERE uid = '$u_id' LIMIT 1"));
if ($nm['mailver'] == 1) { exit('5'); }
if ($nm['mail'] == $mail) { exit('4'); }
$ism = mysqli_num_rows(mysqli_query($connect_db, "SELECT uid FROM ".DB_PREFIX."_users WHERE mail = '$mail' LIMIT 1"));
if($ism > 0){ wu_log_act(0, 'Пытался сменить E-mail на адрес '.wu_filter($_POST['mail']).', зарегистрированный другим пользователем'); exit('6'); }
mysqli_query($connect_db, "UPDATE `".DB_PREFIX."_users` SET `mail` = '$mail' WHERE uid = '$u_id' LIMIT 1");
wu_log_act(0, 'Изменил E-mail');
exit('1');
} else { exit('2'); }
} else { exit('wu-error'); }
?>