<!--#include file="admin_start.asp"-->

<%
dim id
dim ids
dim grade
dim s

id=request("id")
ids=request("ids")
ids=replace(ids," ","")

if not MySys.check.isInteger(id) and request("action")<>"delete" then
MySys.error.info="请选择您要操作的项目！"
MySys.error.location="back"
MySys.error.err()
end if

select case request.form("object_grade_0")
case ">="
grade=request.form("object_grade_0")&"|"&int(request.form("object_grade_radio_1"))
case "<="
grade=request.form("object_grade_0")&"|"&int(request.form("object_grade_radio_1"))
case "="
grade=request.form("object_grade_0")&"|"&request.form("object_grade_checkbox_1")
end select

grade=grade+"|0"

set s = MySys.temp.search
select case request("action")
case "delete"

	dim i
	if ids="" then
		MySys.error.info="请选择你要删除的新闻分类！"
		MySys.error.location="back"
		MySys.error.err()
	end if

	ids=split(ids,",")
	
	for i=0 to ubound(ids)
	
		s.sort_ids=""
		s.Sort_search "jins_news_sort",ids(i) ,""
		if s.sort_ids="" then s.sort_ids=","
		s.sort_ids=right(s.sort_ids,len(s.sort_ids)-1)
		conn.execute("delete from jins_news_sort where sort_id in ("&s.sort_ids&") ")
		
		'/////删除图片
		Set fso = CreateObject("Scripting.FileSystemObject")
		set rs_t=conn.execute("select news_id from jins_news_list where sort_id in ("&s.sort_ids&") ")
		do while not rs_t.eof
			if fso.FolderExists(server.mappath("../NEWSPIC/"&rs_t("news_id"))) then fso.deletefolder server.mappath("../NEWSPIC/"&rs_t("news_id")),true
		rs_t.movenext
		loop
		Set fso = nothing
		
		conn.execute("delete from jins_news_list where sort_id in ("&s.sort_ids&") ")
		
	next
	
	set s=nothing

	MySys.error.info="删除新闻分类成功！"
	MySys.error.location="back"
	MySys.error.suc()
	
case "add"
	sql="select * from jins_news_sort "
	rs.open sql,conn,1,3
	
	if id<>0 and conn.execute("select sort_id from jins_news_sort where sort_id="&id&" ").eof then
		MySys.error.info="您加入的分类的上级分类不存在！"
		MySys.error.location="back"
		MySys.error.err()
	end if
	
	if request("sort_description")="" or request.form("sort_name")="" or request.form("sort_open")="" then
		MySys.error.info="请完整填写相关项目！"
		MySys.error.location="back"
		MySys.error.err()
	end if
	
	rs.addnew
	rs("sort_description")=request("sort_description")	
	rs("sort_customer_grade")=grade	
	rs("sort_up")=id
	rs("sort_num")=0	
	rs("sort_name")=request("sort_name")	
	rs.update
	rs.close
    MySys.error.info="新闻分类添加成功！"
	MySys.error.location="admin/admin_info_news_sort.asp?id="&id
	MySys.error.suc()

case "edit"
	    
	sql="select * from jins_news_sort where sort_id="&id&""
	rs.open sql,conn,1,3
	
	'/////////////////////////////////////////////检测
	
	if request("action")="edit" and rs.eof then
		MySys.error.info="您选择的项目不存在！"
		MySys.error.location="back"
		MySys.error.err()
	end if
	
	if request("sort_description")="" or request.form("sort_name")="" or request.form("sort_open")="" then
		MySys.error.info="请完整填写相关项目！"
		MySys.error.location="back"
		MySys.error.err()
	end if
		
	'/////////////////////////////////////////////
	
	rs("sort_description")=request("sort_description")	
	rs("sort_customer_grade")=grade	
	rs("sort_name")=request("sort_name")	
	'////////////////////////////////////////////////
	if rs("sort_open")<>request("sort_open") then '更改下属分类及商品的开关状态
	
		s.sort_ids=""
		s.Sort_search "jins_news_sort",id ,""
		if s.sort_ids="" then s.sort_ids=","
		s.sort_ids=right(s.sort_ids,len(s.sort_ids)-1)
		
		if request("sort_open")=1 then
		
			s.sort_up_ids=""
			s.Sort_up_search "jins_news_sort",id 
			
			sort_flag=1
			
			set rs_t=conn.execute("select sort_open from jins_news_sort where sort_id in ("&s.sort_up_ids&") and sort_id<>"&id&" ")
			do while not rs_t.eof 
				sort_flag=sort_flag*rs_t("sort_open")
				rs_t.movenext
			loop
			set rs_t=nothing
			
			if sort_flag=1 then conn.execute("update jins_news_list set news_open="&request("sort_open")&" where sort_id in ("&s.sort_ids&")")
			
		else
			conn.execute("update jins_news_list set news_open="&request("sort_open")&" where sort_id in ("&s.sort_ids&")")
		end if
		
		set s=nothing
	
	end if
	'////////////////////////////////////////////////
	
	rs("sort_open")=request("sort_open")	
	rs.update
	MySys.error.location="admin/admin_info_news_sort.asp?id="&rs("sort_up")
	rs.close
	
    MySys.error.info="新闻分类编辑成功！"
	MySys.error.suc()
	
end select
%>
<!--#include file="admin_end.asp"-->
