<!--#include file="lib.asp" -->
<%

Response.Expires = 0  
Response.ExpiresAbsolute = Now() - 1  
Response.cachecontrol = "no-cache" 
response.Charset="gbk"


dim w_url,id,cai,ids,pagenum,cid,cpage
w_url=replace(getForm("url","get"),"'","")
id=replace(getForm("id","get"),"'","")
cai=replace(getForm("cai","get"),"'","")
ids=replace(getForm("ids","get"),"'","")
pagenum=replace(getForm("pagenum","get"),"'","")
cid=replace(getForm("cid","get"),"'","")
cpage=replace(getForm("cpage","get"),"'","")


dim ccid,siteemail,cc_key,cc_pwd,siteurl,vals,code
dim ElapsedBloom,obj_union,obj_external

set ElapsedBloom=new CCAPI
set obj_union=ElapsedBloom.createObject("CCAPI.TypeUnion")
set obj_external=ElapsedBloom.createObject("CCAPI.ExternalProgram")
If union_config_array(4)="" Then
		response.redirect account
Else
		ccid=union_config_array(5)
		siteemail=union_config_array(4)
		cc_key=union_config_array(6)
		cc_pwd=union_config_array(7)
		siteurl=union_config_array(6)
		vals=obj_union.getAllRelationUnionId()
		if cai="" then
			code = server.urlencode(auth_code("email="&siteemail&"&key="&cc_key&"&domain="&siteurl&"&cids="&vals, "encode", cc_key))
		elseif cai="ok" then
			code = server.urlencode(auth_code("email="&siteemail&"&key="&cc_key&"&domain="&siteurl&"&ids="&ids&"&cids="&vals&"&charset=gbk", "encode", cc_key))
		elseif cai="getday" then
			code= server.urlencode(auth_code("email="&siteemail&"&key="&cc_key&"&domain="&siteurl&"&pagenum="&pagenum&"&cids="&vals&"&charset=gbk", "encode", cc_key))
		elseif cai="gettype" then
			code= server.urlencode(auth_code("email="&siteemail&"&key="&cc_key&"&domain="&siteurl&"&pagenum="&pagenum&"&cids="&vals&"&charset=gbk&cid="&cid, "encode", cc_key))
		end if
End If



if cai="" then
	If w_url="" Then
		'echo  openUrl("http://trade.bokecc.com/trade/view/v.jsp?id="&ccid&"&p="&code&"&type=2&ver=asp3.0",2)
		echo  openUrl("http://trade.bokecc.com/maxapi/action/v.jsp?id="&ccid&"&p="&code&"&type=2&ver=dvbbsapi3.0",2)
	else
		echo  openUrl(w_url,2) 
		response.flush
	End If 
elseif cai="ok" then
	call handleResources(ccid,code,1)
elseif cai="getday" then
	call handleResources(ccid,code,2)
elseif cai="gettype" then
	call handleResources(ccid,code,3)
end if

set obj_union=nothing
set obj_external=nothing
set ElapsedBloom=nothing


conn.close
set conn=nothing


Function handleResources(ccid,code,ctype)
	dim handlurl,currenturl,strxml
	currenturl=getForm("backurl","get")
	'alertMsg "chenggong",currenturl 
	if ctype=1 then
		handlurl="http://trade.bokecc.com/trade/action/g.jsp?id="&ccid&"&p="&code&"&type=2"
	elseif ctype=2 then
		handlurl="http://trade.bokecc.com/trade/action/h.jsp?id="&ccid&"&p="&code&"&type=2"
	elseif ctype=3 then
		handlurl="http://trade.bokecc.com/thirdparty/action/c.jsp?id="&ccid&"&p="&code&"&type=2"
	end if

	strxml=openUrl(handlurl,1)
	If Left(strxml, 5) <> "<?xml" Or InStr(strxml, "</vlist>") = 0 Then
		echo  strxml
		set obj_union=nothing
		set obj_external=nothing
		set ElapsedBloom=nothing
		die()
	End If
	
	dim xmldoc,options2,alertContent,options3
	Set xmldoc =createXmlObj(strxml)
	set options2=xmldoc.selectNodes("vlist/alert/content")  
	alertContent=options2(0).text
	if alertContent<>"" then
		echo  "<script>alert('"&URLDecode(alertContent)&"');location.href="""&list&"""</script>"
		set obj_union=nothing
		set obj_external=nothing
		set ElapsedBloom=nothing 
		die()
	end if
	set options2=nothing
	if ctype=2 or ctype=3 then
		set options3=xmldoc.selectNodes("vlist/pagenum/content")  
		pagenum=options3(0).text
		set options3=nothing
	end if
	dim options

	set options=xmldoc.selectNodes("vlist/v")  
	Dim vid_tem(2)
	Dim zt_dy(2)
	echo  "<font color=red>"&gatherstr_array(0)&"</font><br>" 
	obj_external.writeLoadingBar
	obj_external.writeJsFun
	obj_external.writeIfraStr
	dim formnumber
	formnumber=1
	dim i,vid,title,tid,act,pic,des,tag,states,gtid
	for i=0 to options.length-1
			set vid=options(i).selectSingleNode("vid")   
			set title=options(i).childNodes(1)
			set tid=options(i).childNodes(2)
			set act=options(i).childNodes(3)
			set pic=options(i).childNodes(4)
			set des=options(i).childNodes(5)
			set tag=options(i).childNodes(6)
			set states=options(i).childNodes(7)
			gtid=obj_union.isExistRelation(tid.text)

			'判断是否存在绑定的联盟分类
			If gtid <> false Then
				if obj_external.checkIsExistSpecial(trim(vid.text))=false then
					 '-----------Dvbbs.MemberName获取动网登陆用户名-------------------------
					 obj_external.setFormValue gtid,Dvbbs.MemberName,"******",URLDecode(title.text),obj_external.playerStr(vid.text)&replace(URLDecode(des.text),"&nbsp;"," ")
					 obj_external.writeFormStr(formnumber)
					 formnumber=formnumber+1
				end if
			End If
	Next
	'response.End()
	if formNumber-1=0 then
		call alertMsg(gatherstr_array(1),currenturl)
	end if
	'response.End()
	'response.Write "<script>alert('"&pagenum&"')<//script>"
	if replace(pagenum," ","")="" Then
		If cai="getday" Then
			obj_external.writeJsSubmit formNumber-1,list
		elseif  cai="gettype" then
			obj_external.writeJsSubmit formNumber-1,cpage
		Else
			obj_external.writeJsSubmit formNumber-1,currenturl
		End if
	else
		dim backurl
		echo  "<font color=red>"&gatherstr_array(2)&pagenum&gatherstr_array(3)&"</font><br />"
		If cai="getday" Then
			backurl=list&"?cai=getday&pagenum="&pagenum
		elseif cai="gettype" Then
			backurl=list&"?cai=gettype&pagenum="&pagenum&"&cid="&cid&"&cpage="&cpage
		end if
		obj_external.writeTypeJsSubmit formNumber-1,backurl
	end if
	response.Flush()

end Function
%>


<script type="text/javascript">
function a(b){
	location.href="<%=list%>?url="+encodeURIComponent(b)
} 

function h(){
	location.href="<%=list%>?cai=getday"
}

function c(id){
       location.href="<%=list%>?cai=gettype&cid="+id+"&cpage="+encodeURIComponent(location.href)
}


function b(){
	specialid=document.getElementsByName('specialid')
	if(specialid==undefined){
		alert("还没有选要同步的专辑!");
		return;
	}
	var specialids=""
	if(specialid.length!=undefined){
		var isFirst =true;
		for (var i=0;i<specialid.length;i++){
			if(specialid[i].checked){
					if(isFirst){
							specialids+=specialid[i].value;
							isFirst = false;
					}else{
							specialids+=","+specialid[i].value;
					}
		     }
	    }
	 }else{
			if(specialid.checked){
				 	specialids=specialid.value;
			}
	}
	if(specialids==""){
			alert("还没有选要同步的专辑!");
			return;
	}else{
		location.href="<%=list%>?cai=ok&siteemail=<%=siteemail%>&pwd=<%=cc_pwd%>&ids="+specialids+"&backurl="+encodeURIComponent(location.href)
	}
	
}
</script>

