<!--#INCLUDE FILE="setup.asp" -->
<!--#include file=checkuser.asp-->
<title><%=StrVar(1)%>--管理页面</title>
<link href="css.asp" rel="stylesheet" type="text/css">
<!--#include file=theme.css-->
<body class=adminbody>
<%
if  not sysadmin or session("adminlogin")<>"0K" Then
	Errmsg=Errmsg+"<br>"+"<li>本页面为管理员专用，请<a href=superindex.asp target=_top>登陆</a>后进入。"
	Call Error("Information",ErrMsg)
Else
	Call main()
End if

Call endconnection()

Sub main()
%>
<table cellpadding=5 cellspacing=1 border=0 width=100% Class=TableBorder align=center>
<tr>
	<th>欢迎<b><%=membername%></b>进入管理页面</th>
</tr>
</table>
<tr Class=DarkTableBody>
	<td width="100%" valign=top>
		<%
		if Request("action")="send" Then
			Call sendmsg()
		ElseIf Request("action")="delete" Then
			Call delmsg()
		Else
			Call msgform()
		End if
		%>
	</td>
</tr>
</table>
<%
End Sub


Sub msgform()
%>
<BR>
<form method="POST" action=sysadm_sms.asp>
<input type=hidden name=action value=send>
<table width="600" border="0" cellspacing="1" cellpadding="5"  align=center Class=TableBorder>
<!-- <tr> 
<th height="11" colspan="2" align=center><b>短消息发布与管理</b></font></th>
</tr>
 -->
 <tr Class=DarkTableBody> 
<th height="11" colspan="2" >短消息广播</font></th>
</tr>
<tr  Class=LightTableBody> 
<td width="30%" height="18">&nbsp;&nbsp;发送对象</font></td>
<td width="70%" height="18"> 
	<Select name=stype size=1>
	<option value="1">所有班级管理员</option>
	<option value="2">所有同学录用户</option>
	<option value="2">当前在线用户</option>
	</Select>
</td>
</tr>
<tr  Class=LightTableBody> 
<td width="30%" height="18">&nbsp;&nbsp;消息标题</font></td>
<td width="70%" height="18"> 
<input type="text" name="title" size="60" >
</td>
</tr>
<tr   Class=LightTableBody >
<td width="30%" height="18">&nbsp;&nbsp;消息内容</font></td>
<td width="70%" height="18"> 
        <textarea name="content" cols=60 rows=6></textarea>
</td></tr>
<tr Class=DarkTableBody> 
<td height="18" colspan="2" align=right > 
<input type="submit" name="Submit" value="发 送" class=button>&nbsp;&nbsp;<input type="reset" name="reset" value="重 写" class=button>
</td>
</tr>
</table>
</form>
<BR>
<table width="600" border="0" cellspacing="1" cellpadding="5"  align=center Class=TableBorder>
<tr Class=DarkTableBody> 
<th height="11">短消息管理</th>
</tr>
<tr Class=LightTableBody> <form action="sysadm_sms.asp?action=delete" method=post>
<td height="40"><BR><BR>&nbsp;&nbsp;批量删除&nbsp;<Select name="delDate" size=1>
	<option value=7>一个星期前</option>
	<option value=30>一个月前</option>
	<option value=91>三个月前</option>
	<option value=182>半年前</option>
	<option value=365>一年前</option>
	<option value="all">所有信息</option>
	</Select>&nbsp;的短信息					  &nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="isread" value="yes">包括未读信息
			<input type="submit" name="Submit" value="删除" class=button><br><BR></td></form>
</tr>
</table>
<BR>
<%
End Sub


Sub sendmsg()
	Dim rs,sql,sendsql
'on Error resume next
	if Request("title")="" Then
		Errmsg=Errmsg+"<br>"+"<li>请输入短信标题。"
		founderr=True
	Else
		title=trim(checkstr(Request("title")))
	End if

	if Request("content")="" Then
		Errmsg=Errmsg+"<br>"+"<li>请输入短信内容。"
		founderr=True
	Else
		content=rtrim(checkstr(Request("content")))
	End if

	if founderr=True Then 
		Response.Write Errmsg
		Exit Sub
	End if


	if Request("stype")="1" Then
		sql = "Select distinct userid from joinclass where degree>6"
	ElseIf Request("stype")="2" Then
		sql = "Select userid from student"
	End if

	Set rs=conn.execute(sql)
	do until rs.EOF 
		sendsql="insert into message(incept,sender,title,content,sendtime,flag,issend,delS) values('"&rs(0)&"','"&StrVar(1)&"','"&title&"','"&content&"',Now(),0,1,2)"
		conn.Execute(sendsql)
		rs.MoveNext 
	Loop
	rs.Close
	Response.Write "<br><br><center>短信发送成功！</center>"

End Sub


Sub delmsg()

	if Request("isread")="yes" Then
	selflag=""
	Else
	selflag=" and flag=1"
	End if

	howlong=Request("delDate")
	if howlong="all" Then
	sql="delete from message where id>0 "&selflag
	Else
	sql="delete from message where datediff('d',sendtime,Now())>"&cint(howlong)&" "&selflag
	End if 
	conn.Execute(sql)
Response.Write "<br><br><center>短信成功删除！</center>"

End Sub

Function Checkstr(str)
	str=replace(str,"'","''")
	Checkstr=str
End Function

%>



