<!--#include file="admin_start.asp"-->
<%
if request("action")="" then
	%>
	<form name=data action='admin_template_output_handle.asp?action=output' method=post >
	<table cellspacing=0 cellpadding=0 align=center height=100 width=300 bgcolor=#F7F7F7 style='border: 1px solid #EBEBEB; '>
	<tr>
	<td height=30 width='6%' align=center>
	是否清空原始导出模版数据库[templates.mdb]<br><br>
	<input type=radio name=clear value='y' checked> 清空  
	<input type=radio name=clear value='n' > 不清空<br><br>
	<input type=hidden name=ids value='<%=request("ids")%>' >
	<input type=submit  value='开始导出！' >
	</td>
	</tr>
	</table>
	</form>
	<%
else
	'打开数据库
	db_t="../template/output/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 outputTemplate(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")=r("sort_addtime")
		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")=r("sort_sys")
		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,1,1
		
		do while not rss.eof 
			
			if not outputTemplate(rss,id_up) then exit function
			rss.movenext
			
		loop
		
		rss.close
		set rss=nothing
		
		outputTemplate=true
		
	end function
	
	function outputLabel(id)
	
		dim rss
		
		set rss=Server.CreateObject("ADODB.recordset")
		
		rss.open"select * from jins_template_label where label_project="&id&" ",conn,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")=rss("label_addtime")
			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
		
		outputLabel=true
		
	end function
	
	function outputFiles(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","template/output")
			d=server.MapPath("../"&d)
			url=server.MapPath("../"&url)
			
			if not fso.FolderExists(url) then exit function
			
			MySys.check.makenewsdir(d)
			
			set sourcefolder=fso.getfolder(url)
			sourcefolder.copy d,true
			
			set sourcefolder=nothing
		else
			exit function
		end if
		
		set fso=nothing
		
		outputFiles=true
		
	end function
	
	ids=trim(request("ids"))
	cl=trim(request("clear"))
	if cl="" or cl="y" then 
		conn_t.execute("delete from jins_template_sort")
		conn_t.execute("delete from jins_template_label")
	end if
	
	rs.open "select * from jins_template_sort where sort_id in ("&ids&")",conn,1,1
	rs_t.open "select * from jins_template_sort ",conn_t,1,3
	rs_l.open "select * from jins_template_label ",conn_t,1,3
	do while not rs.eof 
	
		'//////导出模版数据
		if not outputTemplate(rs,0) then
			MySys.error.info="模版导出失败！"
			MySys.error.location="admin/admin_template_project_list.asp"
			MySys.error.err()
		end if
		'//////导出自定义标签
		if not outputLabel(rs("sort_id")) then
			MySys.error.info="模版自定义标签导出失败！"
			MySys.error.location="admin/admin_template_project_list.asp"
			MySys.error.err()
		end if
		'//////导出相关文件
		if not outputFiles(rs("sort_folder")) then
			MySys.error.info="模版相关文件导出失败！"
			MySys.error.location="admin/admin_template_project_list.asp"
			MySys.error.err()
		end if
		
		rs.movenext
	loop
		
	MySys.error.info="模版成功导出到 [ 根目录/template/output ]文件夹下！"
	MySys.error.location="admin/admin_template_project_list.asp"
	MySys.error.suc()
	
	rs_t.close
	set rs_t=nothing
end if
%>
<!--#include file="admin_end.asp"-->
