<!--#include file="setup.asp"-->
<!--#include file="../inc/NC_HtmlEditCls.Asp" -->
<%
Dim i
Dim CurrentPage
Dim maxperpage
Dim totalnumber
Dim Pcount
Dim totalPut
Dim isEdit
Dim intMessageid
Dim selMessageid
Dim strTitle
Dim NC_Edit
Dim keyword
Dim TxtContent
Set Rs = Server.CreateObject("ADODB.Recordset")
Set NC_Edit = New HtmlEditor_Cls
NC_Admin.AdminChk = "04"
NC_Admin.Check
DownsysClass.admin_header
Select Case Trim(Request("action"))
	Case "modify"
		Call ModifyMessage
	Case "save"
		Call SaveMessage
	Case "add"
		isEdit = False
		Call EditMessage
	Case "edit"
		isEdit = True
		Call EditMessage
	Case "delall"
		Call DelAllMessage
	Case Else
		Call MessageMain
End Select
If Founderr = True Then
	NC_Admin.Error_Msg (ErrMsg)
End If
Set NC_Edit = Nothing
DownsysClass.admin_footer
NothingObject
'**********************************************
'过程作用：公告首页
'**********************************************
Private Sub MessageMain()
	Dim findword
	Dim bookmark
	If Not IsEmpty(Request("selMessageid")) Then
		selMessageid = Request("selMessageid")
		Select Case Request("type")
			Case "del"
				Call DelMessage
			Case "isTop"
				Call isTop
			Case "noTop"
				Call noTop
			Case Else
				Response.Write "无效参数！"
				Response.End
		End Select
	End If
	Response.Write "<script language=""JavaScript"">" & vbCrLf
	Response.Write "<!--//" & vbCrLf
	Response.Write "function SelectAll() {" & vbCrLf
	Response.Write "for (var i=0;i<document.selform.selMessageid.length;i++) {" & vbCrLf
	Response.Write "var e=document.selform.selMessageid[i];" & vbCrLf
	Response.Write "e.checked=!e.checked;" & vbCrLf
	Response.Write "}" & vbCrLf
	Response.Write "}" & vbCrLf
	Response.Write "function Juge(myform)" & vbCrLf
	Response.Write "{" & vbCrLf
	Response.Write "if (myform.keyword.value == """")" & vbCrLf
	Response.Write "{" & vbCrLf
	Response.Write "alert(""请输入要查询的关键字!"");" & vbCrLf
	Response.Write "myform.keyword.focus();" & vbCrLf
	Response.Write "return (false);" & vbCrLf
	Response.Write "}" & vbCrLf
	Response.Write "}" & vbCrLf
	Response.Write "//-->"
	Response.Write "</script>" & vbCrLf
	Response.Write "<TABLE width=""99%"" border=0 cellpadding=3 cellspacing=1 align=center class=tableBorder>" & vbCrLf
	Response.Write "<TR>" & vbCrLf
	Response.Write "<TH colspan=5>公告管理</TH>" & vbCrLf
	Response.Write "</TR>" & vbCrLf
	Response.Write "<TR><form method=Post name=""myform"" action=""admin_message.asp"" onSubmit=""return Juge(this)"">" & vbCrLf
	Response.Write "<TD colspan=5 height=""28"" class=forumRow>查询： <input align=""absmiddle"" name=""keyword"" type=""text"" id=""keyword"" size=""30""> &nbsp;查询方法:" & vbCrLf
	Response.Write " <select size=""1"" name=""key"">" & vbCrLf
	Response.Write " <option value=""title"">公告标题</option>" & vbCrLf
	Response.Write " <option value=""content"">公告内容</option>" & vbCrLf
	Response.Write " <option value="""">不限条件</option>" & vbCrLf
	Response.Write " </select>" & vbCrLf
	Response.Write " <input type=""submit"" name=""Submit"" align=""absmiddle"" value=""查 询..."" class=button></TD>" & vbCrLf
	Response.Write "</TR></form>" & vbCrLf
	Response.Write "<TR>" & vbCrLf
	Response.Write "<TH noWrap>选择</TH>" & vbCrLf
	Response.Write "<TH width=""70%"">公告标题</TH>" & vbCrLf
	Response.Write "<TH noWrap>编辑公告</TH>" & vbCrLf
	Response.Write "<TH noWrap>公告位置</TH>" & vbCrLf
	Response.Write "<TH noWrap>更新时间</TH>" & vbCrLf
	Response.Write "</TR>" & vbCrLf
	If Not IsEmpty(Request("page")) Then
		CurrentPage = CLng(Request("page"))
	Else
		CurrentPage = 1
	End If
	maxperpage = 20 '###每页显示数
	keyword = Request("keyword")
	If Not IsNumeric(Request("page")) And Request("page") <> "" Then
		Response.Write "错误的系统参数!请输入整数"
		Response.End
	End If
	If Not IsNull(keyword) And keyword <> "" Then
		keyword = Replace(Replace(Replace(keyword, "'", "‘"), "<", "&lt;"), ">", "&gt;")
		If Request("key") = "title" Then
			findword = "title like '%" & keyword & "%'"
		ElseIf Request("key") = "content" Then
			findword = "content like '%" & keyword & "%'"
		Else
			findword = "title like '%" & keyword & "%' or content like '%" & keyword & "%'"
		End If
		SQL = "select * from NC_Message where " & findword & " "
		SQL = SQL & " order by postime desc,id desc"
	Else
		SQL = "select * from NC_Message order by isTop desc,postime desc,id desc"
	End If
	Rs.Open SQL, Conn, 1, 1
	DownsysClass.SqlQueryNum = DownsysClass.SqlQueryNum + 1
	If Rs.bof And Rs.EOF Then
		Response.Write "<tr><td colspan=5 class=forumrow>还没有找到任何公告信息！</td></tr>"
	Else
		totalnumber = Rs.recordcount
		If (totalnumber Mod maxperpage) = 0 Then
			Pcount = totalnumber \ maxperpage
		Else
			Pcount = totalnumber \ maxperpage + 1
		End If
		Rs.MoveFiRst
		If CurrentPage > Pcount Then CurrentPage = Pcount
		If CurrentPage < 1 Then CurrentPage = 1
		Rs.Move (CurrentPage - 1) * maxperpage
		bookmark = Rs.bookmark
		i = 0
		Response.Write "<TR height=""28"">" & vbCrLf
		Response.Write "<TD colspan=5 class=forumRowHighlight align=center>"
		Call showpage
		Response.Write "</TD>" & vbCrLf
		Response.Write "</TR>" & vbCrLf
		Response.Write "<form name=""selform"" method=""post"" action="""">" & vbCrLf
		Do While Not Rs.EOF And i < CLng(maxperpage)
			Response.Write "<TR height=""22"">" & vbCrLf
			Response.Write "<TD class=forumRowHighlight><input type=checkbox name=selMessageid value="""
			Response.Write Rs("id")
			Response.Write """ title=""管理："
			Response.Write Rs("title")
			Response.Write """></TD>" & vbCrLf
			Response.Write "<TD class=forumRow>"
			If Rs("istop") = 0 Then
				Response.Write "<IMG SRC=""images/folder.gif"" WIDTH=""16"" HEIGHT=""16"" BORDER=0 ALT=""开放的影片"">"
			Else
				Response.Write "<FONT color=#000000><IMG SRC=""images/istop.gif"" WIDTH=""15"" HEIGHT=""17"" BORDER=0 ALT=""置顶的影片""></FONT>"
			End If
			Response.Write " <a href=../Message.asp?id="
			Response.Write Rs("id")
			Response.Write " target=_blank> "
			Response.Write Rs("title")
			Response.Write "</a></TD>" & vbCrLf
			Response.Write "<TD class=forumRowHighlight align=center><a href=?action=edit&id="
			Response.Write Rs("id")
			Response.Write " title=""点击修改："
			Response.Write Rs("title")
			Response.Write """>编 辑</a></TD>" & vbCrLf
			Response.Write "<TD class=forumRow align=center>"
			If Rs("statid") = 0 Then Response.Write "所有位置"
			If Rs("statid") = 1 Then Response.Write "下载首页"
			If Rs("statid") = 2 Then Response.Write "文章首页"
			Response.Write "</TD>" & vbCrLf
			Response.Write "<TD class=forumRowHighlight noWrap align=center>"
			If Rs("postime") >= Date Then
				Response.Write "<font color=""#FF3300"">"
				Response.Write FormatDateTime(Rs("postime"), 2)
				Response.Write "</font>"
			Else
				Response.Write FormatDateTime(Rs("postime"), 2)
			End If
			Response.Write "</TD>" & vbCrLf
			Response.Write "</TR>" & vbCrLf
			Rs.movenext
			i = i + 1
			If i >= maxperpage Then Exit Do
		Loop
	End If
	Rs.Close
	Response.Write "<TR height=""30"">" & vbCrLf
	Response.Write "<TD class=forumRow>管理</TD>" & vbCrLf
	Response.Write "<TD colspan=3 class=forumRow><a href=""javascript:SelectAll()"" title=""管理选项：全选/反选"">全选/反选</a><input type=""checkbox"" name=""checkbox"" value=""checkbox"" onClick=""javascript:SelectAll()""> " & vbCrLf
	Response.Write "<input type=""radio"" name=""type"" value=""del"" title=""管理选项：批量删除选中的公告"">批量删除" & vbCrLf
	Response.Write "<input type=""radio"" name=""type"" value=""isTop"" title=""管理选项：批量设置选中的公告置顶"">置顶" & vbCrLf
	Response.Write "<input type=""radio"" name=""type"" value=""noTop"" title=""管理选项：批量取消选中的公告置顶"">取消置顶" & vbCrLf
	Response.Write " [<a href=?action=delall onclick=""{if(confirm('此操作将删除全部的公告,不能恢复\n您确定执行此操作吗?')){return true;}return false;}"">清空所有公告</a>]" & vbCrLf
	Response.Write "<TD class=forumRow><input type=submit name=Submit value=""执行操作"" class=button onclick=""{if(confirm('您确定执行此操作吗?')){this.document.selform.submit();return true;}return false;}""></TD>" & vbCrLf
	Response.Write "</TR></form>" & vbCrLf
	Response.Write "<TR height=""28"">" & vbCrLf
	Response.Write "<TD colspan=5 class=forumRowHighlight align=center>"
	Call showpage
	Response.Write "</TD>" & vbCrLf
	Response.Write "</TR>" & vbCrLf
	Response.Write "</TABLE>" & vbCrLf
	Response.Write Chr(9)
End Sub

'**********************************************
'过程作用：编辑公告
'**********************************************

Private Sub EditMessage()
	Dim MessageTitle
	If isEdit Then
		SQL = "select * from NC_Message where id=" & Request("id")
		Rs.Open SQL, Conn, 1, 1
		DownsysClass.SqlQueryNum = DownsysClass.SqlQueryNum + 1
		MessageTitle = "编辑公告"
	Else
		MessageTitle = "添加公告"
	End If
	Response.Write "<div onkeydown=CtrlEnter()>" & vbCrLf
	Response.Write "<TABLE width=""99%"" border=0 cellpadding=3 cellspacing=1 align=center class=tableBorder>" & vbCrLf
	Response.Write "<TR><form name=""myform"" method=""post"" action=""admin_message.asp"">" & vbCrLf
	If CInt(DownsysClass.Setting(19)) = 1 Then
		Response.Write "<input type=""hidden"" name=""content1"" id=body value="""
		If isEdit Then
			Response.Write Server.HTMLEncode(Rs("Content"))
		End If
		Response.Write """>" & vbCrLf
	End If
	Response.Write " <input type=""Hidden"" name=""action"" value='"
	If isEdit Then
		Response.Write "modify"
	Else
		Response.Write "save"
	End If
	Response.Write "'>" & vbCrLf
	Response.Write " "
	If isEdit Then
		Response.Write " <input type=""Hidden"" name=""id"" value='"
		Response.Write CStr(Request("id"))
		Response.Write "'>" & vbCrLf
		Response.Write " "
	End If
	Response.Write " " & "<TH colspan=2>"
	Response.Write MessageTitle
	Response.Write "</TH>" & vbCrLf
	Response.Write "</TR>" & vbCrLf
	Response.Write "<TR height=""22"">" & vbCrLf
	Response.Write "<TD noWrap align=""right"" class=forumRowHighlight>公告标题：</TD>" & vbCrLf
	Response.Write "<TD width=""85%"" class=forumRow><input type=text name=title size=50 value="""
	If isEdit Then
		Response.Write Rs("title")
	End If
	Response.Write """></TD>" & vbCrLf
	Response.Write "</TR>" & vbCrLf
	Response.Write "<TR height=""22"">" & vbCrLf
	Response.Write "<TD noWrap align=""right"" class=forumRowHighlight>显示位置：</TD>" & vbCrLf
	Response.Write "<TD class=forumRow><select size=""1"" name=""statid"">" & vbCrLf
	Response.Write " <option value=""0"" "
	If isEdit Then
		If Rs("statid") = 0 Then Response.Write " selected"
	End If
	Response.Write ">≡所有位置≡</option>" & vbCrLf
	Response.Write " <option value=""1"" "
	If isEdit Then
		If Rs("statid") = 1 Then Response.Write " selected"
	End If
	Response.Write ">≡下载首页≡</option>" & vbCrLf
	Response.Write " <option value=""2"" "
	If isEdit Then
		If Rs("statid") = 2 Then Response.Write " selected"
	End If
	Response.Write ">≡文章首页≡</option>" & vbCrLf
	Response.Write " </select></TD>" & vbCrLf
	Response.Write "</TR>" & vbCrLf
	Response.Write "<TR height=""22"">" & vbCrLf
	Response.Write "<TD colspan=2 class=forumHeaderBackgroundAlternate align=center>公告内容</TD>" & vbCrLf
	Response.Write "</TR>" & vbCrLf
	Response.Write "<TR height=""22"">" & vbCrLf
	Response.Write "<TD colspan=2 class=forumRow align=center>"
	If CInt(DownsysClass.Setting(19)) = 1 Then
		NC_Edit.Init_HtmlEditor
	Else
		Response.Write "<textarea name=content1 style=""width:100%;"" rows=18>"
		If isEdit Then
			Response.Write Rs("Content")
		End If
		Response.Write "</textarea>"
	End If
	Response.Write "</TD>" & vbCrLf
	Response.Write "</TR>" & vbCrLf
	Response.Write " <tr> " & vbCrLf
	Response.Write " <td height=""22"" align=""right"" class=""forumRowHighlight"">发布人：</td>" & vbCrLf
	Response.Write " <td class=""forumRow""><input name=""writer"" type=""text"" size=""35"" "
	If isEdit Then
		Response.Write "value="""
		Response.Write Rs("writer")
		Response.Write """"
	Else
		Response.Write "value="""
		Response.Write Session(DownsysClass.CacheName & "AdminName")
		Response.Write """"
	End If
	Response.Write "></td>" & vbCrLf
	Response.Write " </tr>" & vbCrLf
	Response.Write " <tr> " & vbCrLf
	Response.Write " <td height=""21"" align=""right"" class=""forumRowHighlight"">是否置顶：</td>" & vbCrLf
	Response.Write " <td class=""forumRow""> <input name=""isTop"" type=""radio"" value=""0"" "
	If isEdit Then
		If CInt(Rs("isTop")) = 0 Then
			Response.Write "checked"
		End If
	Else
		Response.Write "checked"
	End If
	Response.Write ">" & vbCrLf
	Response.Write " 取消置顶　<input type=""radio"" name=""isTop"" value=""1"" "
	If isEdit Then
		If CInt(Rs("isTop")) = 1 Then
			Response.Write "checked"
		End If
	End If
	Response.Write ">" & vbCrLf
	Response.Write " 设为置顶　"
	If isEdit Then
		Response.Write "<input name=""updatetime"" type=""checkbox"" value=""yes"">更新时间"
	End If
	Response.Write "</td>" & vbCrLf
	Response.Write " </tr>" & vbCrLf
	Response.Write " <tr>" & vbCrLf
	Response.Write " <td height=""22"" align=""right"" class=""forumRowHighlight"">&nbsp;</td>" & vbCrLf
	Response.Write " <td align=""center"" class=""forumRow"">" & vbCrLf
	Response.Write " <input type=""button"" name=""Submit1"" onclick=""javascript:history.go(-1)"" value=""返回上一页"" class=button>" & vbCrLf
	Response.Write " <input type=button class=button value=""查看内容长度"" name=Button onclick=""checklength(document.myform);"">　" & vbCrLf
	Response.Write " <input type=reset name=Submit2 class=button value=""清 除"" onclick=""ClearReset()"">　" & vbCrLf
	Response.Write "　<input type=Submit class=button value=""保存公告"" name=Submit>　" & vbCrLf
	Response.Write " </td>" & vbCrLf
	Response.Write " </tr></form>" & vbCrLf
	Response.Write "</table>" & vbCrLf
	Response.Write "</div>" & vbCrLf
	If CInt(DownsysClass.Setting(19)) = 0 Then
		Response.Write "<Script language=javascript>" & vbCrLf
		Response.Write "<!--//" & vbCrLf
		Response.Write "document.myform.content1.value = ubbcode(document.myform.content1.value);" & vbCrLf
		Response.Write "function ubbcode(temp) {" & vbCrLf
		Response.Write "temp = temp.replace(/<br>/ig,""\n"");" & vbCrLf
		Response.Write "temp = temp.replace(/<p>/ig,""\n"");" & vbCrLf
		Response.Write "temp = temp.replace(/<\/p>/ig,""\n"");" & vbCrLf
		Response.Write "return (temp);" & vbCrLf
		Response.Write "}" & vbCrLf
		Response.Write "function ClearReset()" & vbCrLf
		Response.Write "{" & vbCrLf
		Response.Write "	document.myform.content1.value = '';" & vbCrLf
		Response.Write "	focus();" & vbCrLf
		Response.Write "}" & vbCrLf
		Response.Write "function checklength(theform)" & vbCrLf
		Response.Write "{" & vbCrLf
		Response.Write "	alert(""您的内容目前有 ""+theform.content1.value.length+"" 字节。"");" & vbCrLf
		Response.Write "}" & vbCrLf
		Response.Write "//-->" & vbCrLf
		Response.Write "</Script>" & vbCrLf
	End If
	If isEdit Then
		Rs.Close
		Set Rs = Nothing
	End If
End Sub

'**********************************************
'过程作用：判断
'**********************************************

Private Sub ChkMessage()
	If Len(Request.Form("statid")) = 0 Then
		Founderr = True
		ErrMsg = ErrMsg + "<li>显示位置不能为空！</li>"
		Exit Sub
	End If
	If Len(Request.Form("title")) = 0 Then
		Founderr = True
		ErrMsg = ErrMsg + "<li>公告标题不能为空！</li>"
		Exit Sub
	Else
		strTitle = DownsysClass.HTMLEncodes(Request.Form("title"))
	End If
	If Len(Request.Form("content1")) = 0 Then
		Founderr = True
		ErrMsg = ErrMsg + "<li>公告内容不能为空！</li>"
		Exit Sub
	End If
	If CInt(DownsysClass.Setting(19)) = 1 Then
		TxtContent = Request.Form("content1")
	Else
		TxtContent = DownsysClass.HTMLEncodes(Request.Form("content1"))
	End If
End Sub

'**********************************************
'过程作用：保存公告
'**********************************************

Private Sub SaveMessage()
	Call ChkMessage
	If Founderr = False Then
		SQL = "select * from NC_Message where (id is null)"
		Rs.Open SQL, Conn, 1, 3
		Rs.addnew
		Rs("title") = strTitle
		Rs("statid") = Request.Form("statid")
		Rs("content") = TxtContent
		Rs("writer") = Request.Form("writer")
		Rs("postime") = DownsysClass.NowTime
		Rs("hits") = 0
		Rs("isTop") = Request.Form("isTop")
		Rs("isUpdate") = 1
		Rs.Update
		Rs.Close
		Set Rs = Nothing
		NC_Admin.Succeed_Msg ("<li>添加 " & strTitle & " 成功!</li>")
		Response.Write "<meta http-equiv=""refresh"" content=""2;url='admin_message.asp?action=add'"">" & vbCrLf
	End If
End Sub

'**********************************************
'过程作用：保存修改公告
'**********************************************

Private Sub ModifyMessage()
	Call ChkMessage
	If Founderr = False Then
		SQL = "select * from NC_Message where id=" & Request.Form("id")
		Rs.Open SQL, Conn, 1, 3
		Rs("title") = strTitle
		Rs("statid") = Request.Form("statid")
		Rs("content") = TxtContent
		Rs("writer") = Request.Form("writer")
		If Trim(Request.Form("updatetime")) = "yes" Then
			Rs("postime") = DownsysClass.NowTime
		End If
		Rs("isTop") = Request.Form("isTop")
		Rs("isUpdate") = 1
		Rs.Update
		Rs.Close
		Set Rs = Nothing
		NC_Admin.Succeed_Msg ("<li>修改 " & strTitle & " 成功!</li>")
		Response.Write "<meta http-equiv=""refresh"" content=""2;url='admin_message.asp'"">" & vbCrLf
	End If
End Sub

'**********************************************
'过程作用：删除公告
'**********************************************

Private Sub DelMessage()
	DownsysClass.Execute ("delete from NC_Message where id in (" & selMessageid & ")")
	Response.redirect (Request.ServerVariables("HTTP_REFERER"))
End Sub

'**********************************************
'过程作用：清空所有公告
'**********************************************

Private Sub DelAllMessage()
	DownsysClass.Execute ("delete from NC_Message")
	Response.redirect (Request.ServerVariables("HTTP_REFERER"))
End Sub

'**********************************************
'过程作用：设置置顶
'**********************************************

Private Sub isTop()
	DownsysClass.Execute ("update NC_Message set isTop=1 where id in (" & selMessageid & ")")
	Response.redirect (Request.ServerVariables("HTTP_REFERER"))
End Sub

'**********************************************
'过程作用：取消置顶
'**********************************************

Private Sub noTop()
	DownsysClass.Execute ("update NC_Message set isTop=0 where id in (" & selMessageid & ")")
	Response.redirect (Request.ServerVariables("HTTP_REFERER"))
End Sub

'**********************************************
'过程作用：公告分页
'**********************************************

Private Sub showpage()
	Dim FileName
	Dim n
	Dim ii
	FileName = "admin_message.asp"
	If totalnumber Mod maxperpage = 0 Then
		n = totalnumber \ maxperpage
	Else
		n = totalnumber \ maxperpage + 1
	End If
	Response.Write "<table cellspacing=1 width='100%' border=0><form method=Post action=" & FileName & "><tr><td align=center> " & vbCrLf
	If CurrentPage < 2 Then
		Response.Write "共有公告 <font COLOR=#FF0000><B>" & totalnumber & "</B></font> 篇&nbsp;首 页&nbsp;上一页&nbsp;"
	Else
		Response.Write "共有公告 <font COLOR=#FF0000><B>" & totalnumber & "</B></font> 篇&nbsp;<a href=" & FileName & "?page=1>首 页</a>&nbsp;"
		Response.Write "<a href=" & FileName & "?page=" & CurrentPage - 1 & ">上一页</a>&nbsp;"
	End If
	If n - CurrentPage < 1 Then
		Response.Write "下一页&nbsp;尾 页 " & vbCrLf
	Else
		Response.Write "<a href=" & FileName & "?page=" & (CurrentPage + 1) & ">下一页</a>"
		Response.Write "&nbsp;<a href=" & FileName & "?page=" & n & ">尾 页</a>" & vbCrLf
	End If
	Response.Write "&nbsp;页次：<strong><font color=red>" & CurrentPage & "</font>/" & n & "</strong>页 "
	Response.Write "&nbsp;转到："
	Response.Write "&nbsp;<select name='page' size='1' style=""font-size: 9pt"" onChange='javascript:submit()'>" & vbCrLf
	For ii = 1 To n
		Response.Write "<option value='" & ii & "' "
		If CurrentPage = Int(ii) Then
			Response.Write "selected "
		End If
		Response.Write ">第" & ii & "页</option>"
	Next
	Response.Write "&nbsp;</select> " & vbCrLf
	Response.Write "</td></tr></FORM></table>" & vbCrLf
End Sub
%>
