<!--#INCLUDE FILE="conn.asp" -->
<!--#include file="inc/char.asp"-->
<!--#include file="admin_Checkuser.asp"-->
<!--#include file="inc/HTMLEncode.asp"-->
<HTML><HEAD><title><%=StrVar(1)%>--管理页面</title>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<!--#include file="inc/admin_main.css"-->
</HEAD>
<BODY leftMargin=0 topMargin=0 marginwidth="0" marginheight="0">
<%
if  not sysadmin or session("adminlogin")<>"0K" Then
	Errmsg=Errmsg+"<br>"+"<li>本页面为管理员专用，请<a href=admin_index.asp target=_top>登陆</a>后进入。"
	Call Error("Information",ErrMsg)
	elseif request("action")="look" then
	call look()
	elseif request("action")="edit" then
	call edit()
	elseif request("action")="saveedit" then
	call saveedit()
else
call main()
Call endconnection()
end if
sub main()	
%><table cellpadding=5 cellspacing=1 border=0 width=90% Class=TableBorder align=center>
  <tr>
	<th>欢迎<b><%=membername%></b>进入管理页面</th>
</tr>
</table>
      <%
select case request("action")
  case "删除"
     call del()
	case "save"
	call save()
	case "do"
	call godo()
case else	 
	call all()
end select
%>
<%
end sub
sub saveedit()
dim title,content,name
name=trim(request.form("name"))
title=trim(request.form("title"))
content=request.form("content")
if name="" or title="" or content="" then
	Errmsg=Errmsg+"<br>"+"<li>请填写发布者或公告标题或内容！"
	Call Error("Information",ErrMsg)
	Exit Sub
else
sql="Select * from gonggao where id="&request("id")
Set rs=Server.CreateObject("ADODB.RecordSet") 
rs.Open sql,conn,1,3
rs("name")=name
rs("title")=title
rs("content")=content
rs.update
rs.close
set rs=nothing
Call adminmsg("恭喜，修改成功！")
end if
end sub
sub look()
sql="Select * from gonggao where id="&request("id")
Set rs=Server.CreateObject("ADODB.RecordSet") 
rs.Open sql,conn,1,1
if rs.eof and rs.bof then
response.write "没有此公告！" 
else
response.write rs("content")
end if
rs.close
set rs=nothing
end sub

sub save()

dim title,name,content
title=trim(request.form("title"))
name=trim(request.form("name"))
content=request.form("content")
if name="" or title="" or content="" then
	Errmsg=Errmsg+"<br>"+"<li>请填写发布者或公告标题或内容！"
	Call Error("Information",ErrMsg)
	Exit Sub
else
conn.execute("insert into gonggao (name,title,content) values ('"&name&"','"&title&"','"&content&"')")
Call adminmsg("恭喜，成功添加公告！")
end if
end sub
sub godo()
conn.execute("update gonggao Set passed="&request("passed")&" where id="&request("id"))
Call adminmsg("恭喜，成功对该公告操作！")
end sub

sub del()
Dim idlist,idarr,id
   
if Request("id")="" Then
	Errmsg=Errmsg+"<br>"+"<li>请选择所要进行管理操作的公告！"
	Call Error("Information",ErrMsg)
	Exit Sub
End if

idlist=Request("id")

idArr=Split(idlist,",")
SucDelNum=0
for i = 0 to ubound(idarr)
	id=Clng(idarr(i))

   Sql = "Delete From gonggao Where id="&id
   Conn.Execute(Sql)
   SucDelNum=SucDelNum+1
next
Call adminmsg("恭喜，成功删除&nbsp;<font color=brown>"&SucDelNum&"</font>&nbsp;条公告！")
end sub

sub all()
%>
<TABLE border=0 width=600 align=center Class=TableBorder>
  <TR> 
    <TD colspan="2" class=forumRowHighlight><b>说明：</b><br>
      (1)一旦删除公告，就无法恢复，请慎重考虑！</TD>
  </TR>
</TABLE>
<br>
 
<script language=JavaScript src="../inc/jsfun.asp"></script>
 <script language="JavaScript">
function openScript(url, width, height){
	var Win = window.open(url,"openScript",'width=' + width + ',height=' + height + ',resizable=0,scrollbars=no,menubar=no,status=no' );
}</script>
<table width="90%"  border="0" align="center" cellpadding="2" cellspacing="1" Class=TableBorder>
<form action="admin_gonggao.asp" method="post">
  <tr> 
    <th width="77">ID</th>
    <th width="130">发布者</th>
    <th width="389">标题</th>
	<th width="36">修改</th>
    <th width="143">状态</th>
	<th width="175">时间</th>
    <th width="36">选择</th>
  </tr>
  <%

sql="Select id,name,title,passed,time,content from gonggao order by id desc"
Set rs=Server.CreateObject("ADODB.RecordSet") 
rs.Open sql,conn,1,1
if rs.eof and rs.bof then
response.write "<tr><td colspan=""7"" class=forumrow>还没有任何公告！</td></tr>" 
else
page=1 '设置变量初始值PAGE=1
page=request.querystring("page")  'page值为接受值 
const PageSize = 20 '每页显示记录数
if Not IsEmpty(trim(Request("Page"))) then '如果PAGE已经初始化...
 Page = CInt(Request("Page")) '接收PAGE并化为数字型赋给PAGE变量    
    if Page > rs.PageCount then '如果接收的页数大于总页数
        rs.AbsolutePage = rs.PageCount '设置当前显示页等于最后页        
    elseif Page <= 0 then '如果page小于等于0
        Page = 1 '设置PAGE等于第一页
    else
        rs.AbsolutePage = Page '如果大于零,显示当前页等于接收的页数 
    end if
End if
Page = rs.AbsolutePage
dim i
i = 0
do while not rs.eof
%>
  <tr> 
    <td class=forumrow><%=rs(0)%></td>
    <td class=forumrow><%=rs(1)%></td>
    <td class=forumrow><a href=javascript:openScript('admin_gonggao.asp?action=look&id=<%=Rs(0)%>',300,300) title=<%=htmlencode(rs(2))%>><%=htmlencode(rs(2))%></a></td>
    <td class=forumrow><div align="center"><a href=javascript:openScript('admin_gonggao.asp?action=edit&id=<%=Rs(0)%>',300,300)><font color="#FF0000">修改</font></a></div></td>
	<td class=forumrow><div align="center"><%if rs(3)=0 then response.write"<font color=red>隐藏</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href=admin_gonggao.asp?action=do&id="&rs(0)&"&passed=1>显示</a>"%>
        <%if rs(3)=1 then response.write"<font color=red>显示</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href=admin_gonggao.asp?action=do&id="&rs(0)&"&passed=0>隐藏</a>"%>
		</div></td>
	  <td class=forumrow><%=rs(4)%></td>
    <td class=forumrow align=center><input type="checkbox" name="id" value=<%=rs(0)%>></td>
  </tr>
  <%
i=i+1
	      if i>=PageSize then exit do
	      rs.movenext
	loop
  %>
  <tr> 
    <td colspan="7" Class=forumrowhighlight> 
      <div align="right"> 
        <%
	    dim n
  if rs.RecordCount mod pagesize=0 then
     n= rs.RecordCount \ pagesize
  else
     n= rs.RecordCount \ pagesize+1
  end if
  response.write " <table><tr><td>"
  if Page<2 then
    response.write "首页 | 上一页 | "
  else
    response.write "<a href="&filepath&"?&page=1>首页</a> | "
    response.write "<a href="&filepath&"?page="&Page-1&">上一页</a> | "
  end if
  if n-page<1 then
    response.write "下一页 | 尾页"
  else
    response.write "<a href="&filepath&"?page="&(Page+1)&">"
    response.write "下一页</a> | <a href="&filepath&"?page="&n&">尾页</a>"
  end if
    response.write "&nbsp;共"&rs.RecordCount&"个"
    response.write " 转到第&nbsp;<select name=""page"" style=""width:35px"" onChange=""location.href='?page='+this.options[selectedIndex].value"">"
             dim ii
             ii=1
             do while ii<=n
             if ii=Page then
             response.write("<option selected value="&ii&">"&ii&"</option>")
             else
             response.write("<option value="&ii&">"&ii&"</option>")
             end if
             ii=ii+1
             loop
              
response.write "</select>"
 response.write " /"&n&"页 "
 response.write "&nbsp;&nbsp<input type=checkbox name=chkall onclick=""CheckAll(this.form)"">全选/取消&nbsp;&nbsp;<input type=submit value=删除 name=action class=button></td></tr></table>"
%></div></td>
  </tr>
  <%end if
    rs.close   
set rs=nothing
%>
</form>
</table>
<form method="POST" action=admin_gonggao.asp>
<input type=hidden name=Action value="save">
<table width="600" border="0" cellspacing="1" cellpadding="5"  align=center Class=TableBorder>
<tr> 
<th height="11" colspan="2" ><b>公告添加</b></font></th>
</tr>
<tr> 
      <td width="25%" height="18" class=forumrow>&nbsp;&nbsp;发布者：</font></td>
      <td width="75%" height="18" class=forumrow> <input name="name" type="text" id="name" value="<%=StrVar(1)%>"></td>
</tr>
<tr> 
      <td width="25%" height="18" class=forumrow>&nbsp;&nbsp;公告标题：</font></td>
<td width="75%" height="18" class=forumrow> 
<input type="text" name="title" size="65" >
</td>
</tr>
<tr>
      <td width="25%" height="18" class=forumrow>&nbsp;&nbsp;公告内容：</font></td>
<td width="75%" height="18" class=forumrow> 
        <textarea name="content" cols=65 rows=8></textarea>
</td></tr>
<tr> 
<td height="23" colspan="2" align=right Class=forumrowhighlight> 
<input type="submit" name="Submit" value="添 加" class=button>&nbsp;&nbsp;
<input type="reset" name="reset" value="重 写" class=button>
</td>
</tr>
</table>
</form>
<%
end sub
sub edit()
sql="Select * from gonggao where id="&request("id")
Set rs=Server.CreateObject("ADODB.RecordSet") 
rs.Open sql,conn,1,1
%><br>
<form name="form1" method="post" action="admin_gonggao.asp?action=saveedit">
  发布者：
  <input name="name" type="text" id="name" value="<%=rs("name")%>" size="30">
  <br>
<br>
标题： 
  <input name="title" type="text" id="title" value="<%=rs("title")%>" size="35">
  <br><br>
内容：
  <textarea name="content" cols="35" rows="12" id="content"><%=rs("content")%></textarea>
<br><br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  <input name="id" type="hidden" id="id" value="<%=request("id")%>">
  <input type="submit" name="Submit2" value="修改">
</form>
<%rs.close
set rs=nothing
end sub%>
</BODY></HTML>