<?
//attach.php
include "config.inc.php";
include "class/member.class.php";
//$uid=$_GET[uid];
$code=$_GET[code];
$member=new member();
$user_info = $member->member_auth();
if(!$uid=$member->check_code($code)){
//if(!$member->member_auth()=="Guest"){
		include "modules/member/index.php";
}else{
$adb =$PlusDB->prefix(articles);
$fdb = $PlusDB->prefix(attachment);
$sdb = $PlusDB->prefix(server);
$logdb= $PlusDB->prefix(user_log);
$id=$_GET[id];
$sql="select f.*,s.* from $fdb f left join $sdb s on (s.id =f.server) where f.id=$id";
$row=$PlusDB->query_firstrow($sql);
if(!is_array($row)){
	
}else{
	//trace($row);
	//减去耗费的点数
	if($user_info[user_level]=="Member"){
	if(!$member->d_point($user_info[user_id],$row[point])) error(_LANG_0926);
	}
	//记录消费记录
	$aid=$row[aid];
	$point=($user_info[user_level]=="Member")?$row[point]:0;
	$now=date("Y-m-d H:i:s");
	$sql="Insert into $logdb (aid,atid,uid,ctime,point) values ('$aid','$id','$user_info[user_id]','$now','$point')";
	$PlusDB->queryF($sql);
	$server=$row[server];
	//更新下载数
	$sql="update $fdb set hits=hits+1 where id=$id";
	$PlusDB->queryF($sql);
	//更新总的下载数
	$sql="update $adb set hits=hits+1 where id=$row[aid]";
	$PlusDB->queryF($sql);
	if($server=="0"){
		$downurl = $row[url];
	}else{
		$ftpinfo=$member->getFtpInfo($uid);
		$surl=rawurlencode($row[url]);
		$surl=str_replace("%2F","/",$surl);
		$downurl = "ftp://$ftpinfo[FUserName]:$ftpinfo[FPassword]@".$row[host].":".$row[port]."/".$surl;
	}
	header("Location: $downurl");
}
}
?>
