<!--#Include File="../conn.asp"-->
<!--#Include File="const.asp"-->
<%
CheckAdmin(",46,")
dim FilePath
FilePath=Nslove.Ns_InstallDir&Nslove.Ns_Setting(20)&"resource.config"
FilePath = Server.MapPath(FilePath)
Select Case Action
	Case "ctrl"
		Call Tpl_Ctrl()
	Case "template"
		HeadMain()
		Call Tpl_TempLate()
	Case "loadfile"
		HeadMain()
		Call Tpl_LoadFile()
	Case "save"
		Call Tpl_Save()
	Case Else
		HeadMain()
		Call Tpl_Main()
End Select
Footer()
Nslove.PageEnd()

Sub HeadMain()''通用头部过程
head()
%>
<table cellpadding="2" cellspacing="1" width="100%" align=center>
<tr>
	<td align=center colspan=5 class="ttitle">Css样式设计管理</td>
</tr>
<tr>
	<td class="Row" width=20%>注意事项</td>
	<td class="Row" width=80% colspan="4">1、样式命名为英文字符<br />2、使用中样式不可删除，删除即包括样式文件与Css样式文件<br />3、已安装样式与模板是一一对应，选择样式进入修改<br />4、<font id="fontrd">添加非子目录下样式或者目录，需先在配置文件中相应添加节点</font></td>
</tr>
<%
End Sub

Sub Tpl_Main()
%>
<link href='<%=Nslove.Ns_InstallDir&Nslove.SkinsPath%>admin/other.css' rel="stylesheet" type="text/css" />
<tr> 
	<td colspan="5" class="ttitle">已安装样式列表</td>
</tr>
<tr>
	<td class="Row" colspan="5"><div class="template">
	<%dim HtmlStr,DataID,FolderName
	Set XmlDom =Nslove.CreateXmlDoc("Msxml2.FreeThreadedDOMDocument")
	If XmlDom.load(FilePath) Then
		For Each Node in XmlDom.documentElement.SelectNodes("template")
			DataID=Node.selectSingleNode("@templateid").text
			FolderName=Node.selectSingleNode("@skin").text
			HtmlStr=HtmlStr&"<ul>"
			HtmlStr=HtmlStr&"<li id='tit'>"&Node.selectSingleNode("@name").text&iff(Node.selectSingleNode("@enabled").text="1"," <font id='fontrd'>使用中</font>","")&"</li>"
			HtmlStr=HtmlStr&"<li id='img'><a href='?action=template&folder="&FolderName&"'><img src='"&Node.selectSingleNode("@preview").text&"'></a></li>"
			HtmlStr=HtmlStr&"<li>设计者："&Node.selectSingleNode("@author").text&"</li>"
			HtmlStr=HtmlStr&"</ul>"
		Next
	End If
	response.write HtmlStr
	%></div>
	</td>
</tr>
<tr> 
	<td colspan="5" class="Rowlight">&nbsp;</td>
</tr>
</table>
<%
End Sub

Sub Tpl_TempLate()
	dim TplFolder,FolderPath
	TplFolder=Nslove.CheckStr(Request("folder"))
	FolderPath=Nslove.Ns_InstallDir&Nslove.Ns_Setting(20)&TplFolder&"/style.config"
	FolderPath= Server.MapPath(FolderPath)
%>
<tr> 
	<td colspan="5" class="ttitle"><a href="?">管理首页</a> >> 所有样式页管理</td>
</tr>
<tr>
	<td class="Rowlight" align="center"><b>文件名/文件夹</b></td>
	<td class="Rowlight" align="center" width="45%"><b>样式描述说明</b></td>
	<td class="Rowlight" align="center" width="12%"><b>创建时间</b></td>
	<td class="Rowlight" align="center" width="10%"><b>页数</b></td>
	<td class="Rowlight" align="center" width="13%"><b>操作</b></td>
</tr>
<%dim HtmlStr,DataID
	Set XmlDom =Nslove.CreateXmlDoc("Msxml2.FreeThreadedDOMDocument")
	If XmlDom.load(FolderPath) Then
		For Each Node in XmlDom.documentElement.SelectNodes("data")
%>
<tr>
	<td class="Row"><a href="?action=loadfile&folder=<%=TplFolder&"/"&Node.selectSingleNode("@name").text%>"><div style="float:left;width:40px;text-align:center;height:30px"><%if Node.selectSingleNode("@isfile").text="1" then%><img src="/images/folder/folder.gif"><%else%><img src="/images/folder/file.gif"><%end if%></div><%=Node.selectSingleNode("@name").text%></a></td>
	<td class="Row"><%=Node.selectSingleNode("@description").text%></td>
	<td class="Row" align="center"><%=Nslove.FormatDate(Node.selectSingleNode("@lasttime").text,8)%></td>
	<td class="Row" align="center"><%=Node.selectSingleNode("@filesnum").text%></td>
	<td class="Row" align="center"><a href="?action=loadfile&folder=<%=TplFolder&"/"&Node.selectSingleNode("@name").text%>">编辑</a></td>
</tr>
<%
		Next
	end if
%>
<tr> 
	<td colspan="5" class="Rowlight">&nbsp;</td>
</tr>
<%
End Sub

Sub Tpl_LoadFile()
	dim TplFolder,FolderPath,IsFiles:IsFiles=False
	dim ParFolder,IsAdd,HtmlStr
	IsAdd=Nslove.ChkNumeric(Request("add"))
	TplFolder=Nslove.CheckStr(Request("folder"))
	ParFolder=Split(TplFolder,"/")(0)
	FolderPath=Nslove.Ns_InstallDir&Nslove.Ns_Setting(20)&TplFolder
	if InStr(FolderPath,".")>0 then IsFiles=true''是文件，需要读取内容
	if IsAdd=1 then IsFiles=true:FolderPath=FolderPath&"/"
%>
<tr> 
	<td colspan="5" class="ttitle"><a href="?">管理首页</a> >> <a href="?action=template&folder=<%=ParFolder%>">样式列表</a> >> 读取样式页</td>
</tr>
<%if IsFiles=True Then%>
<form method="post" action="?action=save" name="form" id="form">
<tr> 
	<td class="Rowlight" width="20%">样式目录：</td>
	<td class="Rowlight" colspan="4"><input type="text" name="filename" value="<%=FolderPath%>" class="frm320"> (新添加样式，需填写样式名称.css)</td>
</tr>
	<%
	if IsAdd=0 then
		HtmlStr=Server.htmlencode(Nslove.ReadTextFile(FolderPath))
	end if
	%>
<tr> 
	<td class="Row" colspan="5" align="center"><textarea name="content" cols="120" Rows="35"><%=HtmlStr%></textarea></td>
</tr>
<tr>
	<td class="Rowlight" colspan="5" align=center><input type="submit" class="button" name="Submit" value="提交保存" class="button" onclick="return winPop({form:'form',ishow:'false'});"></td>
</tr>
</form>
<%else
	dim FileArry
	FileArry=Nslove.FolderFile(FolderPath,0)
	FileArry=Split(FileArry,",")
%>
<tr> 
	<td class="Row" colspan="5" align="center">
	<%For i=0 to ubound(FileArry)
		if len(FileArry(i))=0 then exit for
		HtmlStr=HtmlStr&"<div style='float:left;width:150px;margin-top:10px'><a href='?action=loadfile&folder="&TplFolder&"/"&FileArry(i)&"'><img src='/images/folder/file.gif'><br />"&FileArry(i)&"</a></div>"
	Next
	HtmlStr=HtmlStr&"<div style='float:left;width:150px;margin-top:10px'><a href='?action=loadfile&folder="&TplFolder&"&add=1'><img src='/images/folder/file.gif'><br /><font id='fontrd'>添加样式</font></a></div>"
	response.write HtmlStr
	%></td>
</tr>
<tr>
	<td class="Rowlight" colspan="5" align=center>&nbsp;</td>
</tr>
<%
end if
End Sub

Sub Tpl_Save()
	dim FileName,Content,IsAdd
	If Nslove.Chkpost=false Then
		Response.write PrintHtml(Nslove.WarnData(0),1,"")
		Exit sub
	End If
	IsAdd=Nslove.ChkNumeric(Request.form("isadd"))
	FileName=FixName(Nslove.CheckStr(Request.form("filename")))
	if InStr(FileName,".css")=0 and InStr(FileName,".config")=0 then
		Response.write PrintHtml("文件名称不正确，请重新输入",1,"")
		Exit sub
	end if
	if InStr(FileName,Lcase(Nslove.Ns_Setting(20)))=0 then
		Response.write PrintHtml("样式目录不正确，请重新输入",1,"")
		Exit sub
	end if
	FilePath=Mid(FileName,1,InStrRev(FileName,"/"))
	Nslove.CreatePath FilePath
	if Request.form("content")="" Then
		Response.write PrintHtml("样式内容不能为空，请输入",1,"")
		Exit sub
	End if
	Content=Request.form("content")
	Content=Replace(Content,Chr(13)&Chr(10)&Chr(13)&Chr(10),Chr(13)&Chr(10))
	Call Nslove.WriteToFile(FileName,Content)
	if InStr(FileName,".config")=0 then
		CtrlName="修改模板内容"
	Else
		CtrlName="修改配置文件"
	end if
	ErrMsg=Nslove.ExReplace(Nslove.WarnData(9),"Tag.ShowTitle",CtrlName)
	Response.write PrintHtml(ErrMsg,2,"")
End Sub

'格式后缀
Function FixName(Byval FileExt)
	If IsEmpty(FileExt) Then Exit Function
	FixName = Lcase(FileExt)
	FixName = Replace(FixName,Chr(0),"")
	FixName = Replace(FixName,"'","")
	FixName = Replace(FixName,"//","/")
	FixName = Replace(FixName,"asp","")
	FixName = Replace(FixName,"asa","")
	FixName = Replace(FixName,"aspx","")
	FixName = Replace(FixName,"php","")
	FixName = Replace(FixName,"jsp","")
	'FixName = Replace(FixName,"cer","")
	FixName = Replace(FixName,"cdx","")
	FixName = Replace(FixName,"htr","")
End Function
%>