<%
'*************************************************************************
'**模 块 名：SiteObject->[jins/root/inc/class_template.asp]
'**说    明：知诸网络::网聚购物系统 版权所有2006 - 2007(C)
'**创 建 人：dustdown
'**日    期：2006-06-5 21:07:12
'**修 改 人：
'**日    期：
'**描    述：模板类
'**版    本：V1.0
'*************************************************************************
Class SiteTemplate
    
	private rs
	'//////////////////////////////////////
	private rs_loop(10)
	private num_show_loop(10) '已显示的记录数目
	private num_all_loop(10) '总共的记录数目
	public rs_loop_num '当前循环层数
	
	public num_pages_loop
	public num_page_loop
	public url_page_pre_loop
	public url_page_next_loop
	public url_page_first_loop
	public url_page_last_loop
	public url_pages_loop
	
	private HandleGetOut
	private show_form_order
	
	'//////////////////////////////////////
	public order_name_loop '排序栏属性列表
	public order_action_loop '排序栏方式列表
	public order_submit_loop '排序栏提交地址
	public order_default_loop '排序栏默认样式
	public pages_default_loop '分页栏默认样式
	public style
	public style_content
	public folder
	public url_request
	public file_request
	public template_project_id
	public template_project_name
	public template_project_description
	public template_project_addtime
	'public search_key
	public guider

	'//////////////////////////////////////////////////
	Private Sub Class_Initialize() '初始化
		pages_default_loop=""
		set rs=server.CreateObject("ADODB.RecordSet")
		rs_loop_num=-1
		url_request = request.servervariables("QUERY_STRING")
	    file_request = request.servervariables("PATH_INFO")
	    if file_request<>"" then file_request=split(file_request,"/")(ubound(split(file_request,"/")))
		show_form_order=0
		'search_key="goods_id"
		guider="<a href='index.asp'>首页</a>" '导航栏初始化

	end sub
	
	Private Sub Class_Terminate() 
	    set rs=nothing
	    'set rs_loop=nothing
	end sub
	
	function Trans_Label_Public(c,k) '模板文件公有标签替换。// 待替换的源文件，替换模式（0:替换为asp码；1:直接执行并输出;2:返回执行结果）
		dim cc
		dim l_s
		dim l_e
		dim l_n
		
		if c="" then 
			Trans_Label_Public=false
			exit function
		end if
		
		if k="" then k=0
		
		cc=c
		
		select case k
			case 0 '替换为asp码
				cc=replace(cc,"{$=","<% ") '不返回值
				cc=replace(cc,"{$","<%= ") '返回值
				cc=replace(cc,"$}","%\>")
			
			case 1 '直接执行并输出
				l_e = 1
				l_s = InStr(l_e, cc, "{$") + 2
				Do While l_s > l_e + 1
					Response.write Mid(cc, l_e, l_s - l_e - 2)
					l_e = InStr(l_s, cc, "$}") + 2
					l_n=Mid(cc, l_s, l_e - l_s - 2)
					
					if left(l_n,1)<>"=" then
						l_n="Response.Write "&l_n
					else
						l_n=right(l_n,len(l_n)-1)
					end if
					
					Execute (l_n)
					l_s = InStr(l_e, cc, "{$") + 2
				Loop
				Response.write Mid(cc, l_e)

				cc=true
			case 2
				cc=Handle_Get_Out(c)
			
		end select
		
		Trans_Label_Public=cc
	
	end function
	
	function Trans_Label_Private(c) '模板文件自定义标签替换。{$$b$}
	
	    dim cc
		dim rss
		dim l_s
		dim l_e
		dim l_n
		dim l_nn
		dim l_c
		dim cs
		dim t_out
		
		if c="" then 
			Trans_Label_Private=false
			exit function
		end if
		
		set rss=server.CreateObject("ADODB.RecordSet")
		
		cc=c
		cs=""
		l_s=instr(1,cc,"{$$")
		
		do while l_s>0 
			l_e=instr(l_s,cc,"$}")
			if l_e>l_s+3 then
				l_n=Mid(cc,l_s+3,l_e-l_s-3 )
			
				l_nn=Trans_Label(replace(l_n,"#","$"),2)
				
				rss.open "select label_content,label_cache_addtime,label_cache_timeout,label_cache_content from jins_template_label where label_name='"&l_nn&"' and label_project="&template_project_id&" ",conn,1,3
				if not rss.eof then
					cc=LabelCacheTactic(rss,cc,l_n,l_nn) '标签缓存策略
				else
					rss.close
					rss.open"select label_content,label_cache_addtime,label_cache_timeout,label_cache_content from jins_template_label where label_name='"&l_nn&"' and label_project=0 ",conn,1,3
					if not rss.eof then
						cc=LabelCacheTactic(rss,cc,l_n,l_nn) '标签缓存策略
					else
						cc=replace(cc,"{$$"&l_n&"$}",l_nn)
					end if
				end if
				rss.close
			end if
	
			l_s=instr(l_e,cc,"{$$")
		loop
		
		Trans_Label_Private=cc
		
		set rss=nothing
		
	end function
	
	function LabelCacheTactic(rss,cc,l_n,l_nn)'标签缓存策略
	
		dim t_o
		dim cs
		
		cs=""
		t_o=trim(rss("label_cache_timeout")) '设置标签缓存生存周期 s
		't_o=0
		if t_o<>"" then t_o=int(t_o) else t_o=0
		
		if t_o=0 then '如果生存周期为0 则视为不缓存
		
			cc=replace(cc,"{$$"&l_n&"$}",rss("label_content"))
			
		else
		
			if rss("label_cache_addtime")<>"" then 
				if DateDiff("s", rss("label_cache_addtime"), Now())>=t_o then '如果过期则更新标签缓存
					cs=Trans_Label(rss("label_content"),2)
					if cs<>false then 
						rss("label_cache_content")=cs
						rss("label_cache_addtime")=now()
						rss.update
						cc=replace(cc,"{$$"&l_n&"$}",cs)
					else
						cc=replace(cc,"{$$"&l_n&"$}",l_nn) '如果生成标签失败则返回标签名
					end if
				else
					cc=replace(cc,"{$$"&l_n&"$}",rss("label_cache_content")) '没有过期则直接输出标签的缓存
				end if
				
			else '如果缓存日期为空则更新标签的缓存
			
				cs=Trans_Label(rss("label_content"),2)
				if cs<>false then 
					rss("label_cache_content")=cs
					rss("label_cache_addtime")=now()
					rss.update
					cc=replace(cc,"{$$"&l_n&"$}",cs)
				else
					cc=replace(cc,"{$$"&l_n&"$}",l_nn)
				end if
				
			end if
			
		end if
		
		LabelCacheTactic=cc

	end function
	
	function Trans_To_Source(c,filepath) '模板文件转换为可执行源文件
	
		dim fso
		dim txt
		dim data
		
		if c="" or filepath="" then 
			Trans_To_Source=false
			exit function
		end if
		
		Set fso = CreateObject("Scripting.FileSystemObject")
		If fso.FileExists(filepath) then  fso.DeleteFile (filepath)
        Set txt = fso.OpenTextFile(filepath, 8, True)
        data = Trans_Label(c,0)
		if data=false then 
			Trans_To_Source=false
			exit function
		end if
        txt.write data
        txt.Close
		set fso=nothing
	
	end function 
		
	function Handle_Get_Out(c) '取得含标签字符串的输出
	
	    dim cc
		dim l_s
		dim l_e
		dim l_n
		
		if c="" then 
			Handle_Get_Out=false
			exit function
		end if
		
		Handle_Get_Out=c
		cc=c
		
		l_e=1
		l_s=instr(l_e,cc,"{$")
		do while l_s>0
		    cc=Handle_Get_Out
			l_s=instr(1,cc,"{$")
			if l_s>0 then
				l_e=instr(l_s,cc,"$}")
				if l_e>l_s+2 then
					l_n=Mid(cc,l_s+2,l_e-l_s-2 )
					
					if left(l_n,1)<>"=" then
						l_n="result_handle="&l_n&" "&vbcrlf&"if result_handle<>"""" then Handle_Get_Out=replace(Handle_Get_Out,""{$"&replace(replace(l_n,"""",""""""),vbcrlf,"""&vbcrlf&""")&"$}"",result_handle) else Handle_Get_Out=replace(Handle_Get_Out,""{$"&replace(l_n,"""","""""")&"$}"","""")"
					else
						l_n=right(l_n,len(l_n)-1)&vbcrlf&"Handle_Get_Out=replace(Handle_Get_Out,""{$"&replace(replace(l_n,"""",""""""),vbcrlf,"""&vbcrlf&""")&"$}"","""")"
					end if
					execute(l_n)
	
				end if
			end if 
	
		loop

	end function
	
'特殊标签替换/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	function TransLabelArgument(s)
		if s="" then exit function
		s=replace(s,"{##","{$$")
		s=replace(s,"{#","{$")
		s=replace(s,"#}","$}")
		TransLabelArgument=s
	end function
	
	Function Handle_Label_Loop(c,l,s,c_loop,num_pepage,content_order,content_h) 'Loop_Pages标签处理函数；// sql查询语句；列数；行分割符；循环体[ {$->{# / {$$->{## /$}-> #} ]；每页显示的数目；排序字符串；插入栏
	
		Dim cc,ccc,num_show,n,num_pages,num_page_show,order_name_search,order_action_search,i_rs_loop ,num_all,num_pages_show
		n=0
		dim t_s
		t_s=timer()
		
		rs_loop_num=rs_loop_num+1
		i_rs_loop=rs_loop_num
		'response.write i_rs_loop
		set rs_loop(i_rs_loop)=server.CreateObject("ADODB.RecordSet")

		if c_loop="" or c="" or l=""  then 
			Handle_Label_Loop=false
			exit function
		end if
		
		'参数解码
		c_loop=TransLabelArgument(c_loop)
		c=TransLabelArgument(c)
		l=TransLabelArgument(l)
		s=TransLabelArgument(s)
		num_pepage=TransLabelArgument(num_pepage)
		content_order=TransLabelArgument(content_order)
		content_h=TransLabelArgument(content_h)
		content_page=TransLabelArgument(content_page)
		'response.write content_page
		'参数生成
		c=Trans_Label(c,2)
		'response.write c
		'response.end
		l=Trans_Label(l,2)
		'content_h=Trans_Label(content_h,2)
		num_pepage=Trans_Label(num_pepage,2)
		If c = "" Then
			Handle_Label_Loop= "<br><center>对不起，你所搜索的范围内暂时没有相关信息！！</center><br>"
			Exit Function
		End If
		If not isInteger(l) then l=1 else l=int(l)
		if l<=0 then l=1
		If not isInteger(num_pepage) then num_pepage=0 else num_pepage=int(num_pepage)
		if num_pepage<0 then l=0
		
		'排序参数
		order_name_search = trim(request("order_name"))
		order_action_search = trim(request("order_action"))
		If order_name_search <> "" and content_order <> "" Then
			c=site.check.replace_re(c,"order[ ]*by[ ]*.*"&order_name_search&"[ ]*desc"," ")
			c=site.check.replace_re(c,"order[ ]*by[ ]*.*"&order_name_search," ")
			
			if not site.check.find_re(c,"order[ ]*by") then
				c = c + " order by " + order_name_search + " " + order_action_search
			else
				c=replace(c,"order by"," order by " + order_name_search + " " + order_action_search+" , ",1,-1,1)
				'if instr(1,c,"order by "&order_name_search,1)c = replace(c," order by "," order by  " + order_name_search + " " + order_action_search+" ,",1,-1,1) 
			end if
		End If
		session("FB_EM_1_SQL_search_order_name") = order_name_search
		session("FB_EM_1_SQL_search_order_action") = order_action_search
		
		'response.write c
		'response.end	


		if request("n_page")="" then num_page=1 else num_page = int(request("n_page"))
		
		'打开sql查询
		c_f=c
		c_f_s=instr(1,c," from ",1)
		c_f_e=instr(1,c," order ",1)
		if c_f_e>c_f_s then c_f=mid(c,c_f_s,c_f_e-c_f_s) else c_f=mid(c,c_f_s)
		c_f="select count(*) "&c_f
		
		tt=t1
		'response.write c_f
		'response.flush
		num_all=conn.execute(c_f)(0) '总记录数
		c_f=mid(c,c_f_s)
		if num_pepage>0 then 
			if instr(1,c,"top",1)=0 then 
			c=replace(c,"select ","select top "&num_pepage*num_page&" ",1,-1,1) 
			'c=replace(c," where "," where "&search_key&" not in (select top "&num_pepage*(num_page)&" "&search_key&" "&c_f&" ) and ",1,-1,1) 
			'c=replace(c," where "," where "&search_key&" > "&(num_all-num_pepage*num_page)&" and "&search_key&" < "&(num_all-num_pepage*(num_page-2))&"  and ",1,-1,1) 
			end if
		end if

		'response.write c
'response.flush
		rs_loop(i_rs_loop).open c, conn, 1, 1
		if num_pepage<=0 or num_pepage="" then  num_all = rs_loop(i_rs_loop).recordcount
		'response.write c
		
		'页数计算
		if num_pepage="" or num_pepage<=0 then 
			num_pepage=num_all
		else
			If num_all Mod num_pepage = 0 Then
				num_pages = num_all \ num_pepage
			Else
				num_pages = num_all \ num_pepage + 1
			End If
			
			if num_page>num_pages then num_page=1
			
			If Not rs_loop(i_rs_loop).EOF Then
				rs_loop(i_rs_loop).Move num_pepage * (num_page - 1)
			Else
				'num_all=0
				Handle_Label_Loop= "<br><center>对不起，你所搜索的范围内暂时没有相关信息！！</center><br>"
				pages_default_loop=""
				Exit Function
			End If
		end if
		
		'url处理
		url_request = Replace(url_request, "&n_page=" & request("n_page"), "")
		url_request=replace(url_request,"&order_name="&request("order_name"),"")
		url_request=replace(url_request,"order_name="&request("order_name"),"")
		url_request=replace(url_request,"&order_action="&request("order_action"),"")
		url_request=replace(url_request,"order_action="&request("order_action"),"")

		'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		'排序栏标签设置
		If content_order <> "" Then
	
			'----排序属性
			content_order =Trans_Label(content_order,2)
			content_order =replace(content_order,vbcrlf,"")
			content_order = Split(content_order, ",")
			cc="<select id=order_name class='input_order_name'>"
			For i = 0 To UBound(content_order)
				content_order(i) = Split(content_order(i), "$")
				cc=cc& "<option value=" & content_order(i)(1) & " "
				If i = 0 Then
					If session("FB_EM_1_SQL_search_order_name") = "" Or session("FB_EM_1_SQL_search_order_name") = content_order(i)(1) Then cc=cc& "selected"
				Else
					If session("FB_EM_1_SQL_search_order_name") = content_order(i)(1) Then cc=cc& "selected"
				End If
				cc=cc& ">" & content_order(i)(0) & "</option>"
			Next
			cc=cc& "</select>"
			order_name_loop=cc
	
			'----排序方式
			cc="<select id=order_action class='input_order_action'>"
			cc=cc& "<option value='desc' "
			If session("FB_EM_1_SQL_search_order_action") = "desc" Then cc=cc& "selected"
			cc=cc& ">降序</option>"
			cc=cc& "<option value='' "
			If session("FB_EM_1_SQL_search_order_action") = "" Then cc=cc& "selected"
			cc=cc& ">升序</option>"
			cc=cc& "</select>"
			order_action_loop=cc
			
			'----排序提交
			order_submit_loop="document.orderform.action="""&file_request&"?"&url_request&"""+""&order_name=""+document.getElementById(""order_name"").value+""&order_action=""+document.getElementById(""order_action"").value;document.orderform.submit();"

			'----排序默认样式
			cc="<table align=center cellpadding='0' cellspacing='0' width='100%' height='20'style='border: 1px solid #ebebeb;'>"
			cc=cc&"<form name=orderform action='' name=form1 method=post>"
			cc=cc& " <tr>"
			cc=cc& "     <td height='30' width='20%'align=left style='padding-left:5px'>·您可以对结果进行排序 >> 按 "
			cc=cc& order_name_loop
			cc=cc& " 的 "&order_action_loop
			
			cc=cc& " <input type=button onclick='"&order_submit_loop&"' value=开始排列 >"
			cc=cc& "</td>"
			cc=cc& " </tr>"
			cc=cc& "</form></table>"
			order_default_loop=cc
			
			cc=""
			
		End If
		
		'分页标签设置
		url_request=url_request&"&order_name="&request("order_name")&"&order_action="&request("order_action")
		num_all_loop(rs_loop_num)=num_all
		num_pages_loop=num_pages
		num_page_loop=num_page
		url_page_first_loop="temp.asp?"&url_request&"&n_page=1"
		url_page_last_loop="temp.asp?"&url_request&"&n_page="&num_pages
		if num_page_loop<=1 then 
			url_page_pre_loop="temp.asp?"&url_request&"&n_page=1"
		elseif num_page_loop>num_pages then
			url_page_pre_loop="temp.asp?"&url_request&"&n_page="&num_pages
		else
			url_page_pre_loop="temp.asp?"&url_request&"&n_page="&(num_pages-1)
		end if
		
		if num_page_loop>=num_pages then 
			url_page_next_loop="temp.asp?"&url_request&"&n_page="&num_pages
		elseif num_page_loop<=0 then
			url_page_next_loop="temp.asp?"&url_request&"&n_page=1"
		else
			url_page_next_loop="temp.asp?"&url_request&"&n_page="&(num_pages+1)
		end if
				
		if num_pages>((num_page \ 10)*10+10) then num_pages_show=(num_page \ 10)*10+10 else num_pages_show=num_pages
		for num_page_show=(num_page \ 10)*10+1  to num_pages_show
		url_pages_loop=url_pages_loop& " [<a href='temp.asp?"&url_request&"&n_page="&num_page_show&"'>"&num_page_show&"</a>] "
		next
		if num_pages>(num_page \ 10)*10+10 then url_pages_loop=url_pages_loop+ " <a title='后10页' href='temp.asp?"&url_request&"&n_page="&num_pages_show+1&"'>...</a>"

		pages_default_loop="<br>"
		pages_default_loop=pages_default_loop+ "<table border='0' width='100%' cellspacing='1' cellpadding='0'>"
		pages_default_loop=pages_default_loop+ "<tr>"
		pages_default_loop=pages_default_loop+ "<td align='center' >"
		pages_default_loop=pages_default_loop+ "<a href='temp.asp?"&url_request&"&n_page=1'><img align='absmiddle' border='0' src='template/folders/sys/btn_pre.gif' width='19' height='21' alt='第一页'></a>"
		if num_page>1 then  pages_default_loop=pages_default_loop+ "<a href='temp.asp?"&url_request&"&n_page="&num_page-1&"'><img align='absmiddle'  border='0' src='template/folders/sys/btn_pre2.gif' width='47' height='21' alt='上一页'></a> "
		pages_default_loop=pages_default_loop+ " 共有 <font color=red >"&num_all&"</font> 项  "
		pages_default_loop=pages_default_loop+ " 页次:<font color=blue >"&num_page&"</font>/"&num_pages&" 页 "
		'pages_default_loop=pages_default_loop+ "  现在是第"&num_page&"页"
		
		if num_pages>((num_page \ 10)*10+10) then num_pages_show=(num_page \ 10)*10+10 else num_pages_show=num_pages
		for num_page_show=(num_page \ 10)*10+1  to num_pages_show
		pages_default_loop=pages_default_loop+ " [<a href='temp.asp?"&url_request&"&n_page="&num_page_show&"'>"&num_page_show&"</a>] "
		next
		if num_pages>(num_page \ 10)*10+10 then pages_default_loop=pages_default_loop+ " <a title='后10页' href='temp.asp?"&url_request&"&n_page="&num_pages_show+1&"'>...</a>"
		
		if num_page<num_pages then  pages_default_loop=pages_default_loop+ "<a href='temp.asp?"&url_request&"&n_page="&num_page+1&"'><img align='absmiddle'  border='0' src='template/folders/sys/btn_next2.gif' width='46' height='21' alt='下一页'></a>"
		pages_default_loop=pages_default_loop+ "<a href='temp.asp?"&url_request&"&n_page="&num_pages&"'><img align='absmiddle'  border='0' src='template/folders/sys/btn_next.gif' width='18' height='21' alt='最后一页'></a></td>"
		pages_default_loop=pages_default_loop+ "</tr>"
		pages_default_loop=pages_default_loop+ "</table>"
		'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

		'插入栏
		cc=cc&Trans_Label(content_h,2)
		
		'循环开始
		For num_show = 1 To num_pepage
			num_show_loop(rs_loop_num)=num_show
			If Not rs_loop(i_rs_loop).EOF Then
				if n mod l=0 and s<>"" and s<>"br" then cc=cc& "<"&s&">"

				ccc=Trans_Label(c_loop,2)'循环体公共标签替换执行
				if ccc=false then  
					Handle_Label_Loop=false
					exit function
				end if
				cc=cc&ccc
				n=n+1
				
				if n mod l=0 and s<>"" then cc=cc&  "</"&s&">"
	
				rs_loop(i_rs_loop).movenext
			Else
				Exit For
			End If
		Next
		rs_loop(i_rs_loop).Close
		
		'分页栏
		'cc=cc&Trans_Label(content_page,2)
		
		set rs_loop(i_rs_loop)=nothing
		'if show_form_order=0 then 
			'Handle_Label_Loop="<form name=orderform action=''  method=post></form>"&cc 
			'show_form_order=1
		'else 
			'Handle_Label_Loop=cc&"||"&(timer-t_s)*1000&"||"
			Handle_Label_Loop=cc
		'end if
		
		rs_loop_num=rs_loop_num-1
		'response.write "||"&(1000*(timer-tt))&"||"

	End Function
'主函数/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
	function Trans_Label(c,k) '模板文件标签转换。// 待替换的源文件，替换模式（0:替换为asp码；1:直接执行并输出;2:返回执行结果）
	
		dim cc
		
		if c="" then 
			Trans_Label=""
			exit function
		end if
		
		if k="" then k=0
		
		cc=Trans_Label_Private(c) '自定义标签转换
		if cc=false then
			Trans_Label=false
			exit function
		end if
		
		cc=Trans_Label_Public(cc,k) '公共标签转换
		if cc=false then
			Trans_Label=false
			exit function
		end if
		
		Trans_Label=cc
	
	end function
	
	function Out(c) '主函数 //请求页面tr
	'先搜索请求页面是否有可用的模版如果没有再向上搜索,知道找到可用的模版，如果仍然没有找到则调用2级页面模版temp
		dim cc
		dim i
		dim ii
		dim s
		dim c_t
		dim fso
		dim c_fso
		dim styles
		
		if c="" then 
			Out=false
			exit function
		end if
		
		cc=c
		
		'////////////////////////////////////////////////出错地址转向处理[config_UrlErrorHandle.asp]

		'////////////////////////////////////////////////
		
		cc=split(cc,"|")
		'if cc(0)="search" or cc(0)="detail" then 'search / detail 替换 goods|search -> goods_search
			'c_t=cc(0)
			'cc(0)=cc(1)
			'cc(1)=c_t
		'end if
		
		for i=0 to ubound(cc)
		
		    s=""
			
			for ii=0 to ubound(cc)-i
				if s="" then s=cc(ii) else s=s&"_"&cc(ii)
			next
			
			if s="" then
				out=false
				exit function
			end if 
			
			rs.open "select * from jins_template_sort where sort_mark='"&s&"' and sort_open=1 ",conn,1,1
			if not rs.eof then
				
				'/////////用户权限检测
				if not rs("sort_customer_grade")="" then
					
					if not site.temp.customer.check.GradeCheck(rs("sort_customer_grade")) then exit function
				
				end if
				
				'/////////读取模版所属的模版方案的信息
				if not get_template_info(rs("sort_id")) then exit function

				'/////////读取模版的设置
				'文件夹
				folder=rs("sort_folder")
				if folder<>"" then 
					if right(folder,1)<>"/" then folder=folder&"/"
				end if
				
				'样式表
				if rs("sort_style")<>"" then
				    style_content=rs("sort_style")
					style=folder&"css_"&rs("sort_mark")&".css"
				else
				    styles=Show_Style(rs("sort_up"))
					style_content=styles(0)
					style=styles(1)
				end if
				'style="<style>"&style&"</style>"
				
				'导航栏信息
				if c<>"default" then 
					guider=guider&" >> <a href='temp.asp?tr="&trim(request("tr"))&"'>"&rs("sort_name")&"</a>"
				else
					guider=site.info.announcement
				end if
				
				'////////模版源码转换
				style=Trans_Label(style,2)
				Trans_Label rs("sort_content"),1 
				'Trans_To_Source rs("sort_content"),server.mappath(".")&"\index.source" 

				rs.close
				exit function
			end if
			rs.close
			
		next
		
		rs.open "select sort_content from jins_template_sort where sort_mark='temp' ",conn,1,1
		if not rs.eof then Trans_Label rs("sort_content"),1
		rs.close 
		
		out = true
	
	end function
	
	function Show_Style(c) '搜索可用的样式表 
	
	    if c="" then exit function
		
		dim rs_s
		dim r(2)
		dim rr
		
		set rs_s=server.CreateObject("ADODB.RecordSet")
		rs_s.open"select sort_style,sort_folder,sort_mark,sort_up from jins_template_sort where sort_id="&c&" ",conn,1,1
		if rs_s.eof then
			r(0)=""
			r(1)=""
		else
			if rs_s("sort_style")="" then 
				rr=Show_Style(rs_s("sort_up")) 
				r(0)=rr(0)
				r(1)=rr(1)
			else 
				r(0)=rs_s("sort_style")
				r(1)=rs_s("sort_folder")&"/css_"&rs_s("sort_mark")&".css"
			end if
		end if
		
		Show_Style=r
		set rs_s=nothing
		
	
	end function
	
	function get_template_info(c) '获取模版所属模版方案 
	
		dim rs_s
		
	    if c="" then exit function
		
		do while c>0 
			set rs_s=conn.execute("select sort_id,sort_name,sort_description,sort_addtime,sort_up from jins_template_sort where sort_id="&c&" ")
			if not rs_s.eof then
				if rs_s("sort_up")=0 then 
					template_project_id=c
					template_project_name=rs_s("sort_name")
					template_project_description=rs_s("sort_description")
					template_project_addtime=rs_s("sort_addtime")
					set rs_s=nothing
					get_template_info=true
					exit function
				else 
					c=rs_s("sort_up")
				end if
			else
				exit function
			end if
			set rs_s=nothing
		loop
		
		template_project_id=1
		get_template_info=true
	
	end function
	
	function Object_Handle(id)
		if id="" then exit function
		
		'dim object
		'object=site.object
		'response.write site.object(0).id
		'site.object(0).name="dfd"

		'response.write site.object(0).Object_handle(id)
		'response.end
		if not site.object(0).Object_handle(id) then exit function
		
		'set object=nothing
	
	end function
	
	Function isInteger(para)
		On Error Resume Next
		Dim str
		Dim l, i
		If IsNull(para) Then
			isInteger = False
			Exit Function
		End If
		str = CStr(para)
		If Trim(str) = "" Then
			isInteger = False
			Exit Function
		End If
		l = Len(str)
		For i = 1 To l
			If Mid(str, i, 1) > "9" Or Mid(str, i, 1) < "0" Then
				isInteger = False
				Exit Function
			End If
		Next
		isInteger = True
		If err.Number <> 0 Then err.Clear
	End Function

End Class
%>