<!--#include file="admin_conn.asp"-->
<%
chkLogin
dim action : action = be("get","action")

Select case action
	case "add","edit" : headAdmin "模版管理" : info
	case "save" : save
	case "del" :del
	case "view" : view
	case "guide" : headAdmin "模版管理" : guide
	case "make" : headAdmin "模版管理" : make
	case else : headAdmin "模版管理" : main
End Select
dispseObj()

sub view
	dim num,file : file = be("get","file")
	objTemplate.html = objFile.getFile(file)
	objTemplate.mark
	objTemplate.vodpagelist()
	num = objTemplate.page_count
	if isNum(objTemplate.par_maxpage) then
		if num >= objTemplate.par_maxpage then
			num = objTemplate.par_maxpage
			objTemplate.page_count = clng(num)
		end if
	end if
	objTemplate.pageshow()
	objTemplate.ifEx
	objTemplate.run
	writeA objTemplate.html
end sub

sub make
	dim num,file : file = be("get","file")
	dim fname : fname = be("get","fname")
	objTemplate.html = objFile.getFile(file)
	objTemplate.mark
	objTemplate.vodpagelist()
	num = objTemplate.page_count
	if isNum(objTemplate.par_maxpage) then
		if num >= objTemplate.par_maxpage then
			num = objTemplate.par_maxpage
			objTemplate.page_count = clng(num)
		end if
	end if
	objTemplate.pageshow()
	objTemplate.ifEx
	objTemplate.run
	fname = replaceStr(fname,"label_","")
	fname = replaceStr(fname,"$$","/")
	objfile.createFile "../"&fname ,objTemplate.html
	writeA " 生成完毕 <a target='_blank' href='"&"../"&fname&"'>&nbsp;&nbsp;<font color=red>浏览</font></a><br>"
end sub

sub del
	Dim file : file = be("all","file")
	objfile.delfile file
	alertUrl "模板删除完毕",getReferer()
end sub

sub save
	dim file : file = be("all","file")
	dim filename : filename = be("all","filename")
	dim suffix : suffix = be("all","suffix")
	dim filepath : filepath = be("all","path")
	dim fcontent : fcontent = be("all","fcontent")
	if isN(filepath) then
		if  left(file,11) <> "../template" or ubound( split(file,"../") ) > 1 then 
			writeA "非法的文件请求"
			exit sub 
		end if
		objfile.createfile file & suffix ,fcontent
	else
		if  left(filepath,11) <> "../template" or ubound( split(filepath,"../") ) > 1 then 
			writeA "非法的文件请求"
			exit sub 
		end if
		objfile.createfile filepath & "/" & filename & suffix ,fcontent
	end if
	writeA "模板修改完毕"
end sub

sub guide
%>
<script type="text/javascript">
	$(document).ready(function(){
		
	});
</script>
<%
end sub

sub info
	dim backurl : backurl =request.ServerVariables("HTTP_REFERER")
	dim file : file = be("get","file")
	dim path : path = be("get","path")
	if isN(backurl) or instr(backurl,"index.asp")>0 then backurl="admin_templates.asp"
	dim fname,fcontent
	if not isN(file) then
		fname = mid(file,instrRev(file,"/")+1)
		if  left(file,11) <> "../template" or ubound( split(file,"../") ) > 1 then 
			writeA "非法的文件请求"
			exit sub 
		end if
		fcontent = server.htmlEncode( objfile.getfile(file))
	end if
%>
<script type="text/javascript">
	$(document).ready(function(){
		$('#form1').form({
			onSubmit:function(){
				if(!$("#form1").valid()) {return false;}
			},
		    success:function(data){
		        $.messager.alert('系统提示', data, 'info',function(){
		        	location.href = $("#backurl").val();
		        });
		    }
		});
		$("#btnCancel").click(function(){
			location.href = $("#backurl").val();
		});
	});
</script>
<form id="form1" name="form1" action="?action=save" method="post">
<table class="tb">
	<input id="backurl" name="backurl" type="hidden" value="<%=backurl%>">
	<tr>
	<td width="10%">文件名称：</td>
	<td><input id="filename" name="filename" type="text" value="<%=fname%>" size="60" <%if action="edit" then%>readonly>&nbsp;注意：编辑时文件名无法修改<%else%>><select name="suffix">
	  <option value=".html">.html</option><option value=".htm">.htm</option><option value=".js">.js</option><option value=".xml">.xml</option><option value=".wml">.wml</option>
	  </select>自定义页面以label_开头,如果需要生成到html目录用$$替换目录/杠，如：html$$hot.html <%end if%>
    </td>
	</tr>
	<tr>
	<td colspan="2">
	<textarea class="temp_t" id="fcontent" name="fcontent" style="width:90%;font-family: Arial, Helvetica, sans-serif;font-size: 14px;" rows="30"><%=fcontent%></textarea>
	</td>
	</tr>
	<tr>
	<td colspan="2" align="center">
	<input id="path" name="path" type="hidden" value="<%=path%>">
	<input id="file" name="file" type="hidden" value="<%=file%>">
	<input class="input" type="submit" value="保存" id="btnSave">
	<input class="input" type="button" value="返回" id="btnCancel">
	</td>
	</tr>
</table>
</form>
<%
end sub


sub main
	dim defaultPahth,filedir,filestr,filearr,fileattr,i
	defaultPahth = "../template" : filedir = be("get","filedir")
	if filedir = "" then filedir = defaultPahth
	if left(filedir,11) <> "../template" then filedir = "../template"
	%>
<table class="tb">
	<tr>
	<td><strong>文件名</strong></td>
	<td width="15%"><strong>模板类型</strong></td>
    <td width="15%"><strong>文件大小</strong></td>
    <td width="20%"><strong>修改时间</strong></td>
    <td width="15%"><strong>操作</strong></td>
	</tr>
<%
	if action="label" then
     	call bianlilabelFile()
    else
		Call bianliFolder(filedir)
	end if
%>
</table>
<%
end sub

function bianliFolder(currentPath)
	Dim nowpath,path,upperFolder,objFolder,objSubFolders,nextPath,fso,objSubFolder
	
	if left(currentPath,11) <> "../template" then currentPath = "../template"
	upperFolder = left(currentPath,(InStrRev(currentPath,"/")-1))
	if left(upperFolder,11) <> "../template" then upperFolder = "../template"
	if  ubound( split(currentPath,"../") ) > 1 then 
		writeA "<tr><td colspan=""5""> 非法的目录请求 </td></tr>"
		exit function 
	end if
	
	if upperFolder <> ".." then
		writeA "<tr><td colspan=""5""><img src=""../images/icons/dir2.gif""> <a href=""?filedir=" &upperFolder&""">上级目录</a> "
		writeA "<a href=""?action=add&path="&currentPath&""">(添加新页面)</a></td></tr>"
	end if
	path = server.mapPath(currentPath)
	set fso = server.CreateObject("scripting.filesystemobject")
    set objFolder=fso.GetFolder(path)
    set objSubFolders=objFolder.Subfolders
    for each objSubFolder in objSubFolders 
            nowpath=objSubFolder.name
            nextPath = currentPath & "/" & objSubFolder.name
			writeA "<tr><td colspan=""5""><img src=""../images/icons/dir.gif""> <a href=""?filedir="&nextPath&""">"&nowpath&"</a></td></tr>"
     next
     set objFolder=nothing
     set objSubFolders=nothing
     set fso = nothing
     Call bianliFile(currentPath)
end function

function bianliFile(currentPath)
     Dim Path,fso,objFolder,nowpath,objFiles,objFile,FileExt,objSubFolders
     path = server.mapPath(currentPath)
     set fso=server.CreateObject("scripting.filesystemobject")
     set objFolder=fso.GetFolder(path)
     nowpath = path
     set objFiles=objFolder.Files
     for each objFile in objFiles
     	if left(objFile.name,6) <> "label_" then
%>
	<tr>
	<td><img src="../images/icons/asp.gif"><%=objFile.name%></td>
	<td><%=templatesname(objFile.name)%></td>
	<td><%=round(objFile.size/1024,3)%>KB</td>
	<td><%=objFile.DateLastModified%></td>
<%
	FileExt = LCase(Mid(objFile.name, InStrRev(objFile.name, ".") + 1))
	Select Case FileExt
		Case "jpg", "gif", "bmp", "png"
		writeA "<td><a href="""&currentPath&"\"&objFile.name&""" target=""_blank"">预览</a></td>"
		Case else
		writeA "<td><a href=""?action=edit&file="&currentPath&"/"&objFile.name&""">编辑</a>&nbsp;<a href=""?action=del&file="&currentPath&"/"&objFile.name&""" onClick=""return confirm('确定要删除吗?');"">删除</a></td>"
		end Select
		writeA "</tr>"
		end if
    next
    set objFolder=nothing
    set objSubFolders=nothing
    set fso = nothing
end function

function bianlilabelFile()
     Dim currentPath,Path,fso,objFolder,nowpath,objFiles,objFile,FileExt,objSubFolders
     currentPath="../template/"&app_templatedir&"/"&app_htmldir
	 writeA "<tr><td colspan=""5""><a href=""?action=add&path="&currentPath&""">(添加新页面)</a>  自定义页面可生成单独页面，也可以内嵌入系统模版中</td></tr>"
     path = server.mapPath(currentPath)
     set fso=server.CreateObject("scripting.filesystemobject")
     set objFolder=fso.GetFolder(path)
     nowpath = path
     set objFiles=objFolder.Files
     for each objFile in objFiles
     	
     	if left(objFile.name,6) = "label_" then
%>
	<tr>
	<td><img src="../images/icons/asp.gif"><%=objFile.name%> &nbsp;&nbsp; 调用标签:{label:<%=replaceStr(objFile.name,"label_","")%>}</td>
	<td><%=templatesname(objFile.name)%></td>
	<td><%=round(objFile.size/1024,3)%>KB</td>
	<td><%=objFile.DateLastModified%></td>
<%
		writeA "<td><a href=""?action=view&file="&currentPath&"/"&objFile.name&""">预览</a>&nbsp;<a href=""admin_makehtml.asp?action=diypage&fname="&objFile.name&""">生成</a>&nbsp;<a href=""?action=edit&file="&currentPath&"/"&objFile.name&""">编辑</a>&nbsp;<a href=""?action=del&file="&currentPath&"/"&objFile.name&""" onClick=""return confirm('确定要删除吗?');"">删除</a></td></tr>"
		end if
    next
    set objFolder=nothing
    set objSubFolders=nothing
    set fso = nothing
end function

function templatesname(filename)
	dim str
	select case filename
	case "head.html"
		str="头部模板"
	case "foot.html"
		str="底部模板"
	case "index.html"
		str="首页模板"
	case "artindex.html"
		str="文章首页模版"
	case "art.html"
		str="文章内容页"
	case "artlist.html"
		str="文章列表页"
	case "arttopic.html"
		str="文章专题首页"
	case "vod.html"
		str="视频内容页"
	case "vodlist.html"
		str="视频分类页"
	case "vodmap.html"
		str="视频地图页"
	case "vodplay.html"
		str="视频播放页"
	case "vodsearch.html"
		str="视频搜索页"
	case "vodtopic.html"
		str="视频专题首页"
	case "vodplayopen.html"
		str="弹窗播放页面"
	case "gbook.html"
		str="留言本"
	case "userlogin.html"
		str="登陆框未登录模板"
	case "userlogged.html"
		str="登陆框已登录模板"
	case else
		str="自定义文件"
	end select
	templatesname=str
end function
%>
</body>
</html>