<?php
class regAction extends security_normal {
	
	function action(){
		if(ConfigV('micefun','user_reg')==0){
			$jsstring='Dialog.alert("会员注册功能已关闭!",function(){history.back(-1);});';
			MessageBox($jsstring);
			exit;
		}

		$miceSession = new session();
		if($miceSession->get('mu__userid')>0){
			$jsstring='Dialog.alert("您已登录系统！!",function(){history.back(-1);});';
			MessageBox($jsstring);
			exit;
		}
		
		global $conn;
		if($_POST){
			if($_POST['checkcode']!=$miceSession->get('checkcode')){
				$jsstring='Dialog.alert("验证码错误!",function(){history.back(-1);});';
				MessageBox($jsstring);
				exit;
			}

			if($_POST['name']==''){
				$jsstring='Dialog.alert("请填写登录名!",function(){history.back(-1);});';
				MessageBox($jsstring);
				exit;
			}

			if($_POST['pwd1']==''){
				$jsstring='Dialog.alert("密码不能为空!",function(){history.back(-1);});';
				MessageBox($jsstring);
				exit;
			}

			if($_POST['pwd1']<>$_POST['pwd2']){
				$jsstring='Dialog.alert("密码和确认密码不一致!",function(){history.back(-1);});';
				MessageBox($jsstring);
				exit;
			}

			$salt = md5(rand(100000, 999999).$_POST['name']);
			$pwd=sha1($salt.$_POST['pwd2']);

			$user2=new model_User();
			$user2->setSubsection('WHERE loginname=\''.$_POST['name'].'\'');
			$results2=$user2->doSelectOne();

			if($results2){
				$jsstring='Dialog.alert("登录名已经被占用!",function(){history.back(-1);});';
				MessageBox($jsstring);
				exit;
			}

			$user=new model_User();
			$user->setLoginname($_POST['name']);
			$user->setSalt($salt);
			$user->setPassword($pwd);

			$user->setRealname($_POST['realname']);
			$user->setEmail(strtolower($_POST['email']));
			$user->setUsergroupId(ConfigV('micefun','user_reg_group'));
			$user->setStatus(0);
			$user->setTelno($_POST['telno']);
			$user->setRegdate(time());
			$user->setStopdate('0');
			$user->setLastlogindate(time());
			$user->setLastloginip(GetRealIp());
			$result=$user->doInsert();

			if($result){
				$exeresult='注册成功';
				$usergroup=new model_Usergroup();
					$usergroup->setSubsection('WHERE usergroup_id='.$user->getUsergroupId());
					$usergroups=$usergroup->doSelectOne();

				$miceSession = new session();
				$miceSession->set('mu__loginname', $user->getLoginname());
						$miceSession->set('mu__userid', $user->getUserId());
						$miceSession->set('mu__groupid', $user->getUsergroupId());
						$miceSession->set('mu__grouplevel', $usergroups->getLevel());
						$miceSession->set('usergroupmenu', $usergroups->getMenu());
						$miceSession->set('usergroupmodule', $usergroups->getModule());
						$jsstring='Dialog.alert(\'注册成功\',function(){window.location.href="'.MICE_URL.'";window.event.returnValue = false;},300,100,"提示信息");';
						MessageBox($jsstring);
						exit;
			}else{
				$jsstring='Dialog.alert(\'注册失败\',function(){window.location.href="'.MICE_URL.'";window.event.returnValue = false;},300,100,"提示信息");';
				MessageBox($jsstring);
				exit;
			}
		}

		$smarty = new Smarty();
		$smarty->load_filter('pre','micePreCompileIndex');
		$smarty->assign("name",$name);
		$smarty->assign("checkcode",MICE_URL.'index.php/checkcode');

		$filename = new getTPLFileName(__CLASS__);
		$tpl=$filename->TPLFileName;
		$smarty->display($tpl);
	}	
}
?>