home *** CD-ROM | disk | FTP | other *** search
/ bombers.k12.ar.us / bombers.k12.ar.us.tar / bombers.k12.ar.us / survey_unconfigured / ImportEmailAddressesAction.asp < prev    next >
Text File  |  2006-10-25  |  5KB  |  132 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 ImportEmailAddresses.asp and does the
  7. '                      actual importing of email addresses into the database.
  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. %>
  17. <!--#Include File="Include/SurveyUtility_inc.asp"-->
  18. <!--#Include File="Include/Utility_inc.asp"-->
  19. <!--#Include File="Include/Constants_inc.asp"-->
  20. <!--#Include File="Include/Config_inc.asp"-->
  21. <!--#Include File="Include/ID_inc.asp"-->
  22. <!--#Include File="Include/adovbs_inc.asp"-->
  23. <!--#Include File="Include/CurrentUser_inc.asp"-->
  24. <!--#Include File="Include/SurveySecurity_inc.asp"-->
  25. <%
  26.     'If the user does not have "Create" or "Admin" permission, redirect them to the access denied page.
  27.     If lngUserSecurityLevel <> SUR_SECURITY_LEVEL_CREATE And lngUserSecurityLevel <> SUR_SECURITY_LEVEL_ADMIN Then
  28.         Response.Redirect "AccessDenied.asp?Reason=" & SUR_ACCESS_DENIED_NOT_ADMIN_SECURITY_LEVEL
  29.     End If
  30.  
  31.     Dim arrEmailAddresses
  32.     Dim arrFields
  33.     Dim i
  34.     Dim strEmailAddress
  35.     Dim strFirstName
  36.     Dim strLastName
  37.     Dim strCustomData1
  38.     Dim strCustomData2
  39.     Dim strCustomData3
  40.     Dim conImport
  41.     Dim lngEmailAddressID
  42.     Dim strSQL
  43.     Dim lngEmailAddressCount
  44.     Dim lngEmailListID
  45.     
  46.     'Initialization
  47.     Set conImport = Server.CreateObject("ADODB.Connection")
  48.     lngEmailListID = Request.Form("EmailListID")
  49.     conImport.Open SURVEY_APP_CONNECTION
  50.     strFirstName = ""
  51.     strLastName = ""
  52.     strCustomData1 = ""
  53.     strCustomData2 = ""
  54.     strCustomData3 = ""
  55.     lngEmailAddressCount = 0
  56.                 
  57.     'Split the list of email addresses on the linefeed character.  Each record contains an email address, followed
  58.     'by, optionally, first name, last name, and custom data.
  59.     arrEmailAddresses = Split(Trim(Request.Form("txtEmailAddresses")), vbCrLf)
  60.                     
  61.     'Loop through the records entered.    
  62.     For i = 0 To UBound(arrEmailAddresses)
  63.         'Make sure that data was entered on each line before processing
  64.         If Len(arrEmailAddresses(i)) > 0 Then
  65.             'Split the fields on comma
  66.             arrFields = Split(Trim(arrEmailAddresses(i)), ",")
  67.                             
  68.             'Get the email address, which is the first field, and is required.  Trim to 75 characters, which is the max length.
  69.             strEmailAddress = Left(arrFields(0), 75)
  70.                             
  71.             'Get the first name, which is the second field, if provided.  Trim to 75 characters, which is the max length.
  72.             If UBound(arrFields) >= 1 Then
  73.                 strFirstName = Left(arrFields(1), 75)
  74.             End If
  75.                             
  76.             'Get the last name, which is the third field, if provided.  Trim to 75 characters, which is the max length.
  77.             If UBound(arrFields) >= 2 Then
  78.                 strLastName = Left(arrFields(2), 75)
  79.             End If
  80.                             
  81.             'Get the first custom data field, which is the fourth field, if provided.  Trim to 75 characters, which is the max length.
  82.             If UBound(arrFields) >= 3 Then
  83.                 strCustomData1 = Left(arrFields(3), 75)
  84.             End If
  85.  
  86.             'Get the second custom data field, which is the fifth field, if provided.  Trim to 75 characters, which is the max length.
  87.             If UBound(arrFields) >= 4 Then
  88.                 strCustomData2 = Left(arrFields(4), 75)
  89.             End If
  90.  
  91.             'Get the third custom data field, which is the sixth field, if provided.  Trim to 75 characters, which is the max length.
  92.             If UBound(arrFields) >= 5 Then
  93.                 strCustomData3 = Left(arrFields(5), 75)
  94.             End If
  95.  
  96.             'Get the next available email address ID
  97.             lngEmailAddressID = ID_GetNextAvailableID("SurveyGenerationEmailAddress")
  98.  
  99.             'Create the INSERT statement and execute        
  100.             strSQL = "INSERT INTO sur_email_address(email_address_id, email_list_id, email_address, first_name, " & _
  101.                         "last_name, custom_data_1, custom_data_2, custom_data_3, active_yn, deleted_yn) VALUES(" & _
  102.                         lngEmailAddressID & ", " & _
  103.                         lngEmailListID & ", " & _
  104.                         SQLEncode(strEmailAddress) & ", " & _
  105.                         SQLEncode(strFirstName) & ", " & _
  106.                         SQLEncode(strLastName) & ", " & _
  107.                         SQLEncode(strCustomData1) & ", " & _
  108.                         SQLEncode(strCustomData2) & ", " & _
  109.                         SQLEncode(strCustomData3) & ", " & _
  110.                         SQLEncode(SUR_BOOLEAN_POSITIVE) & ", " & _
  111.                         SQLEncode(SUR_BOOLEAN_NEGATIVE) & ")"
  112.             conImport.Execute ConvertSQL(strSQL), , adCmdText
  113.             
  114.             'Increment the count of email addresses inserted
  115.             lngEmailAddressCount = lngEmailAddressCount + 1
  116.         End If
  117.     Next
  118.     
  119.     'Update the count of email addresses for this list
  120.     strSQL = "UPDATE sur_email_list " & _
  121.              "SET email_address_count = email_address_count + " & lngEmailAddressCount & _
  122.              " WHERE email_list_id = " & lngEmailListID
  123.     conImport.Execute ConvertSQL(strSQL), , adCmdText
  124.     
  125.     'Clean up
  126.     conImport.Close
  127.     Set conImport = Nothing
  128.     
  129.     'Redirect to the main page for the email list for which email addresses were just imported
  130.     Response.Redirect "EmailListList.asp"
  131. %>
  132.