<?php
defined('ACCESS') or die();
if ($login) {
	if ($_GET['action'] == 'save') {
		$get_user_info = mysql_query("SELECT pe FROM users WHERE id = ".$user_id." LIMIT 1");
		$row = mysql_fetch_array($get_user_info);
		 $upe		= $row['pe'];

		$pass_1 = $_POST['pass_1'];
		$pass_2 = $_POST['pass_2'];
		$email	= addslashes(htmlspecialchars($_POST['email'], ENT_QUOTES, ''));
		$icq	= addslashes(htmlspecialchars($_POST['icq'], ENT_QUOTES, ''));
		$pm		= addslashes(htmlspecialchars($_POST['pm'], ENT_QUOTES, ''));
		$pe		= addslashes(htmlspecialchars($_POST['pe'], ENT_QUOTES, ''));
		$ya		= addslashes(htmlspecialchars($_POST['ya'], ENT_QUOTES, ''));
		$skype	= addslashes(htmlspecialchars($_POST['skype'], ENT_QUOTES, ''));

		if($upm) { $pm = $upm; } 
		if($upe) { $pe = $upe; } 

		if (!$email) {
			echo '<p class="er">Следует ввести E-mail!</p>';
		} else {
			if ($pass_1 != $pass_2) {
				echo '<p class="er">Пароль и подтверждение не совпадают!</p>';
			} else {
				if (!preg_match("/^[a-z0-9_.-]{1,20}@(([a-z0-9-]+\.)+(com|net|org|mil|edu|gov|arpa|info|biz|[a-z]{2})|[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})$/is", $email)) {
					print '<p class="er">Введите правильно e-mail!</p>';
				} elseif ($pm[0] != 'U' && $pm) {
					print '<p class="er">Введите корректный PM кошелёк!</p>';
				} elseif(mysql_num_rows(mysql_query("SELECT pm FROM users WHERE pm = '".$pm."' AND id != ".$user_id)) && $pm) {
					print "<p class=\"er\">Такой PM уже есть в базе!</p>";
				} elseif(mysql_num_rows(mysql_query("SELECT mail FROM users WHERE mail = '".$email."' AND id != ".$user_id))) {
					print "<p class=\"er\">Такой e-mail уже есть в базе!</p>";
				} else {
					$sql = 'UPDATE users SET ';
					if($pass_1) { $sql .= 'pass = "'.as_md5($key, $pass_1).'", '; }

					$sql .= 'mail = "'.$email.'", icq = "'.$icq.'", pm = "'.$pm.'", pe = "'.$pe.'", ya = "'.$ya.'", skype = "'.$skype.'" WHERE id = '.$user_id.' LIMIT 1';
					if (mysql_query($sql)) {
						print '<p class="er">Данные были успешно обновлены!</p>';
					} else {
						print '<p class="er">Не удаётся изменить данные!</p>';
					}
			}
		}
	}
}

$sql	= 'SELECT * FROM users WHERE login = "'.$login.'" LIMIT 1';
$rs		= mysql_query($sql);
$a		= mysql_fetch_array($rs);
?><div class="settings">

			
        
<div class=" form" >
       
        <form method="post" action="?action=save">
                        <div class="block">
                <span class="cap">Платёжные реквизиты</span>
                <div class="double cfix">
                    <label class="pay">
                        <span style="background-image: url(/tmpl/img/brands4.png)"></span>
                    </label>
                                            <input type="text" name="ya" value="<?php print $a['ya']; ?>" placeholder="123456789012345" class="text-field"> 
																									
                </div>
                <div class="double cfix">
                    <label class="pay">
                        <span style="background-image: url(/tmpl/img/brands1.png)"></span>
                    </label>
                                            <input type="text" name="pm" value="<?php print $a['pm']; ?>" placeholder="U1234567" class="text-field">
                                    </div>
                
                <div class="double cfix">
                    <label class="pay">
                        <span style="background-image: url(/tmpl/img/brands2.png)"></span>
                    </label>
                                            <input type="text" name="pe" value="<?php print $a['pe']; ?>" placeholder="P1234567" class="text-field">
                                    </div>
               
           
       
</div>
<div class="form" style=" margin-bottom: 20px;  position: relative;  padding: 20px;  background-color: #f5f6fa;">


 <span class="cap" style="font-size: 20px;line-height: 25px;color: #333;display: block;margin-bottom: 15px;font-family: 'Roboto';">Личные данные</span>

	<div class="double cfix">
		<label class="pay">Пароль: </label>
		<input type='password' name='pass_1' size="30" />
	</div>
	<div class="double cfix">
		<label class="pay">Подтверждение: </label>
		<input type='password' name='pass_2' size="30" />
	</div>
	<div class="double cfix">
		<label class="pay"><font color="red"><b>!</b></font> E-mail:</label>
		<input type='text' name='email' value='<?php print $a['mail']; ?>' size="30" maxlength="30" />
	</div>
	<div class="double cfix">
		<label class="pay">Skype:</label>
		<input type='text' name='skype' value='<?php print $a['skype']; ?>' size="30" maxlength="50" />
	</div>
	<div class="double cfix">
		<label class="pay">ICQ UIN:</label>
		<input type='text' name='icq' value='<?php print $a['icq']; ?>' size="30" maxlength="20" />
	</div>


<div align="center" style="padding-top: 10px;"><button  class="transfer_button" type="submit">Сохранить</button></div>
</form>
</div >

<?php
} else {
	print "<p class=\"er\">Вы должны авторизироваться для доступа к этой странице!</p>";
}
?>
