<?php
require("header.php");
require(R_P."require/groupid.php");

InitGP('action','G');
if ($action == 'm') {
	InitGP(array('u_name_2','u_mail','u_phone','u_mobile','m_u_password_1','m_u_password_2','u_password',),'P');
	require (R_P."require/user_cookie.php");

	$uid = GetCookie('user_id');

	//昵称
	(strlen($u_name_2)>18 || strlen($u_name_2)<1)  && Showmsg('reg_name_2_err_1');
	!preg_match("/^([\x80-\xff]|\w|\d)+$/",$u_name_2) && Showmsg('reg_name_2_err_2');
	$sql = "select * from ".$db_tablepre."user where u_name_2='".$u_name_2."'";
	sql_return($sql,3) && showmsg('reg_name_2_err_3');

	// 邮箱
	(strlen($u_mail)>60 || strlen($u_mail)<6) && Showmsg('reg_email_err_1');
	!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/",$u_mail) && Showmsg('reg_email_err_2');
	$sql = "select * from ".$db_tablepre."user where u_mail='".$u_mail."'";
	sql_return($sql,3)  && showmsg('reg_email_err_3');
	

	//联系方式
	!($u_phone || $u_mobile)  && Showmsg('reg_PhOrMob_err');
	if (!empty($u_phone)) !preg_match("/[0-9|-]{7,25}/",$u_phone) && Showmsg('reg_ph_err');
	if (!empty($u_mobile)) !preg_match("/\d{11}/",$u_mobile) && Showmsg('reg_mobile_err');

	// 密码
	if (!empty($m_u_password_1) && !empty($m_u_password_2)) {
	($m_u_password_1 !== $m_u_password_2)  && Showmsg('reg_pw_err_1');
	(strlen($m_u_password_1)>40 || strlen($m_u_password_1)<6) && Showmsg('reg_pw_err_2');

	$sql = "SELECT * FROM ".$db_tablepre."user WHERE u_id='".$uid."' AND u_password='".md5($u_password)."' ";
	sql_return($sql,3) || Showmsg('updateuser1_e');

	$sql2 = ',u_password=\''.md5($m_u_password_1).'\' WHERE u_id='.$uid;
	}
	else $sql2 = ' WHERE u_id='.$uid;

	$sql = 'UPDATE '.$db_tablepre.'user SET u_name_2=\''.$u_name_2.'\',u_mail=\''.$u_mail.'\',u_phone=\''.$u_phone.'\',u_mobile=\''.$u_mobile."'".$sql2;
	sql_return($sql)   ? Showmsg('updateuser1_s') : Showmsg('err') ;
	//(sql_return($sql) && dle_cookie_user())  ? Showmsg('updateuser1_s') : Showmsg('err') ;

}else {
	$sql = "SELECT * FROM ".$db_tablepre."user  WHERE u_id=".GetCookie('user_id');
	$query = sql_return($sql,2);
	$u_name = $query['u_name'];
	$u_mail = $query['u_mail'];
	$u_phone = $query['u_phone'];
	$u_mobile = $query['u_mobile'];
	$u_name_2 = $query['u_name_2'];
	$u_money = $query['u_money'];

	$u_uptimes = date("Y-m-d H:i:s",$query['u_uptimes']);
	$u_lasttime = date("Y-m-d H:i:s",$query['u_lasttime']);


	$u_group= $group_id['user'][$query['u_group']];

	require PrintEot($self_template,'U');
}
?>
