<!--#include file="admin_start.asp"-->
<%
'打开数据库
db_t="../"&request("url")&"/templates.mdb"
Set conn_t = Server.CreateObject("ADODB.Connection")
connstr_t="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""&db_t&"")
conn_t.Open connstr_t
'/////////////////////////////////
dim rs_t
dim rs_l
dim id_project
set rs_t=Server.CreateObject("ADODB.recordset")
set rs_l=Server.CreateObject("ADODB.recordset")

function inputTemplate(r,up)

	dim rss
	dim id_up
	
	set rss=Server.CreateObject("ADODB.recordset")
	rs_t.addnew
	rs_t("sort_up")=up
	rs_t("sort_mark")=r("sort_mark")
	rs_t("sort_description")=r("sort_description")
	rs_t("sort_name")=r("sort_name")
	rs_t("sort_content")=r("sort_content")
	rs_t("sort_addtime")=now
	rs_t("sort_open")=r("sort_open")
	rs_t("sort_num")=r("sort_num")
	rs_t("sort_style")=r("sort_style")
	rs_t("sort_sys")=0
	rs_t("sort_folder")=r("sort_folder")
	rs_t("sort_customer_grade")=""
	rs_t.update
	
	id_up=rs_t("sort_id")
	if up=0 then id_project=id_up
	
	rss.open"select * from jins_template_sort where sort_up="&r("sort_id")&" ",conn_t,1,1
	
	do while not rss.eof 
		
		if not inputTemplate(rss,id_up) then exit function
		rss.movenext
		
	loop
	
	rss.close
	set rss=nothing
	
	inputTemplate=true
	
end function

function inputLabel(id)

	dim rss
	
	set rss=Server.CreateObject("ADODB.recordset")
	
	rss.open"select * from jins_template_label where label_project="&id&" ",conn_t,1,1
	
	do while not rss.eof 
		
		rs_l.addnew
		rs_l("label_project")=id_project
		rs_l("label_name")=rss("label_name")
		rs_l("label_description")=rss("label_description")
		rs_l("label_content")=rss("label_content")
		rs_l("label_addtime")=now
		rs_l("label_sql")=rss("label_sql")
		rs_l("label_type")=rss("label_type")
		rs_l("label_link")=rss("label_link")
		rs_l.update

		rss.movenext
	loop
	
	rss.close
	set rss=nothing
	
	inputLabel=true
	
end function

function inputFiles(url)

	dim d
	dim fso
	dim sourcefolder
	Set fso = Server.CreateObject("Scripting.FileSystemObject")
	
	if url="" then exit function
	if instr(1,url,"template/folders")=1 then 
		d=replace(url,"template/folders",request("url"))
		d=server.MapPath("../"&d)
		url=server.MapPath("../"&url)
		
		if not fso.FolderExists(d) then 
			MySys.error.info="模版文件夹导入路径不存在！"&d
			exit function
		end if
		
		if fso.FolderExists(url) then
			MySys.error.info="要导入的模版文件夹已经存在！"
			exit function
		else
			MySys.check.makenewsdir(url)
		end if
		
		set sourcefolder=fso.getfolder(d)
		sourcefolder.copy url,true
		
		set sourcefolder=nothing
	else
		exit function
	end if
	
	set fso=nothing
	
	inputFiles=true
	
end function

ids=trim(request("ids"))
rs.open "select * from jins_template_sort where sort_id in ("&ids&")",conn_t,1,1
rs_t.open "select * from jins_template_sort ",conn,1,3
rs_l.open "select * from jins_template_label ",conn,1,3
do while not rs.eof 

	'//////导出模版数据
	if not inputTemplate(rs,0) then
		MySys.error.info="模版导入失败！"
		MySys.error.location="admin/admin_template_input.asp"
		MySys.error.err()
	end if
	'//////导出自定义标签
	if not inputLabel(rs("sort_id")) then
		MySys.error.info="模版自定义标签导入失败！"
		MySys.error.location="admin/admin_template_input.asp"
		MySys.error.err()
	end if
	'//////导出相关文件
	if not inputFiles(rs("sort_folder")) then
		MySys.error.info=MySys.error.info&"模版相关文件导入失败！"
		MySys.error.location="admin/admin_template_input.asp"
		MySys.error.err()
	end if
	
	rs.movenext
loop
	
MySys.error.info="模版成功导入！"
MySys.error.location="admin/admin_template_sort.asp"
MySys.error.suc()

rs_t.close
set rs_t=nothing
%>
<!--#include file="admin_end.asp"-->
