<?php
require './include/common.inc.php';
sajax_init();
sajax_export("doSub");
sajax_handle_client_request();
//$GLOBALS['sajax_debug_mode'] = 1;

$head['title'] = "重设邮箱";
	
//if(!$_userid) showmessage($LANG['please_login'], '/member/login.php?forward='.urlencode($PHP_URL));
if(!$_userid) header('location:/member/login.php?forward='.urlencode($PHP_URL));
$infos = $db->get_one("SELECT question FROM ".TABLE_MEMBER." WHERE userid='$_userid'");


function doSub($answer,$idcard,$newemail)
{
	global $db,$_userid;
	if($answer == '') return "<span class=font06>请填写密码提示答案</span>";
	if($idcard == '') return "<span class=font06>请填写证件号码</span>";
	if($newemail == '') return "<span class=font06>请输入新邮箱地址</span>";
	if(!is_email($newemail)) return "<span class=font06>请输入正确的邮箱地址</span>";

	
  $info = $db->get_one("SELECT answer,idcard FROM ".TABLE_MEMBER." m,".TABLE_MEMBER_INFO." mi WHERE m.userid='$_userid' AND mi.userid='$_userid'");
  if(!$info) return "<span class=font06>未找到相关信息，请查检！</span>";

  if($answer != $info['answer']) return "<span class=font06>密码提示答案不正确</span>";
  if($idcard != $info['idcard']) return "<span class=font06>证件号码错误</span>";
  
  $db->query("UPDATE ".TABLE_MEMBER." SET email='$newemail' WHERE userid='$_userid'");
  if($db->affected_rows())
  {
    return "true";
    }else{
    return "修改失败或者邮箱地址未改变！";
  }  
}

  include template('member', 'rsemail');
  

?>