<?php
 
include_once './include/common.inc.php';
sajax_init();
sajax_export("doSub","listfso","checkserv","doView");
sajax_handle_client_request();
if(!$_userid) header('location:/member/login.php?forward='.urlencode($PHP_URL));
if (!$MOD['enablerfso']) showmessage("对不起，管理员未开启角色恢复功能！");
function doSub($id,$idfso)
{
global $db,$_username,$MOD;
if(!$id) return "<span class=font06>请选择服务器</span>";
if(!$idfso) return "<span class=font06>请选择恢复角色</span>";
if (!check_con($id)) return "<span class=font06>当前分区连接失败，请与管理员联系</span>";
$sqldb = real_con($id);
$sqldb->select_db(game_fso($id));
$fsoinfo = $sqldb->get_one("SELECT AccountID,Faction FROM user WHERE ID='$idfso' AND deleted != 0");
if(!$fsoinfo) return "<span class=font06>错误的请求！</span>";
if ($fsoinfo['deleted'] == '2') return '<span class=font06>该角色正被GM冻结中，不能进行恢复！</span>';
$banks = $sqldb->get_one("SELECT Point FROM t_bank WHERE AccountID='$fsoinfo[AccountID]'");
if($banks['Point'] <$MOD['rfsopoint']) "<span class=font06>角色携带的点数不足！</span>";
$Point = $banks['Point'] -$MOD['rfsopoint'];
$sqldb->select_db(game_acc($id));
$accinfo = $sqldb->get_one("SELECT username FROM user WHERE idx='$fsoinfo[AccountID]'");
if(!$accinfo) return "<span class=font06>错误的请求！</span>";
if($accinfo['username'] != "$_username") return "<span class=font06>非法操作，你的操作已被记录！</span>";
$sqldb->select_db(game_fso($id));
$faction = $sqldb->get_one("SELECT ID FROM user WHERE AccountID='$fsoinfo[AccountID]' AND deleted = 0 AND Faction !='$fsoinfo[Faction]'");
if ($faction) return "<span class=font06>当前帐号下存在不同阵营的角色，不能进行恢复！</span>";
$check = $sqldb->get_one("SELECT count(ID) as num FROM user WHERE AccountID='$fsoinfo[AccountID]' AND deleted = 0");
if($check[num] >2)
{
return "<span class=font06>当前帐号下有".$check[num]."个角色，请保证角色数量不大于两个！</span>";
}else{
$sqldb->query("UPDATE user SET deleted='0',DeleteDate=NULL WHERE ID='$idfso'");
$sqldb->query("UPDATE t_bank SET Point='$Point' WHERE AccountID='$fsoinfo[AccountID]'");
if($sqldb->affected_rows())
{
return "true";
}else{
return "<span class=font06>恢复失败，请与管理员连系！</span>";
}
}
}
function doView($id,$value)
{
global $db,$_username,$MOD;
if(!$id) return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">游戏分区读取错误！</TD></TR></TBODY></TABLE>';
if(!$value) return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">请选择已删角色！</TD></TR></TBODY></TABLE>';
if (!check_con($id)) return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">当前分区连接失败，请与管理员联系</TD></TR></TBODY></TABLE>';
if (is_online($id)) return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">请确保其它角色未在游戏中或在正常退出游戏后三分钟再进行恢复！</TD></TR></TBODY></TABLE>';
$sqldb = real_con($id);
$sqldb->select_db(game_fso($id));
$fsoinfo = $sqldb->get_one("SELECT AccountID,Metier,Level,DeleteDate,deleted,Faction FROM user WHERE ID='$value' AND deleted != 0");
if ($fsoinfo['deleted'] == '2') return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">该角色正被GM冻结中，不能进行恢复！</TD></TR></TBODY></TABLE>';
$banks = $sqldb->get_one("SELECT Point FROM t_bank WHERE AccountID='$fsoinfo[AccountID]'");
$check = $sqldb->get_one("SELECT count(ID) as num FROM user WHERE AccountID='$fsoinfo[AccountID]' AND deleted = 0");
if($check[num] >2) return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">当前帐号下有'.$check[num].'个角色，请保证角色数量不大于两个！</TD></TR></TBODY></TABLE>';
if($fsoinfo)
{
$faction = $sqldb->get_one("SELECT ID FROM user WHERE AccountID='$fsoinfo[AccountID]' AND deleted = 0 AND Faction !='$fsoinfo[Faction]'");
if ($faction) return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">当前帐号下存在不同阵营的角色，不能进行恢复！</TD></TR></TBODY></TABLE>';
$sqldb->select_db(game_acc($id));
$accinfo = $sqldb->get_one("SELECT username FROM user WHERE idx='$fsoinfo[AccountID]'");
if(!$accinfo)
{
return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">非法请求！</TD></TR></TBODY></TABLE>';
}else{
if($accinfo['username'] != "$_username") return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">非法操作，你的操作已被记录！</TD></TR></TBODY></TABLE>';
}
if($banks['Point'] <$MOD['rfsopoint']) return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">帐户中点数不足以支付恢复角色费用</TD></TR></TBODY></TABLE>';
$deledate = strtotime($fsoinfo[DeleteDate]);
$deledate = date("Y年m月d日 H点i分",$deledate);
$Level = $fsoinfo['Level'];
$metier = getmetier($fsoinfo['Metier']);
if($Level &&$metier)
{
return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH style="font-weight:bold;font-size:14px">角色信息： </TH><TD colSpan=2 style="color:#555;font-size:14px;font-weight:bold">'.$metier.'</TD></TR>
<TR><TH style="font-weight:bold;font-size:14px">角色等级： </TH><TD colSpan=2 style="color:#555;font-size:14px;font-weight:bold">'.$Level.'级</TD></TR>
<TR><TH style="font-weight:bold;font-size:14px">可用点数： </TH><TD colSpan=2 style="color:#555;font-size:14px;font-weight:bold">'.$banks[Point].'点</TD></TR>
<TR><TH style="font-weight:bold;font-size:14px">删除时间： </TH><TD colSpan=2 style="color:#555;font-size:14px;font-weight:bold">'.$deledate.'</TD></TR><TR><TH></TH><TD colSpan=2><input id="subok" type="submit" onClick="doSub()" class="hsbtn" value="恢复"></TD></TR></TBODY></TABLE>';
}else{
return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">角色信息读取失败!</TD></TR></TBODY></TABLE>';
}
}else{
return '<TABLE class=regform cellSpacing=0 cellPadding=0 width="80%" align=center border=0><TBODY><TR><TH></TH><TD style="color:#f00;font-size:14px;font-weight:bold;padding:20px 0px;text-align:left;">未读取到角色信息!</TD></TR></TBODY></TABLE>';
}
}
function listfso($id)
{
global $db,$_userid,$_username;
if(!$id) return "游戏分区读取错误";
if (!check_con($id)) return "<span class=font06>当前分区连接失败，请与管理员联系</span>";
$sqldb = real_con($id);
$info = $sqldb->get_one("SELECT idx FROM user WHERE username='$_username'");
if($info)
{
$sqldb->select_db(game_fso($id));
$users = array();
$rs = $sqldb->query("SELECT ID,Name FROM user WHERE AccountID='".$info['idx']."' AND deleted != 0");
if(!$rs)
{
return "该分区没有角色！";
}else{
while($r = $sqldb->fetch_array($rs))
{
$users[] = $r;
}
foreach($users as $value)
{
$bstr .= '<option value='.$value[ID].'>'.$value[Name].'</option>';
$cstr .= '<input type="hidden" id="fso_'.$value[ID].'" value="'.$value[Name].'">';
}
return '<select id="idfso" onchange="doView(this.value)"><option>-- 请选择角色 --</option>'.$bstr.'</select>'.$cstr;
}
}else{
return "您没有激活该分区";
}
}
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 idx FROM user WHERE username='$_username'");
if($info)
{
$sqldb->select_db(game_fso($id));
$infou = $sqldb->get_one("SELECT ID FROM user WHERE AccountID='".$info['idx']."' AND deleted != 0");
if(!$infou)
{
return "<span class=font06>该分区没有被删除的角色！</span>";
}else{
return "true";
}
}else{
return "<span class=font06>您没有激活该分区</span>";
}
return "true";
}
$head['title'] = '已删角色恢复';
$head['keywords'] = $MOD['seo_keywords'];
$head['description'] = $MOD['seo_description'];
$query = "SELECT truename,telephone,qq,area FROM ".TABLE_MEMBER_INFO." WHERE userid=$_userid";
@extract($db->get_one($query));
if(!$area) showmessage("请选激活游戏分区再进行此操作！","/game/actgame.php");
$query = "SELECT * FROM ".TABLE_GAMESERVER." WHERE id IN ($area) ORDER BY id";
$result=$db->query($query);
while($r=$db->fetch_array($result))
{
$gamelists[]=$r;
}
include template($mod,'rfso');
?>