home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
bombers.k12.ar.us
/
bombers.k12.ar.us.tar
/
bombers.k12.ar.us
/
survey_unconfigured
/
CreateEmailListAction.asp
< prev
next >
Wrap
Text File
|
2006-10-25
|
12KB
|
287 lines
<!--#Include File="Include/Top_inc.asp"-->
<%
'***********************************************************************
' Application: SelectSurveyASP Advanced v8.1.11
' Author: Aaron Baril for ClassApps.com
' Page Description: This page creates a new email list either from scratch or by
' copying an existing email list.
'
' COPYRIGHT NOTICE
'
' See attached Software License Agreement
'
' (c) Copyright 2002 - 2006 by ClassApps.com. All rights reserved.
'***********************************************************************
%>
<!--#Include File="Include/Config_inc.asp"-->
<!--#Include File="Include/Utility_inc.asp"-->
<!--#Include File="Include/adovbs_inc.asp"-->
<!--#Include File="Include/ID_inc.asp"-->
<!--#Include File="Include/CurrentUser_inc.asp"-->
<!--#Include File="Include/SurveySecurity_inc.asp"-->
<!--#Include File="Include/Constants_inc.asp"-->
<!--#Include File="Include/Collection_inc.asp"-->
<%
'If the user does not have "Create" or "Admin" permission, redirect them 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
Dim strSQL
Dim conNewEmailList
Dim lngOriginalEmailListID
Dim lngNewEmailListID
Dim rsEmailAddressListSource
Dim rsCount
Dim strActiveYN
Dim strEmailListName
Dim strEmailListDescription
Dim lngOriginalEmailAddressCount
Dim lngEmailAddressCount
Dim lngNewEmailAddressID
Dim strCustomData1
Dim strCustomData2
Dim strCustomData3
Dim strWhere
'Initialization
Set rsEmailAddressListSource = Server.CreateObject("ADODB.Recordset")
Set rsCount = Server.CreateObject("ADODB.Recordset")
Set conNewEmailList = Server.CreateObject("ADODB.Connection")
conNewEmailList.Open SURVEY_APP_CONNECTION
lngNewEmailListID = ID_GetNextAvailableID("SurveyGenerationEmailList")
strEmailListName = Request.Form("txtEmailListName")
lngEmailAddressCount = 0
'Set the values for all fields in the email list based on whether this is a copy or a new email list
If CLng(Request.Form("optType")) = SUR_CREATE_EMAIL_LIST_FROM_SCRATCH Then
'No fields specific to creating an email list from scratch
ElseIf CLng(Request.Form("optType")) = SUR_CREATE_EMAIL_LIST_FROM_USERS Then
'Select the users to copy for the new list
strSQL = "SELECT email_address, first_name, last_name, custom_data_1, custom_data_2, custom_data_3 " & _
"FROM sur_user " & _
"WHERE user_id = user_id "
'If the user is filtering the users, add a filter to the query
If CStr(Request.Form("optUserFilterType")) = CStr(SUR_EMAIL_LIST_WITH_FILTER) Then
'Add the filter for the active flag
If Request.Form("cboUserActive") <> SUR_COMBO_ALL Then
strWhere = strWhere & " AND active_yn = " & SQLEncode(Request.Form("cboUserActive"))
End If
'Add the filter for the email address
If Len(Trim(Request.Form("txtUserEmailAddress"))) > 0 Then
strWhere = strWhere & " AND email_address LIKE " & SQLEncodeContains(Request.Form("txtUserEmailAddress"))
End If
'Add the filter for the position field
If Len(Trim(Request.Form("txtUserPosition"))) > 0 Then
strWhere = strWhere & " AND current_position LIKE " & SQLEncodeContains(Request.Form("txtUserPosition"))
End If
'Add the filter for the company field
If Len(Trim(Request.Form("txtUserCompany"))) > 0 Then
strWhere = strWhere & " AND company LIKE " & SQLEncodeContains(Request.Form("txtUserCompany"))
End If
'Add the filter for the location field
If Len(Trim(Request.Form("txtUserLocation"))) > 0 Then
strWhere = strWhere & " AND location LIKE " & SQLEncodeContains(Request.Form("txtUserLocation"))
End If
'Add the filter for the first custom data field
If Len(Trim(Request.Form("txtUserCustomData1"))) > 0 Then
strWhere = strWhere & " AND custom_data_1 LIKE " & SQLEncodeContains(Request.Form("txtUserCustomData1"))
End If
'Add the filter for the second custom data field
If Len(Trim(Request.Form("txtUserCustomData2"))) > 0 Then
strWhere = strWhere & " AND custom_data_2 LIKE " & SQLEncodeContains(Request.Form("txtUserCustomData2"))
End If
'Add the filter for the third custom data field
If Len(Trim(Request.Form("txtUserCustomData3"))) > 0 Then
strWhere = strWhere & " AND custom_data_3 LIKE " & SQLEncodeContains(Request.Form("txtUserCustomData3"))
End If
End If
'Put the SQL together
strSQL = strSQL & strWhere
'Open the recordset
rsEmailAddressListSource.Open ConvertSQL(strSQL), SURVEY_APP_CONNECTION, adOpenForwardOnly, adLockReadOnly, adCmdText
'If there are users to copy, copy them for the new list
If Not rsEmailAddressListSource.EOF Then
'Get the count of users to be imported
strSQL = "SELECT count(user_id) As UserCount " & _
"FROM sur_user " & _
"WHERE user_id = user_id " & strWhere
rsCount.Open ConvertSQL(strSQL), SURVEY_APP_CONNECTION, adOpenForwardOnly, adLockReadOnly, adCmdText
rsCount.MoveFirst
lngOriginalEmailAddressCount = CLng(rsCount("UserCount"))
rsCount.Close
Set rsCount = Nothing
'Get a range of ID's for email addresses
lngNewEmailAddressID = ID_GetRangeOfIDs("SurveyGenerationEmailAddress", lngOriginalEmailAddressCount)
rsEmailAddressListSource.MoveFirst
Do While Not rsEmailAddressListSource.EOF
strCustomData1 = rsEmailAddressListSource("custom_data_1")
If Len(strCustomData1) = 0 Or IsNull(strCustomData1) = True Then
strCustomData1 = ""
End If
strCustomData2 = rsEmailAddressListSource("custom_data_2")
If Len(strCustomData2) = 0 Or IsNull(strCustomData2) = True Then
strCustomData2 = ""
End If
strCustomData3 = rsEmailAddressListSource("custom_data_3")
If Len(strCustomData3) = 0 Or IsNull(strCustomData3) = True Then
strCustomData3 = ""
End If
'Insert the new email address
strSQL = "INSERT INTO sur_email_address(email_address_id, email_list_id, email_address, first_name, " & _
"last_name, custom_data_1, custom_data_2, custom_data_3, active_yn, deleted_yn) " & _
"VALUES(" & _
lngNewEmailAddressID & ", " & _
lngNewEmailListID & ", " & _
SQLEncode(rsEmailAddressListSource("email_address")) & ", " & _
SQLEncode(rsEmailAddressListSource("first_name")) & ", " & _
SQLEncode(rsEmailAddressListSource("last_name")) & ", " & _
SQLEncode(strCustomData1) & ", " & _
SQLEncode(strCustomData2) & ", " & _
SQLEncode(strCustomData3) & ", " & _
SQLEncode(SUR_BOOLEAN_POSITIVE) & ", " & _
SQLEncode(SUR_BOOLEAN_NEGATIVE) & ")"
conNewEmailList.Execute ConvertSQL(strSQL), , adCmdText
'Track the number of actual email addresses inserted
lngEmailAddressCount = lngEmailAddressCount + 1
'Incremeent the email address ID counter
lngNewEmailAddressID = lngNewEmailAddressID + 1
rsEmailAddressListSource.MoveNext
Loop
'Clean up
rsEmailAddressListSource.Close
End If
'Finish cleaning up
Set rsEmailAddressListSource = Nothing
Else 'SUR_CREATE_EMAIL_LIST_FROM_EXISTING
'Load the existing data from the database
strSQL = "SELECT email_address_count, list_description " & _
"FROM sur_email_list " & _
"WHERE email_list_id = " & Request.Form("cboEmailList")
rsEmailAddressListSource.Open ConvertSQL(strSQL), SURVEY_APP_CONNECTION, adOpenForwardOnly, adLockReadOnly, adCmdText
rsEmailAddressListSource.MoveFirst
'Capture all of the fields in local variables
strEmailListDescription = rsEmailAddressListSource("list_description")
lngOriginalEmailAddressCount = CLng(rsEmailAddressListSource("email_address_count"))
'Clean up
rsEmailAddressListSource.Close
'Copy the email addresses for the new list
strSQL = "SELECT email_address, first_name, last_name, custom_data_1, custom_data_2, custom_data_3, " & _
"active_yn " & _
"FROM sur_email_address " & _
"WHERE email_list_id = " & Request.Form("cboEmailList")
'If the user is filtering the email addresses, add a filter to the query
If CStr(Request.Form("optFilterType")) = CStr(SUR_EMAIL_LIST_WITH_FILTER) Then
'Add the filter for the active flag
If Request.Form("cboActive") <> SUR_COMBO_ALL Then
strSQL = strSQL & " AND active_yn = " & SQLEncode(Request.Form("cboActive"))
End If
'Add the filter for the email address
If Len(Trim(Request.Form("txtEmailAddress"))) > 0 Then
strSQL = strSQL & " AND email_address LIKE " & SQLEncodeContains(Request.Form("txtEmailAddress"))
End If
'Add the filter for the first custom data field
If Len(Trim(Request.Form("txtCustomData1"))) > 0 Then
strSQL = strSQL & " AND custom_data_1 LIKE " & SQLEncodeContains(Request.Form("txtCustomData1"))
End If
'Add the filter for the second custom data field
If Len(Trim(Request.Form("txtCustomData2"))) > 0 Then
strSQL = strSQL & " AND custom_data_2 LIKE " & SQLEncodeContains(Request.Form("txtCustomData2"))
End If
'Add the filter for the third custom data field
If Len(Trim(Request.Form("txtCustomData3"))) > 0 Then
strSQL = strSQL & " AND custom_data_3 LIKE " & SQLEncodeContains(Request.Form("txtCustomData3"))
End If
End If
'Open the recordset
rsEmailAddressListSource.Open ConvertSQL(strSQL), SURVEY_APP_CONNECTION, adOpenForwardOnly, adLockReadOnly, adCmdText
'If there are email addresses, copy them for the new list
If Not rsEmailAddressListSource.EOF Then
'Get a range of ID's for email addresses
lngNewEmailAddressID = ID_GetRangeOfIDs("SurveyGenerationEmailAddress", lngOriginalEmailAddressCount)
rsEmailAddressListSource.MoveFirst
Do While Not rsEmailAddressListSource.EOF
'Insert the new email address
strSQL = "INSERT INTO sur_email_address(email_address_id, email_list_id, email_address, first_name, " & _
"last_name, custom_data_1, custom_data_2, custom_data_3, active_yn, deleted_yn) " & _
"VALUES(" & _
lngNewEmailAddressID & ", " & _
lngNewEmailListID & ", " & _
SQLEncode(rsEmailAddressListSource("email_address")) & ", " & _
SQLEncode(rsEmailAddressListSource("first_name")) & ", " & _
SQLEncode(rsEmailAddressListSource("last_name")) & ", " & _
SQLEncode(rsEmailAddressListSource("custom_data_1")) & ", " & _
SQLEncode(rsEmailAddressListSource("custom_data_2")) & ", " & _
SQLEncode(rsEmailAddressListSource("custom_data_3")) & ", " & _
SQLEncode(rsEmailAddressListSource("active_yn")) & ", " & _
SQLEncode(SUR_BOOLEAN_NEGATIVE) & ")"
conNewEmailList.Execute ConvertSQL(strSQL), , adCmdText
'Track the number of actual email addresses inserted
lngEmailAddressCount = lngEmailAddressCount + 1
'Incremeent the email address ID counter
lngNewEmailAddressID = lngNewEmailAddressID + 1
rsEmailAddressListSource.MoveNext
Loop
'Clean up
rsEmailAddressListSource.Close
End If
'Finish cleaning up
Set rsEmailAddressListSource = Nothing
End If
'Create the new email list using all of the values set above
strSQL = "INSERT INTO sur_email_list(email_list_id, user_id, list_name, list_description, created_date, " & _
"default_yn, email_address_count) " & _
"VALUES(" & lngNewEmailListID & ", " & _
GetUserID() & ", " & _
SQLEncode(strEmailListName) & ", " & _
SQLEncode(strEmailListDescription) & ", " & _
"GETDATE(), " & _
SQLEncode(SUR_BOOLEAN_NEGATIVE) & ", " & _
lngEmailAddressCount & ")"
conNewEmailList.Execute ConvertSQL(strSQL), , adCmdText
'Clean up
conNewEmailList.Close
Set conNewEmailList = Nothing
'If the user created a new email list from scratch, redirect to the import page to add email addresses to the list.
'Otherwise, redirect to the main list of email lists.
If CLng(Request.Form("optType")) = SUR_CREATE_EMAIL_LIST_FROM_SCRATCH Then
Response.Redirect "ImportEmailAddresses.asp?EmailListID=" & lngNewEmailListID & "&EmailListName=" & strEmailListName
Else
Response.Redirect "EmailListList.asp?EmailListID=" & lngNewEmailListID
End If
%>