home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
bombers.k12.ar.us
/
bombers.k12.ar.us.tar
/
bombers.k12.ar.us
/
survey_unconfigured
/
ImportUsersAction.asp
< prev
next >
Wrap
Text File
|
2006-10-25
|
9KB
|
248 lines
<!--#Include File="Include/Top_inc.asp"-->
<%
'***********************************************************************
' Application: SelectSurveyASP Advanced v8.1.11
' Author: Aaron Baril for ClassApps.com
' Page Description: This page is called from ImportUsers.asp and does the
' actual importing of users into the database.
'
' COPYRIGHT NOTICE
'
' See attached Software License Agreement
'
' (c) Copyright 2002 - 2006 by ClassApps.com. All rights reserved.
'***********************************************************************
%>
<!--#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/adovbs_inc.asp"-->
<!--#Include File="Include/CurrentUser_inc.asp"-->
<!--#Include File="Include/SurveySecurity_inc.asp"-->
<html>
<head>
<title>User Import Results</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">User Import Results</a></span> <img style="cursor:hand" alt="Help" onClick="javascript:window.open('Help/Help.htm#ImportingUsers', 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="6" cellspacing="0" class="WhiteBackgroundColor">
<tr>
<td colspan="3">
<table border="0" cellpadding="8" cellspacing="0" width="100%">
<tr>
<td>
<span class="H2HeadingStyle"> User Import Results</span>
</td>
</tr>
</table>
</td>
</tr>
<%
'If the user is not an admin, do not allow them to import user
If lngUserSecurityLevel <> SUR_SECURITY_LEVEL_ADMIN Then
Response.Redirect "AccessDenied.asp?Reason=" & SUR_ACCESS_DENIED_NOT_ADMIN_SECURITY_LEVEL
End If
Dim arrUsers
Dim arrFields
Dim i
Dim strUsername
Dim strPassword
Dim strFirstName
Dim strLastName
Dim strEmailAddress
Dim strCurrentPosition
Dim strCompany
Dim strLocation
Dim strCustomData1
Dim strCustomData2
Dim strCustomData3
Dim strSuccessfulUsernames
Dim strFailedUsernames
Dim conImport
Dim rsUsernameCount
Dim lngUserID
Dim lngUsernameCount
Dim strSQL
'Initialization
Set conImport = Server.CreateObject("ADODB.Connection")
conImport.Open SURVEY_APP_CONNECTION
'Split the list of users on the linefeed character. Each record contains the following fields, with the fields
'marked with an asterisk being required:
' Username *
' Password *
' First Name *
' Last Name *
' Email Address *
' Current Position
' Company
' Location
' Custom Data 1
' Custom Data 2
' Custom Data 3
arrUsers = Split(Trim(Request.Form("txtUsers")), vbCrLf)
'Loop through the records entered.
For i = 0 To UBound(arrUsers)
'Make sure that data was entered on each line before processing
If Len(arrUsers(i)) > 0 Then
'Split the fields on comma
arrFields = Split(Trim(arrUsers(i)), ",")
'Extract each of the fields into a variable, and trim each of the fields to maximum length allowed in
'the database. Since the last six fields are not required, it's possible that none of them were
'entered. Therefore, check the upper bound of the array before attempting to extract each of these fields.
strUsername = Left(arrFields(0), 50)
strPassword = Left(arrFields(1), 75)
strFirstName = Left(arrFields(2), 25)
strLastName = Left(arrFields(3), 25)
strEmailAddress = Left(arrFields(4), 100)
If UBound(arrFields) >= 5 Then
strCurrentPosition = Left(arrFields(5), 50)
End If
If UBound(arrFields) >= 6 Then
strCompany = Left(arrFields(6), 100)
End If
If UBound(arrFields) >= 7 Then
strLocation = Left(arrFields(7), 75)
End If
If UBound(arrFields) >= 8 Then
strCustomData1 = Left(arrFields(8), 100)
End If
If UBound(arrFields) >= 9 Then
strCustomData2 = Left(arrFields(9), 100)
End If
If UBound(arrFields) >= 10 Then
strCustomData3 = Left(arrFields(10), 100)
End If
'Check whether or not the username already exists in the database. Duplicate usernames are
'not allowed.
Set rsUsernameCount = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT count(username) As UsernameCount FROM sur_user WHERE username = " & SQLEncode(strUsername)
rsUsernameCount.Open ConvertSQL(strSQL), SURVEY_APP_CONNECTION, adOpenForwardOnly, adLockReadOnly, adCmdText
rsUsernameCount.MoveFirst
lngUsernameCount = CLng(rsUsernameCount("UsernameCount"))
rsUsernameCount.Close
Set rsUsernameCount = Nothing
'If the username already exists, simply record it in the list of usernames that failed
If lngUsernameCount > 0 Then
strFailedUsernames = strFailedUsernames & strUsername & ", "
Else 'The username is unique, so go ahead and insert it
'Get the next available user ID
lngUserID = ID_GetNextAvailableID("SurveyGenerationUser")
'Create and execute the INSERT statement to create a new user
strSQL = "INSERT INTO sur_user(user_id, username, register_date, user_password, " & _
"first_name, last_name, email_address, current_position, company, location, custom_data_1, " & _
"custom_data_2, custom_data_3, active_yn) VALUES(" & _
lngUserID & ", " & _
SQLEncode(strUsername) & ", " & _
"GETDATE(), " & _
SQLEncode(strPassword) & ", " & _
SQLEncode(strFirstName) & ", " & _
SQLEncode(strLastName) & ", " & _
SQLEncode(strEmailAddress) & ", " & _
SQLEncode(strCurrentPosition) & ", " & _
SQLEncode(strCompany) & ", " & _
SQLEncode(strLocation) & ", " & _
SQLEncode(strCustomData1) & ", " & _
SQLEncode(strCustomData2) & ", " & _
SQLEncode(strCustomData3) & ", " & _
SQLEncode(SUR_BOOLEAN_POSITIVE) & ")"
conImport.Execute ConvertSQL(strSQL), , adCmdText
'Create and execute the INSERT statement to add a role mapping for the new user
strSQL = "INSERT INTO sur_user_to_role_mapping(user_id, role_id) VALUES(" & _
lngUserID & ", " & SUR_SECURITY_LEVEL_USER & ")"
conImport.Execute ConvertSQL(strSQL), , adCmdText
'Preserve the username in the list of successfully imported usernames
strSuccessfulUsernames = strSuccessfulUsernames & strUsername & ", "
End If
End If
Next
'Clean up
conImport.Close
Set conImport = Nothing
%>
<tr>
<td width="10"> </td>
<td width="720" valign="top">
<span class="Normal">
<%
'If there were no failed usernames, display a message indicating that all usernames
'were successfully imported
If Len(Trim(strFailedUsernames)) = 0 Then
%>
All usernames were successfully imported!
<%
Else
'There were failed usernames, so display a message indicating that there were problems, and
'display the lists of failed and successful usernames. First, clean up the username lists.
If Len(strSuccessfulUsernames) = 0 Then
strSuccessfulUsernames = "None"
Else
strSuccessfulUsernames = Left(Trim(strSuccessfulUsernames), Len(Trim(strSuccessfulUsernames)) - 1)
End If
strFailedUsernames = Left(Trim(strFailedUsernames), Len(Trim(strFailedUsernames)) - 1)
%>
Warning! Some users were not imported because the usernames are already
being used.
<br><br>
The following users were imported successfully: <%=strSuccessfulUsernames%>
<br><br>
The following users were not imported because these usernames are already being used: <%=strFailedUsernames%>
<%
End If
%>
</span>
<br>
</td>
<td width="10"> </td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td colspan="2" align="right">
<a href="UserList.asp"><img border="0" alt="Click to return to the list of users" src="Resources/Buttons/OK.gif" name="btnOK"></a>
<br>
</td>
<td> </td>
</tr>
</table>
<!--#Include File="Include/FrameworkBottom_inc.asp"-->
</body>
</html>
<%
'Ensure that the web server returns the page
Response.Flush
%>