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 >
Text File  |  2006-10-25  |  9KB  |  248 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 ImportUsers.asp and does the
  7. '                      actual importing of users 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. <html>
  27. <head>
  28.     <title>User Import Results</title>
  29.     <link rel="stylesheet" href="Resources/StyleSheet/SurveyStyle.css">
  30. </head>
  31.  
  32. <body class="MainBodyStyle">
  33.  
  34. <!--#Include File="Include/FrameworkTop_inc.asp"-->
  35.  
  36. <table border="0" cellspacing="0" cellpadding="0" width="754" class="MediumBlueBackgroundColor">
  37.     <tr>
  38.         <td height="36" valign="center">
  39.               <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">
  40.         </td>
  41.     </tr>
  42. </table>
  43.  
  44. <!--#Include File="Include/FrameworkTop2_inc.asp"-->
  45.  
  46. <table width="740" border="0" cellpadding="6" cellspacing="0" class="WhiteBackgroundColor">
  47.     <tr>
  48.         <td colspan="3">
  49.             <table border="0" cellpadding="8" cellspacing="0" width="100%">
  50.                 <tr>
  51.                     <td>
  52.                         <span class="H2HeadingStyle">   User Import Results</span>
  53.                     </td>
  54.                 </tr>
  55.             </table>
  56.         </td>
  57.     </tr>
  58. <%
  59.     'If the user is not an admin, do not allow them to import user
  60.     If lngUserSecurityLevel <> SUR_SECURITY_LEVEL_ADMIN Then
  61.         Response.Redirect "AccessDenied.asp?Reason=" & SUR_ACCESS_DENIED_NOT_ADMIN_SECURITY_LEVEL
  62.     End If
  63.  
  64.     Dim arrUsers
  65.     Dim arrFields
  66.     Dim i
  67.     Dim strUsername
  68.     Dim strPassword
  69.     Dim strFirstName
  70.     Dim strLastName
  71.     Dim strEmailAddress
  72.     Dim strCurrentPosition
  73.     Dim strCompany
  74.     Dim strLocation
  75.     Dim strCustomData1
  76.     Dim strCustomData2
  77.     Dim strCustomData3
  78.     Dim strSuccessfulUsernames
  79.     Dim strFailedUsernames
  80.     Dim conImport
  81.     Dim rsUsernameCount
  82.     Dim lngUserID
  83.     Dim lngUsernameCount
  84.     Dim strSQL
  85.     
  86.     'Initialization
  87.     Set conImport = Server.CreateObject("ADODB.Connection")
  88.     conImport.Open SURVEY_APP_CONNECTION
  89.                                 
  90.     'Split the list of users on the linefeed character.  Each record contains the following fields, with the fields 
  91.     'marked with an asterisk being required:
  92.     ' Username *
  93.     ' Password *
  94.     ' First Name *
  95.     ' Last Name *
  96.     ' Email Address *
  97.     ' Current Position
  98.     ' Company
  99.     ' Location
  100.     ' Custom Data 1
  101.     ' Custom Data 2
  102.     ' Custom Data 3
  103.     arrUsers = Split(Trim(Request.Form("txtUsers")), vbCrLf)
  104.                                     
  105.     'Loop through the records entered.    
  106.     For i = 0 To UBound(arrUsers)
  107.         'Make sure that data was entered on each line before processing
  108.         If Len(arrUsers(i)) > 0 Then
  109.             'Split the fields on comma
  110.             arrFields = Split(Trim(arrUsers(i)), ",")
  111.                                             
  112.             'Extract each of the fields into a variable, and trim each of the fields to maximum length allowed in 
  113.             'the database.  Since the last six fields are not required, it's possible that none of them were 
  114.             'entered.  Therefore, check the upper bound of the array before attempting to extract each of these fields.
  115.             strUsername = Left(arrFields(0), 50)
  116.             strPassword = Left(arrFields(1), 75)
  117.             strFirstName = Left(arrFields(2), 25)
  118.             strLastName = Left(arrFields(3), 25)
  119.             strEmailAddress = Left(arrFields(4), 100)
  120.             If UBound(arrFields) >= 5 Then
  121.                 strCurrentPosition = Left(arrFields(5), 50)
  122.             End If
  123.             If UBound(arrFields) >= 6 Then
  124.                 strCompany = Left(arrFields(6), 100)
  125.             End If
  126.             If UBound(arrFields) >= 7 Then
  127.                 strLocation = Left(arrFields(7), 75)
  128.             End If
  129.             If UBound(arrFields) >= 8 Then
  130.                 strCustomData1 = Left(arrFields(8), 100)
  131.             End If
  132.             If UBound(arrFields) >= 9 Then
  133.                 strCustomData2 = Left(arrFields(9), 100)
  134.             End If
  135.             If UBound(arrFields) >= 10 Then
  136.                 strCustomData3 = Left(arrFields(10), 100)
  137.             End If
  138.  
  139.             'Check whether or not the username already exists in the database.  Duplicate usernames are 
  140.             'not allowed.
  141.             Set rsUsernameCount = Server.CreateObject("ADODB.Recordset")
  142.             strSQL = "SELECT count(username) As UsernameCount FROM sur_user WHERE username = " & SQLEncode(strUsername)
  143.             rsUsernameCount.Open ConvertSQL(strSQL), SURVEY_APP_CONNECTION, adOpenForwardOnly, adLockReadOnly, adCmdText
  144.             rsUsernameCount.MoveFirst
  145.             lngUsernameCount = CLng(rsUsernameCount("UsernameCount"))
  146.             rsUsernameCount.Close
  147.             Set rsUsernameCount = Nothing
  148.                             
  149.             'If the username already exists, simply record it in the list of usernames that failed
  150.             If lngUsernameCount > 0 Then
  151.                 strFailedUsernames = strFailedUsernames & strUsername & ", "
  152.             Else 'The username is unique, so go ahead and insert it
  153.                                                             
  154.                 'Get the next available user ID
  155.                 lngUserID = ID_GetNextAvailableID("SurveyGenerationUser")
  156.  
  157.                 'Create and execute the INSERT statement to create a new user
  158.                 strSQL = "INSERT INTO sur_user(user_id, username, register_date, user_password, " & _
  159.                          "first_name, last_name, email_address, current_position, company, location, custom_data_1, " & _
  160.                          "custom_data_2, custom_data_3, active_yn) VALUES(" & _
  161.                          lngUserID & ", " & _
  162.                          SQLEncode(strUsername) & ", " & _
  163.                          "GETDATE(), " & _
  164.                          SQLEncode(strPassword) & ", " & _
  165.                          SQLEncode(strFirstName) & ", " & _
  166.                          SQLEncode(strLastName) & ", " & _
  167.                          SQLEncode(strEmailAddress) & ", " & _
  168.                          SQLEncode(strCurrentPosition) & ", " & _
  169.                          SQLEncode(strCompany) & ", " & _
  170.                          SQLEncode(strLocation) & ", " & _
  171.                          SQLEncode(strCustomData1) & ", " & _
  172.                          SQLEncode(strCustomData2) & ", " & _
  173.                          SQLEncode(strCustomData3) & ", " & _
  174.                          SQLEncode(SUR_BOOLEAN_POSITIVE) & ")"
  175.                 conImport.Execute ConvertSQL(strSQL), , adCmdText
  176.  
  177.                 'Create and execute the INSERT statement to add a role mapping for the new user
  178.                 strSQL = "INSERT INTO sur_user_to_role_mapping(user_id, role_id) VALUES(" & _
  179.                          lngUserID & ", " & SUR_SECURITY_LEVEL_USER & ")"
  180.                 conImport.Execute ConvertSQL(strSQL), , adCmdText
  181.  
  182.                 'Preserve the username in the list of successfully imported usernames
  183.                 strSuccessfulUsernames = strSuccessfulUsernames & strUsername & ", "
  184.             End If
  185.         End If
  186.     Next
  187.     
  188.     'Clean up
  189.     conImport.Close
  190.     Set conImport = Nothing
  191. %>
  192.     <tr>
  193.         <td width="10"> </td>
  194.         <td width="720" valign="top">
  195.             <span class="Normal">
  196. <%
  197.                 'If there were no failed usernames, display a message indicating that all usernames
  198.                 'were successfully imported
  199.                 If Len(Trim(strFailedUsernames)) = 0 Then
  200. %>
  201.                     All usernames were successfully imported!
  202. <%                    
  203.                 Else
  204.                     'There were failed usernames, so display a message indicating that there were problems, and
  205.                     'display the lists of failed and successful usernames.  First, clean up the username lists.
  206.                     If Len(strSuccessfulUsernames) = 0 Then
  207.                         strSuccessfulUsernames = "None"
  208.                     Else
  209.                         strSuccessfulUsernames = Left(Trim(strSuccessfulUsernames), Len(Trim(strSuccessfulUsernames)) - 1)
  210.                     End If
  211.                     strFailedUsernames = Left(Trim(strFailedUsernames), Len(Trim(strFailedUsernames)) - 1)
  212. %>
  213.                     Warning!  Some users were not imported because the usernames are already 
  214.                     being used.
  215.                     <br><br>
  216.                     The following users were imported successfully: <%=strSuccessfulUsernames%>
  217.                     <br><br>
  218.                     The following users were not imported because these usernames are already being used: <%=strFailedUsernames%>
  219. <%                        
  220.                 End If
  221. %>                
  222.             </span>
  223.             <br>
  224.         </td>
  225.         <td width="10"> </td>
  226.     </tr>
  227.     <tr>
  228.         <td colspan="3"> </td>
  229.     </tr>
  230.     <tr>
  231.         <td colspan="2" align="right">
  232.             <a href="UserList.asp"><img border="0" alt="Click to return to the list of users" src="Resources/Buttons/OK.gif" name="btnOK"></a>
  233.             <br>
  234.         </td>
  235.         <td> </td>
  236.     </tr>
  237. </table>
  238.  
  239. <!--#Include File="Include/FrameworkBottom_inc.asp"-->
  240.  
  241. </body>
  242. </html>
  243.  
  244. <%        
  245.     'Ensure that the web server returns the page
  246.     Response.Flush
  247. %>
  248.