<!--#include file="conn.asp"-->
<!-- #include file="inc/const.asp" -->
<!-- #include file="inc/DvADChar.asp" -->
<%
	Head()	
	dim admin_flag
	admin_flag=",6,"
	if not Dvbbs.master or instr(","&session("flag")&",",admin_flag)=0 then
		Errmsg=ErrMsg + "<BR><li>本页面为管理员专用，请<a href=admin_index.asp target=_top>登录</a>后进入。<br><li>您没有管理本页面的权限。"
		dvbbs_error()
	else
		dim body
		if Request("action")="add" then
			call savemsg()
		elseif request("action")="del" then
			call del()
		elseif request("action")="delall" then
			call delall()
		elseif request("action")="delchk" then
			call delchk()
		else
			call sendmsg()
		end if
%>
<p align=center><%=body%></p></font>
<%
	Footer()
	end if

sub savemsg()
	dim sendtime,sender
	sendtime=Now()
	sender=Dvbbs.Forum_info(0)
	set rs = server.CreateObject ("adodb.recordset")
	If Not IsObject(Conn) Then ConnectionDatabase
	select case request("stype")
	case 1
	sql="select username from dv_online where userid>0"
	rs.open sql,conn,1,1
	do while not rs.eof
	sql="insert into dv_message(incept,sender,title,content,sendtime,flag,issend) values('"&rs(0)&"','"&sender&"','"&TRim(Request("title"))&"','"&Trim(Request("message"))&"',"&SqlNowString&",0,1)"
	Dvbbs.Execute(sql)
	update_user_msg(Rs(0))
	rs.movenext
	loop
	rs.close
	case 2
    sql = "select username from [dv_user] where usergroupid=8 order by userid desc"
    rs.Open sql,conn,1,1
    do while not rs.EOF 

	sql="insert into dv_message(incept,sender,title,content,sendtime,flag,issend) values('"&rs(0)&"','"&sender&"','"&TRim(Request("title"))&"','"&Trim(Request("message"))&"',"&SqlNowString&",0,1)"
	Dvbbs.Execute(sql)
	update_user_msg(Rs(0))
	rs.MoveNext 
	Loop
	rs.Close
	case 3
    sql = "select username from [dv_user] where usergroupid=3 order by userid desc"
    rs.Open sql,conn,1,1
    do while not rs.EOF 

	sql="insert into dv_message(incept,sender,title,content,sendtime,flag,issend) values('"&rs(0)&"','"&sender&"','"&TRim(Request("title"))&"','"&Trim(Request("message"))&"',"&SqlNowString&",0,1)"
	Dvbbs.Execute(sql)
	update_user_msg(Rs(0))
	rs.MoveNext 
	Loop
	rs.Close
	case 4
    sql = "select username from [dv_user] where usergroupid=1 order by userid desc"
    rs.Open sql,conn,1,1
    do while not rs.EOF 
	sql="insert into dv_message(incept,sender,title,content,sendtime,flag,issend) values('"&rs(0)&"','"&sender&"','"&TRim(Request("title"))&"','"&Trim(Request("message"))&"',"&SqlNowString&",0,1)"
	Dvbbs.Execute(sql)
	update_user_msg(Rs(0))
	rs.MoveNext 
	Loop
	rs.Close
	case 5
    sql = "select username from [dv_user] where usergroupid<4 order by userid desc"
    rs.Open sql,conn,1,1
    do while not rs.EOF 

	sql="insert into dv_message(incept,sender,title,content,sendtime,flag,issend) values('"&rs(0)&"','"&sender&"','"&TRim(Request("title"))&"','"&Trim(Request("message"))&"',"&SqlNowString&",0,1)"
	Dvbbs.Execute(sql)
	update_user_msg(Rs(0))
	rs.MoveNext 
	Loop
	rs.Close
	case 6
    sql = "select username from [dv_user] order by userid desc"
    rs.Open sql,conn,1,1
    do while not rs.EOF 

	sql="insert into dv_message(incept,sender,title,content,sendtime,flag,issend) values('"&rs(0)&"','"&sender&"','"&TRim(Request("title"))&"','"&Trim(Request("message"))&"',"&SqlNowString&",0,1)"
	Dvbbs.Execute(sql)
	update_user_msg(Rs(0))
	rs.MoveNext 
	Loop
	rs.Close
	end select
	set rs=nothing
	body=body+"<br>"+"操作成功！请继续别的操作。"
end sub

sub sendmsg()
%>
<table width="95%" border="0" cellspacing="0" cellpadding="0"  align=center class="tableBorder">
                <tr> 
                  <th colspan="2" height=24>论坛短信管理
                  </th>
                </tr>
            <form action="admin_message.asp?action=del" method=post>
                <tr> 
                  <td colspan="2" class=ForumrowHighLight>
                      批量删除某用户短消息（主要用于删除系统批量信息：动网小精灵）：<br><input type="text" name="username" size="20">
			<input type="submit" name="Submit" value="提 交">
                  </td>
                </tr>
            </form>
			<form action="admin_message.asp?action=delall" method=post>
                <tr> 
                  <td colspan="2" class=ForumrowHighLight>
                      批量删除用户指定日期内短消息（默认为删除已读信息）：<br>
					  <select name="delDate" size=1>
						<option value=7>一个星期前</option>
						<option value=30>一个月前</option>
						<option value=60>两个月前</option>
						<option value=180>半年前</option>
						<option value="all">所有信息</option>
					  </select>
					  &nbsp;<input type="checkbox" name="isread" value="yes">包括未读信息
			<input type="submit" name="Submit" value="提 交">
                  </td>
                </tr>
            </form>
			<form action="admin_message.asp?action=delchk" method=post>
                <tr> 
                  <td colspan="2" class=ForumrowHighLight>
				  批量删除含有某关键字短信（注意：本操作将删除所有已读和未读信息）：<br>
				  关键字：<input type="text" name="keyword" size=30>&nbsp;在
					  <select name="selaction" size=1>
						<option value=1>标题中</option>
						<option value=2>内容中</option>
					  </select>
					  &nbsp;<input type="submit" name="Submit" value="提 交">
                  </td>
                </tr>
            </form>
                <tr> 
                  <th colspan="2" height=24>论坛短信广播
                  </th>
                </tr>
            <form action="admin_message.asp?action=add" method=post>
                <tr> 
                  <td width="22%" class=Forumrow>消息标题</td>
                  <td width="78%" class=Forumrow> 
                    <input type="text" name="title" size="70">
                  </td>
                </tr>
                <tr> 
                  <td width="22%" class=Forumrow>接收方选择</td>
                  <td width="78%" class=Forumrow> 
                    <select name=stype size=1>
					<option value="1">所有在线用户</option>
					<option value="2">所有贵宾</option>
					<option value="3">所有版主</option>
					<option value="4">所有管理员</option>
					<option value="5">贵宾/版主/管理员</option>
					<option value="6">所有用户</option>
					</select>
                  </td>
                </tr>
                <tr> 
                  <td width="22%" height="20" valign="top" class=Forumrow>
                    <p>消息内容</p>
                    <p>(<font color="red">HTML代码支持</font>)</p>
                  </td>
                  <td width="78%" height="20" class=Forumrow> 
                    <textarea name="message" cols="80" rows="10"></textarea>
                  </td>
                </tr>
                <tr> 
                  <td width="22%" height="23" valign="top" align="center" class=Forumrow> 
                    <div align="left"> </div>
                  </td>
                  <td width="78%" height="23" class=Forumrow> 
                    <div align="center"> 
                      <input type="submit" name="Submit" value="发送消息">
                      <input type="reset" name="Submit2" value="重新填写">
                    </div>
                  </td>
                </tr>
            </form>
              </table>
<%
end sub

sub del()
	if request("username")="" then
		body=body+"<br>"+"请输入要批量删除的用户名。"
		exit sub
	end if
	sql="delete from dv_message where sender='"&request("username")&"'"
	Dvbbs.Execute(sql)
	body=body+"<br>"+"操作成功！请继续别的操作。"
end sub

sub delall()
	dim selflag
	if request("isread")="yes" then
	selflag=""
	else
	selflag=" and flag=1"
	end if
	select case request("delDate")
	case "all"
	sql="delete from dv_message where id>0 "&selflag
	case 7
	if IsSqlDataBase=1 then
	sql="delete from dv_message where datediff(d,sendtime,"&SqlNowString&")>7 "&selflag
	else
	sql="delete from dv_message where datediff('d',sendtime,"&SqlNowString&")>7 "&selflag
	end if
	case 30
	if IsSqlDataBase=1 then
	sql="delete from dv_message where datediff(d,sendtime,"&SqlNowString&")>30 "&selflag
	else
	sql="delete from dv_message where datediff('d',sendtime,"&SqlNowString&")>30 "&selflag
	end if
	case 60
	if IsSqlDataBase=1 then
	sql="delete from dv_message where datediff(d,sendtime,"&SqlNowString&")>60 "&selflag
	else
	sql="delete from dv_message where datediff('d',sendtime,"&SqlNowString&")>60 "&selflag
	end if
	case 180
	if IsSqlDataBase=1 then
	sql="delete from dv_message where datediff(d,sendtime,"&SqlNowString&")>180 "&selflag
	else
	sql="delete from dv_message where datediff('d',sendtime,"&SqlNowString&")>180 "&selflag
	end if
	end select
	Dvbbs.Execute(sql)
	body=body+"<br>"+"操作成功！请继续别的操作。"
end sub

sub delchk()
	if request.form("keyword")="" then
	body="请输入关键字！"
	exit sub
	end if
	if request.form("selaction")=1 then
	Dvbbs.Execute("delete from dv_message where title like '%"&replace(request.form("keyword"),"'","")&"%'")
	body="操作成功！请继续别的操作。"
	elseif request.form("selaction")=2 then
	Dvbbs.Execute("delete from dv_message where content like '%"&replace(request.form("keyword"),"'","")&"%'")
	body="操作成功！请继续别的操作。"
	else
	body="未指定相关参数！"
	exit sub
	end if
End Sub
Function inceptid(stype,iusername)
	Dim ars
	set ars=Dvbbs.Execute("Select top 1 id,sender from dv_Message Where flag=0 and issend=1 and delR=0 And incept ='"& iusername &"'")
	if stype=1 then
	inceptid=ars(0)
	else
	inceptid=ars(1)
	end if
	set ars=nothing
End Function
Function update_user_msg(username)
	Dim msginfo
	If newincept(username)>0 Then
		msginfo=newincept(username) & "||" & inceptid(1,username) & "||" & inceptid(2,username)
	Else
		msginfo="0||0||null"
	End If
	Dvbbs.Execute("update [dv_user] set UserMsg='"&dvbbs.CheckStr(msginfo)&"' where username='"&dvbbs.CheckStr(username)&"'")
End Function
'统计留言
Function newincept(iusername)
	Dim rs
	Rs=Dvbbs.Execute("Select Count(id) from dv_Message Where flag=0 and issend=1 and delR=0 And incept='"& iusername &"'")
	newincept=Rs(0)
	Set Rs=Nothing
	If IsNull(newincept) Then newincept=0
End Function
%>