<?php
require($netsFileConfig['sysCoreRoot_Real'].'Inc/netsFunc/Func/netsXml.php');
require($netsFileConfig['sysCoreRoot_Real'].'Inc/netsFunc/Func/netsSimpleXml.php');
require($netsFileConfig['sysCoreRoot_Real'].'Inc/netsFunc/Func/netsMobile.php');


class PaDefault extends CustomPage {
	private $sysErrorClassID='3001';
	private $sysErrorFuncID=0;
	private $sysErrorID=0;
	public $sUserDescriptions=array();
	
	public function PaDefault(){
		$this->CustomPage();
	}
	public function OnBInitial(){
		$this->sMetaTitle='用户注册';
		$this->getUser('1,2,3,4,5,');
		$this->sTable=array(
			array('sttTableName'=>$this->sysTableHead.'netsuserinfo','sttColumnHead'=>'uit'),
			array('sttTableName'=>$this->sysTableHead.'netsuserinfocont','sttColumnHead'=>'uict'),);
		
		$this->sUserDescriptions[0]=$this->sysDbDescriptions[$this->sysTableHead.'netsuserinfo'];
		$this->sUserDescriptions[1]=$this->sysDbDescriptions[$this->sysTableHead.'netsuserinfocont'];
		$this->sUserDescriptions[2]=$this->sysDbDescriptions[$this->sysTableHead.'netsuserunit'];
		$this->sUserDescriptions[3]=$this->sysDbDescriptions[$this->sysTableHead.'netsuserunitcont'];
		$this->sUserDescriptions[4]=$this->sysDbDescriptions[$this->sysTableHead.'netsusertype'];
		$this->sUserDescriptions[5]=$this->sysDbDescriptions[$this->sysTableHead.'netsusertypecont'];
		$this->sUserDescriptions[6]=$this->sysDbDescriptions[$this->sysTableHead.'netsuserdepartment'];
		$this->sUserDescriptions[7]=$this->sysDbDescriptions[$this->sysTableHead.'netsuserdepartmentcont'];
		$this->sUserDescriptions[8]=$this->sysDbDescriptions[$this->sysTableHead.'netsusergroup'];
		$this->sUserDescriptions[9]=$this->sysDbDescriptions[$this->sysTableHead.'netsusergrade'];
		$this->sUserDescriptions[0]['Columns']['uitName']['Value']='';
		$this->sApp=new netsuserinfo($this->sConnString);
	}
	public function OnBEvent(){
		if($this->sActionTypeF=='DRegister'){
			$this->OnRegister();
		}
		if ($this->sActionType=='DCheckRepeate') {
			$this->OnCheckRepeate();
		}
	}
	public function OnRegister(){
		$tmpSTR='uitName';
		$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt','',1);
		$this->sUserDescriptions[0]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
		$tmpSTR='uitEmail';
		$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt','',1);
		$this->sUserDescriptions[0]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
		$tmpSTR='uitMobile';
		$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt','',1);
		$this->sUserDescriptions[0]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
		$tmpSTR='uitRegisterType';
		$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt',0,1);
		$tmpRegisterType=$tmpAR0[0];
		$tmpSTR='uitPxd';
		$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt','',1);
		$this->sUserDescriptions[0]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
		
		$this->sUserDescriptions[0]['Columns']['uitTypeid']['Value']=5;
		$this->sUserDescriptions[4]['Columns']['uttType']['Value']=5;
		$this->sUserDescriptions[0]['Columns']['uitUnitid']['Value']=1;
		$this->sUserDescriptions[0]['Columns']['uitCreateBy']['Value']=1;
		if ($this->sysFileConfig['userUserMailCheckAble']==1 || $this->sysFileConfig['userUserMobileCheckAble']==1) {
			$this->sUserDescriptions[0]['Columns']['uitChecked']['Value']=0;
		}
		//-- ------ #Check ------ --
		if ($tmpRegisterType==0) {
			$this->sUserDescriptions[0]['Columns']['uitName']['Value']=$this->sUserDescriptions[0]['Columns']['uitEmail']['Value'];
		}else {
			$this->sUserDescriptions[0]['Columns']['uitName']['Value']=$this->sUserDescriptions[0]['Columns']['uitMobile']['Value'];
		}
		//-- ------ #UserRegAble ------ --
		if($this->sysFileConfig['userUserRegAble']==0){
			$this->sJscript=$this->Message('ERROR','用户注册失败','对不起，本平台暂停用户注册，请与管理员联系。','');
			return 1;
		}
		//-- ------ #CCode ------ --
		$tmpSTR='CCode';
		$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt','',1);
		$tmpCCode=$tmpAR0[0];
		$tmpSTR=$tmpSTR.'Txt_IFrame';
		if(!array_key_exists($tmpSTR,$_SESSION)){
			$this->sJscript=$this->Message('ERROR','提交失败','验证码错误','');
			return 1;
		}
		if($_SESSION[$tmpSTR]=='' || $_SESSION[$tmpSTR]!=$tmpCCode){
			$this->sJscript=$this->Message('ERROR','提交失败','验证码错误','');
			return 1;
		}
		//-- ------ #Register ------ --
		$this->sApp->sSite=$this->sCode->URL_MakeParameter($this->sysPage,1);
		$tmpINT=$this->sApp->RegAddToUnit($this->sUserDescriptions);
		if($tmpINT!=0){
			$this->sJscript=$this->Message('ERROR','登陆失败',$this->sApp->sysLastError,'');
			return $tmpINT;
		}
		//-- ------ #Send mail or mobile ------ --
		//#Send check mail
		$this->sysLastMessage='欢迎注册'.$this->sysFileConfig['bussinessMetaTitle'].'通用帐号，请登陆。';
		$tmpEmail=new netsEmail(array($this->sysFileConfig['EmailHost'],
			$this->sysFileConfig['EmailHostPost'],
			$this->sysFileConfig['EmailName'],
			$this->sysFileConfig['EmailPxd'],
			$this->sysCharset,));
		$tmpMobile=new netsMobile(array($this->sysFileConfig['MobileUName'],
			$this->sysFileConfig['MobilePxd'],
			$this->sysFileConfig['MobileSendURL'],
			$this->sysFileConfig['MobileReceiveURL'],
			$this->sysFileConfig['MobileCountURL'],));
			
		//#Get userinfo
		$tmpINT=$this->sApp->GetUserinfo($this->sUserDescriptions,'uitEmail');
		if($tmpINT!=0){
			$this->sJscript=$this->Message('ERROR','重新发送注册认证邮件错误',$this->sApp->sysLastError,'');
			return 1;
		}
		//#Daily setting
		$this->sApp->sDbDescriptions_Other=array(
			array($this->sysDbDescriptions[$this->sysTableHead.'netsuserdaily'],
				$this->sysDbDescriptions[$this->sysTableHead.'netsuserdailycont'],),
			);
		$this->sApp->sDbDescriptions_Other[0][1]['Columns']['udctIpAddress']['Value']=$this->getIP();
		//#Send
		if($this->sysFileConfig['userUserMailCheckAble']==1 && $tmpRegisterType==0){
			$tmpINT=$this->sApp->regConfirmMakeMail($this->sUserDescriptions,$this->sysFileConfig['userUserMailCheckAble']);
			
			$tmpSTR=$this->sysFileConfig['EmailConfirmTemplate'];
			$tmpSTR=str_replace('{Nets.Title}',$this->sysFileConfig['bussinessMetaTitle'],$tmpSTR);
			$tmpSTR=str_replace('{Nets.Charset}',$this->sysCharset,$tmpSTR);
			$tmpSTR=str_replace('{Nets.Name}',$this->sUserDescriptions[0]['Columns']['uitName']['Value'],$tmpSTR);
			$tmpSTR=str_replace('{Nets.Page}',$this->sysSiteHome,$tmpSTR);
			$tmpSTR=str_replace('{Nets.Encryption}',$this->sUserDescriptions[0]['Columns']['uitPxd']['Value'],$tmpSTR);
			$tmpAR0=array(
				$this->sUserDescriptions[0]['Columns']['uitEmail']['Value'],
				$this->sysFileConfig['EmailName'],
				$this->sysFileConfig['bussinessMetaTitle'].' - 用户帐号认证邮件',
				$tmpSTR,
				);
			$tmpINT=$tmpEmail->sendSmtp($tmpAR0);
			$this->sysLastMessage='用户注册成功，请到您的电子邮箱['.$this->sUserDescriptions[0]['Columns']['uitEmail']['Value'].']里查收注册认证邮件，以完成您的注册。';
		}else if($this->sysFileConfig['userUserMailCheckAble']==2 && $tmpRegisterType==0){
			$tmpINT=$this->sApp->regConfirmMakeMail($this->sUserDescriptions,$this->sysFileConfig['userUserMailCheckAble']);
			
			$tmpSTR=$this->sysFileConfig['EmailPowerTemplate'];
			$tmpSTR=str_replace('{Nets.Title}',$this->sysFileConfig['bussinessMetaTitle'],$tmpSTR);
			$tmpSTR=str_replace('{Nets.Charset}',$this->sysCharset,$tmpSTR);
			$tmpSTR=str_replace('{Nets.Name}',$this->sUserDescriptions[0]['Columns']['uitName']['Value'],$tmpSTR);
			$tmpSTR=str_replace('{Nets.Page}',$this->sysSiteHome,$tmpSTR);
			$tmpSTR=str_replace('{Nets.Encryption}',$this->sUserDescriptions[0]['Columns']['uitPxd']['Value'],$tmpSTR);
			$tmpAR0=array(
				$this->sUserDescriptions[0]['Columns']['uitEmail']['Value'],
				$this->sysFileConfig['EmailName'],
				$this->sysFileConfig['bussinessMetaTitle'].' - 用户帐号认证邮件',
				$tmpSTR,
				);
			$tmpINT=$tmpEmail->sendSmtp($tmpAR0);
			$this->sysLastMessage='用户注册成功，您可以登陆到本系统中，但在认证您的邮箱前，您将不能使用本系统的会员功能与服务，请到您的电子邮箱['.$this->sUserDescriptions[0]['Columns']['uitEmail']['Value'].']里查收注册认证邮件，以认证您的邮箱。';
		}else if($this->sysFileConfig['userUserMailCheckAble']==0 && $this->sysFileConfig['userUserRegSendEmail']==1 && $tmpRegisterType==0){
			//-- #Send register mail --
			$tmpSTR=$this->sysFileConfig['EmailRegTemplate'];
			$tmpSTR=str_replace('{Nets.Title}',$this->sysFileConfig['bussinessMetaTitle'],$tmpSTR);
			$tmpSTR=str_replace('{Nets.Charset}',$this->sysCharset,$tmpSTR);
			$tmpSTR=str_replace('{Nets.Name}',$this->sUserDescriptions[0]['Columns']['uitName']['Value'],$tmpSTR);
			$tmpSTR=str_replace('{Nets.Page}',$this->sysSiteHome,$tmpSTR);
			$tmpAR0=array(
				$this->sUserDescriptions[0]['Columns']['uitEmail']['Value'],
				$this->sysFileConfig['EmailName'],
				$this->sysFileConfig['bussinessMetaTitle'].' - 欢迎加入',
				$tmpSTR,
				);
			$tmpINT=$tmpEmail->sendSmtp($tmpAR0);
			if ($this->sysFileConfig['userUserCheckAble']==1) {
				$this->sysLastMessage='欢迎注册'.$this->sysFileConfig['bussinessMetaTitle'].'通用帐号，您已注册成功，请等待管理员审核后才能登陆。';
			}
		}else if($this->sysFileConfig['userUserMobileCheckAble']==1 && $tmpRegisterType==1){
			$tmpINT=$this->sApp->regConfirmMakeMobile($this->sUserDescriptions,$this->sysFileConfig['userUserMobileCheckAble']);
			
			$tmpSTR=$this->sysFileConfig['MobileAccountConfirmTemplate'];
			$tmpSTR=str_replace('{Nets.Title}',$this->sysFileConfig['bussinessMetaTitle'],$tmpSTR);
			$tmpSTR=str_replace('{Nets.Name}',$this->sUserDescriptions[0]['Columns']['uitName']['Value'],$tmpSTR);
			$tmpSTR=str_replace('{Nets.Encryption}',$this->sUserDescriptions[0]['Columns']['uitPxd']['Value'],$tmpSTR);
			$tmpINT=$tmpMobile->sendCSMS($this->sUserDescriptions[0]['Columns']['uitMobile']['Value'],$tmpSTR);
			$this->sysLastMessage='用户注册成功，请到您的手机['.$this->sUserDescriptions[0]['Columns']['uitMobile']['Value'].']里查收注册认证短信，以完成您的注册。';
		}else if($this->sysFileConfig['userUserMobileCheckAble']==2 && $tmpRegisterType==1){
			$tmpINT=$this->sApp->regConfirmMakeMobile($this->sUserDescriptions,$this->sysFileConfig['userUserMobileCheckAble']);
			
			$tmpSTR=$this->sysFileConfig['MobileAccountConfirmTemplate'];
			$tmpSTR=str_replace('{Nets.Title}',$this->sysFileConfig['bussinessMetaTitle'],$tmpSTR);
			$tmpSTR=str_replace('{Nets.Name}',$this->sUserDescriptions[0]['Columns']['uitName']['Value'],$tmpSTR);
			$tmpSTR=str_replace('{Nets.Encryption}',$this->sUserDescriptions[0]['Columns']['uitPxd']['Value'],$tmpSTR);
			$tmpINT=$tmpMobile->sendCSMS($this->sUserDescriptions[0]['Columns']['uitMobile']['Value'],$tmpSTR);
			$this->sysLastMessage='用户注册成功，您可以登陆到本系统中，但在认证您的手机号前，您将不能使用本系统的会员功能与服务，请到您的电子邮箱['.$this->sUserDescriptions[0]['Columns']['uitEmail']['Value'].']里查收注册认证邮件，以认证您的邮箱。';
		}else if($this->sysFileConfig['userUserMobileCheckAble']==0 && $tmpRegisterType==1){
			
			if ($this->sysFileConfig['userUserCheckAble']==1) {
				//$this->sysLastMessage='欢迎注册'.$this->sysFileConfig['bussinessMetaTitle'].'通用帐号，您已注册成功，请等待管理员审核后才能登陆。';
			}
		}
		
		$this->sJscript=$this->Message('SUCCESS','注册成功',$this->sysLastMessage,$this->sysFileConfig['businessLoginAddress']);
		return 0;
	}
	public function OnList(){
		//-- ------ #Control ------ --
		$this->sUiDescription_CustomA=array();
		$tmpSTR=$this->sUiDescriptionPath.'User/nets/user_register_unit.php';
		if(file_exists($tmpSTR)){
			require($tmpSTR);
			$this->sUiDescription_CustomA=$sysUiDescriptions['user_register_unit'];
		}
		

	}
	public function OnCheckRepeate(){
		$tmpAR0=$this->AnalyerRequest('DCheckRepeate',',0',0);
		//-- ------ #Type ------ --
		$tmpColumnName='电子邮件地址';
		$tmpColumnValue='uitEmail';
		if ($tmpAR0[1]==0) {
			$tmpColumnName='电子邮件地址';
			$tmpColumnValue='uitEmail';
		}else {
			$tmpColumnName='手机号码';
			$tmpColumnValue='uitMobile';
		}
		//-- ------ #Check ------ --
		//#Value
		if ($tmpAR0[0]==''){
			$this->sMessage='ERROR,请先正确填写'.$tmpColumnName;
			return 1;
		}
		//#SQL
		$tmpSQL=' SELECT A.uitID
			FROM {Nets.TableHead}netsuserinfo AS A
			WHERE 1=1 AND A.uitRecycle=0 AND A.uitChecked>1 AND A.{Nets.COLUMN} LIKE \'{Nets.NAME}\'
			LIMIT 0,2 ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.COLUMN}',$tmpColumnValue,$tmpSTR);
		$tmpSTR=str_replace('{Nets.NAME}',$tmpAR0[0],$tmpSTR);
		$tmpData0=$this->sDb->Search($tmpSTR);
		if (count($tmpData0)>0) {
			$this->sMessage='ERROR,您填写的'.$tmpColumnName.'已被注册，请确认后再试';
			return 1;
		}
		
		$this->sMessage='SUCCESS,您填写的'.$tmpColumnName.'可以使用';
		return 0;
	}
	public function DefUiPanel(&$pColumn,$pFlag){
		parent::DefUiPanel($pColumn,$pFlag);
		if($pColumn['stcotName']=='uitName'){
			$pColumn['Value']=$this->sUserDescriptions[0]['Columns']['uitName']['Value'];
		
		}else if($pColumn['stcotName']=='uitEmail'){
			$pColumn['Parameter_JS_Onchange']='tmpUser.OnReg_Name(\''.$pColumn['stcotName'].'\');';
		}else if($pColumn['stcotName']=='uitPxd'){
			$pColumn['Parameter_JS_Onchange']='tmpUser.OnReg_CheckPxd(\''.$pColumn['stcotName'].'\');';
		}else if($pColumn['stcotName']=='uitPxdConfirm'){
			$pColumn['Parameter_JS_Onchange']='tmpUser.OnReg_CheckPxdConfirm(\''.$pColumn['stcotName'].'\');';
			
			
		}
		return $pColumn;
	}
	
	public function DefUiJscript($pFlag){
?>
function JsDCheck(pPara){
	var tmpControl="";
	var tmpError="";
	var tmpChecker=new netsChecker();
	var tmpActionWithOut=document.getElementById("ActionWithOut");
	document.getElementById(tmpCommon.sysActionTypeF).value=1;
	var Coun0=0;
	//-- ------ #ActionWithOut ------ --
	if(tmpActionWithOut==undefined){
		return true;
	}
	if(tmpActionWithOut.value=="1"){
		return true;
	}else if(tmpActionWithOut.value=="2"){
		return false;
	}
	//-- ------ #Check ------ --
	//#uitName
	tmpINT=tmpUser.OnReg_Name("uitEmail");
	if(tmpINT==1){
		Coun0++;
		tmpError+=Coun0+tmpUser.OnReg_EMessage+tmpCommon.sysSPLIT8;
	}
	//#uitPxd
	tmpINT=tmpUser.OnReg_CheckPxd("uitPxd");
	if(tmpINT==1){
		Coun0++;
		tmpError+=Coun0+tmpUser.OnReg_EMessage+tmpCommon.sysSPLIT8;
	}
	//#uitPxdConfirm
	tmpINT=tmpUser.OnReg_CheckPxdConfirm("uitPxdConfirm");
	if(tmpINT==1){
		Coun0++;
		tmpError+=Coun0+tmpUser.OnReg_EMessage+tmpCommon.sysSPLIT8;
	}
	//#CCode
	tmpCheckCont=document.getElementById("CCodeTxt");
	tmpCheckCont.value=tmpChecker.Filter(tmpCheckCont.value,0);
	if(tmpCheckCont.value.length!=5){
		Coun0++;
		tmpError+=Coun0+".验证码必须为5位"+tmpCommon.sysSPLIT8;
	}
	//-- ------ #Result ------ --
	if(tmpError!=""){
		tmpSTR="<span class=\"FStrong\">对不起，您提交的内容存在以下错误:</span>"+tmpCommon.sysSPLIT8+tmpError;
		tmpFrames.showMessage("系统消息 - <?php echo ($this->sysFileConfig['bussinessMetaTitle']); ?>",tmpSTR,"","0");
		return false;
	}else{
		document.getElementById(tmpCommon.sysActionTypeF).value=0;
		return true;
	}
}
<?php
	}
}
?>