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

if(!$_userid)
{
	showmessage($LANG['login_website'], $MODULE['member']['linkurl'].'login.php?forward='.urlencode($PHP_URL));
}

function doSub($idserver,$idfso,$fsoname,$truename,$telephone,$qq)
{
	global $db,$_userid;
	if(!$idserver) return "<span class=font06>请选择服务器</span>";
	if(!$truename) return "<span class=font06>请填定真实姓名</span>";
	if(!$telephone) return "<span class=font06>请填写电话号码</span>";
	if(!$qq) return "<span class=font06>请填写QQ号码</span>";
	if(!$idfso || !$fsoname) return "<span class=font06>请选择领取角色</span>";
	if(!$idserver) return "<span class=font06>请选择游戏分区</span>";
	if(!is_numeric($telephone) || strlen($telephone) <7 || strlen($telephone) >15) return "<span class=font06>电话号码输入有误</span>";
	if(!is_numeric($qq) || strlen($qq) <5 || strlen($qq) > 11) return "<span class=font06>QQ号码输入有误</span>";
  $db->query("UPDATE ".TABLE_MEMBER_INFO." SET truename='$truename',telephone='$telephone',qq='$qq' WHERE userid=$_userid");
  $db->query("UPDATE ".TABLE_PRODUCT_CART." SET idserver='$idserver',idfso='$idfso',fsoname='$fsoname' WHERE user_id=$_userid AND odr_id=0");
  return "true";
}


function checkserv($id)
{
 global $db,$_userid,$_username;
 if(!$id) return "<span class=font06>请选择分区</span>";
 	$rs = cache_read("gamelist_".$id.".php");
	@extract($rs);

  $msyqlco = @mysql_connect($serverip.':'.$port, $loginname, $loginpass,$dataacc);
	if(!$msyqlco) return "<span class=font06>当前分区连接失败，请与管理员联系</span>";
		
	$sqldb = new db_mysql;
	$sqldb->connect($serverip.':'.$port, $loginname, $loginpass, $dataacc);
		
  $info = $sqldb->get_one("SELECT idx FROM user WHERE username='$_username'");
  if($info)
  {
  $sqldb->select_db($datafso);
  $infou = $sqldb->get_one("SELECT ID FROM user WHERE AccountID='".$info['idx']."'");
    if(!$infou)
    {
      return "<span class=font06>该区没有角色，请先创建角色再购买！</span>";
    }else{
      return "true";
    }  
  
  }else{
  return "<span class=font06>您没有激活该分区</span>";
  }
  return "true";
}

function listfso($id)
{
 global $db,$_userid,$_username;
 if(!$id) return "游戏分区读取错误";
 	$rs = cache_read("gamelist_".$id.".php");
	@extract($rs);

  $msyqlco = @mysql_connect($serverip.':'.$port, $loginname, $loginpass,$dataacc);
	if(!$msyqlco) return "当前分区连接失败，请与管理员联系";
		
	$sqldb = new db_mysql;
	$sqldb->connect($serverip.':'.$port, $loginname, $loginpass, $dataacc);
		
  $info = $sqldb->get_one("SELECT idx FROM user WHERE username='$_username'");
  if($info)
  {
  $sqldb->select_db($datafso);
  $sqldb->query("SET NAMES DEFAULT");
  $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>';
	  $hstr .= '<input type="hidden" id="fso_'.$value[ID].'" value='.$value[Name].'>';
    }
      return '<select id="idfso" onchange="checkselect()"><option>-- 请选择角色 --</option>'.$bstr.'</select>'.$hstr;
    }  
  
  }else{
  return "您没有激活该分区";
  }
  return "true";
}

function doView()
{
	global $db,$_userid,$PHP_TIME,$_username;
	$r = $db->get_one("SELECT * FROM ".TABLE_PRODUCT_CART." where user_id=$_userid AND odr_id=0 limit 0,1");
	if(!$r) return "<H4 style=color:#F00>错误的操作</H4><TABLE class=mw_tabA cellSpacing=0 cellPadding=0 width=90% align=center border=0><TBODY><TR><TD height=205><strong>未读取到所购买的道具信息，请重新在商城中重新购买，如果问题依然存在，请与管理员联系！</strong></TD>
</TR><TR><TD align=center><input type=button class=hsbtn value=关闭 onclick='javascript:window.close()'></TD></TR></TBODY></TABLE>";
	$s = cache_read("gamelist_".$r[idserver].".php");
	$t = $db->get_one("SELECT price FROM ".TABLE_PRODUCT." where productid=".$r['productid']." limit 0,1");
	if($r[fsoname] && $r[pdt_name] && $s[servername] && $t[price])
	{
  $dt = md5(date('Y-m-d',$PHP_TIME));
  $uc = md5($_username.'HARDYSOFT');
  $sessionid = base64_encode($dt.$uc);
  return "<H4 style=color:#F00>服务器信息</H4><TABLE class=mw_tabA cellSpacing=0 cellPadding=0 width=90% align=center border=0><TBODY><TR><TH>游戏分区: </TH><TD>&nbsp;<strong>".$s[servername]."</strong></TD>
</TR><TR><TH>领取角色: </TH><TD>&nbsp;<strong>".$r[fsoname]."</strong></TD>
</TR><TR><TH>&nbsp;</TH><TD></TD></TR></TBODY></TABLE><H4 style=color:#F00>道具信息</H4><TABLE class=mw_tabA cellSpacing=0 cellPadding=0 width=90% align=center border=0><TBODY><TR><TH>道具名称: </TH><TD>&nbsp;<strong>".$r[pdt_name]."</strong></TD>
</TR><TR><TH>道具价格: </TH><TD>&nbsp;<strong>".$t[price]."</strong></TD>
</TR><TR><TH>&nbsp;</TH><TD></TD></TR><TR><TH></TH><TD class=pat10><input type=button class=hsbtn value=支付 onclick=this.disabled=true;window.location.href='{$MOD[linkurl]}order.php?sessionid=".$sessionid."'>&nbsp;&nbsp;<A 
      class=font10 href='javascript:CloseLoad()'>返回重选</A></TD></TR></TBODY></TABLE>";
  }else{
  return "<H4 style=color:#F00>出现严重错误</H4><TABLE class=mw_tabA cellSpacing=0 cellPadding=0 width=90% align=center border=0><TBODY><TR><TD height=205><strong>无法取得相关信息，请重试，如果问题依然存在，请立即停止购买，并与管理员联系！</strong></TD>
</TR><TR><TD align=center><input type=button class=hsbtn value=关闭 onclick='javascript:CloseLoad()'></TD></TR></TBODY></TABLE>";
}
}



if ($action) showmessage($LANG['illegal_operation'],$PHP_REFERER);

	$newframeid = md5(date('Y-m-d',$PHP_TIME));
	$newframeid = base64_encode($newframeid.$_username);
	if(!$frameid || $newframeid != $frameid)
	{
		showmessage('错误的请求！',HS_PATH.$mod.'/');	
	}else{
  $ii =$_SERVER['HTTP_REFERER'];
	$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,'payment');
	exit();
 }


?>