<!--#include file="connart.asp"-->
<%
dim action : action = be("get","action")
headAdminCollect "文章分类转换管理"

select case action
	case "save" : save
	case "del" : del
	case else : main
end select

dispseObj()
on error resume next
if isObject(cjdb) then  set cjdb=nothing
on error goto 0

sub save
	dim ids,id,c_name,c_toid,c_pid
	id = be("post","c_id")
	
	if not isN(id) then
		ids = split(replace(id," ",""),",")
		For Each id In ids
			c_name = be("all","c_name" &id)
			c_toid = be("all","c_toid" &id) 
			c_pid = be("all","c_pid" &id)
			cjdb.Update "tbl_change",array("c_name","c_type","c_toid","c_pid"),array(c_name,"0",c_toid,c_pid),"c_id="&id
		next
	else
		c_name = be("all","c_name")
		c_toid = be("all","c_toid")
		c_pid  = be("all","c_pid")
		cjdb.Add "tbl_change",array("c_name","c_type","c_toid","c_pid"),array(c_name,"0",c_toid,c_pid)
	end if
	redirect getReferer()
end sub

sub del
	dim ids,i,arr
	ids = be("all","c_id")
	arr = split(ids,",")
	for i=0 to ubound(arr)
		cjdb.Delete "tbl_change","c_id="& arr(i)
	next
	redirect getReferer()
end sub

sub main
	dim rs,sql,rsproject
	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")
	if not isNum(project) then project=-1 else project=clng(project)
%>
<script language="javascript">
$(document).ready(function(){
	$("#form2").validate({
		rules:{
			name:{
				required:true,
				maxlength:32
			},
			toid:{
				required:true
			},
			pid:{
				required:true
			}
		}
	});
	
	$("#btnDel").click(function(){
		if(confirm('确定要删除吗')){
			$("#form1").attr("action","collect_art_change.asp?action=del");
			$("#form1").submit();
		}
		else{return false}
	});
	$("#btnEdit").click(function(){
		if(confirm('确定要保存修改吗')){
			$("#form1").attr("action","collect_art_change.asp?action=save");
			$("#form1").submit();
		}
		else{return false}
	});
	$("#btnAdd").click(function(){
		$('#form2').form('clear');
		$('#win1').window('open'); 
	});
	$("#btnCancel").click(function(){
		location.href = location.href ;
	});	
});
</script>

<table width="96%" border="0" align="center" cellpadding="3" cellspacing="1">
	<tr>
	<td>
		菜单：<a href="collect_art_manage.asp?action=">采集规则列表</a> | <a href="collect_art_change.asp">分类转换</a> | <a href="collect_art_filters.asp">信息过滤</a>  
	&nbsp; 按项目查看：<select onchange=javascript:window.location.href=this.options[this.selectedIndex].value>
	<option value="?action=">所有转换</option>
	<option value="?action=&project=0" <%if trim(project)="0" then%>selected <%end if%>>全局转换</option>
	<%
	sql = "select p_id,p_name from tbl_art_project"
	set rsproject = CJDB.db(sql,"rs1")
	do while not rsproject.eof
	%>
	<option value="?action=&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 id="form1" name="form1" method="post">
<table class=tb>
<tr>
	<td width="10%" >ID</td>
	<td width="30%" >采集分类</td>
	<td width="30%" >系统分类</td>
	<td width="30%" >所属项目</td>
</tr>
<%
	sql="select * from [tbl_change] where 1=1 " 
	if project>-1 then
		sql = sql & " and c_pid = " & project
	end if
	sql = sql & " order by c_id desc"
	
	set rs = cjdb.db(sql,"rs1")
	if rs.eof then
	%>
    <tr><td align="center" colspan="5">没有任何记录!</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 name="c_id" type="checkbox" value="<%=rs("c_id")%>" />  <%=rs("c_id") %></td>
      <td><input name="c_name<%=rs("c_id")%>" type="text" value="<%= rs("c_name") %>" size="40"></td>
      <td>
      <select name="c_toid<%=rs("c_id")%>">
      <%=makeSelectAll("{pre}art_type","t_id","t_name","t_pid","t_sort",0,"","&nbsp;|&nbsp;&nbsp;",rs("c_toid"))%>
      </select>
	</td>
	<td>
      <select name="c_pid<%=rs("c_id")%>">
      	<option value="0">全局过滤项目</option>
	  	<% makeProjectOptionselected 0,"&nbsp;|&nbsp;&nbsp;",rs("c_pid"),"art" %>
	  	 </select>
      </td>
	</tr>
<%
	rs.MoveNext
	next 
	end if
%>
<tr>
	<td colspan="5">
	全选<input name="chkall" type="checkbox" id="chkall" value="1" onClick="checkAll(this.checked,'c_id');"/>&nbsp;
    <input type="button" id="btnDel" value="批量删除" class="input">
	<input type="button" id="btnEdit" value="批量修改" class="input">
	<input type="button" id="btnAdd" value="添加转换" class="input">
	</td>
</tr>
<tr>
	<td colspan="5" align=center>
<%=pagelist_manage(rs.PageCount,pagenum,rs.RecordCount,app_pagenum,"collect_art_change.asp?page={p}&project="&project&"")%>
    </td>
</tr>
</table>
</form>


<div id="win1" class="easyui-window" title="窗口" style="padding:5px;width:400px;" closed="true" minimizable="false" maximizable="false">
<form action="?action=save" method="post" id="form2" name="form2">
<table class="tb">
<tr>
	<td>
	采集分类：
	<input name="c_name" type="text" size="30">
	</td>
</tr>
<tr>
	<td>
	目标分类：
	<select name="c_toid" style="width:180px;">
	<%=makeSelectAll("{pre}art_type","t_id","t_name","t_pid","t_sort",0,"","&nbsp;|&nbsp;&nbsp;","")%>
	</select>
	</td>
</tr>
<tr>
	<td>所属项目：
	<select name="c_pid" style="width:180px;">
	<option value="0">全局过滤项目</option>
	  	<% makeProjectOptionselected 0,"&nbsp;|&nbsp;&nbsp;",0,"art" %>
	</select>
	</td>
</tr>
<tr>
	<td align=center>
	<input class="input" type="submit" value="保存" id="btnSave">
	<input class="input" type="button" value="返回" id="btnCancel"> 
	</td>
</tr>
</table>
</form>
</div>
<%
cjdb.c(rs)
end sub
%>