
<!-- #include file="conn.asp" -->
<!-- #include file="check.asp" -->

<% 
 '===========================================================================================
	'软件名称：126 cms 视频影视管理系统
	'程序版权：126电影               '咨询QQ：479025
	'开发作者：magicblack(479025)    '官方网站：http://www.126oo.com/
	'Copyright (C) 2009 - ... 126oo.com  All Rights Reserved.
	'郑重声明:
	'    1、免费版本请在程序首页保留版权信息，并做上本站LOGO友情连接,商业版本无此要求;
	'    2、任何个人或组织不得以盈利为目的发布,修改,本软件及其他副本上一切关于版权的信息；
	'    3、126电影保留此软件的法律追究权利；
'==========================================================================================
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE>模板管理 - 后台管理中心 - 126电影程序CMS</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<LINK href="images/css_body.css" type=text/css rel=stylesheet>
</HEAD>
<BODY>
<DIV class=bodytitle>
<DIV class=bodytitleleft></DIV>
<DIV class=bodytitletxt>模板管理</DIV>
</DIV>
<%
response.Charset="GBK"
dim action
action = SafeData("RQ","action",0)

Select case action
	case "edit" : edit
	case "editsave" : editsave
	case else : main
End Select

Sub edit
%>
<table class=tbtitle style="BACKGROUND: #cad9ea;" cellSpacing="1" cellPadding="5" width="96%" align="center" border="0">
  <form action="admin_templates.asp?Action=editsave" method="post" onSubmit="return Validator.Validate(this,3)">
    <tr bgcolor="#ffffff">
      <td width="15%">文件名称：</td>
      <td><input id="filename" name="filename" type="text" value="<%=LCase(Mid(Trim(Request.QueryString("file")), InStrRev(Trim(Request.QueryString("file")), "\") + 1))%>" size="40" readonly></td>
    </tr>
    <tr bgcolor="#ffffff">
      <td colspan="2"><textarea class="temp_t" id="htmlcontent" name="htmlcontent" style="width:100%;font-family: Arial, Helvetica, sans-serif;font-size: 14px;" rows="25" dataType="Require" msg="请填写模版内容"><%=replace(displayit(Trim(Request.QueryString("file"))),"</textarea>","&lt;/textarea>")%></textarea></td>
    </tr>
    <tr bgcolor="#ffffff">
      <td colspan="2" align="center"><input id="file" name="file" type="hidden" value="<%=Trim(Request.QueryString("file"))%>"><input type="submit" name="Submit" value="修改模板" class=inputbut /></td>
    </tr>
  </form>
</table>
<script language="javascript" src="images/js.js"></script>
	<%
	end sub
	
	sub editsave
	
	Dim file : file = SafeData("R","file",0)
	Dim htmlcontent : htmlcontent = request.Form("htmlcontent")
	
	htmlcontent = replace(htmlcontent,"&lt;/textarea>","</textarea>")
	call writeTextFile(Trim(file),htmlcontent)

	Response.write "<script language=javascript>alert('模板修改成功!');location.href='?';</script>"
	
	end sub
	
	sub main
	Dim rootPath : rootPath = SafeData("RQ","rootPath",0)
	%>
<table class=tbtitle style="BACKGROUND: #cad9ea;" cellSpacing="1" cellPadding="5" width="96%" align="center" border="0">
  <tr align="center" bgcolor="#f5fafe">
    <td><strong>文件名</strong></td>
	<td width="15%"><strong>模板类型</strong></td>
    <td width="10%"><strong>文件大小</strong></td>
    <td width="20%"><strong>修改时间</strong></td>
    <td width="12%"><strong>操作</strong></td>
  </tr>
<%

if rootPath = "" then rootPath = "../template/"&app_templatedir&"/"&app_htmldir
Call bianliFolder(rootPath)
%>
</table>
<%
end sub

	function bianliFolder(currentPath)
	    Dim nowpath,path,upperFolder,objFolder,objSubFolders,nextPath,fso,objSubFolder
		
		path = server.mapPath(currentPath)
		set fso = server.CreateObject("scripting.filesystemobject")    
        set objFolder=fso.GetFolder(path)
		upperFolder = LEFT(currentPath,(InStrRev(currentPath,"/")-1))
		IF upperFolder <> "../template" THEN
				Response.Write "<tr bgcolor=""#ffffff"">"
				Response.Write "<td colspan=""5""><img src=""images/dir2.gif""> <a href=""?rootPath=" &upperFolder&""">上级目录</a></td>"
				Response.Write "</tr>"
		END IF
        set objSubFolders=objFolder.Subfolders
        for each objSubFolder in objSubFolders 

            nowpath=objSubFolder.name
            nextPath = currentPath & "/" & objSubFolder.name
			Response.Write "<tr bgcolor=""#ffffff"" onmouseover=""this.bgColor='#f5fafe'"" onmouseout=""this.bgColor='#ffffff'"">"
			Response.Write "<td colspan=""5""><img src=""images/dir.gif""> <a href=""?rootPath="&nextPath&""">"&nowpath&"</a></td>"
			Response.Write "</tr>"
        next 

        
        Call bianliFile(currentPath)
        set objFolder=nothing
        set objSubFolders=nothing
        set fso = nothing
    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
			    Response.Write "<tr bgcolor=""#ffffff"" onmouseover=""this.bgColor='#f5fafe'"" onmouseout=""this.bgColor='#ffffff'"">"
				Response.Write "<td><img src=""images/asp.gif""> "&objFile.name&"</td>"
				Response.Write "<td align=""center"">"&templatesname(objFile.name)&"</td>"
				Response.Write "<td align=""center"">"&round(objFile.size/1024,3)&" KB</td>"
				Response.Write "<td align=""center"">"&objFile.DateLastModified&"</td>"
				FileExt = LCase(Mid(objFile.name, InStrRev(objFile.name, ".") + 1))
				Select Case FileExt
				Case "jpg", "gif", "bmp", "png"
				Response.Write "<td align=""center""><a href="""&currentPath&"\"&objFile.name&""" target=""_blank"">观看</a></td>"
				Case else
				Response.Write "<td align=""center""><a href=""?action=edit&file="&nowpath&"\"&objFile.name&""">编辑</a></td>"
				end Select
				Response.Write "</tr>"
            next
         set objFolder=nothing
        set objSubFolders=nothing
        set fso = nothing
    end function
	
	function displayit(path)
		dim fso,ts
		set fso=server.CreateObject("scripting.filesystemobject")    
		Set ts = fso.OpenTextFile(path)
		displayit = ts.ReadAll
		ts.Close
		set fso = nothing
		set ts = nothing
    end function
	
	Function writeTextFile(fileName,fileToWrite)
	Dim fso,  fsoFile
	Set fso = CreateObject("Scripting.FileSystemObject")
	set  fsoFile  =  fso.CreateTextFile(fileName)  
	fsoFile.writeline(fileToWrite)
	fsoFile.close
	set fsoFile = nothing
	set fso = nothing
	End Function

function templatesname(filename)
select case filename
case "head.html"
templatesname="头部模板"
case "foot.html"
templatesname="底部模板"
case "index.html"
templatesname="首页模板"
case "list.html"
templatesname="栏目页模板"
case "search.html"
templatesname="搜索页模板"
case "view.html"
templatesname="内容页模板"
case "play.html"
templatesname="播放页模板"
case "map.html"
templatesname="全部影片页模板"
case else
templatesname="自定义文件"
end select
end function
%>
</body>
</html>
