<!--#include file="admin_conn.asp"-->
<!--#include file="../inc/pinyin.asp"-->
<%
chkLogin
dim action : action = be("get","action")
Dim aWhere, keyword, stype, area, topic, level, from, sserver, state, spic,typearr,hide
stype = be("all", "stype")
area = be("all", "area"):   topic = be("all", "topic")
level = be("all", "level"):     from = be("all", "from")
sserver = be("all", "sserver"):  state = be("all", "state")
order = be("all", "order"):     page = be("all", "page")
spic =  be("all", "spic") :  hide = be("all", "hide")
    
If Not isNum(level) Then level = 0 Else level = CInt(level)
If Not isNum(state) Then state = 0 Else state = CInt(state)
If Not isNum(stype) Then stype = 0 Else stype = CInt(stype)
If Not isNum(area) Then area = 0 Else area = CInt(area)
If Not isNum(topic) Then topic = 0 Else topic = CInt(topic)
If Not isNum(page) Then page = 1 else page = Cint(page)
If Not isNum(topic) Then topic = 0 Else topic = CInt(topic)
If Not isNum(spic) Then spic = 0 else spic=cint(spic)
If Not isNum(hide) Then hide = -1 else hide=cint(hide)
If page < 1 Then page = 1

aWhere = "where 1=1"
If Not isN(keyword) Then aWhere = aWhere & " AND d_name LIKE '%" & keyword & "%' "
If stype > 0 Then 
	typearr = getValueByArray(cachevodtype, stype)
	if isarray(typearr) then
		aWhere = aWhere & " AND d_type in( " & typearr(11) & ") "
	else
		aWhere = aWhere & " AND d_type=" & stype & " "
	end if
end if
If stype = -1 Then aWhere = aWhere & " AND d_type=0 "
If area > 0 Then aWhere = aWhere & " AND d_area = " & area & " "
If topic > 0 Then aWhere = aWhere & " AND d_topic = " & topic & " "
If level > 0 Then aWhere = aWhere & " AND d_level = " & level & " "
If state = 1 Then
	aWhere = aWhere & " AND d_state>0 "
ElseIf state = 2 Then
	aWhere = aWhere & " AND d_state=0 "
End If
If hide > -1 then
	aWhere = aWhere & " AND d_hide= " & hide &" "
end if
    
If not isN(sserver) Then aWhere = aWhere & " AND d_playserver like '%" & sserver & "%' "
If not isN(from) Then aWhere = aWhere & " and d_playfrom like  '%" & from & "%' "
If spic=1 then
	aWhere = aWhere & " and d_pic= '' "
elseif spic=2 then
	aWhere = aWhere & " and d_pic like  'http://%' "
end if
    
select case action
	case "save" : save
	case "del" : del
	case "delplay" :  delplay
	case else : headAdmin "视频批量操作管理" : main
end select
dispseObj()

sub save()
	
    writeA "保存完毕"
end sub

sub del
	if aWhere="where 1=1" then
		if app_dbtype="access" then
			call objdb.DB("delete from {pre}vod")
			call objdb.DB("ALTER TABLE {pre}vod ALTER COLUMN d_id COUNTER (1, 1) ")
		else
			call objdb.DB("truncate from {pre}vod")
		end if
	else
		call objdb.DB("delete from {pre}vod "&aWhere,"exe")
	end if
	showMsg "删除数据成功!", "admin_vod_batch.asp"
end sub

sub delplay
    Dim sql,rs,i,j,new_playfrom,new_playserver,new_playurl,rc,sfrom,aserver,surl,d_playurl,d_playfrom,d_playserver,fromarr,serverarr,urlarr
    sql = "SELECT d_id, d_name,d_playfrom,d_playserver,d_playurl FROM {pre}vod " & aWhere & " ORDER BY d_id asc "
    Set rs = objdb.DB(sql, "rs1")
    if rs.eof then
    	showMsg "数据处理完毕!", "admin_vod_batch.asp"
    else
    	rs.PageSize = app_pagenum
	    rs.AbsolutePage = rs.pagecount
    	writeA "<font color=red>共"&rs.recordcount &"条数据包含"&from&"播放器，共"& rs.pagecount &"页正在开始删除第"& rs.pagecount &"页数据</font><br>"
		
		
	    
		for i = 1 to rs.PageSize
	  		if rs.eof then exit for
	  		
	  		d_playurl = rs("d_playurl")
	  		d_playfrom = rs("d_playfrom")
	  		d_playserver = rs("d_playserver")
	  		
	  		if isN(d_playurl) then d_playurl=""
	        if isN(d_playfrom) then d_playfrom=""
	        if isN(d_playserver) then d_playserver=""
	        
	        fromarr = Split(d_playfrom, "$$$")
	        serverarr = Split(d_playserver, "$$$")
	        urlarr = Split(d_playurl, "$$$")
	        new_playfrom = ""
	       	new_playserver = ""
	       	new_playurl = ""
	        rc=false
	        
	        For j = 0 To UBound(fromarr)
	        	sfrom = fromarr(j)
	       		if ubound(serverarr) >= ubound(fromarr) then aserver =serverarr(j)
				if ubound(urlarr) >= ubound(fromarr) then surl= urlarr	(j)
				
	       		if sfrom = from then
	       		else
	       			if rc then
	       				new_playfrom = new_playfrom & "$$$"
	       				new_playserver = new_playserver & "$$$"
	       				new_playurl = new_playurl & "$$$"
	       			end if
	       			new_playfrom = new_playfrom & sfrom
	       			new_playserver = new_playserver & aserver
	       			new_playurl = new_playurl & replaceStr(surl,"'","''")
	       			rc=true
	       		end if
	       	next
	  		objdb.update "{pre}vod", Array("d_playfrom", "d_playserver", "d_playurl"), Array(new_playfrom, new_playserver, new_playurl), "d_id=" & rs("d_id")
			writeF rs("d_name") & "---ok<br>"
			rs.MoveNext
	  	next
		writeA "<br><font color=red>暂停5秒后继续同步远程图片</font><br><script>setTimeout(""updatenext();"",5000);function updatenext(){location.href='admin_vod_batch.asp?action=delplay&page="&(page+1)&"&stype="&stype&"&area="&area&"&topic="&topic&"&level="&level&"&from="&from&"&sserver="&sserver&"&state="&state&"';}</script>"
    end if
    objdb.c(rs)
end sub

sub main()
%>
<script language="javascript">
$(document).ready(function(){
	$("#btnDel").click(function(){
			if(confirm('确定要删除吗')){
				$("#form1").attr("action","admin_vod_batch.asp?action=del");
				$("#form1").submit();
			}
			else{return false}
	});
	$("#btnDelPlay").click(function(){
		if($("#from").val()==""){
			alert("请选择要删除的播放器类型");
			return;
		}
		if(confirm('确定要删除吗')){
			$("#form1").attr("action","admin_vod_batch.asp?action=delplay");
			$("#form1").submit();
		}
		else{return false}
	});
});
</script>
<form id="form1" name="form1" method="post">
<table class="tb">
	<tr>
	<td>
		<table width="96%" border="0" align="center" cellpadding="3" cellspacing="1">
		<tr>
		<td colspan=2>
		过滤条件：<select id="stype" name="stype">
		<option value="0">视频栏目</option>
		<option value="-1">没有栏目</option>
		<%=makeSelectAll("{pre}vod_type","t_id","t_name","t_pid","t_sort",0,"","&nbsp;|&nbsp;&nbsp;","")%>
		</select>
		&nbsp;
		<select id="state" name="state">
		<option value="0">视频连载</option>
		<option value="1" <%if state="1" then%>selected<%end if%>>连载中</option>
		<option value="2" <%if state="2" then%>selected<%end if%>>未连载</option>
		</select>
		&nbsp;
		<select id="level" name="level">
		<option value="0">视频推荐</option>
		<option value="1" <%if level=1 then%>selected <%end if%>>推荐1</option>
		<option value="2" <%if level=2 then%>selected <%end if%>>推荐2</option>
		<option value="3" <%if level=3 then%>selected <%end if%>>推荐3</option>
		<option value="4" <%if level=4 then%>selected <%end if%>>推荐4</option>
		<option value="5" <%if level=5 then%>selected <%end if%>>推荐5</option>
		</select>
		&nbsp;
		<select id="topic" name="topic">
		<option value="0">视频专题</option>
		<%=makeSelect("{pre}vod_topic","t_id","t_name","t_sort","","&nbsp;|&nbsp;&nbsp;","")%>
		</select>
		&nbsp;
		<select id="sserver" name="sserver">
		<option value="">视频服务器</option>
		<%=makeSelectServer("")%>
		</select>
		&nbsp;
		<select id="from" name="from">
		<option value="">视频播放器</option>
		<%=makeSelectPlayer("")%>
		</select>
		&nbsp;
		<select id="spic" name="spic">
		<option value="0">视频图片</option>
		<option value="1">无图片</option>
		<option value="2">远程图片</option>
		</select>
		&nbsp;
		<select id="hide" name="hide">
		<option value="-1">视频显隐</option>
		<option value="0">显示</option>
		<option value="1">隐藏</option>
		</select>
		</td>
		</tr>
		<tr>
		<td>
		<input class="input" type="button" value="批量删除数据" id="btnDel">
		<input class="input" type="button" value="批量删除播放组" id="btnDelPlay">
		</td>
		</tr>
		</table>
	</td>
	</tr>
</table>
</form>
<%
end sub
%>
</body>
</html>