<!--#include file="../conn.asp"-->
<!--#include file="admin_check.asp"-->
<!--#include file="../inc/function.asp"-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>管理页面</title>
<link id="maincss" rel="stylesheet" href="images/css/admin_style_<%= AdminSkin %>.css" type="text/css" media="all" />
<script language="javascript" src="../inc/AjaxAans.js"></script>
</head>
<body leftmargin="0" bottommargin="0" rightmargin="0" topmargin="5" marginheight="0" marginwidth="0" bgcolor="#DDEEFF">
<%
Call chkFlag(21)
Dim Act
act=Trim(Request.QueryString("act"))
opendb
Select Case Act
    Case "add"
	   Call add()
    Case "save"
	   Call saves()
    Case "del"
	   Call del()
	Case Else
	   Call Main()
End Select
closedb

Sub del()
   dim id
   id=Trim(Request.QueryString("id"))
   conn.execute("delete from "&predb&"Announce where id="&id)
   
   Call SendMsg("删除公告成功")
   Response.Write("<script>setTimeout(""location.href='?'"",2000)</script>")
End Sub

Sub Saves()
    Dim title,content,admin,addtime,expired,xtype,isNew,xsite,rs,id
	id=clng(Request.QueryString("id"))
	title=Trim(Request.Form("title"))
	content=Trim(Request.Form("content"))
	admin=Trim(Request.Form("admin"))
	addtime=Trim(Request.Form("addtime"))
	expired=Trim(Request.Form("expired"))
	xtype=Trim(Request.Form("xtype"))
	isNew=clng(Request.Form("isNew"))
	xsite=Trim(Request.Form("xsite"))
	IF expired="" Then expired=0
	IF title="" or content="" Then 
      Call SendMsg("标题或内容不能为空")
	  Response.Write("<script>setTimeout(""history.go(-1)"",1000)</script>")
	  Response.End()
	End IF
	IF isDate(addtime)=False Then
      Call SendMsg("时间格式不正确")
	  Response.Write("<script>setTimeout(""history.go(-1)"",1000)</script>")
	  Response.End()
	End IF

	IF ID>0 Then
		Conn.execute("update "&predb&"Announce set title='"&title&"',content='"&content&"',admin='"&admin&"',addtime='"&addtime&"',expired="&expired&",xtype="&xtype&",isNew="&isNew&",xsite="&xsite&" where id="&id)
		
		Call SendMsg("修改公告成功")
		Response.Write("<script>setTimeout(""location.href='?act=add&id="&id&"'"",2000)</script>")
	Else
		Set rs=conn.execute("select count(id) from "&predb&"Announce")
		IF rs(0)>=20 Then Conn.execute("delete from "&predb&"Announce where id not in (select top 19 id from "&predb&"Announce order by isnew desc,id desc)")
		set rs=nothing
		Conn.execute("insert into "&predb&"Announce(title,content,admin,addtime,expired,xtype,isNew,xsite) values('"&title&"','"&content&"','"&admin&"','"&addtime&"',"&expired&","&xtype&","&isNew&","&xsite&")")
		
		Call SendMsg("添加公告成功")
		Response.Write("<script>setTimeout(""history.go(-1)"",2000)</script>")
	End IF
End Sub

Sub Add()
Dim id,rs,title,content,admin,addtime,expired,xtype,isNew,xsite
id=clng(Request.QueryString("id"))
IF ID>0 then
   Set rs=conn.execute("select * from "&predb&"Announce where id="&id)
       title=rs("title")
	   content=rs("content")
	   admin=rs("admin")
	   addtime=rs("addtime")
	   expired=rs("expired")
	   xtype=rs("xtype")
	   isNew=rs("isNew")
	   xsite=rs("xsite")
   set rs=nothing
End IF
%>
<table class="tableBorder" cellspacing="1" cellpadding="2" width="96%" align="center" border="0">
  <tr>
	<th height="25" colspan="2" align="left">网站公告设置</th>
  </tr>
	<tr>
		<td class="BodyTitle" height="23" align="left" colspan="7"></td>
	</tr>
  <tr>
    <td colspan="7" class="TableRow2"><font color="red"><strong>说明</strong>：系统只允许保留20条公告,多余的公告在添加时自动删除。</font></td>
  </tr>
  <form action="?act=save&id=<%= id %>" method="post" name="frm">
  <tr>
    <td width="16%" align="right" class="TableRow1">显示位置：</td>
    <td width="84%" class="TableRow1">
    <select name="xsite" id="xsite">
      <option value="1" <% If xsite=1 Then %>selected<% End If %>>快问首页</option>
      <option value="2" <% If xsite=2 Then %>selected<% End If %>>所有页面</option>
    </select>
    </td>
  </tr>
  <tr>
    <td align="right" class="TableRow2">标题：</td>
    <td class="TableRow2"><input name="title" type="text" id="title" size="50" maxlength="50" value="<%= title %>">
      <span class="xing">*</span></td>
  </tr>
  <tr>
    <td align="right" class="TableRow1">内容：</td>
    <td class="TableRow1" id="input0" style="position:relative"><textarea name="content" onFocus="getmAjax('M',this.value)" cols="68" rows="12"><%= content %></textarea><span class="xing">*</span></td>
  </tr>
  <tr>
    <td align="right" class="TableRow2">发布人：</td>
    <td class="TableRow2"><input name="admin" type="text" id="admin" size="14" <% If id=0 Then %>value="<%= Request.Cookies("adminname") %>"<% Else %>value="<%= admin %>"<% End If %>></td>
  </tr>
  <tr>
    <td align="right" class="TableRow1">发布时间：</td>
    <td class="TableRow1"><input name="addtime" type="text" id="addtime" size="20" <% If id=0 Then %>value="<%= now() %>"<% Else %>value="<%= addtime %>"<% End If %>>
      <span class="xing">*</span></td>
  </tr>
  <tr>
    <td align="right" class="TableRow2">有效期：</td>
    <td class="TableRow2"><input name="expired" type="text" id="expired" value="<% If id=0 Then %>1<% Else %><%= expired %><% End If %>" size="6" onKeyUp="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
      天&nbsp; <span class="xing">*</span>0表示永久有效</td>
  </tr>
  <tr>
    <td align="right" class="TableRow1">显示类型：</td>
    <td class="TableRow1"><input type="radio" name="xtype" id="radio" value="1" <% If xtype=1 Then %>checked<% End If %>>
      全部
        <input name="xtype" type="radio" id="radio2" value="2" <% If xtype=2 Then %>checked<% End If %><% If id=0 Then %>checked<% End If %>>
        滚动
        <input type="radio" name="xtype" id="radio3" value="3" <% If xtype=3 Then %>checked<% End If %>>
        链接</td>
  </tr>
  <tr>
    <td align="right" class="TableRow2">&nbsp;</td>
    <td class="TableRow2"><label><input name="isNew" type="checkbox" id="isNew" value="1" <% If id=0 Then %>checked<% End If %><% If isNew=1 Then %>checked<% End If %>>设为最新公告</label></td>
  </tr>
  <tr>
    <td align="right" class="TableRow1">&nbsp;</td>
    <td class="TableRow1"><input type="submit" name="button" id="button" value="<% If id=0 Then %>添加<% Else %>修改<% End If %>公告">
      &nbsp; 
    <input type="button" name="button2" id="button2" value="公告管理" onClick="location.href='?'"></td>
  </tr>
  </form>
</table>
<%
End Sub

Sub Main()
Dim rs,i,c
%>
<table class="tableBorder" cellspacing="1" cellpadding="2" width="96%" align="center" border="0">
  <tr>
	<th height="25" colspan="8" align="left">管理员设置</th>
  </tr>  
	<tr>
		<td class="BodyTitle" height="23" align="left" colspan="8"></td>
	</tr>
  <tr>
    <td colspan="8" class="TableRow2"><font color="red"><strong>说明</strong>：系统只允许保留20条公告,多余的公告在添加时自动删除。</font></td>
  </tr>
  <tr>
    <td align="center" class="TableRow1"><strong>标题</strong></td>
    <td width="10%" align="center" class="TableRow1"><strong>发布者</strong></td>
    <td width="15%" align="center" class="TableRow1"><strong>发布时间</strong></td>
    <td width="5%" align="center" class="TableRow1"><strong>过期</strong></td>
    <td width="8%" align="center" class="TableRow1"><strong>显示类型</strong></td>
    <td width="8%" align="center" class="TableRow1"><strong>显示位置</strong></td>
    <td width="5%" align="center" class="TableRow1"><strong>最新</strong></td>
    <td width="12%" align="center" class="TableRow1"><strong>管理</strong></td>
  </tr>
<%
Set rs=conn.execute("select * from "&predb&"Announce order by id desc")
do while not rs.eof
i=i+1
if i mod 2=0 Then c=1 else c=2
%>
  <tr>
    <td class="TableRow<%= c %>"><%= rs("title") %></td>
    <td class="TableRow<%= c %>"><%= rs("admin") %></td>
    <td align="center" class="TableRow<%= c %>"><%= rs("addtime") %></td>
    <td align="center" class="TableRow<%= c %>"><%= rs("expired") %>天</td>
    <td align="center" class="TableRow<%= c %>"><% If rs("xtype")=1 Then %>全部<% ElseIf rs("xtype")=2 Then %>滚动<% Else %>链接<% End If %></td>
    <td align="center" class="TableRow<%= c %>"><% If rs("xsite")=1 Then %>首页<% Else %>所有<% End If %></td>
    <td align="center" class="TableRow<%= c %>"><% If rs("isnew")=1 Then %><img src="Images/yes.gif"><% Else %><img src="Images/no.gif"><% End If %></td>
    <td align="center" class="TableRow<%= c %>"><a href="?act=add&id=<%=rs("id")%>">修改</a>&nbsp; <a href="?act=del&id=<%=rs("id")%>" onClick="return confirm('确认删除吗？');">删除</a></td>
  </tr>
<%
rs.movenext
loop
set rs=nothing
%>
  <tr>
    <td colspan="8" class="TableRow2"><input type="button" name="button2" id="button2" value="添加公告" onClick="location.href='?act=add'"></td>
  </tr>
</table>
<%
End Sub
%>
<br>
</body>
</html>
