<?php
require(dirname(__FILE__)."/"."global.php");

$linkdb=array("郵箱驗證"=>"?job=email","身份驗證"=>"?job=idcard","手機驗證"=>"?job=mob");

if(!$lfjid){
	showerr("你還沒登錄");
}

if($action=='email')
{
	if (!ereg("^[-a-zA-Z0-9_\.]+\@([0-9A-Za-z][0-9A-Za-z-]+\.)+[A-Za-z]{2,5}$",$email)) {
		showerr("郵箱不符合規則"); 
	}
	$Title="來自<$webdb[webname]>的郵箱驗證信息!";
	$eid=mymd5("$lfjid\t$lfjuid\t$email");
	$Content="請點擊以下網址,以完成郵箱的驗證:<br><A HREF='$webdb[www_url]/do/job.php?job=yzemail&eid=$eid'>$webdb[www_url]/do/job.php?job=yzemail&eid=$eid</A>";
	if($webdb[MailType]=='smtp')
	{
		if(!$webdb[MailServer]||!$webdb[MailPort]||!$webdb[MailId]||!$webdb[MailPw])
		{
			showmsg("請管理員設置郵件服務器");
		}
		require_once(PHP168_PATH."inc/class.mail.php");
		$smtp = new smtp($webdb[MailServer],$webdb[MailPort],true,$webdb[MailId],$webdb[MailPw]);
		$smtp->debug = false;
		if($smtp->sendmail($email,$webdb[MailId], $Title, $Content, "HTML")){
			$succeed=1;
		}
	}
	elseif(mail($email, $Title, $Content))
	{
		$succeed=1;
	}

	if($succeed){
		refreshto("$FROMURL","系統剛剛發了一封驗證信息到你郵箱,請盡快查收,以完成郵件驗證",10);
	}else{
		showerr("郵件發送失敗.請管理員檢查郵箱服務器設置");
	}

}
elseif($action=='idcard')
{
	if(!$truename){
		showerr("真實姓名不能為空!");
	}
	if(!$idcard){
		showerr("身份證號碼不能為空!");
	}
	if(!ereg("^[0-9]{15}",$idcard)){
		showerr("身份證號碼有誤!");
	}
	if($idcardpic){
		if(!is_file(PHP168_PATH."$webdb[updir]/$idcardpic")){
			showerr("請上傳身份證復印件,不能引用其它網址!");
		}
		if(!eregi("^{$lfjuid}_",basename($idcardpic))&&$idcardpic!="idcard/$lfjuid.jpg"){
			showerr("請上傳身份證復印件,不能引用其它圖片!");
		}
		if($idcardpic!="idcard/$lfjuid.jpg"){
			unlink(PHP168_PATH."$webdb[updir]/idcard/$lfjuid.jpg");
			rename(PHP168_PATH."$webdb[updir]/$idcardpic",PHP168_PATH."$webdb[updir]/idcard/$lfjuid.jpg");
		}		
	}
	$db->query("UPDATE {$pre}memberdata SET idcard='$idcard',truename='$truename',idcard_yz='-1' WHERE uid='$lfjuid'");
	refreshto("$FROMURL","請等待管理員審核",10);
}
elseif($action=='mobphone')
{
	$code=rand(1000,9999);
	if( !eregi("^1(3|5|8)([0-9]{9})$",$mobphone) ){
		showerr("手機號碼有誤!");
	}
	$msg=sms_send($mobphone,"你的驗證碼是:$code");

	if($msg!==1){
		showerr("系統發送短信失敗,有可能是你的手機號碼有誤,也有可能是系統的短信接口平台出現故障,請聯系管理員在後台檢查短信平台接口!");
	}
	$md5code=mymd5("$code\t$mobphone\t$lfjuid","EN");
	require(dirname(__FILE__)."/"."head.php");
	require(dirname(__FILE__)."/"."template/yz.htm");
	require(dirname(__FILE__)."/"."foot.php");
}
elseif($action=='mobphone2')
{
	if($lfjdb[mob_yz]){
		showerr("請不要重復驗證手機號碼!");
	}
	if(!$yznum){
		showerr("請輸入驗證碼");
	}elseif(!$md5code){
		showerr("資料有誤");
	}else{
		unset($code,$mobphone,$uid);
		list($code,$mobphone,$uid)=explode("\t",mymd5($md5code,"DE") );
		if($code!=$yznum||$uid!=$lfjuid){
			showerr("驗證碼不對");
		}
	}
	add_user($lfjuid,$webdb[YZ_MobMoney]);
	$db->query("UPDATE {$pre}memberdata SET mobphone='$mobphone',mob_yz='1' WHERE uid='$lfjuid'");
	refreshto("yz.php?job=mob","恭喜你,你的手機號碼succeed通過審核,你同時得到 {$webdb[YZ_MobMoney]} 個積分獎勵!",10);
}
else
{	
	unset($idcardpic);
	if($job=='idcard'){
		if(is_file(PHP168_PATH."$webdb[updir]/idcard/$lfjuid.jpg")){
			$idcardpic="idcard/$lfjuid.jpg";
		}
	}
	require(dirname(__FILE__)."/"."head.php");
	require(dirname(__FILE__)."/"."template/yz.htm");
	require(dirname(__FILE__)."/"."foot.php");
}
?>