<?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));
$today = date('Y-m-d',$PHP_TIME);
if (!$MOD['enablepk']) showmessage("对不起，管理员未开启清洗红名功能！");
function doSub($id,$idfso,$tonum,$tocheck)
{
global $db,$_userid,$_username,$MOD,$PHP_TIME;
if(!$id) return "<span class=font06>管理员提醒：请选择服务器。</span>";
if(!$idfso) return "<span class=font06>管理员提醒：请选择角色。</span>";
if(!$tonum) return "<span class=font06>管理员提醒：请输入清洗数量。</span>";
if(!is_numeric($tonum)) return "<span class=font06>管理员提醒：输入的数量必须是数字！</span>";
if($tonum <1 ) return "<span class=font06>管理员提醒：输入的数量必须大于0。</span>";
if(!$tocheck) return "<span class=font06>管理员提醒：请选择清洗内容。</span>";
if($tocheck<>1 and $tocheck<>2) return "<span class=font06>管理员提醒：清洗内容发生异常请联系管理员。</span>";
if (!check_con($id)) return "<span class=font06>管理员提醒：当前分区连接失败，请与管理员联系。</span>";
$sqldb = real_con($id);
if(is_logonline($id,$idfso)) return "<span class=font06>管理员提醒：请确保您已正常退出游戏！</span>";
$sqldb = real_con($id);
$sqldb->select_db(game_fso($id));
$fsoinfo = $sqldb->get_one("SELECT AccountID,Level,OnlineTime FROM user WHERE ID='$value'");
if($fsoinfo)
{
$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>';
}
}
$sqldb->select_db(game_fso($id));
$fsoinfo = $sqldb->get_one("SELECT AccountID,Level,Gold,PK FROM user WHERE ID='$idfso' AND deleted=0");
if(!$fsoinfo) return "<span class=font06>未查询到角色数据！</span>";
$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 ($tocheck==1){
if($fsoinfo['Level'] <$MOD['gamemoneylevel']) return "<span class=font06>您的等级未达到游戏币清洗的等级！</span>";
$PK = $fsoinfo['PK'];
if($PK <1) return "<span class=font06>目前你仍然是一个好人，不需要清洗！</span>";
if($PK <$tonum)  return "<span class=font06>你填写的PK值超过你本身的PK值！</span>";
$newGold=$fsoinfo['Gold']-$tonum*$MOD[gamemoneynum];
$toGold=$tonum*$MOD[gamemoneynum]/10000;
if($newGold <1)  return '<TABLE class=mw_tabA cellSpacing=0 cellPadding=0 width="90%" align=center border=0><TBODY><TR><TD height="30" colspan="2">很遗憾！</TD></TR><TD height=30 style="text-align:center;color:#900;font-weight:bold">清洗失败！</TD></TR><TR><TD height=30 align="center">原因：游戏币不够！本次清洗需花费：'.$toGold.'万游戏币。 </TD></TR><TR><TD class=pat10 align="center"><input type="button" class="hsbtn" value="确认" onclick="doView();CloseLoad();"></TD></TR></TBODY></TABLE>';
$newpk=$PK-$tonum;
$sqldb->select_db(game_fso($id));
$sqldb->query("update  user set Gold='$newGold',PK='$newpk' WHERE ID='$idfso'");
return '<TABLE class=mw_tabA cellSpacing=0 cellPadding=0 width="90%" align=center border=0><TBODY><TR><TD height="30" colspan="2">祝贺你：</TD></TR><TD height=30 style="text-align:center;color:#900;font-weight:bold">清洗'.$tonum.'点PK值！</TD></TR><TR><TD height=30 align="center">本次清洗花费：'.$toGold.'万，还有：'.$newpk.'点PK值需要清洗。 </TD></TR><TR><TD class=pat10 align="center"><input type="button" class="hsbtn" value="确认" onclick="doView();CloseLoad();"></TD></TR></TBODY></TABLE>';
}
if ($tocheck==2){
return "暂时没有开放哈迪币清洗功能";
if($fsoinfo['Level'] <$MOD['hardylevel']) return "<span class=font06>您的等级未达到使用哈迪币清洗的等级！</span>";
$PK = $fsoinfo['PK'];
if($PK <1) return "<span class=font06>目前你仍然是一个好人，不需要清洗！</span>";
if($PK <$tonum)  return "<span class=font06>你填写的PK值超过你本身的PK值！</span>";
$newGold=$fsoinfo['Gold']-$tonum*$MOD[hardynum];
$toGold=$tonum*$MOD[hardynum];
if($newGold <1)  return '<TABLE class=mw_tabA cellSpacing=0 cellPadding=0 width="90%" align=center border=0><TBODY><TR><TD height="30" colspan="2">很遗憾！</TD></TR><TD height=30 style="text-align:center;color:#900;font-weight:bold">清洗失败！</TD></TR><TR><TD height=30 align="center">原因：游戏币不够！本次清洗需花费：'.$toGold.'万游戏币。 </TD></TR><TR><TD class=pat10 align="center"><input type="button" class="hsbtn" value="确认" onclick="doView();CloseLoad();"></TD></TR></TBODY></TABLE>';
$newpk=$PK-$tonum;
$sqldb->select_db(game_fso($id));
$sqldb->query("update  user set Gold='$newGold',PK='$newpk' WHERE ID='$idfso'");
return '<TABLE class=mw_tabA cellSpacing=0 cellPadding=0 width="90%" align=center border=0><TBODY><TR><TD height="30" colspan="2">祝贺你：</TD></TR><TD height=30 style="text-align:center;color:#900;font-weight:bold">清洗'.$tonum.'点PK值！</TD></TR><TR><TD height=30 align="center">本次清洗花费：'.$toGold.'万，还有：'.$newpk.'点PK值需要清洗。 </TD></TR><TR><TD class=pat10 align="center"><input type="button" class="hsbtn" value="确认" onclick="doView();CloseLoad();"></TD></TR></TBODY></TABLE>';
}
}
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_logonline($id,$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>';
$sqldb = real_con($id);
$sqldb->select_db(game_fso($id));
$fsoinfo = $sqldb->get_one("SELECT AccountID,Level,PK FROM user WHERE ID='$value'");
if($fsoinfo)
{
$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>';
}
$Level = $fsoinfo['Level'];
$PK = $fsoinfo['PK'];
if($PK <1) 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($Level &&$PK)
{
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"><em style="font-weight:bold;color:#f00">'.$Level.'</em> 级</TD></TR>
  <TR><TH style="font-weight:bold;font-size:14px">当前PK值： </TH><TD colSpan=2 style="color:#555;font-size:14px;font-weight:bold"><em style="font-weight:bold;color:#f00">'.$PK.'</em> 点</TD></TR>
  <TR><TH style="font-weight:bold;font-size:14px">忏悔方式： </TH><TD colSpan=2 style="color:#555;font-size:14px;font-weight:bold"><select id="tocheck"><option value=1>=游戏币=</option><option value=2>=哈迪币=</option></select>(你想用什么方式来清洗？)</TD></TR> 
  <TR><TH style="font-weight:bold;font-size:14px">清洗数量： </TH><TD colSpan=2 style="color:#555;font-size:14px;font-weight:bold"><INPUT class=inputA type="text" id="tonum" value="'.$PK.'" style="font-weight:bold;font-size:14px;color:#F00"> 点</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 != 1");
if(!$rs)
{
return "该分区没有角色！";
}else{
while($r = $sqldb->fetch_array($rs))
{
$users[] = $r;
}
foreach($users as $value)
{
$bstr .= '<option value='.$value[ID].'>'.$value[Name].'</option>';
}
return '<select id="idfso" onchange="doView()"><option>-- 请选择角色 --</option>'.$bstr.'</select>';
}
}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 != 1");
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'];
$infos = $db->get_one("SELECT area FROM ".TABLE_MEMBER_INFO." WHERE userid='$_userid'");
if(!$infos['area']) showmessage("请选激活游戏分区再进行此操作！","/game/actgame.php");
$gamelists = array();
$rs = $db->query("SELECT * FROM ".TABLE_GAMESERVER." WHERE id IN ($infos[area]) ORDER BY id");
while($r = $db->fetch_array($rs))
{
$gamelists[] = $r;
}
include template($mod,'clearpk');
?>