<!--#INCLUDE FILE="conn.asp" -->
<!--#INCLUDE FILE="Class_Checkuser.asp" -->
<!--#INCLUDE FILE="Class_Top.asp" -->
<!--#INCLUDE FILE="inc/char.asp" -->
<!--#INCLUDE FILE="inc/HTMLEncode.asp" -->
<!--#INCLUDE FILE="inc/email.asp" -->
<%Server.ScriptTimeOut=99999999

Dim locat

if instr(Request("action"),"Invite")<>0 Then
	locat="邀请同学加入"
Else
	locat="学校邮件组"
End if

if membername="" Then
  	ErrMsg=ErrMsg+"<br>"+"<li>您还没有<a href=Class_Login.asp><font color=red>登录或注册校友录</font></a>。"
	Call top(1,1)
	Call Error("Information",ErrMsg)
	
Else
	Dim ClsID,Degree,ClassName
	ClsID=Request("ClassID")
	joinstatus=chkjoinclass(ClsID)
	if joinstatus<>"" Then
		Call top(1,1)
		Call Error("Exclamation",joinstatus)
	Else
		Select Case Request("action")
		Case "SendInviteMail"
			Call SendInviteMail()
		Case "InviteMail"
			Call top(2,1)
			Call WriteInviteMail()
		Case "SendClassMail"
			Call SendClassMail()
		Case "ClassMail"
			Call top(2,1)
			Call WriteClassMail()
		End Select
	End if
End if


Sub WriteInviteMail()

	Dim rs,sql
	Dim StudList

	sql="Select J.userid,U.realname from student U inner join joinclass J "&_
		"on U.userid=J.userid where J.classid="&ClsID&" order by U.realname desc"
	Set rs=Conn.Execute(sql)


	StudCount=0:StudList=""
	do until rs.eof
		StudList=StudList&rs(1)&"("&rs(0)&")"&"&nbsp;&nbsp;"
		StudCount=StudCount+1
		rs.movenext
	loop
	Set rs=Nothing

	sql = "Select realname,email from student where userid='"&membername&"'"
	Set rs=Conn.Execute(sql)
	MailContent="您好，"&rs(0)&"在"&StrVar(1)&"给你发来一封邀请函:"&vbCrLf&vbCrLf&_
		"    忆往昔峥嵘岁月稠，泛黄的毕业照片、搞笑的毕业留言、上课传的小纸条……青涩的笑容，心动的触摸，阳光般的少年，魂牵梦系的倩影……"&_
		"一切的一切，岁月虽然远去，记忆就像昨天。"&vbCrLf&_
		"    老同学，你一定还记得我们曾经一起走过的日子。到我们的网上家园来歇歇脚吧，喝杯清香的茶，"&_
		"让我们拾起过往，开始叙旧——"&vbCrLf&vbCrLf&_
		"    学校名称："&userschoolname&"--"&ClassName&vbCrLf&_
		"    已有"&StudCount&"位成员："&StudList&vbCrLf&_
		"    学校地址："&SchoolmateURL&"Class_index.asp?Classid="&Clsid&""&vbCrLf&_
		"    校友录地址："&SchoolmateURL&vbCrLf&_
		"    期待着您的加盟!"
	%>
	<script language=JavaScript src=inc/invite.asp></script>
	<!--INCLUDE FILE="inc/sendnow.inc" -->
	<!-- <div id="sponsorAdDiv" style="visibility:hidden;z-index:2">
	<table width="400" height="70" Class=TableBorder border=0 cellspacing=1><tr><td>
	<table width="100%" height="100%"  border=0 cellspacing=0><tr bgcolor="<%=LightTBColor%>"><td>
	&nbsp;&nbsp;&nbsp;&nbsp;正在处理邮件，请稍候......
	</td></tr></table></td></tr></table></div>  -->
	<br><br>
			<form style="MARGIN: 0px" name="sendmail" action="Class_Mail.asp?ClassID=<%=ClsID%>" method="post"
			onsubmit="return submit_invitemail();">
			<INPUT type=hidden value=SendInviteMail name=Action>
			  <input type="hidden" name="mailfrom" value="<%=rs(1)%>">
			  <input type="hidden" name="mailfromname" value="<%=rs(0)%>">		  
			  <table border="0" cellspacing="1" align=center width="700" cellpadding="5" Class=TableBorder>
				<tr>
				  <th colspan=3 align=center>邀请同学加入</th>
				</tr>
				<tr Class=LightTableBody>
				  <td height=40>&nbsp;&nbsp;邮件主题：<input size="53" name="subject" value="<%=StrVar(1)&"邀请函！"%>" readonly> </td><td align=center><input size="20" onKeyPress="return Mailadd()" name=mailadd>&nbsp;<input type=button onClick="javascript:addmail()" value="添加" class=button><input type=button onClick="javascript:delmail()" value="删除" class=button></td>
				</tr>
				<tr  align=center Class=LightTableBody>
				  <td><table cellspacing=4>
						<tr><td>信件正文：</td></tr>
						<tr><td><%response.write "<textarea name=content style=""WIDTH:350px;HEIGHT:187px"""
						if not BoolVar(8) then response.write " readonly"
						response.write ">"&MailContent&"</textarea>"%>
						</td></tr></table>
					</td>
							 <td><table cellspacing=4><tr><td>收件人列表：</td></tr><tr><td><SELECT ondblclick="return delmail()" 
				style="WIDTH: 200px; HEIGHT: 190px" multiple 
				name=maillist></SELECT></td></tr></table></td>
				</tr>
				<tr Class=DarkTableBody>
				  <td height="20" align="center" colspan=3><input
				  style="WIDTH: 80px" type="submit" value="发送邀请函" name="submit" class=button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
				  &nbsp; 
				   </td>
				</tr>
			  </table>
			</form>
			<p><br>
	<%
	Set rs=Nothing

End Sub


Sub SendInviteMail()

	dim SendMailNum

	if chkpost=False Then
		ErrMsg=ErrMsg+"<Br>"+"<li>您提交的数据不合法，请不要从校友录外部提交信息。"
		founderr=true
	ElseIf not sysadmin and Cint(IntVar(7))<>0 then
		SendMailNum=request.cookies("SendMailNum")
		if SendMailNum ="" then SendMailNum=0
		SendMailNum=cint(SendMailNum)
		if SendMailNum>=Cint(IntVar(7)) Then
			ErrMsg=ErrMsg+"<br>"+"<li>操作失败，每次只能发送"&IntVar(7)&"封邮件!"
			founderr=True
		End if		
	End if

	if founderr Then
		Call top(2,1)
		Call Error("Exclamation",ErrMsg)
		Exit Sub
	End if

	if Request("maillist")="" Then
		Errmsg=Errmsg+"<br>"+"<li>收件人列表不能为空。"
		founderr=True
	Else
		mailto=trim(Request("maillist"))
	End if
		
	if Request("subject")="" Then
		Errmsg=Errmsg+"<br>"+"<li>请确认输入了邮件主题。"
		founderr=True
	Else
		mailtopic=trim(Request("subject"))
	End if

	if Request("content")="" Then
		Errmsg=Errmsg+"<br>"+"<li>请确认输入了邮件内容。"
		founderr=True
	Else
		mailbody=rtrim(Request("content"))
	End if

	if founderr=True Then
		Call top(2,1)
		Call Error("Information",ErrMsg)
		Exit Sub
	End if

	mailfrom=Request("mailfrom")
	mailfromname=Request("mailfromname")
	if Cint(IntVar(5))=0 Then
		ErrMsg=ErrMsg+"<br>"+"<li>本校友录不支持发送邮件。</li>"
		Call top(2,1)
		Call Error("Exclamation",ErrMsg)
		Exit Sub
	else
		select case Cint(IntVar(5))
		case 1
			Call jmail_smtp()
		case 2
			Call Cdonts()
		case 3
			Call aspemail()
		case 4
			Call jmail_msg()
		end select

		SendMailNum=SendMailNum+1
		response.cookies("SendMailNum")=SendMailNum

	End if

	Call top(2,1)
	if SendMailStatus="0K" Then
		stitle="邮件发送成功"
		smsg="您已经成功向您的同学发送了邮件。[<a href=Class_Mail.asp?ClassID="&ClsID&"&action=InviteMail><font color=red>返回</font></a>]"
		Call success(stitle,smsg)
	Else
		ErrMsg=ErrMsg+"<br>"+"<li>由于以下原因邮件发送失败！</li>"&"<br><font color=gray>"&SendMailStatus&"</font>"
		Call Error("Exclamation",ErrMsg)
	End if

End Sub


Sub WriteClassMail()

	Dim rs
	Set rs=Conn.Execute("Select email,realname from student where userid='"&membername&"'")
	%>

	<script language=JavaScript src=inc/maillist.asp></script>
	<!--INCLUDE FILE="inc/sendnow.inc" -->
	<!-- <div id="sponsorAdDiv" style="visibility:hidden">
	<table width="400" height="70" Class=TableBorder border=0 cellspacing=1><tr><td>
	<table width="100%" height="100%"  border=0 cellspacing=0><tr bgcolor="<%=LightTBColor%>"><td>
	&nbsp;&nbsp;&nbsp;&nbsp;系统正在处理邮件，请稍候......
	</td></tr></table></td></tr></table></div>  -->

	<br><FORM name=sendmail onSubmit="return sendmail_submit(this);" action="Class_Mail.asp?ClassID=<%=ClsID%>" 
	method=post><INPUT type=hidden value=SendClassMail name=action>
	<TABLE width=580 align=center border=0>
	<TR>
		<TD><IMG SRC="images/classmail.gif" BORDER=0 ALT=""></TD>
	</TR>
	</TABLE>
	
  <TABLE cellSpacing=1 cellPadding=5 width=700 align=center border=0 Class=TableBorder>
    <TBODY>
	   <TR Class=DarkTableBody>
		<TD  height=35 align=center>标&nbsp;&nbsp;题:&nbsp;<INPUT size=28 value="<%=ClassName%>" 
		  name=Subject> </TD>
		<TD  height=35 align=center>回复到:&nbsp;<INPUT size=28 
		  value="<%=rs(0)%>" disabled title="<%=rs(0)%>"><INPUT type=hidden  
		  value="<%=rs(0)%>" name="from"><INPUT type=hidden  
		  value="<%=rs(1)%>" name="fromname"> </TD></TR>
	  <TR Class=LightTableBody>
	  
	  <td><table border=0 width=300 cellpadding=4 align=center>
            <tr><TD >全部邮件列表:</TD></TR>
	  <TR >
		<TD align=middle width=250><%Call classmatelist()%></TD></tr></table></td>

	  <td><table border=0 width=300 cellpadding=4 align=center>
            <tr><TD >发送邮件列表:</TD></TR>
	  <TR >
		<TD align=middle width=250 ><SELECT 
		  ondblclick="return delmail()" style="WIDTH: 300px; HEIGHT: 100px" multiple 
	 name=sendmail></SELECT></TD></tr></table></td>

	</tr>
	  <TR Class=DarkTableBody>
		<TD colSpan=2 height=20 align=right><button valign=top style="height:23" onclick=javascript:addmail()>添加<font face=webdings>4</font></button>&nbsp;<button style="height:23" onclick=javascript:selectall()>全选<font face=webdings>8</font></button>&nbsp;<button style="height:23" onclick=javascript:delmail()>删除<font face=webdings>3</font></button>&nbsp;<button style="height:23" onclick=javascript:delall()>全删<font face=webdings>7</font></button>&nbsp;&nbsp;&nbsp;&nbsp;</TD></TR>
	  <TR Class=LightTableBody><td colspan=2>
	  
	  <table width=90% border=0 align=center cellpadding=4>
	  <tr> <TD height=20>信件内容:</TD></TR>
	  <TR >
		<TD align=middle><TEXTAREA name=Content rows=8 cols=100></TEXTAREA> </TD></TR></table></td></tr>
	  <TR Class=DarkTableBody>
		<TD  colSpan=3 height=20 align=center><table width=90%><tr><td><input type=checkbox name=cc id=cc value="1">&nbsp;<label for=cc>抄送给自己</label></td><td align=right><input type=submit value=发送邮件 name=submit class=button></td></tr></table></TD></TR>
	</TBODY></TABLE></FORM>
	<%
	Set rs=Nothing

End Sub


Sub ClassmateList()

	Dim cmrs,cmsql
	cmsql="Select U.realname,U.email from student U inner join joinclass J on U.userid=J.userid where J.classid="&ClsID&" and J.isauditing=0 and J.userid<>'"&membername&"'"
	Set cmrs=Conn.Execute(cmsql)
	Response.Write "<SELECT ondblclick=""return addmail()"" style=""WIDTH:300px;HEIGHT:100px"" multiple name=allmail>"
	do until cmrs.eof
		Response.Write "<option value="&cmrs(1)&">"&cmrs(0)&"&nbsp;["&cmrs(1)&"]"&"</option>"
		cmrs.movenext
	loop
	Response.Write "</Select>"
	Set cmrs=Nothing

End Sub


Sub SendClassMail()

	dim SendMailNum

	if chkpost=False Then
		ErrMsg=ErrMsg+"<Br>"+"<li>您提交的数据不合法，请不要从校友录外部提交信息。"
		founderr=true
	ElseIf not sysadmin and Cint(IntVar(7))<>0 then
		SendMailNum=request.cookies("SendMailNum")
		if SendMailNum ="" then SendMailNum=0
		SendMailNum=cint(SendMailNum)
		if SendMailNum>=Cint(IntVar(7)) Then
			ErrMsg=ErrMsg+"<br>"+"<li>操作失败，每次只能发送"&IntVar(7)&"封邮件!"
			founderr=True
		End if		
	End if

	if founderr Then
		Call top(2,1)
		Call Error("Exclamation",ErrMsg)
		Exit Sub
	End if

	if Request("Subject")="" Then
		Errmsg=Errmsg+"<br>"+"<li>请确认输入了邮件主题。"
		founderr=True
	Else
		mailtopic=Request("Subject")
	End if

	if Request("from")="" Then
		Errmsg=Errmsg+"<br>"+"<li>请输入回复邮件地址。"
		founderr=True
	'ElseIf not IsValidEmail(Request("from")) Then
	'	Errmsg=Errmsg+"<br>"+"<li>您的Email地址不正确，请到个人资料里修改。"
	'	founderr=True
	Else
		mailfrom=trim(Request("from"))
	End if

	mailfromname=trim(Request("fromname"))

	if Request("sendmail")="" Then
		Errmsg=Errmsg+"<br>"+"<li>您没有选择给谁发信！"
		founderr=True
	Else
		mailto=Request("sendmail")
		if Request("cc")="1" Then mailto=mailfrom&","&mailto
	End if

	if Request("Content")="" Then
		Errmsg=Errmsg+"<br>"+"<li>请确认输入了邮件内容。"
		founderr=True
	Else
		mailbody=rtrim(Request("Content"))&vbCrLf&vbCrLf&_
		string(30,"-")&vbCrLf&ClassName&"："&getrealname(membername)
	End if

	if founderr=True Then
		Call top(2,1)
		Call Error("Information",ErrMsg)
		Exit Sub
	End if


	if Cint(IntVar(5))=0 Then
		ErrMsg=ErrMsg+"<br>"+"<li>本校友录不支持发送邮件。</li>"
		Call top(2,1)
		Call Error("Exclamation",ErrMsg)
		Exit Sub
	else
		select case Cint(IntVar(5))
		case 1
			Call jmail_smtp()
		case 2
			Call Cdonts()
		case 3
			Call aspemail()
		case 4
			Call jmail_msg()
		end select

		SendMailNum=SendMailNum+1
		response.cookies("SendMailNum")=SendMailNum
	End if

	Call top(2,1)
	if SendMailStatus="0K" Then
		stitle="邮件发送成功"
		smsg="您已经成功的向校内所选同学发送了邮件。[<a href=Class_Mail.asp?ClassID="&ClsID&"&action=ClassMail><font color=red>返回</font></a>]"
		Call success(stitle,smsg)
	Else
		ErrMsg=ErrMsg+"<br>"+"<li>由于以下原因邮件发送失败！</li>"&"<br><font color=gray>"&SendMailStatus&"</font>"
		Call Error("Exclamation",ErrMsg)
	End if

End Sub%>

<%Call footer%>