<?php
//***********    注 册 页 面    **********//
/***************************************  top      *****************************/
require ("header.php");
require (R_P."require/user_cookie.php");
/***************************************  register      *****************************/



session_start();
InitGP(array('register','u_name', 'u_password_1', 'u_password_2', 'u_mail', 'u_phone',  'u_mobile', 'u_name_2','type','num_check',));
$re_onoff != 1 && Showmsg('re_off');
$chk_user_name = GetCookie('user_name');
if (!empty($chk_user_name)) jumpPage('reg_for','/user');

// 注册信息检测并且入库;
elseif  ($register == 'yes'){


	$num_check !== $_SESSION['num_check'] && Showmsg('num_check_err');

	// 用户ID


	(strlen($u_name)>18 || strlen($u_name)<4)  && Showmsg('reg_username_err_1');

	!preg_match("/^(\w|\d)+$/",$u_name) && Showmsg('reg_username_err_2');
	$sql = "select * from ".$db_tablepre."user where u_name='".$u_name."'";

	sql_return($sql,3) && showmsg('reg_username_err_3') ;

	//昵称
	(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');

	// 密码
	($u_password_1 != $u_password_2)  && Showmsg('reg_pw_err_1');
	(strlen($u_password_1)>40 || strlen($u_password_1)<6) && Showmsg('reg_pw_err_2');
	$u_password = md5($u_password_1);

	// 邮箱
	(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');
	}




	// 固定变量定义;
	$u_group = 1;

	$u_money = 100;

	$u_uptimes = $timestamp;


	//sql语句
	$sql = " INSERT INTO ".$db_tablepre."user (u_name,u_password,u_mail,u_phone,u_mobile,u_name_2,u_group,u_money,u_uptimes,u_lasttime)";
	$sql .= " VALUES ('$u_name', '$u_password', '$u_mail', '$u_phone', '$u_mobile', '$u_name_2', '$u_group', '$u_money', '$u_uptimes','$u_uptimes') ";
	$rs = sql_return($sql);
	if ($rs) {
		echo 1;
		cookie_user(
		array(
		'u_name' => $u_name,
		'u_name' => $u_name,
		'u_name_2' => $u_name_2,
		'u_group' => $u_group,
		'u_id' => sql_return($rs,'Insert_ID') ,
		'u_money' => $u_money,
		)
		);


		//InitGP(array('jumpurl',));
		jumpPage('reg_s','user');
	}
	exit;
}

// 注册用户名和邮箱是否注册检测;
elseif ($register == 'chk'){
	require_once (R_P."require/msg.php");
	// 用户ID是否注册检测;
	if ($u_name){
		$u_name = $u_name;
		(strlen($u_name)>18 || strlen($u_name)<4)  && exit( $arr_msg['reg_username_err_1'] );
		!preg_match("/^([\x80-\xff]|\w|\d)+$/",$u_name) && exit( $arr_msg['reg_username_err_2'] );
		$sql = "select * from ".$db_tablepre."user where u_name='".$u_name."'";
		(sql_return($sql,3) || exit( $arr_msg['reg_username_err_3'] )) && exit( '可以使用该用户名!' );
	}

	elseif ($_GET['u_mail']){
		// 邮箱是否注册检测;
		$u_mail = $u_mail;
		(strlen($u_mail)>60 || strlen($u_mail)<6) && exit( $arr_msg['reg_email_err_1'] );
		!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/",$u_mail) && exit( $arr_msg['reg_email_err_2'] );
		$sql = "select * from ".$db_tablepre."user where u_mail='".$u_mail."'";
		(sql_return($sql,3) || exit( $arr_msg['reg_email_err_3'] )) && exit( '可以使用该邮箱!' );
	}


	exit;

}else $jumpurlfor = $_SERVER['HTTP_REFERER'];


/***************************************  开始替换       *****************************/

/**

if (!$_SESSION['reg_text']) {
	$content = html_exp('<body','<body onload="zoom()"',$content);
	$_SESSION['reg_text'] = 1;
}
**/



$content = html_exp('{header1}','',$content);
$content = html_exp('{topback1}',$topback1,$content);
$content = html_exp('{menu}','注册会员',$content);


$content = html_exp('{jumpurl}',$jumpurlfor,$content);


/***************************************  footer    *****************************/
require (R_P."footer.php");


?>