<!--#include file="const.asp"-->
<!--#include file="../inc/common.asp"-->
<%
Admin_header
'=====================================================================
' 软件名称：新云网站管理系统
' 当前版本：NewAsp Content Management System Version 4.0
' 文件名称：admin_jscript.asp
' 更新日期：2008-09-16
' 官方网站：新云网络(www.NewAsp.net www.NewAsp.cn) QQ：94022511
'=====================================================================
' Copyright 2003-2008 NewAsp.net - All Rights Reserved.
' newasp is a trademark of NewAsp.net
'=====================================================================
%>
<table class="table1" cellspacing="1" cellpadding="3" align="center" border="0">
	<tr>
		<td class="tableline linetitle" width="100" align="left" noWrap="noWrap"><%=NewAsp.ModuleName%>JS文件管理</td>
		<td class="tableline" width="*" align="right"><a href="admin_index.asp?ChannelID=<%=ChannelID%>">管理首页</a>
			 - <a href="?ChannelID=<%=ChannelID%>">JS文件管理</a>
			 - <a href="?action=add&ChannelID=<%=ChannelID%>">添加JS文件</a>
			 - <a href="admin_list.asp?ChannelID=<%=ChannelID%>"><%=NewAsp.ModuleName%>管理</a>
			 - <a href="admin_comment.asp?ChannelID=<%=ChannelID%>">评论管理</a>
			 - <a href="../sys/admin_channel.asp?action=edit&ChannelID=<%=ChannelID%>">频道管理</a>
			 - <a href="admin_makehtml.asp?ChannelID=<%=ChannelID%>">生成HTLM</a>
			 - <a href="../sys/admin_template.asp?ChannelID=<%=ChannelID%>">模板管理</a>
		</td>
	</tr>
</table>
<%
If Not ChkAdmin("JsScript_"&ChannelID) Then
	Call Transfer_error()
End If

Dim Action
Action=LCase(Request("action"))
Select Case Trim(Action)
Case "del"
	Call deleteJsFile()
Case "add"
	Call addJsFile()
Case "edit"
	Call editJsFile()
Case "savenew"
	Call saveNewJsFile()
Case "save"
	Call saveJsFile()
Case "make"
	Call makeJsFile()
Case "demo"
	Call demoJsFile()
Case Else
	Call showmain()
End Select
If FoundErr=True Then
	ReturnError(ErrMsg)
End If
Admin_footer
SaveLogInfo(AdminName)
NewAsp.PageEnd

Sub showmain()
	Dim Rs,i,iCount,lCount
	Dim strJSFileName
	iCount=2:lCount=2:i=0
%>
<form name="selform" method="post" action="?ChannelID=<%=ChannelID%>">
<input type="hidden" name="action" value="make">
<table id="tablehovered" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
<tr>
	<th width="20%">标题说明</th>
	<th width="40%">调用方式</th>
	<th width="15%">JS文件名称</th>
	<th width="25%">管理选项</th>
</tr>
<%
	Set Rs=NewAsp.Execute("SELECT id,ChannelID,sTitle,stype,sFileName FROM NC_ScriptFile WHERE ChannelID="& ChannelID &" ORDER BY id DESC")
	Do While Not Rs.EOF
		If (i mod 2) = 0 Then iCount=2:lCount=1 Else iCount=1:lCount=2
		strJSFileName="<script src="""& NewAsp.ChannelUrl &"js/"& Rs("sFileName") &"""></script>"
%>
<tr align="center">
	<td class="tablerow<%=iCount%> hovered"><input type="hidden" name=id value="<%=Rs("id")%>"><%=Server.HTMLEncode(Rs("sTitle"))%></td>
	<td class="tablerow<%=iCount%> hovered"><input type="text" name="jsfile" size="50" value="<%=Server.HTMLEncode(strJSFileName)%>"></td>
	<td class="tablerow<%=iCount%> hovered" noWrap><%=Rs("sFileName")%></td>
	<td class="tablerow<%=iCount%> hovered" noWrap><a href="?action=edit&ChannelID=<%=ChannelID%>&id=<%=Rs("id")%>">设 置</a> | 
	<a href="?action=del&ChannelID=<%=ChannelID%>&id=<%=Rs("id")%>" onclick="return confirm('您确定要删除此JS文件吗?')">删 除</a> | 
	<a href="?action=make&ChannelID=<%=ChannelID%>&id=<%=Rs("id")%>">生 成</a> | 
	<a href="?action=demo&ChannelID=<%=ChannelID%>&id=<%=Rs("id")%>">演 示</a>
	</td>
</tr>
<%
		Rs.movenext
		i=i+1
	Loop
	Rs.Close:Set Rs = Nothing
%>
<tr>
	<td class="tablerow<%=lCount%>" colspan="4" align="center">
		<input type="submit" name="submit_button1" value=" 生成所有JS文件 " class="button">&nbsp;&nbsp;
		<input type="button" name="submit_button2" value=" 添加新的JS文件 " onclick="window.location.href='?action=add&ChannelID=<%=ChannelID%>';" class="button">
	</td>
</tr>
<tr>
	<td class="tablerow<%=iCount%>" colspan="4">
		<b>说明：</b><br/>&nbsp;&nbsp;&nbsp;&nbsp;请将上面的JS调用代码复制到模板相应的位置；
		由于JS文件是系统生成的静态文件，所以要不定期的生成所有JS文件。
	</td>
</tr>
</table>
</form>
<%
End Sub

Sub addJsFile()
%>
<form name="myform" method="post" action="?ChannelID=<%=ChannelID%>">
<input type="hidden" name="action" value="savenew">
<table border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
<tr>
	<th colspan="2">添加新的JS文件</th>
</tr>
<tr>
	<td class="tablerow1" align="right" width="25%"><b>JS文件说明</b></td>
	<td class="tablerow1" width="75%"><input type="text" name="sTitle" size="50" value=""></td>
</tr>
<tr>
	<td class="tablerow2" align="right"><b>JS文件名</b></td>
	<td class="tablerow2"><input type="text" name="sFileName" size="25" value="new.js"></td>
</tr>
<tr>
	<td class="tablerow1" align="right"><b>文件类型</b></td>
	<td class="tablerow1">
		<input type="radio" name="stype" value="0" checked/> JS脚本代码&nbsp;
		<input type="radio" name="stype" value="1" /> HTML代码
	</td>
</tr>
<tr>
	<td class="tablerow2" align="right"><b>相关标签内容</b></td>
	<td class="tablerow2"><textarea name="sContent" rows="10" cols="80"></textarea><br/>
	<a href="javascript:admin_Size(-10,'sContent')"><img src="../images/minus.gif" unselectable="on" border="0"></a>
	<a href="javascript:admin_Size(10,'sContent')"><img src="../images/plus.gif" unselectable="on" border="0"></a>
	</td>
</tr>
<tr>
	<td class="tablerow1" colspan="2" align="center">
		<input type="button" name="go_button" onclick="javascript:history.go(-1)" value="返回上一页" class="button">&nbsp;&nbsp;
		<input type="submit" name="submit_button1" value=" 保存设置 " class="button">
	</td>
</tr>
</table>
</form>
<%
End Sub

Sub editJsFile()
	Dim Rs
	Set Rs = NewAsp.Execute("SELECT id,sTitle,stype,sFileName,setting,sContent FROM NC_ScriptFile WHERE ChannelID = "& ChannelID &" And id ="& CLng(Request("id")))
	If Rs.BOF And Rs.EOF Then
		FoundErr = True
		ErrMsg = ErrMsg + "<li>错误的系统参数！</li>"
		Set Rs = Nothing
		Exit Sub
	End If
%>
<form name="myform" method="post" action="?ChannelID=<%=ChannelID%>">
<input type="hidden" name="action" value="save">
<input type="hidden" name="id" value="<%=Rs("id")%>">
<table border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
<tr>
	<th colspan="2">编辑JS文件</th>
</tr>
<tr>
	<td class="tablerow1" align="right" width="25%"><b>JS文件说明</b></td>
	<td class="tablerow1" width="75%"><input type="text" name="sTitle" size="50" value="<%=Server.HTMLEncode(Rs("sTitle"))%>"></td>
</tr>
<tr>
	<td class="tablerow2" align="right"><b>JS文件名</b></td>
	<td class="tablerow2"><input type="text" name="sFileName" size="25" value="<%=Server.HTMLEncode(Rs("sFileName"))%>"></td>
</tr>
<tr>
	<td class="tablerow1" align="right"><b>文件类型</b></td>
	<td class="tablerow1">
		<input type="radio" name="stype" value="0"<%If Rs("stype")=0 Then Response.Write " checked"%>/> JS脚本代码&nbsp;
		<input type="radio" name="stype" value="1"<%If Rs("stype")=1 Then Response.Write " checked"%> /> HTML代码
	</td>
</tr>
<tr>
	<td class="tablerow2" align="right"><b>相关标签内容</b></td>
	<td class="tablerow2"><textarea name="sContent" rows="10" cols="80"><%=Server.HTMLEncode(Rs("sContent")&"")%></textarea><br/>
	<a href="javascript:admin_Size(-10,'sContent')"><img src="../images/minus.gif" unselectable="on" border="0"></a>
	<a href="javascript:admin_Size(10,'sContent')"><img src="../images/plus.gif" unselectable="on" border="0"></a>
	</td>
</tr>
<tr>
	<td class="tablerow1" colspan="2" align="center">
		<input type="button" name="go_button" onclick="javascript:history.go(-1)" value="返回上一页" class="button">&nbsp;&nbsp;
		<input type="submit" name="submit_button1" value=" 保存设置 " class="button">
	</td>
</tr>
</table>
</form>
<%
	Rs.Close:Set Rs = Nothing
End Sub

Sub saveNewJsFile()
	Dim sFileName
	If Trim(Request.Form("sTitle")) = "" Then
		FoundErr = True
		ErrMsg = ErrMsg + "<li>JS文件说明不能为空！</li>"
		Exit Sub
	End If
	If Trim(Request.Form("sFileName")) = "" Then
		FoundErr = True
		ErrMsg = ErrMsg + "<li>JS文件名不能为空！</li>"
		Exit Sub
	Else
		sFileName=Trim(Request.Form("sFileName"))
	End If
	If InStr(Lcase(sFileName),".asp")>0 Or InStr(Lcase(sFileName),".aspx")>0 Or InStr(Lcase(sFileName),".php")>0 Then
		FoundErr = True
		ErrMsg = "<li>保存的文件名不合法,必须是有效JS或HTML文件!</li>"
		Exit Sub
	End If
	If LCase(Right(sFileName,3)) <> ".js" And LCase(Right(sFileName,4)) <> ".htm" And LCase(Right(sFileName,5)) <> ".html"  Then
		FoundErr = True
		ErrMsg = ErrMsg + "<li>请输入正确的JS/HTML文件名，扩展名一定要是*.js或*.html！</li>"
		Exit Sub
	End If
	Dim Rs,SQL
	SQL = "INSERT INTO NC_ScriptFile (ChannelID,sTitle,stype,sFileName,sContent) VALUES ("& ChannelID &",'"& NewAsp.CheckStr(Request.Form("sTitle")) &"',"& NewAsp.ChkNumeric(Request.Form("stype")) &",'"& NewAsp.CheckStr(Request.Form("sFileName")) &"','"& NewAsp.CheckStr(Request.Form("sContent")) &"')"
	NewAsp.Execute(SQL)
	Succeed("<li>恭喜您！添加新的JS文件成功。</li>")
End Sub

Sub saveJsFile()
	Dim sFileName
	If Trim(Request.Form("sTitle")) = "" Then
		FoundErr = True
		ErrMsg = ErrMsg + "<li>JS文件说明不能为空！</li>"
		Exit Sub
	End If
	If Trim(Request.Form("sFileName")) = "" Then
		FoundErr = True
		ErrMsg = ErrMsg + "<li>JS文件名不能为空！</li>"
		Exit Sub
	Else
		sFileName=Trim(Request.Form("sFileName"))
	End If
	If InStr(Lcase(sFileName),".asp")>0 Or InStr(Lcase(sFileName),".aspx")>0 Or InStr(Lcase(sFileName),".php")>0 Then
		FoundErr = True
		ErrMsg = "<li>保存的文件名不合法,必须是有效JS或HTML文件!</li>"
		Exit Sub
	End If
	If LCase(Right(sFileName,3)) <> ".js" And LCase(Right(sFileName,4)) <> ".htm" And LCase(Right(sFileName,5)) <> ".html"  Then
		FoundErr = True
		ErrMsg = ErrMsg + "<li>请输入正确的JS/HTML文件名，扩展名一定要是*.js或*.html！</li>"
		Exit Sub
	End If
	Dim Rs,SQL
	SQL = "UPDATE NC_ScriptFile SET sTitle='"& NewAsp.CheckStr(Request.Form("sTitle")) &"',stype="& NewAsp.ChkNumeric(Request.Form("stype")) &",sFileName='"& NewAsp.CheckStr(Request.Form("sFileName")) &"',sContent='"& NewAsp.CheckStr(Request.Form("sContent")) &"' WHERE ChannelID="& ChannelID &" And id="& NewAsp.ChkNumeric(Request("id"))
	NewAsp.Execute(SQL)
	Succeed("<li>恭喜您！编辑JS文件成功。</li>")
End Sub

Sub makeJsFile()
	Dim Rs,SQL,i
	Dim FileName,strJsContent
	Dim strHTML
	IsNowOutputText = False
	Template.IsDispayDomain=True
	SQL="SELECT stype,sFileName,setting,sContent FROM NC_ScriptFile WHERE ChannelID="& ChannelID &" And id in("& NewAsp.CheckIDlist(Request("id")) &")"
	Set Rs=NewAsp.Execute(SQL)
	If Not(Rs.BOF And Rs.EOF) Then
		NewAsp.CreatPathEx(NewAsp.ChannelDest &"js/")
		Do While Not Rs.EOF
			strHTML=Rs("sContent")&""
			strHTML=Replace(strHTML, "{$channelid}", ChannelID)
			strHTML=Replace(strHTML, "{$installdir}", NewAsp.MainsiteDir)
			TPL_Scan strHTML
			If Rs("stype")=0 Then
				strJsContent="document.write ("""& fixjs(TPL_Memory) &""");"
			Else
				strJsContent=TPL_Memory
			End If
			FileName=NewAsp.ChannelDest &"js/"& Rs("sFileName")
			NewAsp.CreatedTextFile FileName,strJsContent
			TPL_Memory="":strHTML=""
			Rs.movenext
		Loop
	End If
	Set Rs = Nothing
	Succeed("<li>恭喜您！生成JS文件成功。</li>")
End Sub

Sub deleteJsFile()
	Dim Rs
	If Trim(Request("id")) <> "" Then
		On Error Resume Next
		Set Rs = NewAsp.Execute("SELECT sFileName FROM NC_ScriptFile WHERE ChannelID="& ChannelID &" And id="& CLng(Request("id")))
		If Not(Rs.BOF And Rs.EOF) Then
			NewAsp.FileDelete(NewAsp.ChannelDest &"js/"& Rs("sFileName"))
		End If
		Set Rs = Nothing
		NewAsp.Execute ("DELETE FROM NC_ScriptFile WHERE ChannelID="& ChannelID &" And id="& CLng(Request("id")))
		Response.Redirect  Request.ServerVariables("HTTP_REFERER")
	Else
		ErrMsg = "<li>错误的系统参数,请选择要删除的文件ID</li>"
		FoundErr = True
	End If
End Sub

Sub demoJsFile()
	Dim Rs,strJSFileName
%>
<table border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
<tr>
	<th><%=NewAsp.ModuleName%>JS文件调用演示</th>
</tr>
<%
	Set Rs = Newasp.Execute("SELECT sFileName FROM NC_ScriptFile WHERE ChannelID="& ChannelID &" And id=" & CLng(Request("id")))
	If Not(Rs.BOF And Rs.EOF) Then
		strJSFileName="<script src="""& NewAsp.ChannelUrl &"js/"& Rs("sFileName") &"""></script>"
%>
<tr>
	<td class="tablerow1" align="center">
		<input type="text" name="jsfile" size="100" value="<%=Server.HTMLEncode(strJSFileName)%>">
	</td>
</tr>
<tr>
	<td class="tablerow2"><%=strJSFileName%></td>
</tr>
<%
	End If
	Rs.Close:Set Rs = Nothing
%>
<tr>
	<td class="tablerow1" align="center">
		<input type="button" name="go_button" onclick="javascript:history.go(-1)" value="返回上一页" class="button">
	</td>
</tr>
</table>
<%
End Sub
Function fixjs(str)
	If str <> "" Then
		str = Replace(str, "\", "\\")
		str = Replace(str, Chr(34), "\""")
		str = Replace(str, Chr(39), "\'")
		str = Replace(str, Chr(13), "")
		str = Replace(str, Chr(10), "")
		'str = replace(str,"'", "&#39;")
	End If
	fixjs = str
	Exit Function
End Function
%>