<!-- #include file="include/admin_onlogin.asp" --> 
<% 
dim remark,dim_tmp,pro,power 
admins=true 
nsort="event" 
index_url="event" 
data_name="user_data" 
tit_fir="群发" 
tit="邮件群发" 
call format_search("username","email,nname",2,1) 
call admin_header(0,0) 
%> 
<table border=0> 
  <tr> 
  <td><%response.write tit_fir%>类型：</td> 
<% call joekoe_user_sort() %> 
  <td width=10></td> 
  <td><a href='?pro=<%response.write pro%>'><b>所有用户</b></a></td> 
  </tr> 
  </table> 
<table border=0> 
   
    <tr> <form action='?' method=get> 
      <td>关键字：</td> 
      <td><input type=text name=keyword value='<%response.write keyword%>' size=15 maxlength=20></td> 
      <td><select name=sea_type size=1> 
          <option value='username'>按用户名</option> 
          <option value='email'>按电子邮件</option> 
          <option value='nname'>按头街</option> 
          </select> 
  </td> 
      <td><select name=sea_term sizs=1> <option value='all'>满足所有条件</option> <option value='only'>满足一个条件</option></seelct> <input type=submit value='搜索'> </td> 
        </form> 
  </tr> 
</table> 

<table width="98%" border="0" align="center"> 
  <tr align=center>  
    <td class=td width='6%'>序号</td> 
    <td class=td width='12%'>用户名</td> 
 <td class=td width='12%'>头街</td> 
    <td class=td width='12%'>邮件地址</td> 
  </tr> 
  <% 
  power=request("power") 
  if power<>"" then  
  sql="select count(id) from "&data_name&sql_add&" where power='"&power&"'" 
  else  
  sql="select count(id) from "&data_name&sql_add 
  end if 
  set rs=joekoe_cms.exec(sql,1) 
  rssum=rs(0) 
  rs.close 
  call format_pagecute() 
  if power<>"" then 
  sql="select top "&nummer*viewpage&" * from "&data_name&sql_add&" where power='"&power&"' order by id desc" 
  else 
  sql="select top "&nummer*viewpage&" * from "&data_name&sql_add&" order by id desc" 
  end if 
  call joekoe_cms.exec(sql,-1) 
  rs.open sql,conn,1,1 
  if int(viewpage)>1 then rs.move (viewpage-1)*nummer 
  if int(viewpage*nummer)>int(rssum) then nums=nummer-(viewpage*nummer-rssum) 
  for i=1 to nums 
%> 
  <tr align=center>  
    <td>  
  
      <%response.write (viewpage-1)*nummer+i%> 
    </td> 
    <td>  
 <%=rs("username")%> 
       
    </td> 
   <td>  
 <%=rs("nname")%> 
       
    </td> 
    <td>  
 <a href="?email=<%=rs("email")%>"><%=rs("email")%></a> 
    </td> 
  </tr> 
  <% 
    rs.movenext 
  next 
  rs.close 
%> 
  <tr class=tr1>  
    <td colspan=4> 现有<font class=red>  
      <%response.write rssum%> 
      </font>条  
      <%response.write tit_fir%> 
      ， 每页<font class=red>  
      <%response.write nummer%> 
      </font>条， 页次：<font class=red>  
      <%response.write viewpage%> 
      </font>/<font class=red>  
      <%response.write thepages%> 
      </font> 分页：  
      <%response.write jk_pagecute(nummer,thepages,viewpage,pageurl,5,"#ff0000")%> 
    </td> 
  </tr> 
</table> 
<table width="799" border="0" align="center"> 
  <tr> 
    <td><form name="form2" method="post" action=""> 
        <table width="100%" border="0" align="center"> 
          <tr bgcolor="#F9F8EC">  
            <td width="279"> <div align="right">邮件地址</div></td> 
            <td width="510"> <input name="email" type="text" id="email" value="<%=request("email")%>" size="50"> 
              群发邮件地址为空</td> 
          </tr> 
          <tr bgcolor="#F9F8EC">  
            <td> <div align="right">邮件主题</div></td> 
            <td> <input name="Subject" type="text" id="Subject" size="50"></td> 
          </tr> 
          <tr bgcolor="#F9F8EC">  
            <td><div align="right">邮件内容</div></td> 
            <td><textarea name="Body" COLS="50" ROWS="10"></TEXTAREA> </td> 
          </tr> 
          <tr bgcolor="#F9F8EC">  
            <td> <div align="right"></div></td> 
            <td><input name="Send" type="submit" id="Send2" value="发送"> </td> 
          </tr> 
          <tr bgcolor="#F9F8EC">  
            <td> <div align="right"></div></td> 
            <td> </td> 
          </tr> 
        </table> 
      </form></td> 
  </tr> 
</table> 
<% 
dim Subject,Body,mail,email,jmail,sendmail,send_jmail 
Subject=request("Subject")'邮件主题 
Body=request("Body")'邮件内容 
mail=request("email") 
if request("send")<>"" then 
   if Body="" then 
      Response.Write "<script>alert('请输入邮件内容！');history.back();</Script>" 
      Response.End 
   end if 
   if Subject="" then 
      Response.Write "<script>alert('请输入邮件主题！');history.back();</Script>" 
      Response.End 
   end if 
   if mail<>"" then 
      email=mail 
      call sentemail(email,Subject,Body) 
      response.write "已经成功向 <b>"&email&"</b> 发送EMAIL" 
   else 
      i=0 
      set rs=server.createobject("adodb.recordset") 
      if power<>"" then 
      sql="select top "&nummer*viewpage&" * from "&data_name&sql_add&" where power='"&power&"' order by id desc" 
      else 
      sql="select top "&nummer*viewpage&" * from "&data_name&sql_add&" order by id desc" 
      end if 
      rs.open sql,conn,1,1 
      do while not rs.eof  
      email=rs("email") 
      sendmail=sentemail(email,Subject,Body) 
      i=i+1 
      rs.movenext 
      loop 
      rs.close 
      set rs=nothing 
      conn.close 
      set conn=nothing 
    
    if sendmail then 
    if i>0 then 
         response.write "已经成功向 <b>"&i&"</b> 个用户发送EMAIL"&email 
      else 
         response.write "数据表中没有记录<br>" 
    
      end if 
     else 
    response.write"<font class=red2>系统配置不正常，注册邮件没有能正确发送！</font>" 
  end if 
       
  end if 
end if 
function sentemail(email,Subject,Body) 
on error resume next 
Set jmail = Server.CreateObject("JMAIL.Message") '建立发送邮件的对象 
'jmail.silent = true '屏蔽例外错误，返回FALSE跟TRUE两值j 
'Jmail.logging = true '启用邮件日志 
jmail.Charset = "GB2312" '邮件的文字编码为国标 
jmail.ContentType = "text/html" '邮件的格式为HTML格式 
jmail.AddRecipient email '邮件收件人的地址 
jmail.From = "jkweb@163.com" '发件人的E-MAIL地址 
jmail.MailServerUserName = "qulai505@163.com" '登录邮件服务器所需的用户名 
jmail.MailServerPassword = "00000" '登录邮件服务器所需的密码 
jmail.Subject = Subject '邮件的标题  
jmail.Body = Body '邮件的内容 
jmail.Send("smtp.163.com") '执行邮件发送（通过邮件服务器地址） 
'jmail.Close() '关闭对象 
Set Jmail=nothing 
  sentemail=true 
if err then 
    err.clear 
    sentemail=false 
  end if 
end function 



sub joekoe_user_sort() 
  dim dp 
  dp=false 
  for i=0 to ubound(dim_user) 
    dim_tmp=split(dim_user(i),":") 
    response.write vbcrlf&"  <td width=5></td>" & _ 
     vbcrlf&"  <td><a href='?pro="&pro&"&power="&dim_tmp(0)&"'" 
    if power=dim_tmp(0)then 
      dp=true 
      tit_name=dim_tmp(1) 
      response.write " class=red" 
    end if 
    response.write ">"&dim_tmp(1)&"</a></td>" 
  next 
  if dp=false then 
    power="" 
  end if 
end sub 
%> 
