<!-- #include file="include/admin_onlogin.asp" -->
<!-- #include file="include/jk_em.asp" -->
<%
index_url="mail"
call admin_master(0,0)
call admin_header(0,0)
%>
<tr><td align=center colspan=2 height=30>
  <table border=0>
  <tr>
  <td><a href='?jk_mod=put'<%if jk_mod="put" then response.write " class=red"%>>批量发送<%response.write tit_fir%></a></td>
  <td width=10></td>
  <td><a href='?jk_mod=data'<%if jk_mod="data" then response.write " class=red"%>>清理<%response.write tit_fir%>数据</a></td>
  </tr>
  </table>
</td></tr>
</table>
<%
select case jk_mod
case "put"
  call admin_table(1,1)
  call joekoe_chk_put()
case "data"
  call admin_table(1,1)
  call joekoe_chk_data()
case else
  call admin_table(1,1)
  call joekoe_chk_put()
end select

call admin_ender(1)

sub joekoe_chk_data()
  dim data_type,clear_msg
  call admin_td("清理"&tit_fir&"数据")
  if chk() then
    data_type=trim(request.form("data_type"))
    select case data_type
    case "all"
      sql="delete from "&data_name
    clear_msg="所有"
    case "week"
      sql="delete from "&data_name&" where DateDiff('d',tim,'"&now()&"')>7"
      clear_msg="一周前"
    case else	'"month"
      sql="delete from "&data_name&" where DateDiff('d',tim,'"&now()&"')>30"
    clear_msg="一个月前"
    end select
    call joekoe_cms.exec(sql,0)
    call admin_msg("已成功清理了"&clear_msg&"的"&tit_fir&"数据！",pageurl,1)
    exit sub
  end if
  call form_first()
%>
<tr>
<form name=data_frm action='<%response.write pageurl%>' method=post>
<input type=hidden name=chk value='yes'>
<td class=htd>注意：<br>清除后将不能再恢复</td>
<td>
  <table border=0>
  <tr><td><input type=radio name=data_type value='month' checked>&nbsp;清除一个月前的数据</td></tr>
  <tr><td><input type=radio name=data_type value='week'>&nbsp;清除一周前的数据</td></tr>
  <tr><td><input type=radio name=data_type value='all'>&nbsp;清除所有的<%response.write tit_fir%>数据</td></tr>
  </table>
</td>
</tr>
<tr>
<td></td>
<td><input type=submit value='执行清除操作' onclick="javascript:return click_return('执行清除操作',0);"></td>
</form>
</tr>
<%
end sub

sub joekoe_chk_put()
  dim dim_user,dim_tmp,tmpp,npower,npower_name,topic,word
  dim_user=split(web_dim(19),"|")
  call admin_td("批量发送短信")
  if chk() then
    tmpp=code_admin("npower",1,20)
    topic=code_admin("topic",1,50)
    word=code_admin("word",1,250)
    if topic="" or word="" then
      erase dim_user
      call admin_error("短信主题 和 短信内容 不能为空！")
      exit sub
    end if
    npower=""
    npower_name=""
    if tmpp="_all" then
      npower=tmpp
      npower_name="所有用户"
    else
      for i=0 to ubound(dim_user)
        dim_tmp=split(dim_user(i),":")
        if dim_tmp(0)=tmpp then
          npower=tmpp
          npower_name=dim_tmp(1)
          erase dim_tmp
          exit for
        end if
        erase dim_tmp
      next
    end if
    if npower="" then
      erase dim_user
      call admin_error("接收用户 不能为空！")
      exit sub
    end if
    i=0
    sql="select username from user_data where hidden=1"
    if npower<>"" and npower<>"_all" then sql=sql&" and power='"&npower&"'"
    sql=sql&" order by id"
    set rs=joekoe_cms.exec(sql,1)
    do while not rs.eof
      call joekoe_cms.exec("insert into user_mail(send_u,accept_u,topic,word,tim,types,isread) values ('"&login_username&"','"&rs(0)&"','"&topic&"','"&word&"','"&joekoe_cms.now_time&"',1,0)",0)
      rs.movenext
      i=i+1
    loop
    rs.close
    erase dim_user
    call admin_msg("已成功给 "&npower_name&"（共"&i&"位） 发送了短信！","?jk_mod="&jk_mod,1)
    exit sub
  end if
  call form_first()
%>
<form name=data_frm action='<%response.write pageurl%>' method=post>
<input type=hidden name=chk value='yes'>
<tr>
<td>接收用户组：</td>
<td><select name=npower size=1>
<option value='_all' class=tr1>所有用户</option>
<%
  for i=0 to ubound(dim_user)
    dim_tmp=split(dim_user(i),":")
    response.write vbcrlf&"<option value='"&dim_tmp(0)&"'>"&dim_tmp(1)&"</option>"
    erase dim_tmp
  next
  erase dim_user
%>
</select><%response.write redx%>请在选择发送前确认该操作</td>
</tr>
<tr>
<td>短信主题：</td>
<td><input type=text name=topic value='' size=60 maxlength=20></td>
</tr>
<tr>
<td class=htd>短信内容：<br>EM贴图支持<br>UBB不支持<br>HTML不支持<br>长度<=250字节</td>
<td><textarea name=word rows=7 cols=60></textarea></td>
</tr>
<tr class=tr1>
<td></td>
<td height=40><input type=submit value='执行批量发送短信' onclick="javascript:return click_return('执行批量发送短信',0);"></td>
</tr>
</form>
<%
end sub
%>