<!-- #include file="include/onlogin.asp" -->
<!-- #include file="include/conn.asp" -->

<%  
tit="<a href='admin_mail.asp?action=addmail'>短信群发</a> ┋ " & _
     "<a href='admin_mail.asp?action=mg'>短信管理</a> ┋ " & _
       "<a href='admin_mail.asp?action=maillist'>导出邮件</a> ┋ " & _
     "<a href='admin_mail.asp?action=adde'>用户积分群管理</a> ┋"
response.write header(7,tit)
dim actions:actions=trim(request.querystring("actions"))
select case action
case "add"
  call savemsg()
case "addmail"
  call addmail()
case "mg"
  call mg()
case "clear_message"
  call clear_message()
case "addemoney"
  call saveemoney ()
case "maillist"
  call maillist()
case "adde"
  call addetb()
end select

sub clear_message()
  dim clear_msg
  select case actions
  case "week"
    sql="delete from user_mail where DateDiff('d',tim,'"&now_time&"')>7"
    'sql="delete from user_mail where datediff(""d"",tim,'"&now_time&"')>7"
    clear_msg="一周前"
  case "all"
    sql="delete from user_mail"
    clear_msg="所有"
  case else
    sql="delete from user_mail where DateDiff('d',tim,'"&now_time&"')>30"
    'sql="delete from user_mail where datediff(""d"",tim,'"&now_time&"')>30"
    clear_msg="一个月前"
  end select
  conn.execute(sql)
  response.write "<script language=javascript>alert(""成功清理了"&clear_msg&"的用户短信息！"");</script>"
 end sub

    sub savemsg()
    dim topic,word,isok
    topic=trim(request.form("topic"))
    word=trim(request.form("word"))
 if var_null(topic)="" or len(topic)>20 then
     isok=1   
 end if
 if var_null(word)="" or len(word)>500 then
      isok=2   
 end if
 if isok="" then
	dim tim
	tim=Now()
	set rs = server.CreateObject ("adodb.recordset")
	select case request("stype")
	case 1
	sql="select l_username from user_login where l_id>0"
	rs.open sql,conn,1,1
	do while not rs.eof
	sql="insert into user_mail(accept_u,send_u,topic,word,tim,types,isread) values('"&rs(0)&"','"&login_username&"','"&TRim(Request("topic"))&"','"&TRim(Request("word"))&"',Now(),1,false)"
	conn.Execute(sql)
	rs.movenext
	loop
	rs.close
	case 2
    sql = "select username from user_data where power='vip' order by id desc"
    rs.Open sql,conn,1,1
    do while not rs.EOF 

	sql="insert into user_mail(accept_u,send_u,topic,word,tim,types,isread) values('"&rs(0)&"','"&login_username&"','"&TRim(Request("topic"))&"','"&TRim(Request("word"))&"',Now(),1,false)"
	conn.Execute(sql)
	rs.MoveNext 
	Loop
	rs.Close
	case 3
     sql = "select username from user_data where power='super' order by id desc"
    rs.Open sql,conn,1,1
    do while not rs.EOF 

	sql="insert into user_mail(accept_u,send_u,topic,word,tim,types,isread) values('"&rs(0)&"','"&login_username&"','"&TRim(Request("topic"))&"','"&TRim(Request("word"))&"',Now(),1,false)"
	conn.Execute(sql)
	rs.MoveNext 
	Loop
	rs.Close
	case 4
    sql = "select username from user_data where power='admin' order by id desc"
    rs.Open sql,conn,1,1
    do while not rs.EOF 

	sql="insert into user_mail(accept_u,send_u,topic,word,tim,types,isread) values('"&rs(0)&"','"&login_username&"','"&TRim(Request("topic"))&"','"&TRim(Request("word"))&"',Now(),1,false)"
	conn.Execute(sql)
	rs.MoveNext 
	Loop
	rs.Close
	case 5
    sql = "select username from user_data where power='puser' order by id desc"
    rs.Open sql,conn,1,1
    do while not rs.EOF 

	sql="insert into user_mail(accept_u,send_u,topic,word,tim,types,isread) values('"&rs(0)&"','"&login_username&"','"&TRim(Request("topic"))&"','"&TRim(Request("word"))&"',Now(),1,false)"
	conn.Execute(sql)
	rs.MoveNext 
	Loop
	rs.Close
	case 6
    sql = "select username from user_data order by id desc"
    rs.Open sql,conn,1,1
    do while not rs.EOF 

	sql="insert into user_mail(accept_u,send_u,topic,word,tim,types,isread) values('"&rs(0)&"','"&login_username&"','"&TRim(Request("topic"))&"','"&TRim(Request("word"))&"',Now(),1,false)"
	conn.Execute(sql)
	rs.MoveNext 
	Loop
	rs.Close
	end select
	set rs=nothing
	response.write "<font class=red>您已成功的发送了短信！</font><br><br><a href='admin_mail.asp?action=addmail'>点击返回</a>"
	else if isok=1 then
	        response.write "<font class=red>短信主题不能为空且长度不能大于20！</font>"
	     ELSE
	        response.write "<font class=red>短信内容</font> 不能为空且长度不能大于500！</font>"  
	     END IF
	END IF     
	
end sub
sub addmail()
%>
<div align="center">
  <center>
<table width="500" border="1" cellspacing="0" cellpadding="3" class="tableBorder" style="border-collapse: collapse" bordercolor="#808080">
                <tr> 
                  <th colspan="2" width="663">群发短信
                  </th>
                </tr>
            <form action="admin_mail.asp?action=add" method=post>
                <tr> 
                  <td width="83" class=Forumrow>消息标题</td>
                  <td width="588" class=Forumrow> 
                    <input type="text" name="topic" size="70">
                  </td>
                </tr>
                <tr> 
                  <td width="83" class=Forumrow>接收方选择</td>
                  <td width="588" class=Forumrow> 
                    <select name=stype size=1>
					<option value="1">所有在线用户</option>
					<option value="2">所有VIP</option>
					<option value="3">所有版主</option>
					<option value="4">所有管理员</option>
					<option value="5">所有认证会员</option>
					<option value="6">所有用户</option>
					</select>
                  </td>
                </tr>
                <tr> 
                  <td width="83" height="20" valign="top" class=Forumrow>
                    <p>消息内容</p>
                    <p>(<font color="">UBB代码支持</font>)</p>
                  </td>
                  <td width="588" height="20" class=Forumrow> 
                    <textarea name="word" cols="80" rows="10"></textarea>
                  </td>
                </tr>
                <tr> 
                  <td width="83" height="23" valign="top" align="center" class=Forumrow> 
                    <div align="left"> </div>
                  </td>
                  <td width="588" height="23" class=Forumrow> 
                    <div align="center"> 
                      <input type="submit" name="Submit" value="发送消息">
                      <input type="reset" name="Submit2" value="重新填写">
                    </div>
                  </td>
                </tr>
            </form>
              </table></center>
</div>
<% end sub
sub mg()
 %>
<table>
<tr align=center height=80>
<td><font class=red_3>清理用户短信息</font></td>
<td class=htd>点击下面的按钮将重新清理用户短信息的数据信息，建议每隔一段时间运行一次。<br>
<input type=button value='清除一个月前的短信' onclick="javascript:clear_message('month');" class=red style="width:140px;">&nbsp;&nbsp;
<input type=button value='清除一周前的短信' onclick="javascript:clear_message('week');" class=red style="width:120px;">&nbsp;&nbsp;
<input type=button value='全部清空' onclick="javascript:clear_message('all');" class=red>
</td>
</tr>
</table>
<script language=JavaScript>
<!--
function clear_message(cv)
{
  if (confirm("此操作将 清理用户短信息！\n\n真的要进行吗？\n\n更新后将无法恢复！"))
    window.location="?action=clear_message&actions="+cv
}
//-->
</script>
<% end sub %>


<%
sub saveemoney()
    dim word,isok,r1,u_n,topic,num,y
    word=trim(request.form("word"))
    r1=trim(request.form("r1"))
    u_n=trim(request.form("user"))
    num=trim(request.form("num"))
    if var_null(word)=""  or len(word)>500 then
      isok=1   
    end if
if var_null(num)="" or (not isnumeric(request.form("num"))) then
 isok=2
end if
if r1="" then 
  isok=2
end if
select case request("r1")
 case "integral"
  y="点积分"
 case "emoney"
  y="枚金币"
 case "usercp"
  y="点魅力"
 case "userpower"
  y="点威望"
end select

if isok="" then
	dim tim
	tim=Now()
    if u_n="" then 
	   set rs = server.CreateObject ("adodb.recordset")
	   select case request("stype")
	   case 1
	   'topic="社区奖励所有在线用户的通知"
	   sql="select l_username from user_login where l_id>0"
	   rs.open sql,conn,1,1
	   do while not rs.eof
	   sql="insert into user_mail(accept_u,send_u,topic,word,tim,types,isread) values('"&rs(0)&"','"&login_username&"','社区奖励您"&num&""&y&"','"&TRim(Request("word"))&"',Now(),1,false)"
	   conn.Execute(sql)
	   sql="update user_data set "&r1&"="&r1&"+"&num&" where username='"&rs(0)&"'"
       conn.execute(sql)
	   rs.movenext
	   loop
	   sql="insert into bbs_cast (sort,username,topic,word,tim) values('forum','"&login_username&"','社区奖励所有在线用户"&num&""&y&"','"&TRim(Request("word"))&"',Now())"
       conn.Execute(sql) 
	   rs.close
	   
	   case 2
	   'topic="社区奖励所有VIP用户的通知"
       sql = "select username from user_data where power='vip' order by id desc"
       rs.Open sql,conn,1,1
       do while not rs.EOF 
	   sql="insert into user_mail(accept_u,send_u,topic,word,tim,types,isread) values('"&rs(0)&"','"&login_username&"','社区奖励您"&num&""&y&"','"&TRim(Request("word"))&"',Now(),1,false)"
	   conn.Execute(sql)
	   sql="update user_data set "&r1&"="&r1&"+"&num&" where username='"&rs(0)&"'"
       conn.execute(sql)
	   rs.MoveNext 
	   Loop
	   sql="insert into bbs_cast (sort,username,topic,word,tim) values('forum','"&login_username&"','社区奖励所有VIP用户"&num&""&y&"','"&TRim(Request("word"))&"',Now())"
       conn.Execute(sql) 
	   rs.Close
	   case 3
	   'topic="社区奖励所有版主用户的通知"
       sql = "select username from user_data where power='super' order by id desc"
       rs.Open sql,conn,1,1
       do while not rs.EOF 
	   sql="insert into user_mail(accept_u,send_u,topic,word,tim,types,isread) values('"&rs(0)&"','"&login_username&"','社区奖励您"&num&""&y&"','"&TRim(Request("word"))&"',Now(),1,false)"
	   conn.Execute(sql)
	   sql="update user_data set "&r1&"="&r1&"+"&num&" where username='"&rs(0)&"'"
       conn.execute(sql)
	   rs.MoveNext 
	   Loop
	   sql="insert into bbs_cast (sort,username,topic,word,tim) values('forum','"&login_username&"','社区奖励所有版主用户"&num&""&y&"','"&TRim(Request("word"))&"',Now())"
       conn.Execute(sql) 
	   rs.Close
	   case 4
       sql = "select username from user_data where power='admin' order by id desc"
       rs.Open sql,conn,1,1
       do while not rs.EOF 
	   sql="insert into user_mail(accept_u,send_u,topic,word,tim,types,isread) values('"&rs(0)&"','"&login_username&"','社区奖励您"&num&""&y&"','"&TRim(Request("word"))&"',Now(),1,false)"
	   conn.Execute(sql)
	   sql="update user_data set "&r1&"="&r1&"+"&num&" where username='"&rs(0)&"'"
       conn.execute(sql)
	   rs.MoveNext 
	   Loop
	   sql="insert into bbs_cast (sort,username,topic,word,tim) values('forum','"&login_username&"','社区奖励所有管理员"&num&""&y&"','"&TRim(Request("word"))&"',Now())"
       conn.Execute(sql) 
	   rs.Close
	   case 5
	  '社区奖励所有会员用户的通知"
       sql = "select username from user_data where power='puser' order by id desc"
       rs.Open sql,conn,1,1
       do while not rs.EOF 
	   sql="insert into user_mail(accept_u,send_u,topic,word,tim,types,isread) values('"&rs(0)&"','"&login_username&"','社区奖励您"&num&""&y&"','"&TRim(Request("word"))&"',Now(),1,false)"
	   conn.Execute(sql)
	   sql="update user_data set "&r1&"="&r1&"+"&num&" where username='"&rs(0)&"'"
       conn.execute(sql)
	   rs.MoveNext 
	   Loop
	   sql="insert into bbs_cast (sort,username,topic,word,tim) values('forum','"&login_username&"','社区奖励所有会员用户"&num&""&y&"','"&TRim(Request("word"))&"',Now())"
       conn.Execute(sql) 
	   rs.Close
	   case 6
	 '"社区奖励所有用户的通知"
       sql = "select username from user_data order by id desc"
       rs.Open sql,conn,1,1
       do while not rs.EOF 
	   sql="insert into user_mail(accept_u,send_u,topic,word,tim,types,isread) values('"&rs(0)&"','"&login_username&"','社区奖励您"&num&""&y&"','"&TRim(Request("word"))&"',Now(),1,false)"
	   conn.Execute(sql)
	   sql="update user_data set "&r1&"="&r1&"+"&num&" where username='"&rs(0)&"'"
       conn.execute(sql)
	   rs.MoveNext 
	   Loop
	   sql="insert into bbs_cast (sort,username,topic,word,tim) values('forum','"&login_username&"','社区奖励所有用户"&num&""&y&"','"&TRim(Request("word"))&"',Now())"
       conn.Execute(sql) 
	   rs.Close
	   end select
	   set rs=nothing
	   response.write "<font class=red>您已成功的的进行啦操作！</font><br><br><a href='admin_mail.asp?action=adde'>点击返回</a>"
	else  
	  '单个用户操作
      set rs = server.CreateObject ("adodb.recordset")
      sql="update user_data set "&r1&"="&r1&"+"&num&" where username='"&u_n&"'"
      conn.execute(sql)
      sql="insert into user_mail(accept_u,send_u,topic,word,tim,types,isread) values('"&u_n&"','"&login_username&"','社区奖励您"&num&""&y&"','"&TRim(Request("word"))&"',Now(),1,false)"
	  conn.Execute(sql)
      sql="insert into bbs_cast (sort,username,topic,word,tim) values('forum','"&login_username&"','社区奖励用户"&u_n&""&num&""&y&"','"&TRim(Request("word"))&"',Now())"
      conn.Execute(sql) 
      'rs.close
      set rs=nothing
       response.write "<font class=red>您已成功的的进行啦操作！</font><br><br><a href='admin_mail.asp?action=adde'>点击返回</a>"
	end if   
else
      if isok=1 then
	      response.write "<font class=red>奖励理由不能为空！</font><br><br><a href='admin_mail.asp?action=adde'>点击返回</a>"
	  ELSE
	     response.write "<font class=red>奖励的分值不能为空或者小于0的数</font><br><br><a href='admin_mail.asp?action=adde'>点击返回</a>"
	  END IF
end if     	
end sub
sub addetb()
%>
<div align="center">
  <center>
<table width="635" border="1" cellspacing="0" cellpadding="3" class="tableBorder" style="border-collapse: collapse" bordercolor="#808080">
                <tr> 
                  <th colspan="2" width="726">用户分值群操作</th>
                </tr>
            <form action="admin_mail.asp?action=addemoney" method=post>
                <tr> 
                  <td width="155" class=Forumrow>选择用户</td>
                  <td width="651" class=Forumrow> 
                    <select name=stype size=1>
					<option value="1">所有在线用户</option>
					<option value="2">所有VIP</option>
					<option value="3">所有版主</option>
					<option value="4">所有管理员</option>
					<option value="5">所有认证会员</option>
					<option value="6">所有用户</option>
					</select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  奖励单个会员请填写：<INPUT name=user size="20"></td>
                </tr>
                <tr> 
                  <td width="155" class=Forumrow>属性：</td>
                  <td width="651" class=Forumrow> 
                    &nbsp;<input type="radio" value="emoney" name="R1" checked>&nbsp; 金币&nbsp;&nbsp; 
                    <input type="radio" value="integral" name="R1"> 积分&nbsp;&nbsp; 
                    <input type="radio" value="usercp" name="R1">&nbsp;&nbsp;魅力
                    <input type="radio" value="userpower" name="R1">&nbsp;&nbsp;威望</td>
                </tr>

                <tr> 
                  <td width="155" class=Forumrow>操作分值</td>
                  <td width="651" class=Forumrow> 
                    <input type="text" name="num" size="16">
                    <font color="#FF0000">（建议不要太多，呵呵）奖励的分值不能为空或者小于0的数</font></td>
                </tr>
                <tr> 
                  <td width="155" height="20" valign="top" class=Forumrow>
                    <p>操作理由（请仔细填写，将会出现在<font color="#FF0000">论坛公告里和用户的邮件通知里</font></p>
                    <p>(<font color="">UBB代码支持</font>)</p>
                  </td>
                  <td width="651" height="20" class=Forumrow> 
                    <textarea name="word" cols="74" rows="16"></textarea>
                  </td>
                </tr>
                <tr> 
                  <td width="155" height="23" valign="top" align="center" class=Forumrow> 
                    <div align="left"> </div>
                  </td>
                  <td width="651" height="23" class=Forumrow> 
                    <div align="center"> 
                      <input type="submit" name="Submit" value="确认操作">
                      <input type="reset" name="Submit2" value="重新填写">
                    </div>
                  </td>
                </tr>
            </form>
              </table></center>
</div>
<% end sub
%>
<%
call close_conn()
response.write ender()
%>
<%sub maillist()%>

<form action="admin_mail.asp?action=maillist&type=show" method=post name="frmAnnounce">
<div align="center">
  <center>
  <table border="0" width="100%" cellspacing="1" bgcolor="#555555" cellpadding="2" style="border-collapse: collapse" bordercolor="#111111">
    <tr>
      <td width="594" bgcolor="#FFFFFF" colspan="2" background="../images/bg1.gif">
        <p><font color="#000000"><b>导出邮件列表</b></font></td>
    </tr>
    <tr>
      <td width="77" bgcolor="#FFFFFF" nowrap bordercolor="#808080">
        用户类别：</td>
      
      <select size="1" name="power">
<option value="user"<%if request("power")="user" then%> selected<%end if%>>注册用户</option>
<option value="puser"<%if request("power")="puser" then%> selected<%end if%>>认证会员</option>
<option value="vip"<%if request("power")="vip" then%> selected<%end if%>>VIP 用户</option>
<option value="super"<%if request("power")="super" then%> selected<%end if%>>论坛版主</option>
<option value="admin"<%if request("power")="admin" then%> selected<%end if%>>管理员</option>
<option value=""<%if request("power")="" then%> selected<%end if%>>所有用户</option>
        </select> <input type=submit value="导出" name=Submit></td>
    </tr>
<%if request("type")="show" then%>
    <tr>
      <td width="77" bgcolor="#FFFFFF" valign="top" nowrap>
        邮件列表：</td>
      <td width="512" bgcolor="#FFFFFF">
        <textarea cols=46 rows=24 name="body"><%dim ddd
Set rs= Server.CreateObject("ADODB.Recordset")
if request("power")<>"" then
ddd=" and power='"&request("power")&"'"
end if
rs.open "select email from User_data where email<>''"&ddd&"",conn,1,1
if rs.eof and rs.bof then
i=0
else
do while not rs.eof%><%=rs("email")&chr(13)%><%
i=i+1
rs.movenext
loop
end if
rs.close
set rs=nothing
%></textarea></td>
    </tr>
    <tr>
      <td width="77" bgcolor="#FFFFFF" nowrap background="../images/bg1.gif">
       导出数量：</td>
      <td width="512" bgcolor="#FFFFFF" background="../images/bg1.gif">
        <font color="#FF0000"><%=i%></font></td>
    </tr>
<%end if%>
    </table>
  </center>
</div>
</form><%end sub%>