<!--#include file="setup.asp"-->
<!--#include file="temphelp.asp"-->
<%
Dim strcontent,action,Makename
Dim fso,fout,cname1,cname2
Dim strcontent1,fso1,fout1,strbody
Dim srs,TempDir,Style_CSS
Dim id,i,SkinID,StyleID
NC_Admin.AdminChk = "02"
NC_Admin.Check

DownsysClass.admin_header
action = Trim(Request("action"))
StyleID = Request("StyleID")
id = Request("ID")
'取当前系统默认模板编号
SkinID = DownsysClass.Tempid
If StyleID = "" Then
	StyleID = SkinID
ElseIf Not IsNumeric(StyleID) Then
	StyleID = SkinID
End If
StyleID = CLng(StyleID)
Set srs = CreateObject("adodb.recordset")
Response.Write "<table width=""100%"" border=""0"" cellspacing=""1"" cellpadding=""3"" align=center class=""tableBorder"">"
Response.Write "<tr>"
Response.Write "<th width=""100%"" class=""tableHeaderText"" colspan=2 height=25>模板管理"
Response.Write "</th>"
Response.Write "</tr>"
Response.Write "<tr>"
Response.Write "<td class=""forumRowHighlight"" colspan=2>"
Response.Write "<p><B>注意</B>：<BR>①在这里，您可以新建和修改模板，可以编辑CSS样式，可以新建模板页面。<BR>②当前正在使用的默认模板不能删除;<BR>"
Response.Write "③编样式的同时，系统会按样式目录名自动生成样式文件“style.css”"
Response.Write "</td>"
Response.Write "</tr>"
Response.Write "<tr>"
Response.Write "<td class=""forumRowHighlight"" width=20% height=25 align=left>"
Response.Write "<B>模板操作选项</B></td>"
Response.Write "<td class=""forumRowHighlight"" width=""80%""><a href=""admin_template.asp"">模板管理首页</a>"
If Request("page") <> "" Then
	Response.Write " | <a href=""?action=edit&stype=1&page=" & Request("page") & "&StyleID=" & StyleID & """>模板基本设置</a>"
	Response.Write " | <a href=""?action=edit&stype=2&page=" & Request("page") & "&StyleID=" & StyleID & """>模板界面风格</a>"
	Response.Write " | <a href=""?action=editcss&StyleID=" & StyleID & """>修改当前模板CSS样式</a>"
End If
Response.Write "</td>"
Response.Write "</tr>"
Response.Write "</table>"
Select Case action
	Case "manage"
		If Request("mostyle") = "编 辑" Then
			TempMain
			ElseIf Request("mostyle") = "删 除" Then
			DelStyle
		End If
	Case "savecss"
		Call SaveCSS
	Case "edit"
		Call Edit
	Case "editcss"
		Call EditCSS
	Case "saveedit"
		Call SaveEdit
	Case "addpage"
		Call addpage
	Case "delpage"
		Call delpage
	Case "pagerename"
		Call temprename
	Case "rename"
		Call rename
	Case "addstyle"
		Call addstyle
Case Else
	Call TempMain
End Select
If FoundErr = True Then
	Response.Redirect ("showmsg.asp?action=error&Message=" & Server.URLEncode(ErrMsg) & "")
	Response.End
End If
DownsysClass.admin_footer
NothingObject

Private Sub TempMain()
	Dim NowOpenTemplate
	Dim Templateslist
	Response.Write "<p></p>"
	Response.Write "<table width=""100%"" border=""0"" cellspacing=""1"" cellpadding=""3"" align=center class=""tableBorder"">"
	Response.Write "<tr>"
	Response.Write "<th width=""100%"" class=""tableHeaderText"" colspan=2 height=25>当前模板管理"
	Response.Write "</th>"
	Response.Write "</tr>"
	Response.Write "<tr>"
	Response.Write "<form method=post action=""?action=manage"">"
	Response.Write "<td class=""forumRowHighlight"" height=40 align=left>"
	Response.Write "请选择模板： "
	'利用系统缓存数据取得所有模板名称和ID

	DownsysClass.Name = "Templateslist"
	If DownsysClass.ObjIsEmpty Then DownsysClass.ReloadTemplateslist
	Templateslist = DownsysClass.Value
	Templateslist = Split(Templateslist, "@@@")
	Response.Write "<select name=""StyleID"" size=1>"
	For i = 0 To UBound(Templateslist)
		Templateslist(i) = Split(Templateslist(i), "|||")
		Response.Write "<option value=""" & Templateslist(i)(0) & """"
		If CLng(Templateslist(i)(0)) = CLng(StyleID) Then
			Response.Write " selected"
			NowOpenTemplate = Templateslist(i)(1)
		End If
		Response.Write ">" & Templateslist(i)(1) & "</option>"
	Next
	Response.Write "</select>"
	Response.Write "&nbsp;"
	Response.Write "<input type=submit value=""编 辑"" name=""mostyle"" class=button>&nbsp;"
	Response.Write "<input type=submit value=""删 除"" name=""mostyle"" class=button>"
	Response.Write "<br><b>说明：</b>删除操作将删除该模板所有数据，慎用。"
	Response.Write "</td>"
	Response.Write "</FORM>"
	Response.Write "<FORM METHOD=POST ACTION=""?action=addpage"">"
	Response.Write "<td class=""forumRowHighlight"" height=25 align=left>"
	Response.Write "新建分模板页面：&nbsp;<BR>"
	Response.Write "<input type=text size=25 name=""StylePageName"">&nbsp;&nbsp;"
	Response.Write "<input type=submit name=submit value=""添 加"" class=button> "
	Response.Write "</td>"
	Response.Write "</FORM>"
	Response.Write "</tr>"
	Response.Write "<tr>"
	Response.Write "<td class=""forumRowHighlight"" height=25 align=right colspan=2>"
	Response.Write "↑请输入ASP页面名（不要包含后缀），新建立的页面模板既是该页面的模板资源）↑"
	Response.Write "</td></tr>"
	Response.Write "<tr>"
	Response.Write "<th height=25 colspan=2>"
	Response.Write NowOpenTemplate & "－－模板资源管理</th></tr><tr><td height=25 class=""bodytitle"" colspan=2>"
	Response.Write "分页面模板就是每个页面的风格模板，括号中是字段名，字段的命名规则为：temp_页面名（不要后缀）"
	Response.Write "</td>"
	Response.Write "</tr>"
	Set Rs = DownsysClass.Execute("Select top 1 * From NC_Template ")
	For i = 3 To Rs.Fields.Count - 1
		If i > 12 Then
			Response.Write "<form method=post action=""?action=pagerename"">"
		End If
		Response.Write "<tr onmouseover=""this.style.backgroundColor='#F3F3FA';this.style.color='red'"" onmouseout=""this.style.backgroundColor='';this.style.color=''"">"
		Response.Write "<td height=25 align=left>"
		Response.Write "<li>"
		Select Case i
			Case 3
				Response.Write "当前模板CSS设置<a href=#>"
			Case 4
				Response.Write "当前模板主模块<a href=#>"
			Case 5
				Response.Write "当前首页模板<a href=#>"
			Case 6
				Response.Write "软件列表页模板<a href=#>"
			Case 7
				Response.Write "软件信息页模板<a href=#>"
			Case 8
				Response.Write "当前搜索页模板<a href=#>"
			Case 9
				Response.Write "文章首页模板<a href=#>"
			Case 10
				Response.Write "文章列表页模板<a href=#>"
			Case 11
				Response.Write "文章内容页模板<a href=#>"
			Case 12
				Response.Write "下载帮助信息<a href=#>"
			Case Else
				Response.Write "当前分页模板<a href=#>"
		End Select
		If i > 12 Then
			Response.Write "</a>&nbsp;&nbsp;temp_"
			Response.Write "<input type=text size=15 name=newpagename value=" & Replace(Rs(i).Name, "temp_", "") & ">&nbsp;&nbsp;"
			Response.Write "<input type=hidden size=15 name=oldpagename value=" & Replace(Rs(i).Name, "temp_", "") & ">"
			Response.Write "<input type=submit value=""分模板页面改名"" name=""mo"" title=""修改名称后提交"" class=button>"
		Else
			Response.Write "(" & Rs(i).Name & ")</a>&nbsp;&nbsp;"
		End If
		Response.Write "</td>"
		Response.Write "<td height=""25"" align=""left"">"
		If i > 3 Then
			Response.Write "编辑该模块："
			Response.Write " <a href=""?action=edit&stype=1&page="
			Response.Write Rs(i).Name
			Response.Write "&StyleID="
			Response.Write StyleID
			Response.Write """>模板基本设置</a> "
			Response.Write " | <a href=""?action=edit&stype=2&page="
			Response.Write Rs(i).Name
			Response.Write "&StyleID="
			Response.Write StyleID
			Response.Write """>模板界面风格</a>"
			ElseIf i = 3 Then
			Response.Write "编辑该模块："
			Response.Write "<a href=""?action=editcss&StyleID=" & StyleID & """>修改CSS样式</a>"
		End If
		If i > 12 Then
			Response.Write "&nbsp;&nbsp;<a href=""?action=delpage&StylePageName=" & Rs(i).Name & """ title=""注意，删除后不可恢复""> 删除分模板页面 </a>"
		End If
		Response.Write "</td>"
		Response.Write "</tr>"
		If i > 8 Then
			Response.Write "</form>"
		End If
	Next
	Response.Write "</table><p></p>"
	Response.Write "<table width=""100%"" border=""0"" cellspacing=""1"" cellpadding=""3"" align=center class=""tableBorder"">"
	Response.Write "<tr>"
	Response.Write "<th width=""100%"" class=""tableHeaderText"" colspan=2 height=25>模板管理"
	Response.Write "</th>"
	Response.Write "</tr>"
	Response.Write "<tr>"
	Response.Write "<FORM METHOD=POST ACTION=""?action=addstyle"">"
	Response.Write "<td class=""forumRowHighlight"" height=40 align=left width=45% >"
	Response.Write "新建模板：&nbsp;"
	Response.Write "<input type=text size=25 name=""TempName"">&nbsp;&nbsp;"
	Response.Write "<input type=submit value=""添 加"" name=""mostyle"" class=button>&nbsp;&nbsp;填写模板名"
	Response.Write "<br><b>说明：</b>新建模板将把当前默认模版数据复制到新的模板中"
	Response.Write "</td>"
	Response.Write "</FORM>"
	Response.Write "</tr>"
	Response.Write "<tr>"
	Response.Write "<FORM METHOD=POST ACTION=""?action=rename"">"
	Response.Write "<td class=""forumRowHighlight"" height=25 align=left>"
	Response.Write "<select name=""StyleID"" size=1>"
	For i = 0 To UBound(Templateslist)
		Response.Write "<option value=""" & Templateslist(i)(0) & """"
		If CLng(Templateslist(i)(0)) = CLng(StyleID) Then
			Response.Write " selected"
		End If
		Response.Write ">" & Templateslist(i)(1) & "</option>"
	Next
	Response.Write "</select>"
	Response.Write "&nbsp;&nbsp;"
	Response.Write "改名为：<input type=text size=20 name=""TempName"" value="""
	Response.Write """>&nbsp;&nbsp;"
	Response.Write "<input type=submit name=submit value=""修 改"" class=button>"
	Response.Write "</td>"
	Response.Write "</FORM>"
	Response.Write "</tr>"
	Response.Write "</table>"
	Rs.Close
	Set Rs = Nothing
End Sub

Private Sub Edit()
	Dim page
	Dim mystr
	Dim MyRemark
	Dim TempStr
	Dim TemplateStr
	Dim stype
	Dim TempStyleHelp
	Dim StyleHelpValue
	Dim vtitle
	Dim vSorting
	Dim vSoftInfo
	Dim SetHelpStr
	Dim StyleHelpStr
	stype = DownsysClass.checkStr(Request("stype"))
	page = DownsysClass.checkStr(Request("page"))
	If Not IsNumeric(stype) Then
		ErrMsg = ErrMsg + "<BR><li>错误的样式参数"
		FoundErr = True
	End If
	If Not IsTruePage(page) Then
		ErrMsg = ErrMsg + "<BR><li>要编辑的页面模板字段尚未建立。"
		FoundErr = True
	End If
	Select Case page
		Case "main_style"
			SetHelpStr = SetHelp_Main
			StyleHelpStr = StyleHelp_Main
		Case "temp_index"
			SetHelpStr = SetHelp_index
			StyleHelpStr = StyleHelp_index
		Case "temp_sorting"
			SetHelpStr = SetHelp_sorting
			StyleHelpStr = StyleHelp_sorting
		Case "temp_softinfo"
			SetHelpStr = SetHelp_softinfo
			StyleHelpStr = StyleHelp_softinfo
		Case "temp_search"
			SetHelpStr = SetHelp_search
			StyleHelpStr = StyleHelp_search
		Case "temp_infoindex"
			SetHelpStr = SetHelp_infoindex
			StyleHelpStr = StyleHelp_infoindex
		Case "temp_listing"
			SetHelpStr = SetHelp_listing
			StyleHelpStr = StyleHelp_listing
		Case "temp_article"
			SetHelpStr = SetHelp_article
			StyleHelpStr = StyleHelp_article
		Case "temp_help"
			SetHelpStr = SetHelp_help
			StyleHelpStr = StyleHelp_help
		Case Else
			SetHelpStr = ""
			StyleHelpStr = ""
	End Select
	Set Rs = DownsysClass.Execute("Select ID,TempName," & page & " From [NC_Template] Where ID=" & StyleID)
	TempStr = Split(Rs(2), "@@@")
	Select Case stype
		Case 1
			TemplateStr = Split(TempStr(1), "|||")
			TempStyleHelp=Split(SetHelpStr,"|||")
		Case 2
			TemplateStr = Split(TempStr(0), "|||")
			TempStyleHelp=Split(StyleHelpStr,"|||")
	End Select
	Response.Write "<form name=""template"" action=""?action=saveedit&page=" & page & "&stype=" & stype & "&StyleID=" & StyleID & """ method=post>"
	Response.Write "<table width=""100%"" border=""0"" cellspacing=""1"" cellpadding=""3"" align=center class=""tableBorder"">"
	Response.Write "<tr>"
	Response.Write "<th width=""100%"" class=""tableHeaderText"" colspan=3 height=25>"
	Response.Write Rs(1)
	Select Case page
		Case "main_style"
			Response.Write "｜模板主模块("
		Case "temp_index"
			Response.Write "｜首页模板("
		Case "temp_sorting"
			Response.Write "｜软件列表页模板("
		Case "temp_softinfo"
			Response.Write "｜软件信息页模板("
		Case "temp_search"
			Response.Write "｜搜索页模板("
		Case "temp_infoindex"
			Response.Write "｜文章首页模板("
		Case "temp_listing"
			Response.Write "｜文章列表页模板("
		Case "temp_article"
			Response.Write "｜文章内容页模板("
		Case Else
			Response.Write "｜分页面模板("
	End Select
	Response.Write page
	Response.Write ")"
	Response.Write "<input Type=""hidden"" name=""DownsysClass"" value=""OK!"">"
	Select Case stype
		Case 1
			Response.Write "基本设置"
			mystr = "DownsysClass.TempSet"
			MyRemark = ""
			If page = "main_style" Then mystr = "DownsysClass.mainset"
			 MyRemark = ""
		Case 2
			Response.Write "界面风格"
			mystr = "DownsysClass.TempHtml"
			If page = "main_style" Then mystr = "DownsysClass.mainhtml"
			MyRemark = ""
	End Select
	Response.Write "管理</th></tr>"
	If TemplateStr(UBound(TemplateStr)) = "" Then TemplateStr(UBound(TemplateStr)) = "del"
	For i = 0 To UBound(TemplateStr)
		If i<ubound(TempStyleHelp) Then
			StyleHelpValue=TempStyleHelp(i)
		Else
			StyleHelpValue="//"
		End IF
		Response.Write "<tr><td class=""forumRowHighlight"" width=20% height=22 align=left>"
		Response.Write mystr & "(" & i & ")"
		Response.Write "</td>"
		Response.Write "<td class=""forumRowHighlight"" width=80% height=22 align=left>"
		Select Case stype
			Case 1
				vtitle = "表格的宽度|导航栏每行显示软件分类数|导航栏每行显示文章分类数|||||||||||软件排行显示的数|软件排行名称长度|软件名称循环|文章排行数|文章标题长度|文章标题循环|首页最新和推荐文章数|标题长度|文章标题循环|首页最新和推荐软件数|软件名称长度|软件名称循环|显示公告数|公告字符长度|公告循环|总分类每行显示数|最近更新页显示软件数|推荐下载页最多显示软件数|每页显示数|简介长度|最多显示热门软件数|每页显示热门软件数|||||||||||||||||||"
				vSorting = "软件列表每页显示数|||||||软件简介字符长度"
				vSoftInfo = "|||||软件下载页显示评论数|显示字符长度|发表评论最多字符|相关软件与文章显示数|标题长度|相关软件循环|相关文章循环||||"
				vtitle = Split(vtitle, "|")
				vSorting = Split(vSorting, "|")
				vSoftInfo = Split(vSoftInfo, "|")
				If page = "main_style" And i < 3 Then
					Response.Write "<input type=text name=""TemplateStr"" value="""
					Response.Write Server.HTMLEncode(TemplateStr(i))
					Response.Write """ size=10> " & vtitle(i) & ""
					ElseIf LenB(TemplateStr(i)) > 70 Then
					Response.Write "<textarea name=""TemplateStr"" id=""t" & i & """  cols=""100"" rows=""3"">"
					Response.Write Server.HTMLEncode(TemplateStr(i))
					Response.Write "</textarea>"
				Else
					Response.Write "<input Type=""text"" name=""TemplateStr"" id=""t" & i & """ value="""
					Response.Write Server.HTMLEncode(TemplateStr(i))
					Response.Write """ size=50> "
					If page = "main_style" Then Response.Write vtitle(i)
					If page = "temp_sorting" And i < 8 Then Response.Write vSorting(i)
					If page = "temp_softinfo" And i < 12 Then Response.Write vSoftInfo(i)
				End If
				Response.Write "<INPUT TYPE=""hidden"" NAME=""ReadME"" id=""r" & i & """ value=""" & StyleHelpValue & """>"
				Response.Write " <a href=# onclick=""helpscript(r"&i&");return false;"" class=""helplink""><img src=""images/help.gif"" border=0 title=""点击查阅管理帮助！""></a>"
			Case 2
				Response.Write "<textarea name=""TemplateStr"" id=""t" & i & """ cols=""100"" rows=""5"">"
				Response.Write Server.HTMLEncode(TemplateStr(i))
				Response.Write "</textarea>"
				Response.Write "</td></tr><tr><td class=""forumRowHighlight""></td><td class=""forumRowHighlight""><a href=""javascript:admin_Size(-5,'t" & i & "')""><img src=""images/minus.gif"" unselectable=""on"" border='0'></a> <a href=""javascript:admin_Size(5,'t" & i & "')""><img src=""images/plus.gif"" unselectable=""on"" border='0'></a>"
				Response.Write "<img src=images/viewpic.gif onclick=runscript(t" & i & ")>"
				Response.Write "<INPUT TYPE=""hidden"" NAME=""ReadME"" id=""r" & i & """ value=""" & StyleHelpValue & """>"
				Response.Write "<a href=# onclick=""helpscript(r" & i & ");return false;"" class=""helplink""><img src=""images/help.gif"" border=0 title=""点击查阅管理帮助！""></a>"
		End Select
		Response.Write "</td></tr>"
	Next
	Response.Write "<tr><td class=""forumRowHighlight"" height=""25"" align=""center"" colspan=""3"">"
	Response.Write "" & MyRemark & "</td></tr>"
	Response.Write "<tr><td class=""forumRowHighlight"" height=""25"" align=""center"">"
	Response.Write "<input type=""reset"" name=""Submit"" value=""重 填"" class=button>"
	Response.Write "</td>"
	Response.Write "<td class=""forumRowHighlight"" height=""25"" colspan=2 align=""center"">"
	Response.Write "<input type=""button"" name=""Submit1"" onclick=""javascript:location.href='admin_template.asp'"" value=""返回上一页"" class=button>　　<input type=""submit"" name=""B1"" value=""保存模板"" class=button>"
	Response.Write "</td></tr>"
	Response.Write "<tr>"
	Response.Write "<td colspan=3 Class=""forumRowHighlight"">"
	Response.Write "<br><li>模板编辑规则：如果想清除该字段，请在对应的文本框中输入""del""，那么模板数据的序号就会前移。"
	Response.Write "<br><li>如果不想改变模板数据的序号,仅把该项目的数据清空,则只需要把内容清空。"
	Response.Write "</td></tr>"
	Response.Write "</table>"
	Response.Write "</form>"
	Rs.Close
	Set Rs = Nothing
End Sub

Private Sub EditCSS()
	Set Rs = Server.CreateObject("Adodb.Recordset")
	SQL = "select * from NC_Template where id=" & Request("styleid")
	Rs.Open SQL, conn, 1, 1
	DownsysClass.SqlQueryNum = DownsysClass.SqlQueryNum + 1
	If Rs.bof And Rs.EOF Then
		FoundErr = True
		ErrMsg = ErrMsg + "<br><li>数据库出现错误,没有此配色样式!</li>"
		Rs.Close
		Set Rs = Nothing
		Exit Sub
	End If
	Response.Write "<p></p>"
	Response.Write "<table width=""100%"" align=""center"" border=""0"" cellpadding=""2"" cellspacing=""1"" class=""tableBorder"">" & vbCrLf
	Response.Write "<form method=""POST"" name=""myform"" action=""admin_template.asp?action=savecss&id=" & Request("styleid") & """>" & vbCrLf
	Response.Write "    <tr> " & vbCrLf
	Response.Write "      <th colspan=""2"" >" & vbCrLf
	Response.Write "当前编辑样式[" & Rs("TempName") & "]（修改以下设置必须具备一定网页知识）" & vbCrLf
	Response.Write "</th>" & vbCrLf
	Response.Write "    </tr>" & vbCrLf
	Response.Write "    <tr> " & vbCrLf
	Response.Write "      <td width=""22%"" height=""22"" class=""forumRowHighlight"">模板样式目录名称：</td>" & vbCrLf
	Response.Write "      <td width=""78%"" class=""forumRow""><input name=""TempDir"" type=""text"" value=""" & Rs("TempDir") & """ size=""22"" class=""kuang""> * 注意：请在目录名后面加上“/”</td>" & vbCrLf
	Response.Write "    </tr>" & vbCrLf
	Response.Write "    <tr> " & vbCrLf
	Response.Write "      <td height=""22"" class=""forumRowHighlight"">样式名称：</td>" & vbCrLf
	Response.Write "      <td class=""forumRow""><input name=""TempName"" type=""text"" value=""" & Rs("TempName") & """ size=""22"" maxlength=""15"" class=""kuang""></td>" & vbCrLf
	Response.Write "    </tr>" & vbCrLf
	Response.Write "    <tr> " & vbCrLf
	Response.Write "      <td height=""22"" colspan=""2"" class=""forumRowHighlight""><div align=""center"">定义CSS样式表</div></td>" & vbCrLf
	Response.Write "    </tr>" & vbCrLf
	Response.Write "    <tr> " & vbCrLf
	Response.Write "      <td colspan=""2"" class=""forumRow""><textarea name=""Style_CSS"" style=""width:100%; height:400;"" rows=""5"" class=""tableBorder"">" & Rs("Style_CSS") & "</textarea> " & vbCrLf
	Response.Write "      </td>" & vbCrLf
	Response.Write "    </tr>" & vbCrLf
	Response.Write "    <tr>" & vbCrLf
	Response.Write "      <td height=""22"" class=""forumRowHighlight"">&nbsp;</td>" & vbCrLf
	Response.Write "      <td class=""forumRow""><input type=""button"" name=""Submit1"" onclick=""javascript:history.go(-1)"" value=""返回上一页"" class=button>　　" & vbCrLf
	Response.Write "<input type=""submit"" name=""Submit2"" value="" 保存修改 "" class=button>" & vbCrLf
	Response.Write "</td>" & vbCrLf
	Response.Write "    </tr></form>" & vbCrLf
	Response.Write "  </table>" & vbCrLf
	Response.Write "" & vbCrLf
	Rs.Close
	 Set Rs = Nothing
End Sub

Private Sub CheckSkin()
	Dim FoundErr
	FoundErr = False
	If Trim(Request.Form("TempName")) = "" Then
		FoundErr = True
		ErrMsg = ErrMsg + "<BR><li>你没有输入CSS样式名称。</li>"
	End If
	FoundErr = False
	If Trim(Request.Form("TempDir")) = "" Then
		FoundErr = True
		ErrMsg = ErrMsg + "<BR><li>你没有输入CSS样式路径。</li>"
	End If
End Sub

Private Sub SaveCSS()
	Dim strTempDir
	Call CheckSkin
	If Right(Request.Form("TempDir"), 1) <> "/" Then
		strTempDir = Request.Form("TempDir") & "/"
	Else
		strTempDir = Request.Form("TempDir")
	End If
	If FoundErr = False Then
		Set Rs = CreateObject("adodb.recordset")
		SQL = "select * from NC_Template where id=" & Request("id")
		Rs.Open SQL, conn, 1, 3
		If Rs.bof And Rs.EOF Then
			FoundErr = True
			NC_Admin.Error_Msg ("没有选定参数!")
			Err.Raise -19691969
		Else
			Rs("TempDir") = strTempDir
			Rs("TempName") = Request.Form("TempName")
			Rs("Style_CSS") = Request.Form("Style_CSS")
			Rs.Update
			id = Rs("id")
			DownsysClass.DelCahe ("Style_CSS" & id)
			Call DvaspCss(id)
			Call NC_Admin.Succeed_Msg("保存配色CSS样式设置成功!")
		End If
		Rs.Close
		Set Rs = Nothing
	End If
End Sub

Private Sub DvaspCss(id)
	Dim RsSkin
	Dim sqlSkin
	Dim MakeFile
	Dim TempDir
	Set RsSkin = CreateObject("Adodb.Recordset")
	sqlSkin = "select * from NC_Template where id=" & id
	RsSkin.Open sqlSkin, conn, 1, 1
	strbody = RsSkin("Style_CSS")
	strbody = Replace(strbody, "{$SetupDir}", DownsysClass.SetupDir)
	strbody = Replace(strbody, "{$PicUrl}", RsSkin("TempDir"))
	TempDir = DownsysClass.SetupDir & RsSkin("TempDir")
	RsSkin.Close
	Set RsSkin = Nothing
	If Not DownsysClass.IsObjectFSO(DownsysClass.Script_FSO) Then
		Response.Write "<b><font color=red>你的服务器不支持 FSO(Scripting.FileSystemObject)! style.css文件没有更新</font></b>"
	Else
		Set fso = Server.CreateObject(DownsysClass.Script_FSO)
		If fso.FolderExists(Server.MapPath(TempDir)) = False Then
			fso.CreateFolder Server.MapPath(TempDir)
		End If
		Makename = TempDir & "style.css"
		MakeFile = Server.MapPath(Makename)
		Set fout = fso.CreateTextFile(MakeFile)
		fout.WriteLine strbody
		fout.Close
		Set fout = Nothing
	End If
End Sub

Private Sub addpage()
	Dim StylePageName
	StylePageName = DownsysClass.checkStr(Request("StylePageName"))
	If StylePageName = "" Then
		ErrMsg = ErrMsg + "<BR><li>请填写字段名称"
		FoundErr = True
		Exit Sub
	End If
	StylePageName = "temp_" & StylePageName
	If IsTruePage(StylePageName) Then
		ErrMsg = ErrMsg + "<BR><li>您要创建的模板字段已经存在。"
		FoundErr = True
		Exit Sub
	End If
	DownsysClass.Execute ("alter table [NC_Template] add " & StylePageName & " text not Null default'|||@@@|||@@@|||@@@|||'")
	DownsysClass.Execute ("Update [NC_Template] Set " & StylePageName & "='|||@@@|||@@@|||@@@|||'")
	NC_Admin.Succeed_Msg ("新页面模板创建成功!")
End Sub

Private Sub delpage()
	Dim StylePageName
	Dim Fieldslist
	StylePageName = DownsysClass.checkStr(Request("StylePageName"))
	If StylePageName = "" Then
		ErrMsg = ErrMsg + "<BR><li>请填写字段名称"
		FoundErr = True
		Exit Sub
	End If
	If Not IsTruePage(StylePageName) Then
		ErrMsg = ErrMsg + "<BR><li>要删除的字段不存在。"
		FoundErr = True
		Exit Sub
	End If
	If DownsysClass.IsSqlDataBase = 1 Then
		Set Rs = DownsysClass.Execute("select * from NC_Template")
		Fieldslist = "id"
		For i = 1 To Rs.Fields.Count - 1
			If LCase(Rs(i).Name) <> LCase(StylePageName) Then
				Fieldslist = Fieldslist & "," & Rs(i).Name
			End If
		Next
		Set Rs = Nothing
		'复制有用数据到临时表

		DownsysClass.Execute ("Select " & Fieldslist & " into NC_TempTable From NC_Template")
		'删除原有表

		DownsysClass.Execute ("Drop table NC_Template")
		'再把临时表中的数据复制过来.

		DownsysClass.Execute ("Select " & Fieldslist & " into NC_Template From NC_TempTable ")
		'删除临时表

		DownsysClass.Execute ("Drop table NC_TempTable")
		'再把临时表中的数据复制过来.

		DownsysClass.Execute ("Select " & Fieldslist & " into NC_Templatehelp From NC_TempTable ")
		'删除临时表

		DownsysClass.Execute ("Drop table NC_TempTable")
	Else
		DownsysClass.Execute ("Alter Table [NC_Template] Drop [" & StylePageName & "]")
	End If
	NC_Admin.Succeed_Msg ("页面模板删除成功！")
End Sub

Private Sub temprename()
	Dim oldpagename
	Dim newpagename
	Dim i
	Dim Fieldslist
	Dim Rs
	oldpagename = DownsysClass.checkStr(Request("oldpagename"))
	newpagename = DownsysClass.checkStr(Request("newpagename"))
	If LCase(newpagename) = LCase(oldpagename) Then
		ErrMsg = ErrMsg + "<BR><li>你没有更改名称"
		FoundErr = True
		Exit Sub
	End If
	If newpagename = "" Then
		ErrMsg = ErrMsg + "<BR><li>新名称不能为空"
		FoundErr = True
		Exit Sub
	End If
	If oldpagename = "" Then
		ErrMsg = ErrMsg + "<BR><li>您提交的数据是错误的."
		FoundErr = True
		Exit Sub
	End If
	oldpagename = "temp_" & oldpagename
	newpagename = "temp_" & newpagename
	If Not IsTruePage(oldpagename) Then
		ErrMsg = ErrMsg + "<BR><li>要改名的字段不存在。"
		FoundErr = True
		Exit Sub
	End If
	If IsTruePage(newpagename) Then
		ErrMsg = ErrMsg + "<BR><li>字段名称" & newpagename & "已经被占用."
		FoundErr = True
		Exit Sub
	End If
	Set Rs = DownsysClass.Execute("select * from NC_Template")
	Fieldslist = "id"
	For i = 1 To Rs.Fields.Count - 1
		If LCase(Rs(i).Name) <> LCase(oldpagename) Then
			Fieldslist = Fieldslist & "," & Rs(i).Name
		Else
			Fieldslist = Fieldslist & "," & Rs(i).Name & " as " & newpagename
		End If
	Next
	Set Rs = Nothing
	'复制有用数据到临时表
	DownsysClass.Execute ("Select " & Fieldslist & " into NC_TempTable From NC_Template")
	'删除原有表
	DownsysClass.Execute ("Drop table NC_Template")
	'再把临时表中的数据复制过来.
	DownsysClass.Execute ("Select * into NC_Template From NC_TempTable ")
	'删除临时表
	DownsysClass.Execute ("Drop table NC_TempTable")
	NC_Admin.Succeed_Msg ("成功把 " & oldpagename & " 字段改名为 " & newpagename & "")
End Sub


Private Sub DelStyle()
	'检查是否有版面使用本模版
	If StyleID = SkinID Then
		ErrMsg = ErrMsg + "<BR><li>本模板是默认模版，不允许删除。"
		FoundErr = True
		Exit Sub
	Else
		DownsysClass.Execute ("Delete From [NC_Template] Where id=" & StyleID & "")
		NC_Admin.Succeed_Msg ("成功删除了一个模板。")
		DownsysClass.DelCahe ("Templateslist") '删除模板列表缓存
		DownsysClass.DelCahe ("SortingMenu" & StyleID)
		DownsysClass.DelCahe ("ClassMenu" & StyleID)
		DownsysClass.DelCahe ("SortingList" & StyleID)
		DownsysClass.DelCahe ("ClassList" & StyleID)
	End If
End Sub

Private Function IsTruePage(page)
	Dim myrs
	IsTruePage = False
	If page <> "" Then
		page = LCase(Trim(page))
		Set myrs = DownsysClass.Execute("Select top 1 * From [NC_Template]")
		For i = 2 To myrs.Fields.Count - 1
			If LCase(myrs(i).Name) = page Then
				IsTruePage = True
				Exit For
			End If
		Next
	End If
End Function

Private Sub SaveEdit()
	Dim page
	Dim TempStr
	Dim TemplateStr
	Dim stype
	If Request("DownsysClass") <> "OK!" Then
		ErrMsg = ErrMsg + "<BR><li>您提交了非法数据"
		FoundErr = True
		Exit Sub
	End If
	stype = DownsysClass.checkStr(Request("stype"))
	page = DownsysClass.checkStr(Request("page"))
	If Not IsNumeric(stype) Then
		ErrMsg = ErrMsg + "<BR><li>错误的样式参数"
		FoundErr = True
		Exit Sub
	End If
	If Not IsTruePage(page) Then
		ErrMsg = ErrMsg + "<BR><li>要编辑的页面模板字段尚未建立。"
		FoundErr = True
		Exit Sub
	End If
	'提取表单中的数据
	TemplateStr = ""
	For Each TempStr In Request.Form("TemplateStr")
		If LCase(TempStr) <> "del" Then
			TemplateStr = TemplateStr & Replace(TempStr, "|||", "") & "|||"
		End If
	Next
	TemplateStr = DownsysClass.checkStr(Replace(TemplateStr, "@@@", ""))
	If Trim(TemplateStr) = "" Then
		TemplateStr = "|||"
	End If
	Set Rs = DownsysClass.Execute("Select ID,TempName," & page & " From [NC_Template] Where ID=" & StyleID)
	TempStr = Split(DownsysClass.checkStr(Rs(2)), "@@@")
	Select Case stype
		Case 1
			TemplateStr = TempStr(0) & "@@@" & TemplateStr & "@@@" & TempStr(2)
		Case 2
			TemplateStr = TemplateStr & "@@@" & TempStr(1) & "@@@" & TempStr(2)
	End Select
	Rs.Close
	 Set Rs = Nothing
	DownsysClass.Execute ("update [NC_Template] set " & page & "='" & TemplateStr & "' Where ID=" & StyleID)
	Select Case stype
		Case 1
			NC_Admin.Succeed_Msg (page & "基本设置修改成功!")
		Case 2
			NC_Admin.Succeed_Msg (page & "界面风格修改成功!")
	End Select
	'更新缓存。此处是在模板数据变化的时候需要更新的代码。如有漏掉，可以在这添加。

	DownsysClass.DelCahe (page & StyleID)
	DownsysClass.DelCahe ("SortingMenu" & StyleID)
	DownsysClass.DelCahe ("ClassMenu" & StyleID)
	DownsysClass.DelCahe ("SortingList" & StyleID)
	DownsysClass.DelCahe ("ClassList" & StyleID)
	If InStr(LCase(page), "main_style") > 0 Then
		DownsysClass.DelCahe ("head_" & StyleID)
		DownsysClass.DelCahe ("GroupTitle")
		DownsysClass.DelCahe ("ForumPlusMenu" & StyleID)
	End If
End Sub

Private Sub rename()
	Dim TempName
	TempName = DownsysClass.checkStr(Request("TempName"))
	If Trim(TempName) = "" Then
		ErrMsg = ErrMsg + "<BR><li>修改名称请输入新的模板名称。"
		FoundErr = True
		Exit Sub
	End If
	DownsysClass.Execute ("update [NC_Template] set TempName='" & TempName & "' where id=" & StyleID & "")
	DownsysClass.DelCahe ("Templateslist") '删除模板列表缓存
	NC_Admin.Succeed_Msg ("模板名修改成功!")
End Sub

Private Sub addstyle()
	Dim TempName
	Dim SQL
	Dim styleFields
	Dim stylevalues
	TempName = DownsysClass.checkStr(Request("TempName"))
	If Trim(TempName) = "" Then
		ErrMsg = ErrMsg + "<BR><li>请输入模板名称。"
		FoundErr = True
		Exit Sub
	End If
	Set Rs = DownsysClass.Execute("select * From [NC_Template] where ID=" & StyleID & "")
	styleFields = "TempName"
	stylevalues = "'" & TempName & "'"
	For i = 2 To Rs.Fields.Count - 1
		styleFields = styleFields & "," & Rs(i).Name
		stylevalues = stylevalues & ",'" & DownsysClass.checkStr(Rs(i)) & "'"
	Next
	Set Rs = Nothing
	SQL = "insert into [NC_Template](" & styleFields & ")values(" & stylevalues & ")"
	DownsysClass.Execute (SQL)
	NC_Admin.Succeed_Msg ("新模板创建成功!")
	DownsysClass.DelCahe ("Templateslist") '删除模板列表缓存
End Sub
%>
