home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
bombers.k12.ar.us
/
bombers.k12.ar.us.tar
/
bombers.k12.ar.us
/
survey
/
SendEmailMessageAction.asp
< prev
next >
Wrap
Text File
|
2006-11-29
|
12KB
|
308 lines
<!--#Include File="Include/Top_inc.asp"-->
<%
'***********************************************************************
' Application: SelectSurveyASP Advanced v8.1.5
' Author: Aaron Baril for ClassApps.com
' Page Description: This page is called from SendEmailMessage2.asp and sends the emails
' for the data input on the SendEmailMessage2.asp and
' SendEmailMessage2.asp pages.
'
' COPYRIGHT NOTICE
'
' See attached Software License Agreement
'
' (c) Copyright 2002 - 2006 by ClassApps.com. All rights reserved.
'***********************************************************************
'Buffering must be on for sending emails
Response.Buffer = True
Server.ScriptTimeout = 1500
'If the user does not have "Create" or "Admin" permission, redirect to the access denied page.
If lngUserSecurityLevel <> SUR_SECURITY_LEVEL_CREATE And lngUserSecurityLevel <> SUR_SECURITY_LEVEL_ADMIN Then
Response.Redirect "AccessDenied.asp?Reason=" & SUR_ACCESS_DENIED_NOT_ADMIN_SECURITY_LEVEL
End If
%>
<!--#Include File="Include/SurveyUtility_inc.asp"-->
<!--#Include File="Include/Utility_inc.asp"-->
<!--#Include File="Include/Constants_inc.asp"-->
<!--#Include File="Include/Config_inc.asp"-->
<!--#Include File="Include/ID_inc.asp"-->
<!--#Include File="Include/Email_inc.asp"-->
<!--#Include File="Include/adovbs_inc.asp"-->
<!--#Include File="Include/CurrentUser_inc.asp"-->
<!--#Include File="Include/SurveySecurity_inc.asp"-->
<!--#Include File="Include/Encryption_inc.asp"-->
<html>
<head>
<title>Send Email Message Confirmation</title>
<link rel="stylesheet" href="Resources/StyleSheet/SurveyStyle.css">
</head>
<body class="MainBodyStyle">
<!--#Include File="Include/FrameworkTop_inc.asp"-->
<table border="0" cellspacing="0" cellpadding="0" width="754" class="MediumBlueBackgroundColor">
<tr>
<td height="36" valign="center">
<span class="H1HeadingStyle"><a name="skipnav" tabindex="1">Send Email Message</a></span> <img style="cursor:hand" alt="Help" onClick="javascript:window.open('Help/Help.htm#EmailMessages', null, 'menubar=no,toolbar=no,titlebar=no,status=no,left=10,top=10,scrollbars=yes,resizable=yes,height=550,width=770');" border="0" src="Resources/Images/Help.gif">
</td>
</tr>
</table>
<!--#Include File="Include/FrameworkTop2_inc.asp"-->
<table width="740" border="0" cellpadding="0" cellspacing="6" class="LightGrayBackgroundColor">
<tr>
<td width="1"></td>
<td height="36" valign="center">
<span class="H2HeadingStyle">Email Message Sent</span>
</td>
<td width="1"> </td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td height="1" background="Resources/Images/ThinDivider.gif"></td></tr>
<table border="0" cellpadding="0" cellspacing="6" width="740" class="WhiteBackgroundColor">
<tr>
<td width="1" rowspan="10"></td>
<td>
<br>
<span class="Normal">The following emails were sent:</span>
</td>
<td width="1" rowspan="10"> </td>
</tr>
<tr>
<td width="730" valign="top" height="80">
<span class="Normal">
<%
Dim strBody
Dim strEmailAddress
Dim strFirstName
Dim strLastName
Dim strCustomData1
Dim strCustomData2
Dim strCustomData3
Dim strSQL
Dim rsEmailList
Dim strDisplay
Dim flgEmailInHTMLFormat
Dim lngEmailMessageID
Dim conEmailMessage
Dim lngEmailSentCount
Dim strURLUniqueID
Dim strTempURL
'Initialization
Set rsEmailList = Server.CreateObject("ADODB.Recordset")
Set conEmailMessage = Server.CreateObject("ADODB.Connection")
conEmailMessage.Open SURVEY_APP_CONNECTION
lngEmailMessageID = ID_GetNextAvailableID("SurveyGenerationEmailMessage")
If Request.Form("chkHTMLFormat") = "on" Then
flgEmailInHTMLFormat = True
Else
flgEmailInHTMLFormat = False
End If
lngEmailSentCount = 0
'Insert a record into the email message table for this message
strSQL = "INSERT INTO sur_email_message(email_message_id, email_list_id, email_subject, email_body, " & _
"email_cc_addresses, email_bcc_addresses, email_from_address, html_yn, survey_id, " & _
"sent_date, email_sent_count, email_response_count) VALUES(" & _
lngEmailMessageID & ", " & _
Request.Form("EmailListID") & ", " & _
SQLEncode(Request.Form("txtSubject")) & ", " & _
SQLEncode(Request.Form("txtEmailText")) & ", " & _
SQLEncode(Request.Form("txtCCAddress")) & ", " & _
SQLEncode(Request.Form("txtBCCAddress")) & ", " & _
SQLEncode(Request.Form("txtFromAddress")) & ", "
If flgEmailInHTMLFormat = True Then
strSQL = strSQL & SQLEncode(SUR_BOOLEAN_POSITIVE) & ", "
Else
strSQL = strSQL & SQLEncode(SUR_BOOLEAN_NEGATIVE) & ", "
End If
strSQL = strSQL & Request.Form("cboSurvey") & ", GETDATE(), 0, 0)"
conEmailMessage.Execute ConvertSQL(strSQL), , adCmdText
'Get the list of email addresses for the email list
strSQL = "SELECT email_address_id, email_address, first_name, last_name, custom_data_1, " & _
"custom_data_2, custom_data_3 " & _
"FROM sur_email_address " & _
"WHERE email_list_id = " & Request.Form("EmailListID") & _
" AND deleted_yn = " & SQLEncode(SUR_BOOLEAN_NEGATIVE)
'If the user is filtering the email addresses, add a filter to the query
If CStr(Request.Form("FilterType")) = CStr(SUR_EMAIL_LIST_WITH_FILTER) Then
'Add the filter for the active flag
If Request.Form("Active") <> SUR_COMBO_ALL Then
strSQL = strSQL & " AND active_yn = " & SQLEncode(Request.Form("Active"))
End If
'Add the filter for the email address
If Len(Trim(Request.Form("EmailAddress"))) > 0 Then
strSQL = strSQL & " AND email_address LIKE " & SQLEncodeContains(Request.Form("EmailAddress"))
End If
'Add the filter for the first custom data field
If Len(Trim(Request.Form("CustomData1"))) > 0 Then
strSQL = strSQL & " AND custom_data_1 LIKE " & SQLEncodeContains(Request.Form("CustomData1"))
End If
'Add the filter for the second custom data field
If Len(Trim(Request.Form("CustomData2"))) > 0 Then
strSQL = strSQL & " AND custom_data_2 LIKE " & SQLEncodeContains(Request.Form("CustomData2"))
End If
'Add the filter for the third custom data field
If Len(Trim(Request.Form("CustomData3"))) > 0 Then
strSQL = strSQL & " AND custom_data_3 LIKE " & SQLEncodeContains(Request.Form("CustomData3"))
End If
End If
'Open the list of email addresses
rsEmailList.Open ConvertSQL(strSQL), SURVEY_APP_CONNECTION, adOpenForwardOnly, adLockReadOnly, adCmdText
'Loop through the email addresses
'rsEmailList.MoveFirst
Do While Not rsEmailList.EOF
'Get the text of the email, with tokens.
strBody = Request.Form("txtEmailText")
'Get the email address
strEmailAddress = rsEmailList("email_address")
'Set the first name, if provided, to be used in replacing the token in the email, below
If Len(rsEmailList("first_name")) > 0 Then
strFirstName = Trim(rsEmailList("first_name"))
Else
strFirstName = ""
End If
'Set the last name, if provided, to be used in replacing the token in the email, below
If Len(rsEmailList("last_name")) > 0 Then
strLastName = Trim(rsEmailList("last_name"))
Else
strLastName = ""
End If
'Set the first custom data fields, if provided, to be used in replacing the token in the email, below
If Len(rsEmailList("custom_data_1")) > 0 Then
strCustomData1 = Trim(rsEmailList("custom_data_1"))
Else
strCustomData1 = ""
End If
'Set the second custom data fields, if provided, to be used in replacing the token in the email, below
If Len(rsEmailList("custom_data_2")) > 0 Then
strCustomData2 = Trim(rsEmailList("custom_data_2"))
Else
strCustomData2 = ""
End If
'Set the third custom data fields, if provided, to be used in replacing the token in the email, below
If Len(rsEmailList("custom_data_3")) > 0 Then
strCustomData3 = Trim(rsEmailList("custom_data_3"))
Else
strCustomData3 = ""
End If
'Generate a string to be encrypted as a unique identifier for this email
strURLUniqueID = Encrypt(SUR_ENCRYPTION_EMAIL_PART_1 & Request.Form("cboSurvey") & SUR_ENCRYPTION_EMAIL_PART_2 & rsEmailList("email_address_id") & SUR_ENCRYPTION_EMAIL_PART_3 & lngEmailMessageID & SUR_ENCRYPTION_EMAIL_PART_4)
'Replace all of the tokens
strBody = Replace(strBody, "#FirstName#", strFirstName)
strBody = Replace(strBody, "#LastName#", strLastName)
strBody = Replace(strBody, "#CustomData1#", strCustomData1)
strBody = Replace(strBody, "#CustomData2#", strCustomData2)
strBody = Replace(strBody, "#CustomData3#", strCustomData3)
strTempURL = SUR_APPLICATION_ROOT_URL & "/TakeSurvey.asp?EID=" & strURLUniqueID
If flgEmailInHTMLFormat = True Then
strTempURL = "<a href=""" & strTempURL & """>" & strTempURL & "</a>"
End If
strBody = Replace(strBody, "#SurveyLink#", strTempURL)
strTempURL = SUR_APPLICATION_ROOT_URL & "/DeclineSurvey.asp?EID=" & strURLUniqueID
If flgEmailInHTMLFormat = True Then
strTempURL = "<a href=""" & strTempURL & """>" & strTempURL & "</a>"
End If
strBody = Replace(strBody, "#DeclineLink#", strTempURL)
'Make sure the email address is valid before sending the email
If IsValidEmailAddress(strEmailAddress) = True Then
'Send the email
SendMail strEmailAddress, Request.Form("txtFromAddress"), Request.Form("txtCCAddress"), Request.Form("txtBCCAddress"), strBody, Request.Form("txtSubject"), flgEmailInHTMLFormat
'Track the number of emails sent
lngEmailSentCount = lngEmailSentCount + 1
'Insert a record into the database recording the sent email
strSQL = "INSERT INTO sur_email_sent_history(email_address_id, email_message_id, " & _
"url_unique_id, response_date, response_id, current_status) VALUES(" & _
rsEmailList("email_address_id") & ", " & _
lngEmailMessageID & ", " & _
SQLEncode(strURLUniqueID) & ", " & _
"Null, " & _
"Null, " & _
SQLEncode(SUR_EMAIL_STATUS_NO_RESPONSE) & ")"
conEmailMessage.Execute ConvertSQL(strSQL), , adCmdText
strDisplay = Now() & ": Sent to " & strEmailAddress
If Len(strFirstName) > 0 Or Len(strLastName) > 0 Then
strDisplay = strDisplay & " ("
End If
If Len(strFirstName) > 0 Then
strDisplay = strDisplay & strFirstName & " "
End If
If Len(strLastName) > 0 Then
strDisplay = LTrim(strDisplay) & strLastName
End If
If Len(strFirstName) > 0 Or Len(strLastName) > 0 Then
strDisplay = Trim(strDisplay) & ")"
End If
Response.Write strDisplay & "<br>"
Else 'Email address in not valid
If Len(Trim(strEmailAddress)) > 0 And Trim(strEmailAddress) <> vbCrLf Then
Response.Write Now() & ": INVALID EMAIL ADDRESS: " & strEmailAddress & "<br>"
End If
End If
'Flush after each email so the progress can be seen on the page
Response.Flush
rsEmailList.MoveNext
Loop
'After sending all of the emails, update the email message table with the number of emails sent
strSQL = "UPDATE sur_email_message " & _
"SET email_sent_count = " & lngEmailSentCount & _
" WHERE email_message_id = " & lngEmailMessageID
conEmailMessage.Execute ConvertSQL(strSQL), , adCmdText
'Clean up
conEmailMessage.Close
Set conEmailMessage = Nothing
rsEmailList.Close
Set rsEmailList = Nothing
%>
</span>
<br>
</td>
</tr>
<tr>
<td align="right">
<a href="EmailListList.asp"><img border="0" alt="Click to return to the list of email lists" src="Resources/Buttons/OK.gif" name="btnOK"></a>
<br>
</td>
</tr>
</table>
<!--#Include File="Include/FrameworkBottom_inc.asp"-->
</body>
</html>
<%
'Ensure that the web server returns the page
Response.Flush
%>