<?
if(@$act!="reg"){
		$smartydate = array("pagetitle" => "用户注册",);
		$tplpath = "user/reg.tpl";
}else{
		$iserror = 0;
		
		if($username == "" and $iserror == 0){
				$pagecontent = "<b>注册失败:</b><br/>";
				$pagecontent .= "用户名不能为空！<br/>";
				$iserror = 1;
		}
		
		/*用户名是否为字母开头的6-16位字母及数字组成？*/
		if(!ereg("^[a-zA-Z]+([a-zA-Z0-9_]{6,16})",$username) and $iserror == 0){
				$pagecontent = "<b>注册失败:</b><br/>";
				$pagecontent .= "用户名应为字母开头6-16位字母及数字组成！<br/>";
				$iserror = 1;
		}
		/*注册密码是否为空*/
		if($password == "" and $iserror == 0){
				$pagecontent = "<b>注册失败:</b><br/>";
				@$pagecontent .= "密码不能为空！<br/>";
				$iserror = 1;
		}
		/*两次密码是否一致判断*/
		if($password != $passwordtoo and $iserror == 0){
				$pagecontent = "<b>注册失败:</b><br/>";
				@$pagecontent .= "两次密码不一致，请重新输入！<br/>";
				$iserror = 1;
		}
		/*注册密码长度判断*/
		if($iserror == 0){
				if(strlen($password) >= 6 and strlen($password) <= 16){
				}else{
						$pagecontent = "<b>注册失败:</b><br/>";
						@$pagecontent .=strlen($password)."密码长度控制在6-16位！<br/>";
						$iserror = 1;
				}
		}
		/*手机号码是否为数字判断*/ 
		if(preg_match("/[^\d-., ]/",$mobile) and $iserror == 0){
				$pagecontent = "<b>注册失败:</b><br/>";
				@$pagecontent .= "手机号只能为11位数字！<br/>";
				$iserror = 1;
		}
		/*邮箱格式判断*/
		if(!ereg("^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+",$email) and $iserror == 0){
				$pagecontent = "<b>注册失败:</b><br/>";
				@$pagecontent .= "请填写正确的邮箱地址！<br/>";
				$iserror = 1;
		}
		/*用户名是否存在验证*/
		if($iserror == 0){
				$sql = "select uid from ".JIEQI_DB_PREFIX."_system_users where uname = '".$username."'";
				$userdate = $db->query_num($sql);
				if($userdate){
						$pagecontent = "<b>注册失败:</b><br/>";
						@$pagecontent .= "该用户名已经存在！<br/>";
						$iserror = 1;
				}
		}
		/*手机号是否存在验证*/
		if($iserror == 0){
				$sql = "select uid from ".JIEQI_DB_PREFIX."_system_users where mobile = '".$mobile."'";
				$userdate = $db->query_num($sql);
				if($userdate){
						$pagecontent = "<b>注册失败:</b><br/>";
						@$pagecontent .= "该手机号码已被注册！<br/>";
						$iserror = 1;
				}
		}
		/*邮箱是否存在验证*/
		if($iserror == 0){
				$sql = "select uid from ".JIEQI_DB_PREFIX."_system_users where email = '".$email."'";
				$userdate = $db->query_num($sql);
				if($userdate){
						$pagecontent = "<b>注册失败:</b><br/>";
						@$pagecontent .= "该邮箱已被注册！<br/>";
						$iserror = 1;
				}
		}
		/*昵称是否存在验证*/
		if($iserror == 0){
				$sql = "select uid from ".JIEQI_DB_PREFIX."_system_users where name = '".$nickname."'";
				$userdate = $db->query_num($sql);
				if($userdate){
						$pagecontent = "<b>注册失败:</b><br/>";
						@$pagecontent .= "该昵称已被注册！<br/>";
						$iserror = 1;
				}
		}
		if($iserror == 0){
				$sql = "INSERT INTO ".JIEQI_DB_PREFIX."_system_users(uname,name,pass,groupid,regdate,initial,email,mobile,sign,intro,setting,badges,lastlogin,experience,score)
				VALUE('".$username."','".$nickname."','".md5($password)."',3,'".time()."','A','".$email."','".$mobile."','','','','','".time()."',10,10)";
				$userdate = $db->query($sql);
				if($userdate){
						$sql = "select * from ".JIEQI_DB_PREFIX."_system_users where uname = '".$username."'";
						$userdate = $GLOBALS['db']->query_object($sql);
						$_SESSION["member"] = $userdate;
						$_SESSION["member"]->sid = generate_password(12);
						$sql = "SELECT uid,sid,setdata FROM hon6_sid WHERE uid = ".$_SESSION["member"]->uid;
						$set = $GLOBALS['db']->query_object($sql);
						if($set){
								$sql = "UPDATE hon6_sid SET sid = '".$_SESSION["member"]->sid."' WHERE uid = ".$_SESSION["member"]->uid;
								$GLOBALS['db']->query($sql);
								$_SESSION["set"] = unserialize($set->setdata);
						}else{
								$sql = "INSERT INTO hon6_sid(uid,sid) VALUES(".$_SESSION["member"]->uid.",'".$_SESSION["member"]->sid."')";
								$GLOBALS['db']->query($sql);
						}
						$pagecontent = "登录成功！<br/>".$_SESSION["member"]->name.",欢迎您回来，正在返回之前页！<br/>";
				}
		}
		if($iserror == 1){
				$url = array("act"=>"",
										"backurl" => urlencode($_GET["backurl"]),
										);
				$tourl = URL_user_reg($url);
		}elseif($iserror == 0){
				$tourl = $GLOBALS['backurl'];
				$urlarray = parse_url($tourl);
				@$GLOBALS['tourl'] = "?".url_set_value($urlarray["query"],"sid",$_SESSION["member"]->sid);
		}
		$smartydate = array("pagetitle" => "用户注册",
											"pagecontent" => $pagecontent,
											"tourl" => $tourl,
											"redirecturl" => $tourl,
											);
		$tplpath = "public.tpl";
}
?>