<?php
require("../class/connect.php");
require("../class/q_functions.php");
require("../member/class/user.php");
require("../data/dbcache/MemberLevel.php");
eCheckCloseMods('pay');//關閉模塊
$link=db_connect();
$empire=new mysqlquery();
//是否登錄
$user=islogin();
//支付平台
$payid=intval($_POST['payid']);
if(!$payid)
{
	printerror('請選擇支付平台','',1,0,1);
}
//充值類型
$id=intval($_POST['id']);
if(!$id)
{
	printerror('請選擇充值類型','',1,0,1);
}
$payr=$empire->fetch1("select * from {$dbtbpre}enewspayapi where payid='$payid' and isclose=0".do_dblimit_one());
if(!$payr['payid'])
{
	printerror('請選擇支付平台','',1,0,1);
}
$buyr=$empire->fetch1("select * from {$dbtbpre}enewsbuygroup where id='$id'");
if(!$buyr['id'])
{
	printerror('請選擇充值類型','',1,0,1);
}
//權限
if($buyr['buygroupid']&&$level_r[$buyr['buygroupid']]['level']>$level_r[$user['groupid']]['level'])
{
	printerror('此充值類型需要 '.$level_r[$buyr['buygroupid']]['groupname'].' 會員級別以上','',1,0,1);
}
//有效期驗證
if($buyr['gdate']&&$user['groupid']!=$buyr['ggroupid'])
{
	if($user['userdate']&&$user['userdate']>=time())
	{
		if(!$public_r['mhavedatedo'])
		{
			printerror('您當前的會員組有效期未到，不能充值新會員組','',1,0,1);
		}
	}
}
$ddno='';
$productname='';
$productsay='';

include('payfun.php');

$money=$buyr['gmoney'];
$money=efmmoney($money);
if($money<=0)
{
	printerror('此充值類型金額有誤','',1,0,1);
}
//支付參數
$prdr=array();
$prdr['userid']=$user['userid'];
$prdr['username']=$user['username'];
$prdr['orderid']='';
$prdr['money']=$money;
$prdr['posttime']='';
$prdr['paybz']='';
$prdr['paytype']=$payr['paytype'];
$prdr['payip']='';
$prdr['ispay']=0;
$prdr['paydo']='BuyGroupPay';
$prdr['payfor']=$buyr['id'];
$prdr['payckcode']='';
$prdr['payddno']=epayapi_ReturnDdno($prdr['userid']);
$prdr['endtime']='';
//支付參數
$ddno='';
$prdr['pname']="充值類型:".$buyr['gname'].",UID:".$user['userid'].",UName:".$user['username'];
$prdr['psay']="充值類型:".$buyr['gname'].",用戶ID:".$user['userid'].",用戶名:".$user['username'];
$ddno=$prdr['payddno'];
$productname=$prdr['pname'];
$productsay=$prdr['psay'];

esetcookie("payphome","BuyGroupPay",0);
esetcookie("paymoneybgid",$id,0);
//返回地址前綴
$PayReturnUrlQz=$public_r['newsurl'];
if(!stristr($public_r['newsurl'],'://'))
{
	$PayReturnUrlQz=eReturnDomain().$public_r['newsurl'];
}
//編碼
$iconv='';
$char='';
$targetchar='';
/*
if($ecms_config['sets']['pagechar']!='gb2312')
{
	$char=$ecms_config['sets']['pagechar']=='big5'?'BIG5':'UTF8';
	$targetchar='GB2312';
	$productname=DoIconvVal($char,$targetchar,$productname);
	$productsay=DoIconvVal($char,$targetchar,$productsay);
	@header('Content-Type: text/html; charset=gb2312');
}
*/
//記錄
$re_prdr=epayapi_AddPayRecord($prdr);
$prdr['id']=$re_prdr['id'];
$prdr['payckcode']=$re_prdr['payckcode'];
$prdr['posttime']=$re_prdr['posttime'];
$prdr['payip']=$re_prdr['payip'];

eCheckStrType(4,$payr['paytype'],1);
$file=$payr['paytype'].'/to_pay.php';
@include($file);
db_close();
$empire=null;
?>