<!-- #Include File="Include/AMH_onlogin.asp" -->
<!-- #Include File="../Include/Cls_UbbCode.asp" -->
<%
'=======================================================
' 欢迎使用《阿赛大型门户网站系统V2.0》，简称“AsaiMHV2”
' 技术支持、商业版咨询、官方唯一指定联系QQ“4941172”
' 官方网站：http://77ya.com      程序负责人：阿赛
'=======================================================

Index_Url="mail"
call AMH_master(0,0)
Call AMH_Header(1)
%>
<tr><td align=center colspan=2 height=30>
  <table border=0>
  <tr>
  <td><a href='?'><%Response.Write tit%></a></td>
  <td width=10></td>
  <td><a href='?AsaiMHMod=put'<%if AsaiMHMod="put" then Response.Write " class=red"%>>批量发送<%Response.Write tit_fir%></a></td>
  <td width=10></td>
  <td><a href='?AsaiMHMod=data'<%if AsaiMHMod="data" then Response.Write " class=red"%>>清理<%Response.Write tit_fir%>数据</a></td>
  </tr>
  </table>
</td></tr>
</table>
<%
call AMH_table(1)
select case AsaiMHMod
case "put"
  call AsaiMHChk_Put()
case "data"
  call AsaiMHChk_Data()
case "view"
  call AsaiMHChk_View()
case else
  call AsaiMHChk_Main()
end select
Call AMH_Ender(tit)
sub AsaiMHChk_Data()
  dim data_type,clear_msg,data_isread
  call AMH_td("清理"&tit_fir&"数据")
  if chk() then
    data_type=trim(request.form("data_type"))
    data_isread=trim(request.form("data_isread"))
    select case data_type
    case "all"
	if data_isread="yes" then
      sql="delete from "&Data_Name&" where isread=1"
     clear_msg="所有已阅读的"
    else
      sql="delete from "&Data_Name
     clear_msg="所有"
    end if
    case "week"
	if data_isread="yes" then
      sql="delete from "&Data_Name&" where DateDiff("&s_d&",tim,"&s_tim&")>7 and isread=1"
     clear_msg="一周前已阅读的"
    else
      sql="delete from "&Data_Name&" where DateDiff("&s_d&",tim,"&s_tim&")>7"
     clear_msg="一周前"
    end if
    case else	'"month"
	if data_isread="yes" then
      sql="delete from "&Data_Name&" where DateDiff("&s_d&",tim,"&s_tim&")>30 and isread=1"
     clear_msg="一个月前已阅读的"
	else
      sql="delete from "&Data_Name&" where DateDiff("&s_d&",tim,"&s_tim&")>30"
     clear_msg="一个月前"
    end if
    end select
    call Cls.exec(sql,0)
    call AMH_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 width='20%' class=htd>注意：<br />清除后将不能再恢复</td>
<td width='80%'>
<table border=0>
 <tr>
 <td width=180>
  <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>
 <td width=*>
  <table border=0>
  <tr><td><input type=radio name=data_isread value='yes' checked>&nbsp;<font class=blue>已阅读的</font></td></tr>
  <tr><td><input type=radio name=data_isread value='all'>&nbsp;<font class=red>所有短信</font></td></tr>
  </table>
 </td>
 </tr>
</table>
</td>
</tr>
<tr>
<td></td>
<td><input type=submit value='执行清除操作' onclick="javascript:return click_return('执行清除操作',0);" class=btn></td>
</form>
</tr>
<%
end sub
sub AsaiMHChk_Put()
  dim dim_user,tmpp,npower,npower_name,topic,word,emoney,eint,doing,suser,suser_dim,j
  dim_user=Cls.Cache_Get("User_Group")
  call AMH_td("批量发送短信")
  if chk() then
    tmpp=Cls.Code_Admin("npower",1,20)
    topic=Cls.Code_Admin("topic",1,50)
    word=Cls.Code_Admin("word",1,250)
    suser=Cls.Code_Admin("suser",1,250)
    emoney=trim(request.form("emoney"))
    eint=trim(request.form("ints"))
    if not isnumeric(emoney) or emoney="" or isnull(emoney) then
      emoney=0
    else
      emoney=int(emoney)
    end if
    if not isnumeric(eint) or eint="" or isnull(eint) then
      eint=0
    else
      eint=int(eint)
    end if
    doing=trim(request.form("doing"))
    if doing<>0 then doing=1
    if doing=0 then
      emoney=-emoney
      eint=-eint
    end if
    if topic="" or word="" then
      call AMH_error("短信主题 和 短信内容 不能为空！")
      exit sub
    end if
    if suser="" or isnull(suser) then
      npower=""
      npower_name=""
      if tmpp="_all" then
        npower=tmpp
        npower_name="所有用户"
      else
        for i=0 to ubound(dim_user,2)
         if dim_user(0,i)=tmpp then
           npower=tmpp
           npower_name=dim_user(1,i)
           exit for
         end if
        next
      end if
      if npower="" then
        call AMH_error("接收用户 不能为空！")
        exit sub
      end if
      i=0
      sql="select username,id from AsaiMHUserData where hidden=1"
      if npower<>"" and npower<>"_all" then sql=sql&" and power='"&npower&"'"
      sql=sql&" order by id"
      call Cls.exe_conn(rs,sql,3)
      do while not rs.eof
       if emoney>0 or eint>0 then call Cls.exec("update AsaiMHUserData set emoney=emoney+"&emoney&",integral=integral+"&eint&"  where username='"&rs(0)&"'",0)
       call Cls.exec("insert into AsaiMHUserMail(send_u,accept_u,topic,word,tim,types,isread) values ('"&login_username&"','"&rs(0)&"','"&topic&"','"&word&"','"&Cls.now_time&"',1,0)",0)
       rs.movenext
       i=i+1
      loop
      rs.close
	else
      suser_dim=split(suser,"|")
      i=0
      for j=0 to ubound(suser_dim)
        sql="select top 1 username,id from AsaiMHUserData where hidden=1 and username='"&suser_dim(i)&"' order by id"
		call Cls.exe_conn(rs,sql,3)
        if not rs.bof then
		  if emoney<>0 or eint<>0 then call Cls.exec("update AsaiMHUserData set emoney=emoney+"&emoney&",integral=integral+"&eint&"  where username='"&rs(0)&"'",0)
		  call Cls.exec("insert into AsaiMHUserMail(send_u,accept_u,topic,word,tim,types,isread) values ('"&login_username&"','"&rs(0)&"','"&topic&"','"&word&"','"&Cls.now_time&"',1,0)",0)
		  i=i+1
        end if
        rs.close
      next
      erase suser_dim
    end if
    call AMH_msg("已成功给 "&npower_name&"（共"&i&"位） 发送了短信！","?AsaiMHMod="&AsaiMHMod,1)
    exit sub
  end if
  call form_first()
%>
<script language=javascript>
<!--
function isCharsInBag(inputchar)
{
  var ii,cc;
  var bagchar="0123456789";
  for (ii = 0; ii < inputchar.length; ii++)
  {
  cc = inputchar.charAt(ii);
    if (bagchar.indexOf(cc) > -1)
    {
      return "no";
    }
    else
    {
      return "yes";
    }
  }
}
function show_word()
{
  var ne=document.data_frm.emoney.value;
  var ni=document.data_frm.ints.value;
  var dos=document.data_frm.doing.options[document.data_frm.doing.selectedIndex].value;
  var tmp1="";
  var tmp2="";
  var tmp3="";
  if (isCharsInBag(ne)=="yes")
  {
    alert("<%=Web_Dim(8)%>只能是数字并为正数！");
    document.data_frm.emoney.focus();
    return false;
  }
  if (isCharsInBag(ni)=="yes")
  {
    alert("积分只能是数字并为正数！");
    document.data_frm.ints.focus();
    return false;
  }
  if (dos==0)
  {
  tmp2="处罚";
  tmp3="由于您在本站的表现令人失望，";
  }
  if (dos==1)
  {
  tmp2="奖励";
  tmp3="为感谢您对本站的贡献，";
  }
  if (ne!=="" && ne!=null) { tmp1+=tmp3+'特此'+tmp2+'您 '+ne+' 个<%Response.Write Web_Dim(8)%>！\n'; }
  if (ni!=="" && ni!=null) { tmp1+=tmp3+'特此'+tmp2+'您 '+ni+' 个积分！'; }
  if (ne!=="" && ne!=null || ni!=="" && ni!=null)
  {
  document.data_frm.word.value=tmp1;
  document.data_frm.topic.value=tmp2+'通知';
  }
  else
  {
  document.data_frm.word.value="";
  document.data_frm.topic.value="";
  }
}
-->
</script>
<form name=data_frm action='<%Response.Write pageurl%>' method=post>
<input type=hidden name=chk value='yes'>
<tr>
<td width='20%'>接收用户组：</td>
<td width='80%'><select name=npower size=1>
<option value='_all' class=tr1>所有用户</option>
<%
  for i=0 to ubound(dim_user,2)
    Response.Write vbcrlf&"<option value='"&dim_user(0,i)&"'>"&dim_user(1,i)&"</option>"
  next
%>
</select><%Response.Write redx%>请在选择发送前确认该操作。<font class=red>如果以下输入了单独用户，则此选项失效</font></td>
</tr>
<tr>
<td>单独用户：</td>
<td><input type=text name=suser value='' size=60 maxlength=250>&nbsp;&nbsp;多个用户请用“|”分隔开！</td>
</tr>
<tr>
<td>奖罚操作：</td>
<td><select name=doing size=1>
<option value=1>奖励</option>
<option value=0>处罚</option>
</select>&nbsp;&nbsp;<%Response.Write Web_Dim(8)%>&nbsp;<input type=text name=emoney value='' size=5 maxlength=3>
&nbsp;&nbsp;积分&nbsp;<input type=text name=ints value='' size=5 maxlength=3>&nbsp;&nbsp;&nbsp;&nbsp;<input type=button onclick="javascript:show_word();" value='生成主题及内容' class=btn>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%call AMH_read("操作","短信奖惩功能说明","请先输入奖惩数值，然后点击“生成主题及内容”按钮，生成此次奖惩相关内容；如不进行奖罚操作时，可不填写奖惩数值，并且此时按钮将无效！ ")%></td>
</tr>
<tr>
<td>短信主题：</td>
<td><input type=text name=topic value='' size=60 maxlength=20></td>
</tr>
<%Response.Write ShowUBBEditor("","data_frm","word","内容","","Default",560,200)%>

<tr class=tr1>
<td></td>
<td height=40><input type=submit value='执行批量发送短信' onclick="javascript:return click_return('执行批量发送短信',0);" class=btn>&nbsp;&nbsp;&nbsp;&nbsp;<input type=reset value='重新填写' class=btn></td>
</tr>
</form>
<%
end sub
sub AsaiMHChk_View()
  dim accept_u,send_u,isread,word
  call AMH_td(tit_fir&"浏览")
  sql="select top 1 * from AsaiMHUserMail where id="&id
  set rs=Cls.exec(sql,1)
  if rs.eof then
    rs.close
    call AMH_msg(tit_fir&"ID（"&id&"）不存在！","?",1)
    exit sub
  end if
  accept_u=rs("accept_u")
  send_u=rs("send_u")
  word=rs("word")
  isread=rs("isread")
  'word=Cls.Code_Html(word,2,0)
  word=Ubb.Ubbcode(word)
%>
<tr class=tr1><td colspan=2 height=30><B>短信主题</B>：<font class=red2><%Response.Write Cls.Code_Html(rs("topic"),1,0)%></font></td></tr>
<tr><td colspan=2 align=center height=100>
  <table border=0 width='96%' class=tf>
  <tr><td class=bw><%Response.Write word%></td></tr>
  </table>
</td></tr>
<tr class=tr1><td colspan=2 height=30 align=center>
  <table border=0 width='100%'>
  <tr class=tr1>
  <td>发送者：<%Response.Write format_user_view(rs("send_u"),1,0)%>　按收者：<%Response.Write format_user_view(rs("accept_u"),1,0)%>　时间：<u><%Response.Write Cls.time_type(rs("tim"),2)%></u></td>
  <td align=right><%Response.Write go_back%></td>
  </tr>
  </table>
</td></tr>
<%
  rs.close
end sub
sub AsaiMHChk_Main()
  dim nid,topic,types,tim,isread,td_temp,read_pic,read_alt,sel_id,hdim,hnum,hid,hi,htype
  if action="handle" then
    sel_id=trim(request.form("sel_id"))
    sel_id=replace(sel_id," ","")
    hdim=split(sel_id,",")
    hnum=ubound(hdim)
    for hi=0 to hnum
      hid=hdim(hi)
      if isnumeric(hid) then call Cls.exec("delete from "&Data_Name&" where id="&hid,0)
    next
    call AMH_msg("已成功删除了"&(hnum+1)&"条"&tit_fir,pageurl,1)
  end if
  Cls.LoadTemplate(0)
%>
<form name=sel_form action='<%Response.Write pageurl%>action=handle' method=post>
<tr align=center>
<td class=td width='6%'>序号</td>
<td class=td width='5%'>图</td>
<td class=td width='15%'>发送者</td>
<td class=td width='40%'><%Response.Write tit_fir%>主题</td>
<td class=td width='15%'>接收者</td>
<td class=td width='14%'>发送时间</td>
<td class=td width='5%'><input type=checkbox name=sel_all value='yes' onclick="javascript:select_all(this.form);"></td>
</tr>
<%
  dim obj_page
  set obj_page=new Cls_PageCute
  obj_page.pageurl=pageurl			
  obj_page.nummer=nummer						
  obj_page.page_t=1									
  obj_page.page_p=5									
  obj_page.page_unit="条"
  obj_page.page_tit=tit_fir
  obj_page.v_id="id"
  call obj_page.p_init("*",Data_Name,sql_add,"id desc")
  sql=obj_page.sql_count
  set rs=Cls.exec(sql,1)
  obj_page.rssum=rs(0)
  rs.close
  call obj_page.p_main("*",Data_Name,sql_add,"id desc")
  for i=1 to obj_page.page_num
    nid=rs("id")
    topic=rs("topic")
    types=rs("types")
    isread=rs("isread")
    tim=rs("tim")
    read_pic="state_old"
    read_alt="已读"
    if isread=false then
      read_alt="未读"
      read_pic="state_new"
    end if
    if types=2 then
      read_alt="草稿"
      read_pic="state_send"
    end if
%>
<tr align=center>
<td class=tims><%Response.Write obj_page.page_now+i%></td>
<td><img src='<%Response.Write Cls.web_skindir%>mail/<%Response.Write read_pic%>.gif' border=0 alt='<%Response.Write read_alt%>'></td>
<td><%Response.Write format_user_view(rs("send_u"),1,0)%></td>
<td align=left><a href='?AsaiMHMod=view&id=<%Response.Write nid%>'><%Response.Write Cls.Code_Html(topic,1,0)%></a></td>
<td><%Response.Write format_user_view(rs("accept_u"),1,0)%></td>
<td><font alt='<%Response.Write Cls.time_type(tim,2)%>' class=tims><%Response.Write Cls.time_type(tim,3)%></font></td>
<td><input type=checkbox name=sel_id value='<%Response.Write nid%>'></td>
</tr>
<%
    rs.movenext
  next
  rs.close
%>
<tr class=tr1>
<td colspan=5>
  <table border=0>
  <tr class=tr1>
  <td></td>
  <td><%Response.Write obj_page.page_var%></td>
  <td width=3></td>
  <td>分页：</td>
  <td><%Response.Write obj_page.page_cute%></td>
  </tr>
  </table>
</td>
<td colspan=2 align=center>
<select name=sel_type size=1>
<option value='删除'>删除</option>
</select>
<input type=submit value='操作' onclick="return sel_click(this.form);" class=btn>
</td>
</tr>
</form>
<%
end sub
%>
