home *** CD-ROM | disk | FTP | other *** search
/ bombers.k12.ar.us / bombers.k12.ar.us.tar / bombers.k12.ar.us / survey_unconfigured / SendFollowUpMessageAction.asp < prev    next >
Text File  |  2006-10-25  |  10KB  |  263 lines

  1. <!--#Include File="Include/Top_inc.asp"-->
  2. <%
  3. '***********************************************************************
  4. '   Application: SelectSurveyASP Advanced v8.1.11
  5. '   Author: Aaron Baril for ClassApps.com
  6. '   Page Description: This page is called from SendReportShareMessage.asp and sends the emails
  7. '                      for the data input on the previous page.
  8. '
  9. '   COPYRIGHT NOTICE                                
  10. '
  11. '   See attached Software License Agreement
  12. '
  13. '   (c) Copyright 2002 - 2006 by ClassApps.com.  All rights reserved.
  14. '***********************************************************************
  15.  
  16.     'Buffering must be on for sending emails
  17.     Response.Buffer = True
  18.     Server.ScriptTimeout = 1500
  19.  
  20.     Dim lngEmailMessageID
  21.     Dim rsEmailAddresses
  22.     Dim strSelectedStatuses
  23.     Dim strSQL
  24.     Dim strEmailAddresses
  25.     Dim conEmailAddresses
  26.     Dim flgEmailInHTMLFormat
  27.     Dim lngEmailSentCount
  28.     Dim strBody
  29.     Dim strSentEmailAddresses
  30.     Dim lngSurveyID
  31.     Dim strSurveyName
  32.     Dim rsSurvey
  33.     Dim strEmailAddress
  34.     Dim strFirstName
  35.     Dim strLastName
  36.     Dim strCustomData1
  37.     Dim strCustomData2
  38.     Dim strCustomData3
  39.     Dim strTempURL
  40.                 
  41.     'Initialization
  42.     lngEmailMessageID = Request.Form("EmailMessageID")
  43.     Set rsEmailAddresses = Server.CreateObject("ADODB.Recordset")
  44.     Set rsSurvey = Server.CreateObject("ADODB.Recordset")
  45.     Set conEmailAddresses = Server.CreateObject("ADODB.Connection")
  46.     conEmailAddresses.Open SURVEY_APP_CONNECTION
  47.     If Request.Form("chkHTMLFormat") = "on" Then
  48.         flgEmailInHTMLFormat = True
  49.     Else
  50.         flgEmailInHTMLFormat = False
  51.     End If
  52.     lngEmailSentCount = 0
  53.  
  54.     'Get the survey ID and survey name
  55.     strSQL = "SELECT s.survey_id, title " & _
  56.              "FROM sur_email_message em, sur_survey s " & _
  57.              "WHERE em.survey_id = s.survey_id " & _
  58.              "AND email_message_id = " & lngEmailMessageID
  59.     rsSurvey.Open ConvertSQL(strSQL), conEmailAddresses, adOpenForwardOnly, adLockReadOnly, adCmdText
  60.     rsSurvey.MoveFirst
  61.     lngSurveyID = rsSurvey("survey_id")
  62.     strSurveyName = rsSurvey("title")
  63.     rsSurvey.Close
  64.     Set rsSurvey = Nothing
  65.     
  66.     'If the user does not either own this survey or have admin permission, deny them access to this functionality.
  67.     If IsUserOwnerOrAdmin(lngSurveyID) = False Then
  68.         Response.Redirect "AccessDenied.asp?Reason=" & SUR_ACCESS_DENIED_NOT_OWNER_FOR_RESULTS_SHARING
  69.     End If
  70.     
  71.     'Create a string for us in the query with the list of statuses to query on
  72.     If Request.Form("NoResponse") = "on" Then
  73.         strSelectedStatuses = strSelectedStatuses & SQLEncode(SUR_EMAIL_STATUS_NO_RESPONSE) & ", "
  74.     End If
  75.     If Request.Form("Declined") = "on" Then
  76.         strSelectedStatuses = strSelectedStatuses & SQLEncode(SUR_EMAIL_STATUS_DECLINED) & ", "
  77.     End If
  78.     If Request.Form("Responded") = "on" Then
  79.         strSelectedStatuses = strSelectedStatuses & SQLEncode(SUR_EMAIL_STATUS_RESPONDED) & ", "
  80.     End If
  81.     strSelectedStatuses = Left(strSelectedStatuses, Len(strSelectedStatuses) - 2)
  82.     
  83.     'Get the list of email recipient to send to
  84.     strSQL = "SELECT url_unique_id, email_address, first_name, last_name, custom_data_1, custom_data_2, custom_data_3 " & _
  85.              "FROM sur_email_address ea, sur_email_sent_history esh " & _
  86.              "WHERE ea.email_address_id = esh.email_address_id " & _
  87.              "AND email_message_id = " & lngEmailMessageID & _
  88.              " AND current_status IN (" & strSelectedStatuses & ")"
  89.     rsEmailAddresses.Open ConvertSQL(strSQL), conEmailAddresses, adOpenForwardOnly, adLockReadOnly, adCmdText
  90.     If rsEmailAddresses.EOF = False Then
  91.         rsEmailAddresses.MoveFirst
  92.         Do While Not rsEmailAddresses.EOF
  93.         
  94.             'Get the email address
  95.             strEmailAddress = rsEmailAddresses("email_address")
  96.                                 
  97.             'Set the first name, if provided, to be used in replacing the token in the email, below
  98.             If Len(rsEmailAddresses("first_name")) > 0 Then
  99.                 strFirstName = Trim(rsEmailAddresses("first_name"))
  100.             Else
  101.                 strFirstName = ""
  102.             End If
  103.                                 
  104.             'Set the last name, if provided, to be used in replacing the token in the email, below
  105.             If Len(rsEmailAddresses("last_name")) > 0 Then
  106.                 strLastName = Trim(rsEmailAddresses("last_name"))
  107.             Else
  108.                 strLastName = ""
  109.             End If
  110.                                 
  111.             'Set the first custom data fields, if provided, to be used in replacing the token in the email, below
  112.             If Len(rsEmailAddresses("custom_data_1")) > 0 Then
  113.                 strCustomData1 = Trim(rsEmailAddresses("custom_data_1"))
  114.             Else
  115.                 strCustomData1 = ""
  116.             End If
  117.  
  118.             'Set the second custom data fields, if provided, to be used in replacing the token in the email, below
  119.             If Len(rsEmailAddresses("custom_data_2")) > 0 Then
  120.                 strCustomData2 = Trim(rsEmailAddresses("custom_data_2"))
  121.             Else
  122.                 strCustomData2 = ""
  123.             End If
  124.  
  125.             'Set the third custom data fields, if provided, to be used in replacing the token in the email, below
  126.             If Len(rsEmailAddresses("custom_data_3")) > 0 Then
  127.                 strCustomData3 = Trim(rsEmailAddresses("custom_data_3"))
  128.             Else
  129.                 strCustomData3 = ""
  130.             End If
  131.  
  132.             'Get the text of the email and replace all of the tokens
  133.             strBody = Request.Form("txtEmailText")
  134.             strBody = Replace(strBody, "#FirstName#", strFirstName)
  135.             strBody = Replace(strBody, "#LastName#", strLastName)
  136.             strBody = Replace(strBody, "#CustomData1#", strCustomData1)
  137.             strBody = Replace(strBody, "#CustomData2#", strCustomData2)
  138.             strBody = Replace(strBody, "#CustomData3#", strCustomData3)
  139.             strTempURL = SUR_APPLICATION_ROOT_URL & "/TakeSurvey.asp?EID=" & rsEmailAddresses("url_unique_id")
  140.             If flgEmailInHTMLFormat = True Then
  141.                 strTempURL = "<a href=""" & strTempURL & """>" & strTempURL & "</a>"
  142.             End If
  143.             strBody = Replace(strBody, "#SurveyLink#", strTempURL)
  144.             strTempURL = SUR_APPLICATION_ROOT_URL & "/DeclineSurvey.asp?EID=" & rsEmailAddresses("url_unique_id")
  145.             If flgEmailInHTMLFormat = True Then
  146.                 strTempURL = "<a href=""" & strTempURL & """>" & strTempURL & "</a>"
  147.             End If
  148.             strBody = Replace(strBody, "#DeclineLink#", strTempURL)
  149.                                 
  150.             'Make sure the email address is valid before sending the email
  151.             If IsValidEmailAddress(strEmailAddress) = True Then
  152.                 'Send the email
  153.                 SendMail strEmailAddress, Request.Form("txtFromAddress"), Request.Form("txtCCAddress"), Request.Form("txtBCCAddress"), strBody, Request.Form("txtSubject"), flgEmailInHTMLFormat
  154.                             
  155.                 'Track the number of emails sent
  156.                 lngEmailSentCount = lngEmailSentCount + 1
  157.             End If
  158.                         
  159.             'Track the list of sent email addresses
  160.             strSentEmailAddresses = strSentEmailAddresses & strEmailAddress & "; "
  161.  
  162.             'Flush after each email so the progress can be seen on the page
  163.             Response.Flush
  164.             
  165.             rsEmailAddresses.MoveNext
  166.         Loop    
  167.  
  168.         'Strip the trailing semi-colon and space off the list of sent email addresses
  169.         strSentEmailAddresses = Left(strSentEmailAddresses, Len(strSentEmailAddresses) - 2)
  170.     End If
  171.  
  172.     'Clean up
  173.     rsEmailAddresses.Close
  174.     Set rsEmailAddresses = Nothing
  175.     conEmailAddresses.Close
  176.     Set conEmailAddresses = Nothing
  177. %>
  178. <!--#Include File="Include/SurveyUtility_inc.asp"-->
  179. <!--#Include File="Include/Utility_inc.asp"-->
  180. <!--#Include File="Include/Constants_inc.asp"-->
  181. <!--#Include File="Include/Config_inc.asp"-->
  182. <!--#Include File="Include/ID_inc.asp"-->
  183. <!--#Include File="Include/Email_inc.asp"-->
  184. <!--#Include File="Include/adovbs_inc.asp"-->
  185. <!--#Include File="Include/CurrentUser_inc.asp"-->
  186. <!--#Include File="Include/SurveySecurity_inc.asp"-->
  187. <!--#Include File="Include/Encryption_inc.asp"-->
  188.  
  189. <html>
  190. <head>
  191.     <title>Send Follow-Up Message Confirmation</title>
  192.     <link rel="stylesheet" href="Resources/StyleSheet/SurveyStyle.css">
  193. </head>
  194.  
  195. <body class="MainBodyStyle">
  196.  
  197. <!--#Include File="Include/FrameworkTop_inc.asp"-->
  198.  
  199. <table border="0" cellspacing="0" cellpadding="0" width="754" class="MediumBlueBackgroundColor">
  200.     <tr>
  201.         <td height="36" valign="center">
  202.               <span class="H1HeadingStyle"><a name="skipnav" tabindex="1">Send Follow-Up 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">
  203.         </td>
  204.     </tr>
  205. </table>
  206.  
  207. <!--#Include File="Include/FrameworkTop2_inc.asp"-->
  208.  
  209. <table width="740" border="0" cellpadding="0" cellspacing="6" class="LightGrayBackgroundColor">
  210.     <tr>
  211.         <td width="1"></td>
  212.         <td height="40" valign="center">
  213.             <span class="H2HeadingStyle">Follow-Up Message Sent for Survey '<%=strSurveyName%>'</span>
  214.         </td>
  215.         <td width="1" rowspan="2"> </td>
  216.     </tr>
  217. </table>
  218. <table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td height="1" background="Resources/Images/ThinDivider.gif"></td></tr></table>
  219. <table border="0" cellpadding="0" cellspacing="6" width="740" class="WhiteBackgroundColor">
  220.     <tr>
  221.         <td width="1" rowspan="10"></td>
  222.         <td>
  223.             <br>
  224.             <span class="Normal">
  225. <%
  226.                 If lngEmailSentCount = 0 Then
  227. %>
  228.                     There were no email recipients that matched the specified criteria.  No emails were sent.
  229. <%
  230.                 ElseIf lngEmailSentCount = 1 Then
  231. %>
  232.                     One email was sent to the following email address:
  233. <%
  234.                 Else
  235. %>
  236.                     A total of <%=lngEmailSentCount%> emails were sent to the following email addresses:
  237. <%
  238.                 End If
  239. %>
  240.                 <br><br>
  241.                 <%=strSentEmailAddresses%>
  242.             </span>
  243.         </td>
  244.         <td width="1" rowspan="10"> </td>
  245.     </tr>
  246.     <tr>
  247.         <td align="right">
  248.             <br><br>
  249.             <a href="EmailMessageList.asp?EmailListID=<%=Request.Form("EmailListID")%>&EmailListName=<%=Request.Form("EmailListName")%>"><img border="0" alt="Click to return to the list of report shares for this survey" src="Resources/Buttons/OK.gif" name="btnOK"></a>
  250.         </td>
  251.     </tr>
  252. </table>
  253.  
  254. <!--#Include File="Include/FrameworkBottom_inc.asp"-->
  255.  
  256. </body>
  257. </html>
  258.  
  259. <%        
  260.     'Ensure that the web server returns the page
  261.     Response.Flush
  262. %>
  263.