<?php

require './include/common.inc.php';
sajax_init();
sajax_export("Checkit","sucheck","checkserv","doSub");
sajax_handle_client_request();
$head['title'] = "重置游戏密码";
if(!$_userid) header('location:/member/login.php?forward='.urlencode($PHP_URL));
$infos = $db->get_one("SELECT question,answer,idcard,area FROM ".TABLE_MEMBER." m,".TABLE_MEMBER_INFO." mi WHERE m.userid='$_userid' AND mi.userid='$_userid'");
if(!$infos['area']) showmessage("请选激活游戏分区再进行此操作！","/game/actgame.php");
$servers = array();
$rs = $db->query("SELECT * FROM ".TABLE_GAMESERVER." WHERE id IN ($infos[area]) ORDER BY id");
while($r = $db->fetch_array($rs))
{
$servers[] = $r;
}
function checkserv($id)
{
global $db,$_userid,$_username;
if(!$id) return "<span class=font06>请选择分区</span>";
if (!check_con($id)) return "<span class=font06>当前分区连接失败，请与管理员联系</span>";
$sqldb = real_con($id);
$info = $sqldb->get_one("SELECT password FROM user WHERE username='$_username'");
if(!$info) return "<span class=font06>您没有激活该分区</span>";
return "true";
}
function Checkit($id,$settype,$memo)
{
global $db,$_userid,$_username;
if(!$id) return "<span class=font06>请选择分区</span>";
if (!check_con($id)) return "<span class=font06>当前分区连接失败，请与管理员联系</span>";
$sqldb = real_con($id);
$info = $sqldb->get_one("SELECT password FROM user WHERE username='$_username'");
if(!$info) return "<span class=font06>您没有激活该分区</span>";
if($settype == "setques")
{
if(!$memo) return "<span class=font06>请填写密码提示答案</span>";
$info = $db->get_one("SELECT answer FROM ".TABLE_MEMBER." WHERE userid='$_userid'");
$ans = $memo;
if($ans != $info['answer'])
{
return "<span class=font06>您输入的提示问题答案错误！</span>";
exit;
}else{
return "true";
}
}elseif($settype == "setcard")
{
if(!$memo) return "<span class=font06>请填写身份证号码</span>";
$info = $db->get_one("SELECT idcard FROM ".TABLE_MEMBER_INFO." WHERE userid='$_userid'");
if($memo != $info['idcard'])
{
return "<span class=font06>您输入的身份证号码错误！</span>";
exit;
}else{
return "true";
}
}else{
return "<span class=font06>类型参数传递错误！</span>";
}
}
function sucheck($id)
{
global $db;
if ($id)
{
$info = $db->get_one("SELECT servername FROM ".TABLE_GAMESERVER." WHERE id='$id'");
return '<div class="tipsboxC" id="message"><span class="font06" style="color:green;font-weight:bold">请为 <font color=red>《'.$info[servername].'》</font> 设置一个新密码！</span></div><TABLE class=regform cellSpacing=0 cellPadding=0 width=80% align=center border=0><TBODY><TR><TH>新密码： </TH><TD colSpan=2><INPUT class=inputA id=npwd type=password> </TD></TR><TR><TH>确认新密码： </TH><TD colSpan=2><INPUT class=inputA id=rpwd type=password> </TD></TR><TR><TH></TH><TD colSpan=2><input name=submit type=submit class=hsbtn onclick=doSub('.$id.') value="修改"></TD></TR></TBODY></TABLE>';
}else{
return "非法操作！";
}
}
function doSub($id,$npwd,$rpwd)
{
global $db,$_username;
if($id == '') return "<span class=font06>参数传递错误</span>";
if($npwd == '') return "<span class=font06>新密码不能为空</span>";
if(strlen($npwd) <5 ||strlen($npwd) >20) return "<span class=font06>新密码长度为5-20位</span>";
if($rpwd == '') return "<span class=font06>确认密码不能为空</span>";
if($npwd != $rpwd) return "<span class=font06>两次密码输入不一致</span>";
if (!check_con($id)) return "<span class=font06>当前分区连接失败，请与管理员联系</span>";
$sqldb = real_con($id);
$info = $sqldb->get_one("SELECT password FROM user WHERE username='$_username'");
if(!$info) return "<span class=font06>您没有激活该分区</span>";
$npwd = hsmd5($npwd);
if($npwd == $info['password']) return "true";
$sqldb->query("UPDATE user SET password='$npwd' WHERE username='$_username'");
if($sqldb->affected_rows())
{
return "true";
}else{
return "错误类型：UPDATE ERROR!，请与管理员连系！";
}
}
include template('game','resetgpass');
?>