<!--#include file = "Startup.asp"-->
<!-- #include file="Function.asp" -->
<%
call adminer()
call Header()
Call ComeUrl()
%>
<%
Dim Action,FoundErr,ErrMsg
Dim Id,ComName,ComUrl,ComKEY,ComAdd,LanXiRen,ComCode,ComTel,ComFax,ComMail

Action=Trim(Request("Action"))
if Action="" Or Action="Manage" then
	call Main()
elseif Action="AddAnnounce" then
	call AddAnnounce()
elseif Action="AddSaveAnnounce" then
	call AddSaveAnnounce()
elseif Action="ModifyAnnounce" then
	call ModifyAnnounce()
elseif Action="ModifySaveAnnounce" then
	call ModifySaveAnnounce()
elseif Action="DelAnnounce" then
	call DelAnnounce()
Else
	FoundErr=True
	ErrMsg=ErrMsg & "<br><li>参数错误！</li>"
end if

if founderr=true then
	call WriteErrMsg()
End if
%>
<%
Sub AddAnnounce()
%>
<Script Language=JavaScript>
function doSubmit(){
	if (document.myform.Title.value==""){
		alert("公告标题不能为空！");
		return false;
	}
		// getHTML()为eWebEditor自带的接口函数，功能为取编辑区的内容
		if (eWebEditor1.getHTML()==""){
			alert("公告内容不能为空！");
			return false;
		}
}
</Script>
<table width="100%"  border="0" cellpadding="3" cellspacing="1" bgcolor="#DEDFDE">
  <form name="myform" method="post" action="Announce.asp?Action=AddSaveAnnounce"><tr>
    <td colspan="2" bgcolor="#f7f7f7"><div align="center">
      <strong>公 告 添 加</strong></div></td>
  </tr>
    <tr>
      <td bgcolor="#FFFFFF">公告标题：</td>
      <td bgcolor="#FFFFFF"><input name="Title" type="text" class="input_text" id="Title" size="50"></td>
    </tr>
    <tr>
    <td width="120" bgcolor="#FFFFFF"><p>公告内容：</p>
        <p>换行请按<FONT color=#ff6600>Enter。</FONT><BR>
          支持UBB标记。</p></td>
<td bgcolor="#FFFFFF">
<textarea name="Content"  class="input_text" rows="8" cols="54"></textarea>
</td>
  </tr>
  <tr>
    <td height="40" colspan="2" bgcolor="#FFFFFF"><div align="center">
      <input type="submit" name="Submit" value=" 提　交 " class="input_submit" onClick="return doSubmit()">
　　　　　 
     <input type="reset" name="Submit" value=" 重　置 " class="input_submit">
</div></td>
    </tr>
  </form>
</table>

<%
End Sub
%>


<%
Sub ModifyAnnounce()

dim AnnID,Title,Content
AnnID=trim(Request("AnnID"))
if AnnID="" then
	FoundErr=True
	ErrMsg=ErrMsg & "<br><li>请选择要删除的公告！</li>"
	exit sub
else
	AnnID=CLng(AnnID)
end if
sSql="Select * From SiteAnnounce Where ID="&AnnID
oRs.Open sSql,oConn,1,1
If oRs.Eof Then
	FoundErr=True
	ErrMsg=ErrMsg & "<br><li>无此公告！</li>"
	exit sub
Else
	Title=oRs("Title")
	Content=oRs("Content")
End If
oRs.Close

%>
<Script Language=JavaScript>
function doSubmit(){
	if (document.myform.Title.value==""){
		alert("公告标题不能为空！");
		return false;
	}
		// getHTML()为eWebEditor自带的接口函数，功能为取编辑区的内容
		if (eWebEditor1.getHTML()==""){
			alert("公告内容不能为空！");
			return false;
		}
}
</Script>
<table width="100%"  border="0" cellpadding="3" cellspacing="1" bgcolor="#DEDFDE">
  <form name="myform" method="post" action="Announce.asp?Action=ModifySaveAnnounce&AnnID=<%=AnnID%>"><tr>
    <td colspan="2" bgcolor="#f7f7f7"><div align="center">
      <strong>公 告 添 加</strong></div></td>
  </tr>
    <tr>
      <td bgcolor="#FFFFFF">公告标题：</td>
      <td bgcolor="#FFFFFF"><input name="Title" type="text" class="input_text" id="Title" size="50" value="<%=Title%>"></td>
    </tr>
    <tr>
    <td width="120" bgcolor="#FFFFFF"><p>公告内容：</p>
      <p>换行请按<FONT color=#ff6600>Enter。</FONT><BR>
          支持UBB标记。</p></td>
<td bgcolor="#FFFFFF">
<textarea name="Content" class="input_text"  rows="8" cols="57"><%=Content%></textarea>
</td>
  </tr>
  <tr>
    <td height="40" colspan="2" bgcolor="#FFFFFF"><div align="center">
      <input type="submit" name="Submit" value=" 提　交 " class="input_submit" onClick="return doSubmit()">
     　　　　　  
     <input type="reset" name="Submit" value=" 重　置 " class="input_submit">
</div></td>
    </tr>
  </form>
</table>

<%
End Sub
%>




<%
Sub Main
%>
<SCRIPT language=javascript>
function unselectall()
{
    if(document.myform.chkAll.checked){
	document.myform.chkAll.checked = document.myform.chkAll.checked&0;
    } 	
}

function CheckAll(form)
  {
  for (var i=0;i<form.elements.length;i++)
    {
    var e = form.elements[i];
    if (e.Name != "chkAll"&&e.disabled==false)
       e.checked = form.chkAll.checked;
    }
  }
  

function ConfirmDel()
{
	if(document.myform.Action.value=="Del")
	{
		if(confirm("确定要删除选中的公告吗？一但删除将无法恢复！"))
		    return true;
		else
			return false;
	}
}
</SCRIPT>
<table width="100%"  border="0" cellpadding="3" cellspacing="1" bgcolor="#DEDFDE">
  <form name="myform" method="post" action="Announce.asp?Action=DelAnnounce" onsubmit="return ConfirmDel();"><tr>
    <td width="40" bgcolor="#F7F7F7"><div align="center"><strong>选中</strong>
      
      
    </div></td>
    <td bgcolor="#F7F7F7"><div align="center"><strong>公告标题</strong></div></td>
    <td bgcolor="#F7F7F7"><div align="center"><strong>添加人员</strong></div></td>
    <td bgcolor="#F7F7F7"><div align="center"><strong>添加时间</strong></div></td>
    <td bgcolor="#F7F7F7"><div align="center"><strong>修改</strong></div></td>
    <td bgcolor="#F7F7F7"><div align="center"><strong>删除</strong></div></td>
  </tr>
  
<%
sSql="Select * From SiteAnnounce Order By ID Desc"
oRs.Open sSql,oConn,1,3
If oRs.Eof Then
	Response.Write "<tr><td colspan='6' bgcolor='#FFFFFF'><div align='center'>暂无公告信息！</div></td></tr></form></table>"
Else

const MaxPerPage=15   '单独页最大记录数 const 用来申明常量
dim totalPut   '总记录
dim CurrentPage  '当前页次
dim TotalPages   '总页数
dim i



'!-- 分页功能代码块,可独立使用
if not ors.eof then
  ors.MoveFirst  '注意放到前面来,否则到任何页总是在第一个记录上
  end if
  ors.pagesize=MaxPerPage  '设置每页最多显示多少条记录
  If trim(Request("Page"))<>"" then  '如果请求的页次不为空
	CurrentPage= CLng(request("Page"))   'clng是转换成长整型数据类型,并赋值到当前页次上
	If CurrentPage> ors.PageCount then  '如果当前页次大于总页数,则将最大页次赋值到当前页次上
		CurrentPage = ors.PageCount 
	End If 
Else 
	CurrentPage= 1 '一切条件不成立,将当前页设为第一页
End If 

 totalPut=ors.recordcount '将总记录赋值于TOTALPUT
	if CurrentPage<>1 then '如果当前页数不等于第一页
		if (currentPage-1)*MaxPerPage<totalPut then  '如果当前页减一乘以每页最大的记录数小于总记录的话
			ors.move(currentPage-1)*MaxPerPage  '相对当前记录数向后移动
			dim bookmark  '定义书签变量
			bookmark=ors.bookmark '将当前记录的标签赋于变量BOOKMARK上
		end if 
	end if

	dim n,k
	if (totalPut mod MaxPerPage)=0 then  '总记录数与每页最大记录数求余的结果为零时,则N返回整数页次,否则再加一.
		n= totalPut \ MaxPerPage
	else  
		n= totalPut \ MaxPerPage + 1  
	end if

	Do While Not oRs.Eof and i<maxperpage
%>  
  <tr>
    <td width="40" bgcolor="#FFFFFF"><div align="center">
      <input name="AnnID" type="checkbox" onClick="unselectall()" id="AnnID" value="<%=oRs("ID")%>">
    </div></td>
    <td bgcolor="#FFFFFF"><a href="Announce.asp?Action=ModifyAnnounce&AnnID=<%=oRs("ID")%>" tilte="<%=oRs("Title")%>"><%=gotTopic(oRs("Title"),50)%></a></td>
    <td bgcolor="#FFFFFF"><div align="center"><%=oRs("Editor")%></div></td>
    <td bgcolor="#FFFFFF"><div align="center"><%=oRs("DateTime")%></div></td>
    <td bgcolor="#FFFFFF"><div align="center">[<a href="Announce.asp?Action=ModifyAnnounce&AnnID=<%=oRs("ID")%>">修改</a>]</div></td>
    <td bgcolor="#FFFFFF"><div align="center"><%If session("userclass")=1 Then%>[<span onClick='return ConfirmDel()'><a href="Announce.asp?Action=DelAnnounce&AnnID=<%=oRs("ID")%>">删除</a></span>]<%End If%></div></td>
  </tr>
  
  <%
  oRs.MoveNext
  i=i+1
  Loop
  %>
  
  <tr>
    <td colspan="6" bgcolor="#FFFFFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="40"><div align="center">
            <input name="chkAll" type="checkbox" id="chkAll" onclick=CheckAll(this.form) value="checkbox">
        </div></td>
        <td>选中本页显示的所有文章</td>
        <td><div align="right">
		<input name="Action" type="hidden" id="Action2" value="Del">
        <input type="submit" name="Submit1" value=" 删　除 " onClick="document.myform.Action.value='Del'" class="input_submit">
&nbsp;&nbsp; </div></td>
      </tr>
    </table></td>
  </tr></form>
</table>

<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="30"><div align="center">
        <%
	Response.Write "共 <font color='#FF0000'>"&totalPut&"</font> 条公告　" 
          k=currentPage
		if k<>1 then
			response.write "[<b>"+"<a href='Announce.asp?page=1'>首页</a></b>] "
			response.write "[<b>"+"<a href='Announce.asp?page="&cstr(k-1)&"'>上一页</a></b>] "
		else
			Response.Write "[首页] [上一页]"
		end if
		if k<>n then
			response.write "[<b>"+"<a href='Announce.asp?page="&cstr(k+1)&"'>下一页</a></b>] "
			response.write "[<b>"+"<a href='Announce.asp?page="&cstr(n)&"'>尾页</a></b>] "
		else
			Response.Write "[下一页] [尾页]"
		end if	
		Response.Write "　页次：<font color='#ff0000'>"&currentpage&"</font>/"&n&"页　15条公告/页"
		%>
　转到：
<select name="select" onchange="javascript:window.location='Announce.asp?page='+this.options[this.selectedIndex].value;">
<option>跳转页</option>
<%
Dim z
For z=1 To n%>
  <option value="<%=z%>">第<%=z%>页</option>
<%
Next
%> 
</select>
        </div></td>
  </tr></table>
<%
End If
End Sub
%>


<%
Sub AddSaveAnnounce()
Dim Title,Content,i
Title=Trim(Request.Form("Title"))
Content = ""
For i = 1 To Request.Form("Content").Count
	Content = Content & Request.Form("Content")(i)
Next
	
if Title="" then
	founderr=true
	errmsg=ErrMsg & "<br><li>公告标题不能为空！</li>"
end if
if Content="" then
	founderr=true
	errmsg=errmsg & "<br><li>公告内容不能为空！</li>"
end if
if FoundErr=True then
	exit sub
end if

sSql="Select * From SiteAnnounce Where ID=0"
oRs.Open sSql,oConn,1,3
oRs.AddNew
oRs("Title")=Title
oRs("Content")=Content
oRs("Editor")=Session("username")
oRs.Update
Response.Write "<p align=center>公告添加成功，3秒后自动返回公告管理页！<script>window.setTimeout(""location.href='Announce.asp?Action=Manage'"",3000);</script></p>"
End Sub
%>



<%
Sub ModifySaveAnnounce()
Dim Title,Content,i,AnnID
AnnID=trim(Request("AnnID"))
Title=Trim(Request.Form("Title"))
Content = ""
For i = 1 To Request.Form("Content").Count
	Content = Content & Request.Form("Content")(i)
Next

if AnnID="" then
	FoundErr=True
	ErrMsg=ErrMsg & "<br><li>请选择要删除的公告！</li>"
	exit sub
else
	AnnID=CLng(AnnID)
end if
if Title="" then
	founderr=true
	errmsg=ErrMsg & "<br><li>公告标题不能为空！</li>"
end if
if Content="" then
	founderr=true
	errmsg=errmsg & "<br><li>公告内容不能为空！</li>"
end if
if FoundErr=True then
	exit sub
end if

sSql="Select * From SiteAnnounce Where ID="&AnnID
oRs.Open sSql,oConn,1,3
If Not oRs.Eof Then
oRs("Title")=Title
oRs("Content")=Content
oRs.Update
Response.Write "<p align=center>公告修改成功，3秒后自动返回公告管理页！<script>window.setTimeout(""location.href='Announce.asp?Action=Manage'"",3000);</script></p>"
Else
	FoundErr=True
	ErrMsg=ErrMsg & "<br><li>无此公告！</li>"
	exit sub
End If
End Sub
%>




<%
Sub DelAnnounce()

dim AnnID
AnnID=trim(Request("AnnID"))
if AnnID="" then
	FoundErr=True
	ErrMsg=ErrMsg & "<br><li>参数不足</li>"
	exit sub
end if
sSql="Select * From SiteAnnounce Where ID In ("&AnnID&")"
oRs.Open sSql,oConn,1,1
If oRs.Eof Then
	FoundErr=True
	ErrMsg=ErrMsg & "<br><li>无此公告！</li>"
	exit sub
End If
oRs.Close
sSql = "DELETE FROM SiteAnnounce WHERE ID In ("&AnnID&")"
oConn.Execute sSql
	
Response.Write "<p align=center>公告删除成功，3秒后自动返回公告管理页！<script>window.setTimeout(""location.href='Announce.asp'"",3000);</script></p>"

End Sub
%>