<!--#include file="connvod.asp"-->
<%
dim action : action = be("get","action")
headAdminCollect "视频过滤转换管理"

select case action
	case "add","edit" : edit
	case "save" : save
	case "del" : del
	case "sflag": sflag
	case else : main
end select

sub save
	dim f_id,f_name,f_object,f_type,F_Content,f_strstart,f_strend,f_rep,f_flag,f_pid
	dim sql,rs
	
	f_id = be("post","f_id") : f_pid = be("post","f_pid")
	f_name = be("post","f_name") :  f_object = be("post","f_object")
	f_type = be("post","f_type") :  F_Content = be("post","F_Content")
	f_strstart = be("post","f_strstart") :  f_strend = be("post","f_strend")
	f_rep = be("post","f_rep") :  f_flag = be("post","f_flag")
	
	if not isNum(f_id) then f_id = 0 else f_id=clng(f_id)
	if isN(f_pid) then f_pid = 0
	if f_type = 1 then
		if isN(f_content) then alert "过滤的内容不能为空!"
	elseif f_type = 2 then
		if isN(f_strstart) or isN(f_strend)  then alert "开始/结束标记不能为空!"
	end if
	
	sql ="select *  from tbl_filters where f_id=" &f_id
    set rs = cjdb.db(sql,"rs3")
    if f_id=0 then RS.Addnew
    
	rs("f_name") = f_name
	rs("f_object") = f_object
	rs("f_type") = f_type
	rs("f_pid")=f_pid
	if f_type = 1 then
		rs("F_Content") = F_Content
	elseif f_type = 2 then
		rs("f_strstart") = f_strstart
		rs("f_strend") = f_strend
	end if
	rs("f_rep") = f_rep
	if f_flag = "yes" then
	   rs("f_flag")=True
	Else
	   rs("f_flag")=False
	End if
	rs.Update
    cjdb.c(rs)
	showmsg "成功修改过滤规则!",getReferer()
end sub

Sub del
	dim ids:ids=replace(be("all","f_id")," ","")
	if not isN(ids) then
		cjdb.db "delete from [tbl_filters] WHERE f_id in ("&ids&")","exe"
	end if
	redirect getReferer()
end sub

Sub sflag
	Dim sql,rs,f_id,f_flag
	f_id = be("all","f_id")
	f_flag = be("all","f_flag")
	
	if not isN(f_id) then
		sql="update tbl_filters set f_flag = '"&f_flag&"' Where f_id in(" & f_id & ") "
		cjdb.db sql,"exe"
	end if
	redirect getReferer()
end sub

sub edit
	dim sql,rs,rsproject
	dim f_id,f_name,f_object,f_type,f_content,f_strstart,f_strend,f_rep,f_flag,f_pid
	dim backurl : backurl = getReferer()
	
	f_id = be("get","f_id")
	if not isN(f_id) then
		sql="Select * from tbl_filters Where f_id=" & f_id
		set rs =cjdb.db(sql,"rs1")
		f_name = rs("f_name")
		f_object = rs("f_object")
		f_type = rs("f_type")
		f_content = rs("f_content")
		f_strstart = rs("f_strstart")
		f_strend = rs("f_strend")
		f_rep = rs("f_rep")
		f_flag = rs("f_flag")
		f_pid =rs("f_pid")
		cjdb.c(rs)
	else
		f_type= 1
	end if
%>
<script language="javascript">
$(document).ready(function(){
	
});

function showset(v)
{
	if(v==2)
	{
		$("#FilterType1").hide();
		$("#FilterType2").show();
	}
	else
	{
		$("#FilterType1").show();
		$("#FilterType2").hide();
	}
}
</script>
<form action="?action=save" method="post" name="form">
<input type="hidden" id="f_id" name="f_id" value="<%=f_id%>">
<input id="backurl" name="backurl" type="hidden" value="<%=backurl%>">
<table class=tb >
	<tr>
	<td vAlign=center width="20%" >过滤名称：</td>
	<td>
		<INPUT id="f_name" name="f_name" size="50" value="<%=f_name%>" >
	</td>
	</tr>
	<tr>
	<td vAlign=center >过滤项目;</td>
	<td>
		<select name="f_projectid" id="f_projectid" size="1">
		<option value="0" <%if trim(f_pid)="0" then %>selected<%end if%>>全局过滤项目</option>
	<%
		sql = "select P_ID,P_Name from Tbl_Vod_Project"
		set rsproject=cjdb.db(sql,"rs1")
		do while not rsproject.eof
		%>
		<option value="<%=rsproject("p_id")%>" <%if trim(f_pid)=trim(rsproject("p_id")) then %>selected<%end if%>><%=rsproject("p_name")%></option>
		<%
		rsproject.movenext
		loop
		cjdb.c(rsproject)
	%>
		</select>
	(全局过滤项目将过滤所有的项目) </td>
	</tr>
	<tr>
	<td vAlign=center width="20%" >过滤对象：</td>
	<td>
		<select name="f_object" id="f_object" size="1">
		<option value="0" <%if f_object=0 then writeA " selected"%>>全局过滤</option>
		<option value="1" <%if f_object=1 then writeA " selected"%>>标题过滤</option>
		<option value="2" <%if f_object=2 then writeA " selected"%>>简介过滤</option>
		<option value="3" <%if f_object=3 then writeA " selected"%>>播放地址过滤</option>
		</select>
	</td>
    </tr>
    <tr>
	<td vAlign=center width="20%" >过滤类型：</td>
	<td>
		<select name="f_type" id="f_type" onchange=showset(this.options[this.selectedIndex].value)>
		<option value="1" <%if f_type=1 then writeA " selected"%>>简单替换</option>
		<option value="2" <%if f_type=2 then writeA " selected"%>>高级过滤</option>
		</select>
	</td>
    </tr>
	<tr id="FilterType1"  style="display:<%if f_type=2 then writeA "none"%>"> 
	<td> 过虑内容：</td>
	<td>
		<textarea id="f_content" name="f_content" cols="49" rows="5"><%=F_Content%></textarea>
		<font color="#FF0000">&nbsp;&nbsp;&nbsp; 填你要过虑的内容,每条规则只能填一个内容!</font>
	</td>
	</tr>
	<tr id="FilterType2" style="display:<%if f_type=1 then writeA "none"%>">
	<td> 开始标记：<br><br><br><br><br> 结束标记：
	</td>
	<td>
		<textarea id="f_strstart" name="f_strstart" cols="49" rows="5"><%=f_strstart%></textarea>
		<font color="#FF0000">&nbsp;&nbsp;&nbsp; 
		过虑开始标记,包括标记同时过虑掉!</font><br>
		<textarea id="f_strend" name="f_strend" cols="49" rows="5"><%=f_strend%></textarea>
		<font color="#FF0000">&nbsp;&nbsp;&nbsp;
		过虑结束标记,包括标记同时过虑掉!</font>
	</td>
	</tr>
	<tr id="FilterRep">
	<td> 过虑替换：</td>
	<td>
		<textarea id="f_rep" name="f_rep" cols="49" rows="5"><%=f_rep%></textarea>&nbsp;
		<font color="#FF0000">&nbsp;&nbsp; 
		可为空,为空则只过虑掉你要过虑的内容.</font>
	</td>
	</tr>
	<tr>
	<td><b>是否启用：</b></td>
	<td>&nbsp;&nbsp;
	<input id='f_flag' name='f_flag' type='checkbox' value='yes' <%if f_flag<>False then writeA "Checked"%>></td>
	</tr>     
	<tr>
	<td colspan="2">
	<input  type="submit" class="btn" name="Submit" value="确&nbsp;&nbsp;定" >&nbsp;&nbsp;&nbsp;&nbsp;
	<input name="Cancel" class="btn" type="button" id="Cancel" value="返&nbsp;&nbsp;回" onClick="window.location.href='collect_vod_filters.asp'">       </td>
	</tr>
</table>
</form>
<%
end sub

sub main
	Dim pagenum : pagenum = be("all","page")
	if isN(pagenum) or not isNum(pagenum) then pagenum = 1
	if pagenum < 1 then pagenum = 1
	pagenum = clng(pagenum)
	dim project : project = be("all","project")
	dim sql,rs,rsproject
	Sql="select a.*,b.P_Name from tbl_filters a left join tbl_vod_project b on a.f_pid=b.p_id where 1=1 "
	if project<> "" then
		sql = sql & " and a.f_pid = " & project
	end if
	sql = sql & " order by f_id desc"
	set rs =cjdb.db(sql,"rs3")
%>
<script language="javascript">
$(document).ready(function(){
	$("#btnDel").click(function(){
		if(confirm('确定要删除吗')){
			$("#form1").attr("action","collect_vod_filters.asp?action=del");
			$("#form1").submit();
		}
		else{return false}
	});
	$("#btnFlag1").click(function(){
		$("#form1").attr("action","collect_vod_filters.asp?action=sflag&f_flag=1");
		$("#form1").submit();
	});
	$("#btnFlag2").click(function(){
		$("#form1").attr("action","collect_vod_filters.asp?action=sflag&f_flag=0");
		$("#form1").submit();
	});
	$("#btnAdd").click(function(){
		location.href='collect_vod_filters.asp?action=add';
	});
});
</script>
<table width="96%" border="0" align="center" cellpadding="3" cellspacing="1">
	<tr>
	<td>
		菜单：<a href="collect_vod_manage.asp?action=">采集规则列表</a> | <a href="collect_vod_change.asp">分类转换</a> | <a href="collect_vod_filters.asp">信息过滤</a>  
	&nbsp; 按项目查看：<select onchange=javascript:window.location.href=this.options[this.selectedIndex].value>
	<option value="?">所有转换</option>
	<option value="?project=0" <%if trim(project)="0" then%>selected <%end if%>>全局转换</option>
	<%
	sql = "select p_id,p_name from tbl_vod_project"
	set rsproject=CJDB.db(sql,"rs1")
	do while not rsproject.eof
	%>
	<option value="?project=<%=rsproject("p_id")%>" <%if trim(project)=trim(rsproject("P_ID")) then %>selected<%end if%>><%=rsproject("p_name")%></option>
	<%
	rsproject.movenext
	loop
	CJDB.c(rsproject)
	%>
	</select>
	</td>
	</tr>
</table>

<form action="" method="post" id="form1" name="form1">
<table class=tb >
    <tr>
	  <td width="4%">&nbsp;</td>
      <td>过滤名称</td>
      <td width="15%" >过滤对象</td>
      <td width="15%">过滤类型</td>
      <td width="15%">所属项目</td>
      <td width="13%">状态</td>
      <td width="10%">操作</td>
	</tr>
	<%
		if rs.eof then
	 %>
    <tr><td align="center" colspan="8">没有任何记录!</td></tr>
    <%
		else
		Dim i
		rs.PageSize = app_pagenum
	    rs.AbsolutePage = pagenum
	  	for i = 1 to rs.PageSize
	  	if rs.eof then exit for
	%>
	<tr>
	<td>
	<input type="checkbox" value=<%=rs("f_id")%> name="f_id">
	</td>
	<td><%=rs("f_name")%></td>
	<td>
      <%
     if rs("f_object")=1 Then
         writeA "标题过滤" 
      elseif rs("f_object")=2 Then 
         writeA "简介过滤" 
      elseif rs("f_object")=3 Then 
         writeA "播放地址过滤"
      else
         writeA "全局过滤"
      end if
      %>
	</td>
	<td>
	<%
      If rs("f_type")=1 Then
         writeA "简单替换"
      ElseIf rs("f_type")=2 Then
         writeA "高级过滤"
      Else
         writeA "请选择！"
      End If
	%>
      </td>
      <td>
      <%  If rs("f_pid")=0 Then writeA "所有项目" Else writeA rs("p_name")   %>
      </td>
      <td>
	  <%
      If rs("f_flag")=True Then writeA "<b>√</b>" Else writeA "<font color='red'><b>×</b></font>" 
      %>
      </td>
      <td  >
      &nbsp;<a href="collect_vod_filters.asp?action=edit&f_id=<%=rs("f_id")%>">修改</a></td>
    </tr>
<%
	rs.MoveNext
	next
	end if
%>
<tr>
	<td  colspan="8">
	全选<input name="chkall" type="checkbox" id="chkall" value="1" onClick="checkAll(this.checked,'f_id');"/>&nbsp;
	<input type="button" value="批量删除" id="btnDel" class="input"  />
	<input type="button" value="批量启用" id="btnFlag1" class="input"  />
	<input type="button" value="批量禁用" id="btnFlag2" class="input"  />
	<input type="button" id="btnAdd" value="添加转换" class="input">
	</td>
</tr>
<tr >
      <td align="center" colspan="8">
      <%=pagelist_manage(rs.PageCount,pagenum,rs.RecordCount,app_pagenum,"collect_vod_filters.asp?page={p}&project="&project)%>
      </td>
    </tr>
</table>
</form>
<%
cjdb.c(rs)
end sub
%>