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

<%
dim id
dim ids
dim n_ids

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


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

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,",")
	dim s
	set s=MySys.temp.search
	
	for i=0 to ubound(ids)

		set rsss=conn.execute("select sort_base,sort_up,sort_id from jins_template_sort where sort_id="&ids(i)&" ")
		if rsss.eof then
			set rsss=nothing
			MySys.error.info="您要删除的模板不存在！"
			MySys.error.location="back"
			MySys.error.err()
		end if	
		if rsss("sort_base")=1 then
			set rsss=nothing
			MySys.error.info="系统自带的模板不能删除！"
			MySys.error.location="back"
			MySys.error.err()
		end if	
		sort_up=rsss("sort_up")
		sort_id=rsss("sort_id")
		set rsss=nothing

		s.sort_ids=""
		s.Sort_search "jins_template_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_template_sort where sort_id in ("&s.sort_ids&") ")
		'////如果是模板方案则删除对应的自定义标签
		if sort_up=0 then conn.execute("delete from jins_template_label where label_project="&sort_id&" ")
	
	next
	set s=nothing

	MySys.error.info="删除模版成功！"
	MySys.error.location="back"
	MySys.error.suc()
	
case else

	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

	if request("action")="add" then
	    sql="select * from jins_template_sort "
	else
	    sql="select * from jins_template_sort where sort_id="&id&" "
	end if
	
	rs.open sql,conn,1,3
	
	'/////////////////////////////////////////////检测
	
	if request("action")="add" then
	    rs.addnew
		MySys.error.info="模版添加成功！"
	    MySys.error.location="admin/admin_template_sort.asp"
	else
		MySys.error.info="模版编辑成功！"
	    MySys.error.location="back"
	end if

	if request("action")="edit" and rs.eof then
		MySys.error.info="您选择的模版不存在！"
		MySys.error.location="back"
		MySys.error.err()
	end if
	

	if request("sort_name")="" or request("sort_mark")="" then 	
		MySys.error.info="请完整填写相关项目！"
		MySys.error.location="back"
		MySys.error.err()
	end if
	
	if request("action")="add" and request("sort_up")="" then 	
		MySys.error.info="请选择模版的上级模版！"
		MySys.error.location="back"
		MySys.error.err()
	end if
	
	if request("action")="add" and request("sort_up")>0 and conn.execute("select sort_id from jins_template_sort where sort_id="&request("sort_up")&" ").eof then 	
		MySys.error.info="您选择的上级模版不存在！"
		MySys.error.location="back"
		MySys.error.err()
	end if

	if request("action")="add" and  request("sort_up")>0 and not conn.execute("select sort_id from jins_template_sort where sort_mark='"&request("sort_mark")&"' and sort_up="&request("sort_up")&" ").eof then 	
		MySys.error.info="您选择或填写的模版标识已经存在，请重新选择或填写一个新的模版类型！"
		MySys.error.location="back"
		MySys.error.err()
	end if
	
	sort_folder=trim(request("sort_folder"))
	if sort_folder<>"" then 
		if right(sort_folder,1)<>"/" then sort_folder=sort_folder&"/"
		if not MySys.check.makenewsdir(server.MapPath("../"&sort_folder)) then
			MySys.error.info=MySys.error.info&"模版文件夹建立失败，请您手动建立此文件夹！"
		end if
	end if
	
	'/////普通项
	rs("sort_up")=int(request("sort_up"))
	if request("sort_name")<>"" then rs("sort_name")=trim(request("sort_name"))
	if request("sort_open")<>"" then rs("sort_open")=int(request("sort_open"))	
	if request("sort_mark")<>"" then rs("sort_mark")=trim(request("sort_mark"))
	if request("sort_description")<>"" then rs("sort_description")=trim(request("sort_description"))
	if request("sort_addtime")<>"" then rs("sort_addtime")=trim(request("sort_addtime"))
	if request("sort_content")<>"" then rs("sort_content")=trim(request("sort_content"))
	if grade<>"" then rs("sort_customer_grade")=grade&"|1"
	rs("sort_folder")=sort_folder
	rs("sort_style")=trim(request("sort_style"))
	if request("sort_up")>0 then rs("sort_sys")=conn.execute("select sort_sys from jins_template_sort where sort_id="&request("sort_up")&" ")("sort_sys")

	rs.update
	
	rs.close
	
	'////////样式表文件生成
	Set fso = CreateObject("Scripting.FileSystemObject")
	'response.write Server.MapPath(sort_folder&"css_"&trim(request("sort_mark"))&".css")
	'response.end
	if fso.fileexists(Server.MapPath("../"&sort_folder&"css_"&trim(request("sort_mark"))&".css")) then
		fso.DeleteFile(Server.MapPath("../"&sort_folder&"css_"&trim(request("sort_mark"))&".css"))
	else
		MySys.check.MakeNewsDir(Server.MapPath("../"&sort_folder&"css_"&trim(request("sort_mark"))&".css"))
	end if
	Set txt = fso.OpenTextFile(Server.MapPath("../"&sort_folder&"css_"&trim(request("sort_mark"))&".css"), 8, True)
	txt.write trim(request("sort_style"))
	txt.Close
	set fso=nothing
	'//////////////////////

	MySys.error.suc()

	'/////////////////////////////////////////////
end select

%>
<!--#include file="admin_end.asp"-->
