<!--#include file="admin_conn.asp"-->
<!--#include file="../inc/pinyin.asp"-->
<%
chkLogin
Response.Buffer = true
Server.ScriptTimeOut=999999
dim action, rpage, cjurl, cjflag, rtype, rkey ,rday, fa, xt, rid, url, typearr, backurl

action = be("all", "action")
rtype = be("all", "rtype")
rpage = be("all", "rpage")
cjurl = be("all", "cjurl")
rkey = be("all", "rkey")
rday = be("all", "rday")
fa = be("all", "fa")
xt = be("all","xt")
rid = be("all","rid")
cjflag = be("all","cjflag")
backurl = Request.ServerVariables("HTTP_REFERER")

If Not isNum(rtype) Then rtype = 0 Else rtype = CInt(rtype)
If Not isNum(rpage) Then rpage = 1 Else rpage = CInt(rpage)
If Not isNum(rday) Then rday = 1 Else rday = CInt(rday)
If rpage < 1 Then rpage = 1

Select Case action
	Case "bindunion": headAdmin "联盟资源": bindunion
	Case "bindunionsave": bindunionsave
	Case "cjsel": headAdmin "联盟资源": cjsel
	Case "cjday": headAdmin "联盟资源": cjday
	Case "cjtype": headAdmin "联盟资源": cjtype
	Case "cjall": headAdmin "联盟资源": cjall
	Case "breakpoint": headAdmin "联盟资源": breakpoint
	Case "list": headAdmin "联盟资源": list
	Case Else: headAdmin "联盟资源": main
End Select
set typearr=nothing
footAdmin

Function cut(str, start, start_num, Over, over_num)
    cut = Mid(str, InStr(str, start) + start_num, InStr(str, Over) + over_num - InStr(str, start) - start_num)
End Function

Sub breakpoint()
    writeA gBreakpoint("../upload/maccjbreakpoint") & "正在载入断点续传数据，请稍后......"
End Sub

Sub cjsel()
    Dim ids
    ids = be("all", "ids")
    If isN(ids) Then ErrMsg "采集提示", "请选择采集数据": Exit Sub
    if xt="1" then
    	url = cjurl & "?ac=videolist&rid="&rid&"&ids=" & ids
    elseif xt="2" then
    	url = cjurl &  "-action-ids-vodids-"&ids&"-cid--play--inputer--wd--h-0-p-1"
    else
    	url = cjurl & "?action=cjsel&ids=" & ids
    end if
    Call insertdata(url, "cjsel")
End Sub

Sub cjday()
    if xt="1" then
    	url = cjurl & "?ac=videolist&rid="&rid&"&h="&rday&"&pg=" & rpage
    elseif xt="2" then
    	url = cjurl &"-action-day-vodids--cid--play--inputer--wd--h-"&rday&"-p-"&rpage
    else
    	url = cjurl & "?action=cjday&rday="&rday&"&rpage=" & rpage
    end if
    Call insertdata(url, "cjday")
End Sub

Sub cjtype()
    If isN(rtype) Then
        showMsg "请先进入分类,否则无法使用采集分类!", backurl
        Exit Sub
    End If
    if xt="1" then
    	url = cjurl & "?ac=videolist&rid="&rid&"&pg=" & rpage & "&t=" & rtype
    elseif xt="2" then
    	url = cjurl & "-action-all-vodids--cid-"&rtype&"-play--inputer--wd--h-0-p-"&rpage
    else
    	url = cjurl & "?action=cjtype&rpage=" & rpage & "&rtype=" & rtype
    end if
    Call insertdata(url, "cjtype")
End Sub

Sub cjall()
    if xt="1" then
    	url = cjurl & "?ac=videolist&rid="&rid&"&pg=" & rpage
    elseif xt="2" then
    	url = cjurl & "-action-all-vodids--cid--play--inputer--wd--h-0-p-" & rpage
    else
    	url = cjurl & "?action=cjall&rpage=" & rpage
    end if
    Call insertdata(url, "cjall")
End Sub

function getFrom(byval f)
	select case f
		case "百度影音" : f="baidu"
		case "bdhd":f="baidu"
		case "皮皮影音":f="pipi"
		case "闪播Pvod":f="pvod"
		case "迅播高清":f="gvod"
		case "优酷","yuku":f="youku"
		case "qq播客":f="qq"
		case "yuku":f="youku"
	end select
	getFrom = f
end function

function getVUrl(byval u)
	dim arr1,arr2,arr3,i,j,str,rc
	arr1 = split(u,"#")
	rc=false
	for i=0 to ubound(arr1)
		if not isN(arr1(i)) then
			if instr( arr1(i),"$$") > 0 then
				arr3 = split(arr1(i),"$$")
				arr2= split(arr3(1),"$")
			else
				arr2= split(arr1(i),"$")
			end if
			if rc then str = str & "#"
			if ubound(arr2)=2 or ubound(arr2)=1 then
				str = str & arr2(0) & "$" & arr2(1)
			else
				str = str & arr2(0)
			end if
			rc =true
			set arr2=nothing
			set arr3=nothing
		end if
	next
	set arr1=nothing
	getVUrl = str
end function

Sub insertdata(ByVal surl, ByVal cjtype)
    Dim objxml, xmlnode, html, i, j, k, strpic, arr1, arr2, tmpplayfrom, tmpplayurl, tmpplayserver, vodurls, rc,sql, rs, pagecount, resultdes
    Dim vodid, vodname, vodenname,vodnote, vodstate, vodtype, vodstarring, vodpic, vodtime, vodyear, vodarea, vodlanguage,voddes, autoid, vodsubname, vodcolor, voddirected, vodremarks, vodhitstime,vodletter,vodfrom,vodserver,vodurl,voddownfrom,voddownserver,voddownurl
    Dim xn_list,xn_type,xn_vod,xn_vod_time,xn_vod_from,xn_vod_tid,xn_vod_starring,xn_vod_directed,xn_vod_language,xn_vod_lang,xn_vod_urls
    
    wBreakpoint "../upload/maccjbreakpoint", "admin_maccj.asp?action=" & action & "&xt="& xt & "&rid="& rid & "&cjflag="& cjflag & "&rpage=" & rpage & "&rtype=" & rtype & "&rkey=" & rkey & "&cjurl=" & cjurl
    
    if xt="1" or xt="2" then
    	xn_list = "list"
    	xn_type = "rss/class/ty"
    	xn_vod = "rss/list/video"
    	xn_vod_time = "last"
    	xn_vod_from = "flag"
    	xn_vod_tid = "tid"
    	xn_vod_starring = "actor"
    	xn_vod_directed = "director"
    	xn_vod_language = "lang"
    	xn_vod_urls = "dl"
    else
    	xn_list = "vods"
    	xn_type = "maccms/types/type"
    	xn_vod = "maccms/vods/vod"
    	xn_vod_time = "time"
    	xn_vod_from = "from"
    	xn_vod_tid = "type"
    	xn_vod_starring = "starring"
    	xn_vod_directed = "directed"
    	xn_vod_language = "language"
    	xn_vod_urls = "urls"
    	cjflag=""
    end if
    
    html = getPage(surl, "utf-8")
    If html = False Then writeE "<table class=""tb""><tr><td colspan=2>&nbsp;<a href=""javascript:void(0)"" onclick=""location.reload();"">获取数据失败，请点击我重试</a></td></tr></table>"
    on error resume next
    Set objxml = New AppXMLDOM
    objxml.LoadXml (html)
    Set xmlnode = objxml.Root
    
    if xt="1" or xt="2" then
    	pagecount = xmlnode.getElementsByTagName(xn_list).Item(0).getAttributeNode("pagecount").nodevalue
    else
    	pagecount = xmlnode.getElementsByTagName("pagecount").Item(0).Text
    end if
    If Not isNum(pagecount) Then pagecount = 1 Else pagecount = CLng(pagecount)
    Set xmlnode = objxml.FindNodes(xn_vod)
    
    If Err.Number > 0 Or xmlnode.length = 0 Then
        writeA "<table class=""tb""><tr><td><br>没有任何可用数据<script language=""javascript"">setTimeout(""gonextpage();"",3000);function gonextpage(){location.href='?action=list&rid="&rid&"&xt="&xt&"&cjflag="&cjflag&"&cjurl=" & cjurl & "';}</script></td></tr></table>"
        Exit Sub
    End If
    Err.Clear
    On Error GoTo 0
    writeF "<table class=""tb""><tr><td colspan=2>视频采集地址&nbsp;" & url & "</td></tr><tr><td colspan=2>&nbsp;共"&pagecount&"页，正在采集第" & rpage & "页</td></tr>"
    
    For i = 0 To xmlnode.length - 1
        rc = False
        vodid = xmlnode(i).SelectNodes("id")(0).Text
        vodname = xmlnode(i).SelectNodes("name")(0).Text
        vodremarks = xmlnode(i).SelectNodes("note")(0).Text
        vodstate = xmlnode(i).SelectNodes("state")(0).Text
        vodtype = cjflag & xmlnode(i).SelectNodes(xn_vod_tid)(0).Text
        vodstarring = xmlnode(i).SelectNodes(xn_vod_starring)(0).Text
        voddirected = xmlnode(i).SelectNodes(xn_vod_directed)(0).Text
        vodpic = xmlnode(i).SelectNodes("pic")(0).Text
        vodtime = xmlnode(i).SelectNodes(xn_vod_time)(0).Text
        vodyear = xmlnode(i).SelectNodes("year")(0).Text
        vodarea = xmlnode(i).SelectNodes("area")(0).Text
        vodlanguage = xmlnode(i).SelectNodes(xn_vod_language)(0).Text
        voddes = xmlnode(i).SelectNodes("des")(0).Text
        Set vodurls = xmlnode(i).SelectNodes(xn_vod_urls)(0).childNodes
        
        vodsubname = ""
        vodcolor = ""
        vodhitstime = ""
        voddownurl = ""
        
        
        vodname = replaceStr(vodname, "'", ""): If Len(vodname) > 255 Then vodname = Left(vodname, 255)
        vodenname = Hanzi2PinYin(vodname): If Len(vodenname) > 255 Then vodenname = Left(vodenname, 255)
        if not isN(vodenname) then vodletter = UCase(left(vodenname,1))
        vodstate = replaceStr(vodstate, "[", ""): vodstate = replaceStr(vodstate, "]", ""):    If Not isNum(vodstate) Then vodstate = 0
        vodstarring = CStr(replaceStr(vodstarring, "'", "")): If Len(vodstarring) > 255 Then vodstarring = Left(vodstarring, 255)
        vodyear = replaceStr(vodyear, "'", ""):  If Len(vodyear) > 32 Then vodyear = Left(vodyear, 32)
        vodlanguage = replaceStr(vodlanguage, "'", ""):  If Len(vodlanguage) > 32 Then vodlanguage = Left(vodlanguage, 32)
        vodarea = replaceStr(vodarea, "'", ""):  If Len(vodarea) > 32 Then vodarea = Left(vodarea, 32)
        vodpic = replaceStr(vodpic, "'", ""):  If Len(vodpic) > 255 Then vodpic = Left(vodpic, 255)
        voddes = htmlDecode(voddes) : voddes = replaceStr(voddes, "'", "")
        vodtype = getTypeID(vodtype):  If Not isNum(vodtype) Then vodtype = 0
        vodfrom =""
        vodurl = ""
        vodserver = ""
        
        If not isN(vodname) and vodtype > 0 Then
            sql = "SELECT * FROM {pre}vod WHERE d_name ='" & vodname & "' "
            if app_vodmaccjsname = 1 then sql = sql & " and d_type= " & vodtype
            Set rs = objdb.DB(sql, "rs3")
            If rs.EOF And rs.Bof Then
                For j = 0 To vodurls.length - 1
                    
                    If rc Then vodfrom = vodfrom & "$$$": vodurl = vodurl & "$$$" : vodserver = vodserver & "$$$" :end if
                    vodfrom = vodfrom & getFrom(vodurls(j).getAttributeNode(xn_vod_from).nodevalue)
                    if xt="1" then
                    	vodurl = vodurl & getVUrl(vodurls(j).Text)
                    elseif xt="2" then
                    	vodurl = vodurl & replaceStr(vodurls(j).Text,chr(10),"#")
                    	vodurl = replace(vodurl,chr(13),"#")
                    	vodurl = replace(vodurl,"##","#")
                    else
                    	vodurl = vodurl & vodurls(j).Text
                    end if
                    vodurl = replaceStr(vodurl, "'", "''")
                    vodserver = vodserver & "0"
                    rc = True
                Next
                objdb.add "{pre}vod", Array("d_type", "d_name", "d_subname", "d_enname","d_letter", "d_state", "d_color", "d_content", "d_remarks", "d_pic", "d_level", "d_hits", "d_starring", "d_directed", "d_year", "d_area", "d_language", "d_addtime", "d_time", "d_playfrom", "d_playserver","d_playurl", "d_downfrom","d_downserver","d_downurl"), Array(vodtype, vodname, vodsubname, vodenname, vodletter, vodstate, vodcolor, voddes, vodremarks, vodpic, 0, 0, vodstarring, voddirected, vodyear, vodarea, vodlanguage, Now(), Now(), vodfrom, vodserver, vodurl,voddownfrom,voddownserver, voddownurl )
                wTips vodname, "新增数据"
            Else
                
                tmpplayurl = rs("d_playurl")
                tmpplayfrom = rs("d_playfrom")
                tmpplayserver = rs("d_playserver")
                
                For j = 0 To vodurls.length -1
                    vodfrom = getFrom(vodurls(j).getAttributeNode(xn_vod_from).nodevalue)
                    if xt="1" then
                    	vodurl = getVUrl(vodurls(j).Text)
                    elseif xt="2" then
                    	vodurl = replaceStr(vodurls(j).Text,chr(10),"#")
                    	vodurl = replace(vodurl,chr(13),"#")
                    	vodurl = replace(vodurl,"##","#")
                    else
                    	vodurl = vodurls(j).Text
                    end if
                    vodurl = replaceStr(vodurl, "'", "''")
                    If tmpplayurl = vodurl Then
                         resultdes = "无需更新播放地址"
                    ElseIf isN(tmpplayurl) Or InStr(rs("d_playfrom"), vodfrom) <= 0 Then
                        resultdes = "新增播放地址组"
                        tmpplayurl = tmpplayurl & "$$$" & vodurl
                        tmpplayfrom = tmpplayfrom & "$$$" & vodfrom
                        tmpplayserver = tmpplayserver & "$$$" & vodserver
                        rs("d_time") = Now()
                    Else
                        resultdes = "更新播放地址"
                        arr1 = Split(tmpplayurl, "$$$"): arr2 = Split(tmpplayfrom, "$$$"): rc = False: tmpplayurl = ""
                        For k = 0 To UBound(arr2)
                            If rc Then tmpplayurl = tmpplayurl & "$$$"
                            if ubound(arr1) >= k then
								If arr2(k) = vodfrom Then arr1(k) = vodurl
								tmpplayurl = tmpplayurl & arr1(k)
							else
								tmpplayurl = tmpplayurl & vodurl
							end if
                            rc = True
                        Next
                        rs("d_time") = Now()
                    End If
                Next
                tmpplayurl = replaceStr(tmpplayurl, Chr(13), "#")
                strpic = rs("d_pic")
                If InStr(","&strpic, "http:") > 0 Then rs("d_pic") = vodpic
                rs("d_state") = vodstate
                rs("d_remarks") = vodremarks
                rs("d_playurl") = tmpplayurl
                rs("d_playfrom") = tmpplayfrom
                rs("d_playserver") = tmpplayserver
                rs.update
                
                wTips vodname, resultdes
            End If
            objdb.C (rs)
        Else
            wTips vodname, "没有绑定分类、跳过"
        End If
    Next
    
    Set vodurls = Nothing
    Set xmlnode = Nothing
    Set objxml = Nothing
    writeA "</table>"
    
    
    If action = "cjday" Or action = "cjall" Or action = "cjtype" Then
        If rpage >= pagecount Then
            dBreakpoint "../upload/maccjbreakpoint"
            writeF "<br>数据采集完成<script language=""javascript"">setTimeout(""gonextpage();"",3000);function gonextpage(){location.href='?action=list&fa=1&xt="&xt&"&rid="&rid&"&cjflag="&cjflag&"&rtype="&rtype&"&cjurl=" & cjurl & "';}</script>"
        Else
            writeF "<br>暂停3秒后继续采集...<script language=""javascript"">setTimeout(""gonextpage();"",3000);function gonextpage(){location.href='?action=" & action & "&rpage=" & rpage + 1 & "&rtype=" & rtype & "&xt="&xt&"&rid="&rid&"&cjflag="&cjflag& "&rday="& rday & "&cjurl=" & cjurl & "';}</script><a href=""?action=" & action & "&rpage=" & rpage + 1 & "&rtype=" & rtype & "&xt="&xt&"&rid="&rid&"&cjflag="&cjflag&"&cjurl=" & cjurl & """ >点击进入下一页</a>"
        End If
    Else
            dBreakpoint "../upload/maccjbreakpoint"
            writeF "<br>数据采集完成<script language=""javascript"">setTimeout(""gonextpage();"",3000);function gonextpage(){location.href='?action=list&fa=1&xt="&xt&"&rid="&rid&"&cjflag="&cjflag&"&rtype="&rtype&"&cjurl=" & cjurl & "&rpage=" & rpage & "';}</script>"
    End If
End Sub

Sub wTips(vname, vdes)
    writeF "<tr><td>&nbsp;" & vname & "(<font color='#FF0000'>OK</font>)</td><td>&nbsp;" & vdes & "</td></tr>"
End Sub

Sub list()
%>
<style>
.nav{margin-top:1px; margin-bottom:1px;width:96%;}
.nav a,.menulist a:visited{ font-size:13px; color:blue;}
.nav ul { width:100%;}
.nav .spanli{ background:#2473A2; }
.nav ul li{ float:left; width:110px; text-align:left}
</style>
<script language="javascript">
var curtype="";
var rpage=<%=rpage%>;
var rtype="<%=rtype%>";
var rkey="<%=rkey%>";
var rday="<%=rday%>";
var cjurl="<%=cjurl%>";
var fa="<%=fa%>"
var xt="<%=xt%>";
var cjflag="<%=cjflag%>";
var rid="<%=rid%>";

$(document).ready(function(){
	$("#loading",window.parent.document).ajaxStart(function(){
		$(this).show();
	});
	$("#loading",window.parent.document).ajaxStop(function(){
    	$(this).hide();
 	});
	setbtn();
	var status =false;
	if(fa!=""){ status=true; }
});
function getsearch()
{
	var url= '?action=list&xt='+xt+'&rid='+rid+'&cjflag='+cjflag+'&rpage=1&rtype=0&rkey='+ encodeURI( $("#rkey").val() ) +'&cjurl='+cjurl;
	location.href= url;
}
function setbtn()
{
	$("#cjsel").click(function(){
	    var item = $("input[@type=radio][name=ids][checked]").val();
	    if (item==undefined || item==""){ alert("请先选择所采集的数据,否则无法使用采集分类"); return;}
	    $("#form3").attr("action","admin_maccj.asp?action=cjsel&xt="+xt+'&rid='+rid+"&cjflag="+cjflag+"&rpage="+rpage + "&rtype="+rtype);
	    $("#form3").submit();
	});
	$("#cjday").click(function(){
		if(xt=="1" || xt=="2"){ rday="24"; } else { rday="1"; }
	    $("#form3").attr("action","admin_maccj.asp?action=cjday&rday="+rday+"&xt="+xt+'&rid='+rid+"&cjflag="+cjflag );
	    $("#form3").submit();
	});
	$("#cjtype").click(function(){
	    if (rtype=="0"){ alert("请先进入分类,否则无法使用采集分类"); return;}
	    $("#form3").attr("action","admin_maccj.asp?action=cjtype&rtype="+rtype+"&xt="+xt+'&rid='+rid+"&cjflag="+cjflag);
	    $("#form3").submit();
	});
	$("#cjall").click(function(){
	    $("#form3").attr("action","admin_maccj.asp?action=cjall&xt="+xt+'&rid='+rid+"&cjflag="+cjflag+"" );
	    $("#form3").submit();
	});
}
function setunion(dtype,utype)
{
	$("#u_type").val(utype);
	var offset=$("#type"+dtype).offset();
	var tt=offset.top;
	var tl=offset.left;
	creatediv(99997,250,20);
	curtype=dtype;
	$("#confirm").css('border','1px solid #55BBFF').css('background','#C1E7FF').css('padding',' 3px 0px 3px 4px').css('top',tt-4+'px').css('left',tl-100+'px').html('正在加载内容......');
	$("#confirm").html( $("#typehtml").html() );
	$("#confirm").show();
}
function bindsave()
{
	var dtype = $("#confirm").find("#d_type").val();
	var utype = $("#confirm").find("#u_type").val();
	$.get("admin_maccj.asp","action=bindunionsave&u_type="+utype+"&d_type="+dtype+"&rnd="+new Date(), function(obj) {
	    if(obj=="ok"){
	    	if(dtype==""){
	    		$('#type'+curtype).text("[未绑]");
	    		$('#type'+curtype).css("color","");
	    	}
	    	else{
	    		$('#type'+curtype).text("[已绑]");
	    		$('#type'+curtype).css("color","red");
	    	}
	    }
	    else{
	    	alert("绑定时出现错误："+ obj);
	    }
	    $("#confirm").remove();
	});
}
</script>
<span id="typehtml" style="display:none">
<input type="hidden" id="u_type" value=""/>
<select id="d_type" name="d_type">
<option value="">取消绑定</option>
<%=makeSelectAll("{pre}vod_type", "t_id", "t_name", "t_pid", "t_sort", 0, "", "&nbsp;|&nbsp;&nbsp;", "")%>
</select>
<input class="input" type="button" value="绑定" onclick="bindsave();">
<input class="input" type="button" value="取消" onclick="closew();">
</span>
<%
    Dim url, unionids, html, typeid, typename, typebind, cjallflag, vodid, vodname, vodtype, vodfrom, vodtime, date2, curfontstart, curfontend, vodpagesize, vodpagecount, vodrecordcount , objxml,xmlnode,i
    dim xn_list,xn_type,xn_vod,xn_vod_time,xn_vod_from
    
    unionids = getunionids()
    if xt = "1" then
    	url = cjurl & "?ac=list&pg=" & rpage & "&t=" & rtype & "&rid=" & rid & "&wd=" & Server.URLEncode(rkey)
    	
    	html = getPage(url, "utf-8")
    	xn_list = "list"
    	xn_type = "rss/class/ty"
    	xn_vod = "rss/list/video"
    	xn_vod_time = "last"
    	xn_vod_from = "dt"
    	
    	If instr(html, "</rss>") <=0 Then writeE "<a href="""&getUrl()&""">获取数据失败，请点击我重试</a>"
    elseif xt = "2" then
    	url = cjurl & "-action--vodids--cid-"&rtype&"-play--inputer--wd-"& Server.URLEncode(rkey) &"-h-"&rday&"-p-"&rpage
    	html = getPage(url, "utf-8")
    	xn_list = "list"
    	xn_type = "rss/class/ty"
    	xn_vod = "rss/list/video"
    	xn_vod_time = "last"
    	xn_vod_from = "dt"
    	
    	If instr(html, "</rss>") <=0 Then writeE "<a href="""&getUrl()&""">获取数据失败，请点击我重试</a>"	
    else
    	url = cjurl & "?action=list&rpage=" & rpage & "&rtype=" & rtype & "&rkey=" & Server.URLEncode(rkey)
    	html = getPage(url, "utf-8")
    	xn_list = "vods"
    	xn_type = "maccms/types/type"
    	xn_vod = "maccms/vods/vod"
    	xn_vod_time = "time"
    	xn_vod_from = "from"
    	If instr(html, "</maccms>") <=0 Then writeE "<a href="""&getUrl()&""">获取数据失败，请点击我重试</a>"
    end if
    
    Set objxml = New AppXMLDOM
    objxml.LoadXml (html)
    Set xmlnode = objxml.Root
    if cjflag ="" then cjflag = xmlnode.getElementsByTagName("cjflag").Item(0).Text
    vodpagesize = xmlnode.getElementsByTagName(xn_list).Item(0).getAttributeNode("pagesize").nodevalue
    vodpagecount = xmlnode.getElementsByTagName(xn_list).Item(0).getAttributeNode("pagecount").nodevalue
    vodrecordcount = xmlnode.getElementsByTagName(xn_list).Item(0).getAttributeNode("recordcount").nodevalue
    
    writeA "<div class='nav'><ul><li style=""width:70px;""><a href=""?action=list&xt="&xt&"&rid="&rid&"&cjflag="&cjflag&"&rpage=1&rtype=&rkey=&cjurl="&cjurl&"""><font color=""#FF0000""><b>全部资源</b></font></a></li>"
    
    Set xmlnode = objxml.FindNodes(xn_type)
    For i = 0 To xmlnode.length - 1
        typeid = xmlnode(i).getAttributeNode("id").nodevalue
        typename = xmlnode(i).Text
        typebind = "<a id='type" & typeid & "' href=""javascript:void(0)"" onclick='setunion(" & typeid & ",""" & cjflag & typeid & """);' "
        If InStr(unionids, "," & cjflag & typeid & ",") > 0 Then
            typebind = typebind & " style=""color:red;"">[已绑]"
        Else
            typebind = typebind & ">[未绑]"
        End If
        typebind = typebind & "</a>"
        writeA "<li><a href=""?action=list&xt="&xt&"&rid="&rid&"&cjflag="&cjflag&"&rpage=1&rtype="&typeid&"&rkey=&cjurl="&cjurl&""")>" & typename & "</a> "& typebind & "</li>"
    Next
    
    writeF "</ul></div><table class=""tb"" style=""padding-top:0px;border-top:1px solid #DEEFFA;border-bottom:0px solid #DEEFFA;"">    <tr>  <td>    数据查询：<input id=""rkey"" name=""rkey"" type=""text"" onFocus=""if (value =='请输入关键词'){value =''}"" onBlur=""if (value ==''){value='请输入关键词'}"" value=""请输入关键词"" size=""30"" value='" & rkey & "'> &nbsp;<input type=""button"" id=""btnsearch"" value=""查询数据"" onclick=""getsearch();"" />&nbsp;<font color='red'>采集前请【绑定相应分类】 ，没有绑定分类的将不会采集入库</font>(<a href=""http://www.maccms.com"" target=""_blank"">maccms联盟专用采集服务端[请不要删除版权]</a>)</td>  </tr></table>" & vbCrLf
	
    Set xmlnode = objxml.FindNodes(xn_vod)
    
    writeA "<form action="""" method=""post"" id=""form3"" name=""form3""><table class=""tb""> <input type=""hidden"" id=""cjurl"" name=""cjurl"" value=""" & cjurl & """/>" & vbCrLf
    If xmlnode.length = 0 Then
        writeA "<tr><td align=""center"" colspan=""5"">没有任何数据</td></tr>"
        Exit Sub
    End If
    writeA "<tr>   <td width=""4%"">&nbsp;</td>    <td>名称</td>   <td width=""20%"">分类</td>    <td width=""20%"">来源</td>   <td width=""20%"">时间</td>   </tr>"
    
    For i = 0 To xmlnode.length - 1
        vodid = xmlnode(i).SelectNodes("id")(0).Text
        vodname = xmlnode(i).SelectNodes("name")(0).Text
        vodtype = xmlnode(i).SelectNodes("type")(0).Text
        vodfrom = xmlnode(i).SelectNodes(xn_vod_from)(0).Text
        vodtime = xmlnode(i).SelectNodes(xn_vod_time)(0).Text
        date2 = DateDiff("d", vodtime, Date)
        If date2 = 0 Then curfontstart = "<font color=#FF0000>": curfontend = "</font>" Else curfontstart = "": curfontend = ""
        writeA "<tr>    <td><input name=""ids"" type=""checkbox"" id=""ids"" value=""" & vodid & """/></td>    <td>" & curfontstart & vodname & curfontend & "</td>    <td>" & curfontstart & vodtype & curfontend & "</td>    <td>" & curfontstart & vodfrom & curfontend & "</td>   <td>" & curfontstart & vodtime & curfontend & "</td>   </tr>" & vbCrLf
    Next
    Set xmlnode = Nothing
    Set objxml = Nothing
    
    writeA "<tr>   <td colspan=""2"">   全选<input name=""chkall"" type=""checkbox"" id=""chkall"" value=""1"" onClick=""checkAll(this.checked,'ids');""/>&nbsp;   <input type='button' id='cjsel' value='采集选中'/>   <input type='button' id='cjday' value='采集当天'/>    <input type='button' id='cjtype'value='采集当前分类'/>   <input type='button' id='cjall' value='采集全部'/>    </td>    </tr>   <tr>    <td colspan=""5"" align=""center"">" & pagelist_manage(vodpagecount, rpage, vodrecordcount, vodpagesize, "?action=list&xt="&xt&"&rid="&rid&"&cjflag="&cjflag&"&rpage={p}&rtype="&rtype&"&rkey="&Server.UrlENCode(rkey)&"&cjurl="&cjurl) &  " </td>    </tr></table></form>" & vbCrLf
End Sub

Sub bindunion()
%>
<style>
.nav{margin-top:1px; margin-bottom:1px;width:96%;}
.nav a,.menulist a:visited{ font-size:13px; color:blue;}
.nav ul { width:100%;}
.nav .spanli{ background:#2473A2; }
.nav ul li{ float:left; width:110px; text-align:left}
</style>
<script language="javascript">
function setunion(dtype,utype)
{
	$("#u_type").val(utype);
	var offset=$("#type"+dtype).offset();
	var tt=offset.top;
	var tl=offset.left;
	creatediv(99997,250,20);
	curtype=dtype;
	$("#confirm").css('border','1px solid #55BBFF').css('background','#C1E7FF').css('padding',' 3px 0px 3px 4px').css('top',tt-4+'px').css('left',tl-100+'px').html('正在加载内容......');
	$("#confirm").html( $("#typehtml").html() );
	$("#confirm").show();
}
function bindsave()
{
	var dtype = $("#confirm").find("#d_type").val();
	var utype = $("#confirm").find("#u_type").val();
	$.get("admin_maccj.asp","action=bindunionsave&u_type="+utype+"&d_type="+dtype+"&rnd="+new Date(), function(obj) {
	    if(obj=="ok"){
	    	if(dtype==""){
	    		$('#type'+curtype).text("[未绑]");
	    		$('#type'+curtype).css("color","");
	    	}
	    	else{
	    		$('#type'+curtype).text("[已绑]");
	    		$('#type'+curtype).css("color","red");
	    	}
	    }
	    else{
	    	alert("绑定时出现错误："+ obj);
	    }
	    $("#confirm").remove();
	});
}
</script>
<span id="typehtml" style="display:none">
<input type="hidden" id="u_type" value=""/>
<select id="d_type" name="d_type">
<option value="">取消绑定</option>
<%=makeSelectAll("{pre}vod_type", "t_id", "t_name", "t_pid", "t_sort", 0, "", "&nbsp;|&nbsp;&nbsp;", "")%>
</select>
<input class="input" type="button" value="绑定" onclick="bindsave();">
<input class="input" type="button" value="取消" onclick="closew();">
</span>
<p>请绑定分类后进行采集操作，否则没有绑定分类的数据不会入库。 点击【未绑】弹出绑定菜单，选择对应的本地分类即可。</p>
<p>绑定完毕后点击 <a href="?action=list&xt=<%=xt%>&rid=<%=rid%>&cjflag=<%=cjflag%>&cjurl=<%=cjurl%>">【进入采集数据列表】 </a> 。</p>
<p>本地分类列表：</p>
<%
	Dim url, unionids, html, typeid, typename, typebind, cjallflag, vodid, vodname, vodtype, vodfrom, vodtime, date2, curfontstart, curfontend, vodpagesize, vodpagecount, vodrecordcount , objxml,xmlnode,i
    dim xn_list,xn_type,xn_vod,xn_vod_time,xn_vod_from
    
    unionids = getunionids()
    if xt = "1" then
    	url = cjurl & "?ac=list&pg=" & rpage & "&t=" & rtype & "&wd=" & rkey
    	html = getPage(url, "utf-8")
    	xn_list = "list"
    	xn_type = "rss/class/ty"
    	xn_vod = "rss/list/video"
    	xn_vod_time = "last"
    	xn_vod_from = "dt"
    	
    	If instr(html, "</rss>") <=0 Then writeE "加载数据发生错误 , <a href=""javascript:void(0)"" onclick="""&getUrl()&""">获取数据失败，请点击我重试</a>"
    elseif xt="2" then
    	url = cjurl & "-action--vodids--cid-"&rtype&"-play--inputer--wd-"&rkey&"-h-"&rday&"-p-"&rpage
    	html = getPage(url, "utf-8")
    	xn_list = "list"
    	xn_type = "rss/class/ty"
    	xn_vod = "rss/list/video"
    	xn_vod_time = "last"
    	xn_vod_from = "dt"
    	
    	If instr(html, "</rss>") <=0 Then writeE "加载数据发生错误 , <a href=""javascript:void(0)"" onclick="""&getUrl()&""">获取数据失败，请点击我重试</a>"	
    else
    	url = cjurl & "?action=list&rpage=" & rpage & "&rtype=" & rtype & "&rkey=" & rkey
    	html = getPage(url, "utf-8")
    	xn_list = "vods"
    	xn_type = "maccms/types/type"
    	xn_vod = "maccms/vods/vod"
    	xn_vod_time = "time"
    	xn_vod_from = "from"
    	If instr(html, "</maccms>") <=0 Then writeE "加载数据发生错误 , <a href=""javascript:void(0)"" onclick="""&getUrl()&""">获取数据失败，请点击我重试</a>"
    end if
    
    
    Set objxml = New AppXMLDOM
    objxml.LoadXml (html)
    Set xmlnode = objxml.Root
    if cjflag ="" then cjflag = xmlnode.getElementsByTagName("cjflag").Item(0).Text
    vodpagesize = xmlnode.getElementsByTagName(xn_list).Item(0).getAttributeNode("pagesize").nodevalue
    vodpagecount = xmlnode.getElementsByTagName(xn_list).Item(0).getAttributeNode("pagecount").nodevalue
    vodrecordcount = xmlnode.getElementsByTagName(xn_list).Item(0).getAttributeNode("recordcount").nodevalue
    
    writeA "<div class='nav'><ul>"
    
    Set xmlnode = objxml.FindNodes(xn_type)
    For i = 0 To xmlnode.length - 1
        typeid = xmlnode(i).getAttributeNode("id").nodevalue
        typename = xmlnode(i).Text
        typebind = "<a id='type" & typeid & "' href=""javascript:void(0)"" onclick='setunion(" & typeid & ",""" & cjflag & typeid & """);' "
        If InStr(unionids, "," & cjflag & typeid & ",") > 0 Then
            typebind = typebind & " style=""color:red;"">[已绑]"
        Else
            typebind = typebind & ">[未绑]"
        End If
        typebind = typebind & "</a>"
        writeA "<li><a href='###'>" & typename & "</a> "& typebind & "</li>"
    Next
    
    Set xmlnode = Nothing
    Set objxml = Nothing
%>
</ul></div>
<%
end Sub


Sub main()
    writeA "<script language=""JavaScript"">$(document).ready(function(){$('#xmllist').html($('#xml').html());$('#xml').html('');});</script><table width=""100%"" border=""0"" cellspacing=""0"" cellpadding=""0"" ><tr><td align=right>"
    if cBreakpoint("../upload/maccjbreakpoint") then
		writeA "<a href=""?action=breakpoint""><font color=""red"" style=""font-size:16px;"">继续上次断点采集</font></a>"
	end if
	writeA "</td></tr><tr><td><span id=""xmllist"">资源列表载入中……</span></td></tr></table><span id=""xml""><script type=""text/javascript"" src=""http://www.maccms.com/union/xmlutf.js"" charset=""utf-8""></script></span>"
End Sub

Function getTypeID(ByVal servertype)
    Dim sql, unionids, i, arrayLen
    
    if not isarray(typearr) then
    	sql = "select t_id,t_union from {pre}vod_type where t_union is not null"
    	typearr = objdb.DB(sql, "arr")
    end if
    
    if isarray(typearr) then
    	arrayLen = ubound(typearr,2)
	    For i = 0 To arrayLen
	        unionids = typearr(1, i)
	        If InStr("," & unionids, "," & servertype & ",") > 0 Then
	            getTypeID = typearr(0, i)
	            Exit function
	        End If
	    Next
    end if
    getTypeID = ""
End Function

Function getunionids()
    Dim sql, i, unionids,arrayLen
    if not isarray(typearr) then
    	sql = "select t_id,t_union from {pre}vod_type where t_union is not null "
    	typearr = objdb.DB(sql, "arr")
    end if
    if isArray(typearr) then
    	arrayLen = ubound(typearr,2)
    	for i=0 to arrayLen
    		unionids = unionids & typearr(1,i) & ","
    	next
    end if
    unionids = replaceStr(unionids, ",,,", ",")
    unionids = replaceStr(unionids, ",,", ",")
    getunionids = unionids
End Function

Sub bindunionsave()
    Dim u_type, d_type, typeid, newunionids, result, backurl
    Dim sql, rs
    u_type = be("all", "u_type")
    d_type = be("all", "d_type")
    typeid = getTypeID(u_type)
    backurl = be("all", "backurl")
    
    If isN(d_type) Then
        sql = "select * from {pre}vod_type where t_id =" & typeid
        Set rs = objdb.DB(sql, "rs1")
        If Not rs.EOF Then
            If InStr(rs("t_union"), u_type) > 0 Then
                newunionids = replaceStr(rs("t_union"), u_type, "")
                newunionids = replaceStr(newunionids, ",,", ",")
                If Trim(newunionids) = "," Then newunionids = ""
                objdb.update "{pre}vod_type", Array("t_union"), Array(newunionids), "t_id=" & rs("t_id")
            End If
        End If
        objdb.C (rs)
    Else
        sql = "select * from {pre}vod_type where t_id =" & d_type
        Set rs = objdb.DB(sql, "rs1")
        If Not rs.EOF Then
            If (isN(InStr(rs("t_union"), "," & u_type & ","))) Or (InStr(rs("t_union"), "," & u_type & ",") <= 0) Then
                newunionids = rs("t_union") & "," & u_type & ","
                newunionids = replaceStr(newunionids, ",,", ",")
                If Trim(newunionids) = "," Then newunionids = ""
                objdb.update "{pre}vod_type", Array("t_union"), Array(newunionids), "t_id=" & rs("t_id")
            End If
        End If
        objdb.C (rs)
    End If
    dispseObj()
    writeE "ok"
End Sub
%>