<?php
class PaDefault extends CustomPage {
	private $sysErrorClassID='3001';
	private $sysErrorFuncID=0;
	private $sysErrorID=0;
	
	public $sError='';
	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.'netsuserdepartment'];
		$this->sUserDescriptions[5]=$this->sysDbDescriptions[$this->sysTableHead.'netsuserdepartmentcont'];
		$this->sUserDescriptions[6]=$this->sysDbDescriptions[$this->sysTableHead.'netsusertype'];
		$this->sUserDescriptions[7]=$this->sysDbDescriptions[$this->sysTableHead.'netsusergroup'];
		$this->sUserDescriptions[8]=$this->sysDbDescriptions[$this->sysTableHead.'netsusergrade'];
		$this->sUserDescriptions[0]['Columns']['uitEmail']['Value']='';
		$this->sApp=new netsuserinfo($this->sConnString);
		
		$this->sTemplatePath='User/FindPxd_Submit.php';
	}
	public function OnBEvent(){
		if($this->sActionTypeF=='DFindpxd'){
			$this->OnFindpxd();
		}else if($this->sActionTypeF=='DModifypxd'){
			$this->OnModifypxd();

		}
	}
	public function OnBLoad(){
		if($this->sActionType=='Sendcode'){
			$this->OnSendcode();
		}
	}
	public function OnFindpxd(){
		$tmpSTR='uitEmail';
		$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt','',1);
		$this->sUserDescriptions[0]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
		$tmpSTR='uttType';
		$this->sUserDescriptions[6]['Columns'][$tmpSTR]['Value']='1,2,3,4,5,';
		//-- ------ #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;
		}
		//-- ------ #Get Encryption string ------ --
		//#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();
		//#FIND
		$tmpINT=$this->sApp->FindPxd($this->sUserDescriptions);
		if($tmpINT!=0){
			$this->sJscript=$this->Message('ERROR','找回密码失败','对不起，您所填写的用户名或电邮地址不存在','');
			return 1;
		}
		$tmpEncryption=$this->sUserDescriptions[0]['Columns']['uitPxd']['Value'];
		//-- ------ #Send Email ------ --
		$tmpEmail=new netsEmail(array($this->sysFileConfig['EmailHost'],
			$this->sysFileConfig['EmailHostPost'],
			$this->sysFileConfig['EmailName'],
			$this->sysFileConfig['EmailPxd'],
			$this->sysCharset,));
		$tmpSTR=$this->sysFileConfig['EmailFindpxdTemplate'];
		$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}',$tmpEncryption,$tmpSTR);
		$tmpAR0=array(
			$this->sUserDescriptions[0]['Columns']['uitEmail']['Value'],
			$this->sysFileConfig['EmailName'],
			$this->sysFileConfig['bussinessMetaTitle'].' - 用户找回密码邮件',
			$tmpSTR,
			);
		$tmpINT=$tmpEmail->sendSmtp($tmpAR0);
		$this->sJscript=$this->Message('ERROR','找回密码','本站已发送密码邮件到您的邮箱，请查收',$this->sysFileConfig['businessLoginAddress']);
		return 0;
	}
	public function OnModifypxd(){
		$this->sUserDescriptions=array(
			$this->sysDbDescriptions[$this->sysTableHead.'netsuserinfo'],
			$this->sysDbDescriptions[$this->sysTableHead.'netsuserinfocont']);
		//-- #uitID, --
		$tmpSTR='uitID';
		$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt','',1);
		$this->sUserDescriptions[0]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
		//-- #uitName, --
		$tmpSTR='uitName';
		$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt','',1);
		$this->sUserDescriptions[0]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
		//-- #uitPxd, --
		$tmpSTR='uitPxd';
		$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt','',1);
		$this->sUserDescriptions[0]['Columns'][$tmpSTR]['Value']=$tmpAR0[0];
		//-- #uitConfirmPxd, --
		$tmpSTR='uitConfirmPxd';
		$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt','',1);
		$tmpConfirmPxd=$tmpAR0[0];
		//-- ------ #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;
		}
		//-- #Check --
		if($this->sUserDescriptions[0]['Columns']['uitPxd']['Value']!=$tmpConfirmPxd){
			$this->sJscript=$this->Message('ERROR','重设置密码错误','两次输入的密码必须一致','');
		}
		$tmpINT=$this->sApp->UpdatePxd($this->sUserDescriptions);
		if($tmpINT!=0){
			$this->sJscript=$this->Message('ERROR','重设置密码错误',$tmpINT,'');
			return 1;
		}
		
		$this->sJscript=$this->Message('ERROR','重设置密码成功','重设置密码成功，请用新密码登陆',$this->sysFileConfig['businessLoginAddress']);
		return 0;
	}

	public function OnSendcode(){
		$tmpAR0=$this->AnalyerRequest('Sendcode',',0',0);
		$this->sUserDescriptions=array($this->sysDbDescriptions[$this->sysTableHead.'netsuserinfo']);
		
		if(count($tmpAR0)!=2){
			$this->sTemplatePath='User/FindPxd_PxdLinkError.php';
			$this->sError='对不起，链接地址错误，请重新申请找回密码或与客服人员联系。';
			return 1;
		}
		
		$this->sUserDescriptions[0]['Columns']['uitID']['Value']=$tmpAR0[1];
		$this->sUserDescriptions[0]['Columns']['uitPxd']['Value']=$tmpAR0[0];
		$tmpINT=$this->sApp->FindPxd_callback($this->sUserDescriptions);
		if($tmpINT!=0){
			$this->sTemplatePath='User/FindPxd_PxdLinkError.php';
			$this->sError=$this->sApp->sysLastError;
			return 1;
		}
		
		$Coun0=0;
		while (count($this->sUiDescription_Custom0)>$Coun0) {
			if ($this->sUiDescription_Custom0[$Coun0]['stcotName']=='uitID') {
				$this->sUiDescription_Custom0[$Coun0]['Value']=$this->sUserDescriptions[0]['Columns']['uitID']['Value'];
			}
			$Coun0++;
		}
		$this->sTemplatePath='User/FindPxd_ModifyPxd.php';
		return 0;
	}
	public function OnList(){
		//-- ------ #Control ------ --
		#-- #0 --
		$this->sUiDescription_Custom0=array();
		$tmpSTR=$this->sUiDescriptionPath.'User/nets/findpxd_newpxd.php';
		if(file_exists($tmpSTR)){
			require($tmpSTR);
			$this->sUiDescription_Custom0=$sysUiDescriptions['findpxd_newpxd'];
		}
		
	}
	public function DefUiPanel(&$pColumn,$pFlag){
		parent::DefUiPanel($pColumn,$pFlag);
		if($pColumn['stcotName']=='soudtName'){
			$pColumn['ControlStyle']='width:540px;';

		}
		return $pColumn;
	}
	
	public function DefUiJscript($pFlag){
?>
function JsDCheck(pPara){
	var tmpControl="";
	var tmpError="";
	var tmpChecker=new netsChecker();
	var tmpActionWithOut=document.getElementById("ActionWithOut");
	var Coun0=0;
	//-- ------ #ActionWithOut ------ --
	if(tmpActionWithOut==undefined){
		return true;
	}
	if(tmpActionWithOut.value=="1"){
		return true;
	}else if(tmpActionWithOut.value=="2"){
		return false;
	}
	//-- ------ #Check ------ --
<?php if($this->sActionType=='Sendcode'){ ?>
	//#uitPxd
	tmpCheckCont=document.getElementById("uitPxdTxt");
	tmpCheckCont.value=tmpChecker.Filter(tmpCheckCont.value,0);
	if(!tmpChecker.CheckLen(tmpCheckCont.value,5,32)){
		Coun0++;
		tmpError+=Coun0+".登陆密码名必须大于5位"+tmpCommon.sysSPLIT8;
	}
	//#uitPxdConfirm
	tmpSTR=tmpCheckCont.value;
	tmpCheckCont=document.getElementById("uitPxdConfirmTxt");
	tmpCheckCont.value=tmpChecker.Filter(tmpCheckCont.value,0);
	if(tmpCheckCont.value!=tmpSTR){
		Coun0++;
		tmpError+=Coun0+".两次输入的密码必须一致"+tmpCommon.sysSPLIT8;
	}
<?php }else{ ?>
	//#uitEmail
	tmpCheckCont=document.getElementById("uitEmailTxt");
	tmpCheckCont.value=tmpChecker.Filter(tmpCheckCont.value,0);
	if(!tmpChecker.CheckLen(tmpCheckCont.value,5,64)){
		Coun0++;
		tmpError+=Coun0+".电邮地址必须大于5位"+tmpCommon.sysSPLIT8;
	}
<?php } ?>
	//#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{
		return true;
	}
}
<?php
	}
}
?>