<!--#include file="../lib/base.asp"-->
<!--#include file="../theme.asp"-->
<%
''' EYCMS 下载
''' ==================================================================
	eycms.stophack
	dim id:id=eycms.getint(eycms.fget("id",0),0)
	dim order:order=eycms.getint(eycms.fget("order",0),-1)
	get_down id,order
	
	sub get_down(byval t0,byval t1)
		if t0=0 or t1<0 then
			eycms.echo "0无效的下载"
			exit sub
		end if
			dim data,point
			 data=eycms.db.dbload(1,"point","ey_content","id="&t0&" and islock=1","")
			 if ubound(data)<0 then
				eycms.echo "0无效的下载"
				exit sub
			 end if
			 point=data(0,0)
			 data=eycms.db.dbload(1,"downurl","ey_model_down","cid="&t0&"","")
			 if ubound(data)<0 then
				eycms.echo "0无效的下载"
				exit sub
			 end if
			 downdata=data(0,0)
			 dim downarr,downdata,downurl
			 downarr=split(downdata,",")
			 if t1>ubound(downarr) then
				 eycms.echo "0无效的下载"
				exit sub
			 end if
			 downurl=downarr(t1)
			 if point=0 then
				 if instr(downurl,"thunder://")>0 then
					 eycms.echo "<script src=""http://pstatic.xunlei.com/js/webThunderDetect.js""></script>"&vbcrlf
					 eycms.echo "<script type=""text/javascript"">OnDownloadClick('"&downurl&"','',location.href,'132450',false)</script>"
				 else
					 eycms.go downurl
				 end if
				 exit sub
			 end if
				if not(eycms.is_login) then
					eycms.echo "1请先登录或注册"
					exit sub
				else
					dim userdata:userdata=eycms.userinfo
					dim userid:userid=userdata(0)
					if userdata(8)=1 then
						if userdata(9)=0 then
						else
							if instr(downurl,"thunder://")>0 then
								 eycms.echo "<script src=""http://pstatic.xunlei.com/js/webThunderDetect.js""></script>"&vbcrlf
								 eycms.echo "<script type=""text/javascript"">OnDownloadClick('"&downurl&"','',location.href,'132450',false)</script>"
							 else
								 eycms.echo "3"&downurl
							 end if
							exit sub
						end if
					end if
					dim upoint:upoint=eycms.db.dbloadone("point","ey_user","id="&userid&"")
				end if
			dim npoint:npoint=upoint-point
			dim rs,ure
			ure=0
			set rs=server.createobject("adodb.recordset")
			rs.open "select contentid,point,userid,createdate,lastupdate from ey_user_buy where contentid="&t0&" and userid="&userid&"",eycms.db.conn,1,3
			if rs.eof then
				 if upoint<point then
					eycms.echo "2您的积分不足，请先充值！"
					exit sub
				end if
				ure=1
				rs.addnew
				rs(0)=t0
				rs(1)=point
				rs(2)=userid
				rs(3)=now()
				rs(4)=now()
			else
				rs.update
				rs(4)=now()
			end if
			rs.update
			rs.close
			set rs=nothing
			if ure=1 then
				eycms.db.dbupdate "ey_user","id="&userid&"",array(array("point",npoint,10,0))
				eycms.createuserpoint array(array("point",point,0,0),array("userid",userid,0,0),array("type",2,0,0),array("content","<a href='../show.asp?id="&t0&"' target='_blank'>下载资源，支付："&point&"积分</a>",0,1),array("createdate",now(),0,1))
			end if
			eycms.echo "3"&downurl
	end sub

	eycms.db.dbclose
%>
