<?php
/*
*用户注册类
*/
require root_path."/include/code.fun.php";
class reg{
	function main(){
		$go = $_GET['go'];
		if($go != 'reg'){
			$this->reg_view();
		}else{
			$this->reg_back();
		}
	}
	function reg_view(){
		$code = codeRight('1');
		include root_path."/view/reg.php";
	}
	function reg_back(){
		$this->yzinfo();
		if($this->intosql()){
			echo head("注册成功",CSS);;
			echo "太好了！注册成功!<br>";
			echo "用户名:".$_POST['name']." <br>";
			echo "密码:".$_POST['pass']."<br />";
			echo "昵称:".$_POST['nc']."<br>";
			echo "请妥善保管<br>";
			echo footer(1);
			exit();
		}else{
			echo head("注册失败",CSS);;
			echo '<div class="tip">注册失败了</div>';
			echo footer(1);
			exit();
		}
	}
	function intosql(){
		$sql = new MySql;
		$xid = user("qsid","id",WAPID) + 1;
		$sid = $this->md5info();
		$info['stitle']    =    'NULL';
		$info['name']      =    $_POST['name'];
		$info['pass']      =    $_POST['pass'];
		$info['nc']        =    $_POST['nc'];
		$info['head']      =    'http://'.HTTP_HOST.'/style/nohead.jpg';
		$info['qianm']     =    '还木有签名哦';
		$info['email']     =    $_POST['email'];
		$info['vip']       =    '0';
		$info['admin']     =    '0';
		$info['sex']       =    $_POST['sex'];
		$info['sid']       =    $sid;
		$info['site']      =    'NO';
		$info['xid']       =    $xid;
		$info['qsid']      =    '1000';
		$info['site_u']    =    WAPID;
		$info['crevalue']  =    '100';
		$info['time']      =    time();
		$info['site_reg']  =    '0';
		$info['site_vip']  =    '0';
		$info['site_stop'] =    '0';
		if($sql->sqlinsert($info,'user')){
		mysql_query("UPDATE user SET qsid='{$xid}' WHERE id='{$wapid}'");
			return TRUE;
		}
		return FALSE;
	}
	function yzinfo(){
		
		if(user('site_reg','id',WAPID) == 'no'){
			echo head('注册会员');
			echo '<div class="tip">非常抱歉，本站的会员注册功能已经被网站管理员暂时关闭！</div>';
			echo footer(1);
			exit();
		}
		$code2 = codeRight('2');
		if($_POST['name'] == "" or $_POST['pass'] == "" or $_POST['nc'] == "" ){
			die('用户名、密码、昵称均不能为空！');
		}
		if(!YZ($_POST['name'])==4&&!YZ($_POST['name'])==6&&!YZ($_POST['name'])==7){
			die('用户名只能是英文或数字');
		}
		if(YZ($_POST['pass'])==4||YZ($_POST['pass'])==6||YZ($_POST['pass'])==7){
			}else{
		die('密码只能是英文或数字');
		}
		//验证邮箱信息
		if (preg_match('/(.+?)\@(.+?)\.(.+?)/',$_POST['email'])) { 
		}else{
			die('请填写正确的邮箱格式！');
		}  
		$sql = "SELECT name FROM user WHERE name='{$_POST['name']}' AND site_u='".WAPID."'";
		$logininfo = mysql_query($sql);
		if($logininfo && mysql_num_rows($logininfo)>0){
			die("哎呦，用户名已经被注册了，再换一个吧！");

		}
		if($_POST['code'] != $code2){
			die("验证码错误");
		}
		
	}
	function md5info(){
	    $D = time();
		$data=$_POST['name'].$_POST['nc'].$_POST['pass'].$D;
			$data1 = md5($data);
	        $data2 = md5($data1);
	        $data3 = md5($data2);
	        $data4 = md5($data3);
	        return strtoupper($data4);
	}
	
}