<!--#include file="../conn.asp"-->
<!--#include file="admin_check.asp"-->
<!--#include file="../inc/function.asp"-->
<!--#include file="../inc/editor/class_fckeditor.asp"-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>管理页面</title>
<link id="maincss" rel="stylesheet" href="images/css/admin_style_<%= AdminSkin %>.css" type="text/css" media="all" />
<script language="javascript">
function CheckAll()
{
var length = document.formed.checkbox.length;
var tocheck = document.formed.SelectAll.checked;

  if (length>=2)
  {
    for (var i=0; i<length; i++){document.formed.checkbox[i].checked = tocheck;}
   }
  else
  {
    document.formed.checkbox.checked = tocheck;    
  }
   
}
</script>
<script language="javascript" src="../inc/AjaxAans.js"></script>
</head>
<body leftmargin="0" bottommargin="0" rightmargin="0" topmargin="5" marginheight="0" marginwidth="0" bgcolor="#DDEEFF">
<%
Call chkFlag(17)
opendb
Dim AskD
Set AskD = Server.CreateObject("KwAsk.FunAsk")
	set AskD.myConn =conn
	AskD.myPredb =predb
	AskD.Getsetting()
	siteinfo=AskD.siteinfo
	setting=AskD.setting
	regForm=AskD.regForm
Dim act
act=Trim(Request.QueryString("act"))

Select Case act
	Case "send"
	  Call send()
	Case else
	   Call Main()
End Select
set AskD.myConn =Nothing
closedb
Set AskD = Nothing

Sub Send()
Dim From,FromName,Topic,MailBody,ToMail,SmtpName,SmtpPass,MailSmtp,rs,ToMails,ToMailp,i,tempstr,Isgo
	Topic=Trim(Request.Form("topic"))
	MailBody=Trim(Request.Form("Content"))
	ToMail=Trim(Request.Form("tomail"))
	MailSmtp=setting(39)
	SmtpName=setting(40)
	SmtpPass=setting(41)
	From=setting(42)
	FromName=siteInfo(4)
	
	IF Instr(ToMail,"|")=0 Then
	   IF instr(Tomail,"@")=0 Then
			Set rs=conn.execute("select Usermail from "&predb&"user where isActivated=1 and userid='"&ToMail&"'")
			IF (rs.bof and rs.eof) Then
			    Call SendMsg("接收对象不存在或邮箱未激活！")
			    Response.Write("<script>setTimeout(""history.go(-1)"",2000)</script>")
			    Response.End()
			ElseIF rs(0)="" or isnull(rs(0)) Then
				Call SendMsg("接收对象邮件为空！")
				Response.Write("<script>setTimeout(""history.go(-1)"",2000)</script>")
				Response.End()
			Else
			    ToMail=rs(0)
			End IF
			Set rs=nothing
		    Call AskD.SendMail(From,FromName,Topic,MailBody,ToMail,SmtpName,SmtpPass,MailSmtp)
			IF Isgo then 
				tempstr="'"&ToMail&"'邮件发送成功！"
			Else
				tempstr="'"&ToMail&"'邮件发送失败！"
			End IF
	   Else
		    Call AskD.SendMail(From,FromName,Topic,MailBody,ToMail,SmtpName,SmtpPass,MailSmtp)
			IF Isgo then 
				tempstr="'"&ToMail&"'邮件发送成功！"
			Else
				tempstr="'"&ToMail&"'邮件发送失败！"
			End IF
	   End IF
	Else
	   ToMails=split(ToMail,"|")
	   For i=0 To Ubound(ToMails)
		   IF ToMails(i)<>"" Then
			   IF instr(ToMails(i),"@")=0 Then
					Set rs=conn.execute("select Usermail from "&predb&"user where isActivated=1 and userid='"&ToMails(i)&"'")
					IF  rs.bof and rs.eof Then
						tempstr=tempstr&"接收对象'"&ToMails(i)&"'不存在或邮箱未激活！<br>"
					ElseIF rs(0)="" or isnull(rs(0)) Then
                        tempstr=tempstr&"接收对象'"&ToMails(i)&"'的邮件为空！<br>"
					Else
						ToMailp=rs(0)
						Call AskD.SendMail(From,FromName,Topic,MailBody,ToMailp,SmtpName,SmtpPass,MailSmtp)
						IF Isgo then 
							tempstr=tempstr&"'"&ToMails(i)&"'邮件发送成功！<br>"
						Else
							tempstr=tempstr&"'"&ToMails(i)&"'邮件发送失败！<br>"
						End IF
					End IF
					Set rs=nothing
			   Else
					Call AskD.SendMail(From,FromName,Topic,MailBody,ToMails(i),SmtpName,SmtpPass,MailSmtp)
					IF Isgo then 
					    tempstr=tempstr&"'"&ToMails(i)&"'邮件发送成功！<br>"
					Else
					    tempstr=tempstr&"'"&ToMails(i)&"'邮件发送失败！<br>"
					End IF
			   End IF
		   End IF
	   Next
	End IF
	Call SendMsg("发送邮件成功！")
End Sub

Sub Main()
%>
<table class="tableBorder" cellspacing="1" cellpadding="2" width="96%" align="center" border="0">
  <tr>
	<th height="25" colspan="2" align="left">邮件发送管理</th>
  </tr>
  <form method="post" action="?act=send" name="formed">
  <tr>
    <td width="21%" align="right" class="TableRow1">邮件标题：</td>
    <td width="79%" class="TableRow1"><input name="topic" type="text" id="topic" size="50" maxlength="50">
    <span class="xing">*</span>50字符以内</td>
  </tr>
  <tr>
    <td align="right" class="TableRow2">接收对象：</td>
    <td class="TableRow2"><input name="tomail" type="text" id="tomail" size="50" value="<%= Trim(Request.QueryString("user")) %>">
      <br>
      <span class="xing">*</span>多个用户用“|”隔开；可直接填写邮件地址或用户名(<font color="#FF0000">给多用户发送将严重增加服务器负担</font>)</td>
  </tr>
  <tr>
    <td align="right" class="TableRow1">邮件内容：</td>
    <td class="TableRow1" id="input0" style="position:relative">
    <textarea name="Content" onFocus="getmAjax('M',this.value)" onKeyDown="ChkPut(this,nr,250)" onKeyUp="ChkPut(this,nr,250)" id="Content" cols="68" rows="12"></textarea></td>
  </tr>
  <tr>
    <td align="right" class="TableRow2">&nbsp;</td>
    <td class="TableRow2"><input type="submit" name="button" id="button" value="确认发送">
      &nbsp; <input type="button" name="button2" id="button2" value="返回管理" onClick="location.href='?'">
      <% If Trim(Request.QueryString("user"))<>"" Then %>&nbsp; <input type="button" name="button2" id="button2" value="返回用户管理" onClick="location.href='admin_user.asp'"><% End If %>
      </td>
  </tr>
  </form>
</table>
<%
End Sub
%>
<br>
</body>
</html>
