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

$head['title'] = "消费明细";
$head['keywords'] = $MOD['seo_keywords'];
$head['description'] = $MOD['seo_description'];

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

	$pagesize = isset($pagesize) ? $pagesize : $HS['pagesize'];
	$page = isset($page) ? intval($page) : 1;
	$offset = ($page-1)*$pagesize;
	$r = $db->get_one("SELECT count(*) as num  FROM ".TABLE_PRODUCT_ORDER." WHERE memberid=".$_userid);
	$number = $r['num'];
	$pages  = phppages($number,$page,$pagesize);
	$query = 'SELECT o.*,c.pdt_name,g.servername FROM '.TABLE_PRODUCT_ORDER.' o,'.TABLE_PRODUCT_CART.' c,'.TABLE_GAMESERVER.' g WHERE o.idserver=g.id AND o.odr_id=c.odr_id AND o.memberid='.$_userid.' ORDER BY o.odr_id desc,o.isship asc limit '.$offset.','.$pagesize;
	$result = $db->query($query);

	$orders = array();
	while($r = $db->fetch_array($result))
	{
		$orders[] =$r;		
	}	
	include template($mod,'myorder');

function senditem($id)
{
  global $db,$_userid,$PHP_TIME;
 	$rs = $db->get_one("SELECT g.*,o.idfso,o.odr_id,o.isship,c.pdt_No FROM ".TABLE_GAMESERVER." g,".TABLE_PRODUCT_ORDER." o,".TABLE_PRODUCT_CART." c WHERE o.idserver=g.id AND o.odr_id=c.odr_id AND o.odr_No='$id'");
	@extract($rs);
 	if($isship == "1") return "非法请求，此道具已发送！请不要试图破坏系统。你的帐号已被记录。";
 	
  $msyqlco = @mysql_connect($serverip.':'.$port, $loginname, $loginpass,$datafso);
	if(!$msyqlco) return "不能连接到游戏服务器，请与管理员联系,发送失败！";
		
	$sqldb = new db_mysql;
	$sqldb->connect($serverip.':'.$port, $loginname, $loginpass, $datafso);
	
	$buytime =date("Y-m-d H:i:s",$PHP_TIME);
	$gift = $sqldb->query("INSERT INTO t_gift (`charID`,`level`,`type`,`attribute`,`addTime`,`limitTime`,`msg`) VALUES ('$idfso',0,1,'ver=1;count=1;|id=$pdt_No;color=$itemcolor;lev=0;bind=$itembind;|','$buytime','','网站购买道具')");
	if($sqldb->affected_rows())
	 {
	  $shipstatus = 1;
	 }else{
	  $shipstatus = 0;
	  return "更新数据错误，请与管理员联系,发送失败！";
	 }
	  
	$query = "UPDATE ".TABLE_PRODUCT_ORDER." SET isship='$shipstatus',shiptime='$PHP_TIME' WHERE odr_id='$odr_id'";
	$db->query($query);
  return "true";
  
}
?>