VERSION 1.0 CLASS BEGIN MultiUse = -1 'True Persistable = 0 'NotPersistable DataBindingBehavior = 0 'vbNone DataSourceBehavior = 0 'vbNone MTSTransactionMode = 2 'RequiresTransaction END Attribute VB_Name = "clsUsersWO" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = True Attribute VB_PredeclaredId = False Attribute VB_Exposed = True Option Explicit '*** Constant declarations Private Const strMODULE_NAME As String = "clsUsersWO" '*** This procedure adds a set of users to an instance with a specified role Public Sub AddUsersToInstanceWithOneRole(ByVal intAppInstanceId As Integer, _ ByVal strAppInstanceAbbr As String, _ ByVal strUsers As String, _ ByVal strRole As String) On Error GoTo ErrorHandler Dim arrUsers As Variant Dim i As Integer Dim strUserId As String '*** Split the users string into an array an iterate through the array arrUsers = Split(strUsers, ",") For i = 0 To UBound(arrUsers) strUserId = Trim(arrUsers(i)) '*** Add current user to the instance UpdateUserAppInstance strUserId, intAppInstanceId '*** Give the current user the specified role in the instance UpdateUserRole strAppInstanceAbbr, strUserId, strRole Next i CommonExit: GoSub ObjectCleanup Exit Sub ObjectCleanup: Return ErrorHandler: '*** Abort the transaction GoSub ObjectCleanup '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".AddUsersToInstanceWithOneRole()]", Err.Description End Sub '*** This procedure deletes a set of users from a role in an instance Public Sub DeleteUsersFromRoleInInstance(ByVal intAppInstanceId As Integer, _ ByVal strAppInstanceAbbr As String, _ ByVal strUsers As String, _ ByVal strRole As String) On Error GoTo ErrorHandler Dim objContext As ObjectContext Dim objUsersDA As ChvCITCUserMgr.clsUsersDA Dim arrUsers As Variant Dim i As Integer Dim strUserId As String '*** Acquire a reference to the transaction context Set objContext = GetObjectContext() '*** Create the data access object and execute the data access method Set objUsersDA = CreateObject("ChvCITCUserMgr.clsUsersDA") '*** Split the users string into an array an iterate through the array arrUsers = Split(strUsers, ",") For i = 0 To UBound(arrUsers) strUserId = Trim(arrUsers(i)) '*** Delete user from role objUsersDA.DeleteUserRole strAppInstanceAbbr, strUserId, strRole '*** If the user does not have any roles left in this instance then delete them from the instance '*** - if this is there only instance then they will be completely deleted If objUsersDA.blnUserHasAnyRoles(strAppInstanceAbbr, strUserId) = False Then intDelete strAppInstanceAbbr, strUserId, intAppInstanceId End If Next i '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Sub ObjectCleanup: If Not (objUsersDA Is Nothing) Then Set objUsersDA = Nothing Return ErrorHandler: '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort GoSub ObjectCleanup '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".DeleteUsersFromRoleInInstance()]", Err.Description End Sub '*** This function changes the extranet login password for the specified user Public Sub ChangePassword(ByVal strUserId As String, _ ByVal strNewPassword As String) Dim objContext As ObjectContext Dim objUsersDA As clsUsersDA '*** Enable error handling On Error GoTo ErrorHandler '*** Get the MTS Object Context Set objContext = GetObjectContext() '*** Create the data access object Set objUsersDA = CreateObject("ChvCITCUserMgr.clsUsersDA") objUsersDA.ChangePasswordInLDAP strUserId, strNewPassword '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Sub ObjectCleanup: If Not (objUsersDA Is Nothing) Then Set objUsersDA = Nothing Return ErrorHandler: '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort GoSub ObjectCleanup '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".ChangePassword()]", Err.Description End Sub '*** This function updates the specified user in all eQuest data stores Public Function intUpdate(ByVal strAppInstanceAbbr As String, _ ByVal strUserId As String, _ ByVal strRoles As String, _ ByVal strMBPs As String, _ ByVal blnExtranetOnly As Boolean, _ Optional ByVal strFirstName As String, _ Optional ByVal strLastName As String, _ Optional ByVal strPassword As String, _ Optional ByVal strPhoneNbr As String, _ Optional ByVal strEmail As String, _ Optional ByVal strCompanyName As String, _ Optional ByVal strCountry As String) As Integer Dim objContext As ObjectContext Dim objUsersDA As clsUsersDA Dim objEdaadDA As clsEdaadDA Dim arrRoles As Variant Dim i As Integer Dim arrMBPs As Variant Dim intAppInstanceId As Integer '*** Enable error handling On Error GoTo ErrorHandler '*** Get the MTS Object Context Set objContext = GetObjectContext() '*** Create the data access object Set objUsersDA = CreateObject("ChvCITCUserMgr.clsUsersDA") Set objEdaadDA = CreateObject("ChvCITCeDaad.clsEdaadDA") '*** Initialize a successful return code intUpdate = 0 '*** If Extranet-only user then... If blnExtranetOnly = True Then '*** Update their user attributes in the USERS table (only maintained here for Extranet-only users) objUsersDA.UpdateUser strUserId, strFirstName, strLastName, strPhoneNbr, _ strEmail, strCompanyName, strCountry '*** If the user id does not already exist in the eQuest LDAP group then attempt '*** to add the id (for extranet access only) with a default hard password If objUsersDA.blnUserExistsInLDAP(strUserId) = False Then objUsersDA.CreateUserInDLAP strUserId, strFirstName, strLastName, _ "", strPhoneNbr, strEmail, strCompanyName, strCountry '*** If successful then got here - set return code to inform the Admin of the default password If strPassword = "" Then intUpdate = 5 Else intUpdate = 0 End If Else objUsersDA.UpdateUserInLDAP strUserId, strFirstName, strLastName, _ strPassword, strPhoneNbr, strEmail, strCompanyName, strCountry End If End If '*** Update the USER_APP_INSTANCE table portion of the user attributes intAppInstanceId = objEdaadDA.intGetAppInstanceIdFromAbbr(strAppInstanceAbbr) UpdateUserAppInstance strUserId, intAppInstanceId '*** Create the USER_ROLE table portion of the user attributes '*** Delete all current roles DeleteUserRoles strAppInstanceAbbr, strUserId '*** Split the "," delimited role string into an array and iterate through each role adding it to the table arrRoles = Split(strRoles, ",") For i = 0 To UBound(arrRoles) UpdateUserRole strAppInstanceAbbr, strUserId, Trim(arrRoles(i)) Next i '*** Create the MBP_OWNER table portion of the user attributes '*** Delete all current MBP's owned by the user DeleteUserMBPs strAppInstanceAbbr, strUserId '*** Split the "," MBP string into an array and iterate through each MBP adding it to the table arrMBPs = Split(strMBPs, ",") For i = 0 To UBound(arrMBPs) UpdateUserMBP strAppInstanceAbbr, strUserId, Trim(arrMBPs(i)) Next i '*** Object cleanup Set objUsersDA = Nothing '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Function ObjectCleanup: If Not (objUsersDA Is Nothing) Then Set objUsersDA = Nothing If Not (objEdaadDA Is Nothing) Then Set objEdaadDA = Nothing Return ErrorHandler: '*** If the id already exists in another LDAP group then log and event, '*** clear the error and resume If Err.Number = -2147220475 Then UpdateAuditLog "", "Update User", strUserId, _ "User id already exists in another LDAP user group", "", 0 Err.Clear intUpdate = 1 Resume Next End If '*** If there was any other error updating the LDAP record then log, '*** clear the error and resume If Err.Number > dsLowerBound And Err.Number < dsUpperBound Then UpdateAuditLog "", "Update User", strUserId, "Error updating LDAP record:" & _ Err.Number & "-" & Err.Description, "", 0 Err.Clear intUpdate = 3 Resume Next End If '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort GoSub ObjectCleanup '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".intUpdate()]", Err.Description End Function '*** This function creates a new user in all eQuest data stores Public Function intCreate(ByVal strAppInstanceAbbr As String, _ ByVal strUserId As String, _ ByVal strRoles As String, _ ByVal strMBPs As String, _ ByVal blnExtranetOnly As Boolean, _ ByVal strFirstName As String, _ ByVal strLastName As String, _ ByVal strPhoneNbr As String, _ ByVal strEmail As String, _ ByVal strCompanyName As String, _ ByVal strCountry As String, _ Optional ByVal strPassword As String) As Integer Dim objContext As ObjectContext Dim objUsersDA As clsUsersDA Dim objEdaadDA As clsEdaadDA Dim arrRoles As Variant Dim i As Integer Dim arrMBPs As Variant Dim intAppInstanceId As Integer '*** Enable error handling On Error GoTo ErrorHandler '*** Get the MTS Object Context Set objContext = GetObjectContext() '*** Create the data access object and business objects Set objUsersDA = CreateObject("ChvCITCUserMgr.clsUsersDA") Set objEdaadDA = CreateObject("ChvCITCeDaad.clsEdaadDA") '*** Initialize a successful return code intCreate = 0 '*** Verify the user does not already exist before proceeding If objUsersDA.blnUserExists(strUserId) = True Then Err.Raise vbObjectError + 512, strMODULE_NAME & ".intCreate()]", "User id: " & _ strUserId & " already exists" End If '*** If the user was previously marked for deletion then update the attributes If objUsersDA.blnUserMarkedForDelete(strUserId) = True Then objUsersDA.UpdateUser strUserId, strFirstName, strLastName, strPhoneNbr, _ strEmail, strCompanyName, strCountry Else '*** Else create the user's attributes CreateUser strUserId, blnExtranetOnly, strFirstName, strLastName, strPhoneNbr, _ strEmail, strCompanyName, strCountry End If '*** If the user id does not already exist in the eQuest LDAP group then attempt '*** to add the id (for extranet access only) If blnExtranetOnly = True Then If objUsersDA.blnUserExistsInLDAP(strUserId) = False Then objUsersDA.CreateUserInDLAP strUserId, strFirstName, strLastName, strPassword, _ strPhoneNbr, strEmail, strCompanyName, strCountry End If End If '*** Create the USER_APP_INSTANCE table portion of the user attributes intAppInstanceId = objEdaadDA.intGetAppInstanceIdFromAbbr(strAppInstanceAbbr) UpdateUserAppInstance strUserId, intAppInstanceId '*** Create the USER_ROLE table portion of the user attributes '*** Split the "," role string into an array and iterate through each role adding it to the table arrRoles = Split(strRoles, ",") For i = 0 To UBound(arrRoles) UpdateUserRole strAppInstanceAbbr, strUserId, arrRoles(i) Next i '*** Create the MBP_OWNER table portion of the user attributes '*** Split the "," MBP string into an array and iterate through each MBP adding it to the table arrMBPs = Split(strMBPs, ",") For i = 0 To UBound(arrMBPs) UpdateUserMBP strAppInstanceAbbr, strUserId, arrMBPs(i) Next i '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Function ObjectCleanup: If Not (objUsersDA Is Nothing) Then Set objUsersDA = Nothing If Not (objEdaadDA Is Nothing) Then Set objEdaadDA = Nothing Return ErrorHandler: '*** If the id already exists in another LDAP group then log the event, '*** clear the error and resume If Err.Number = -2147220475 Then UpdateAuditLog "", "Create User", strUserId, _ "User id already exists in another LDAP user group", "", 0 Err.Clear intCreate = 1 Resume Next End If '*** If there was any other error updating the LDAP record then log, '*** clear the error and resume If Err.Number > dsLowerBound And Err.Number < dsUpperBound Then UpdateAuditLog "", "Create User", strUserId, "Error creating LDAP record:" & _ Err.Number & "-" & Err.Description, "", 0 Err.Clear intCreate = 2 Resume Next End If '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort GoSub ObjectCleanup '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".intCreate()]", Err.Description End Function '*** This function copies the specified user to a new user name Public Function Copy(ByVal strUserId As String, _ ByVal strNewUserID As String, _ ByVal blnExtranetOnly As Boolean) As Integer Dim objContext As ObjectContext Dim objUsersDA As clsUsersDA Dim rsUserAtts As ADODB.Recordset Dim strFirstName As String Dim strLastName As String Dim strEmail As String Dim strPhone As String Dim strCountry As String Dim strCompany As String Dim rsUserAppInstances As ADODB.Recordset Dim rsUserRoles As ADODB.Recordset Dim rsUserMBPs As ADODB.Recordset Dim rsUserPubViews As ADODB.Recordset Dim strAppInstAbbr As String Dim intAppInstId As Integer Const strEMPTY_PASSWORD = "" '*** Enable error handling On Error GoTo ErrorHandler '*** Get the MTS Object Context Set objContext = GetObjectContext() '*** Create the data access object and business objects Set objUsersDA = CreateObject("ChvCITCUserMgr.clsUsersDA") '*** Verify the new user does not already exist before proceeding If objUsersDA.blnUserExists(strNewUserID) = True Then Err.Raise -10000, strMODULE_NAME & ".Copy()]", "User id: " & _ strNewUserID & " already exists" End If '*** Fetch the existing user id's attributes and add the new USERS record Set rsUserAtts = objUsersDA.rsGetUserInfo(strUserId) If Not (rsUserAtts.EOF And rsUserAtts.BOF) = True Then With rsUserAtts strFirstName = .Fields("first_name").Value strLastName = .Fields("last_name").Value strPhone = .Fields("phone").Value strEmail = .Fields("email").Value strCompany = .Fields("company").Value strCountry = .Fields("country").Value End With CreateUser strNewUserID, blnExtranetOnly, strFirstName, strLastName, strPhone, _ strEmail, strCompany, strCountry Else Err.Raise -10001, strMODULE_NAME & ".Copy()]", "User id: " & _ strUserId & " attributes not found" End If '*** If the user id does not already exist in the eQuest LDAP group then attempt '*** to add the new id (for extranet access only) If blnExtranetOnly = True Then If objUsersDA.blnUserExistsInLDAP(strUserId) = False Then objUsersDA.CreateUserInDLAP strUserId, strFirstName, strLastName, strEMPTY_PASSWORD, _ strPhone, strEmail, strCompany, strCountry End If End If '*** Fetch the users application instances and iterate through them Set rsUserAppInstances = objUsersDA.rsGetUserAppInstances(strUserId) If Not (rsUserAppInstances.EOF And rsUserAppInstances.BOF) = True Then While Not rsUserAppInstances.EOF With rsUserAppInstances '*** Assign the new user to this AppInstance strAppInstAbbr = .Fields("abbr").Value intAppInstId = CInt(.Fields("app_instance_id").Value) objUsersDA.CreateUserAppInstance strNewUserID, intAppInstId '*** Fetch the user's roles and add them to the new user Set rsUserRoles = objUsersDA.rsGetUserRoles(strAppInstAbbr, strUserId) If Not (rsUserRoles.EOF And rsUserRoles.BOF) = True Then While Not rsUserRoles.EOF objUsersDA.CreateUserRole strAppInstAbbr, strNewUserID, _ rsUserRoles.Fields("role").Value rsUserRoles.MoveNext Wend Else Err.Raise -10003, strMODULE_NAME & ".Copy()]", "User id: " & _ strUserId & " user has no roles" End If If intAppInstId <> 300 Then '*** Fetch the user's MPBs-owned and add them to the new user Set rsUserMBPs = objUsersDA.rsGetUserMBPs(strAppInstAbbr, strUserId) If Not (rsUserMBPs.EOF And rsUserMBPs.BOF) = True Then While Not rsUserMBPs.EOF objUsersDA.CreateUserMBP strAppInstAbbr, strNewUserID, _ rsUserMBPs.Fields("process_name").Value rsUserMBPs.MoveNext Wend End If End If If intAppInstId <> 300 Then '*** Fetch the user's Pub Views and add them to the new user Set rsUserPubViews = objUsersDA.rsGetUserPubViews(strAppInstAbbr, strUserId) If Not (rsUserPubViews.EOF And rsUserPubViews.BOF) = True Then While Not rsUserPubViews.EOF objUsersDA.CreateUserPubView strAppInstAbbr, strNewUserID, _ rsUserPubViews.Fields("view_name").Value, _ rsUserPubViews.Fields("mbp_name").Value, _ rsUserPubViews.Fields("mbp_type").Value, _ rsUserPubViews.Fields("tab_name").Value, _ rsUserPubViews.Fields("tab_number").Value, _ rsUserPubViews.Fields("row_group_id").Value, _ rsUserPubViews.Fields("page_number").Value, _ rsUserPubViews.Fields("sort_column").Value, _ rsUserPubViews.Fields("sort_column_name").Value, _ rsUserPubViews.Fields("sort_direction").Value rsUserPubViews.MoveNext Wend End If End If End With rsUserAppInstances.MoveNext Wend Else Err.Raise -10002, strMODULE_NAME & ".Copy()]", "User id: " & _ strUserId & " user has no appinstances" End If '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Function ObjectCleanup: If Not (rsUserAtts Is Nothing) Then Set rsUserAtts = Nothing If Not (rsUserAppInstances Is Nothing) Then Set rsUserAppInstances = Nothing If Not (rsUserRoles Is Nothing) Then Set rsUserRoles = Nothing If Not (rsUserMBPs Is Nothing) Then Set rsUserMBPs = Nothing If Not (rsUserPubViews Is Nothing) Then Set rsUserPubViews = Nothing If Not (objUsersDA Is Nothing) Then Set objUsersDA = Nothing Return ErrorHandler: '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort '*** If LDAP create user error then... If Err.Number > dsLowerBound And Err.Number < dsUpperBound Then Err.Number = -10004 Err.Description = "Unable to create user: " & strNewUserID & " in LDAP" End If GoSub ObjectCleanup '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".Copy()]", Err.Description End Function '*** This function updates the audit log Public Sub UpdateAuditLog(ByVal strUserId As String, _ ByVal strTransType As String, _ ByVal strEditRecord As String, _ ByVal strTransDetail As String, _ ByVal strServerName As String, _ ByVal intInstanceId As Integer) On Error GoTo ErrorHandler Dim objContext As ObjectContext Dim objUsersDA As ChvCITCUserMgr.clsUsersDA '*** Acquire a reference to the transaction context Set objContext = GetObjectContext() '*** Create the data access object and execute the data access method Set objUsersDA = CreateObject("ChvCITCUserMgr.clsUsersDA") '*** Update the audit log objUsersDA.UpdateAuditLog strUserId, strTransType, strEditRecord, strTransDetail, _ strServerName, intInstanceId '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Sub ObjectCleanup: If Not (objUsersDA Is Nothing) Then Set objUsersDA = Nothing Return ErrorHandler: '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort GoSub ObjectCleanup '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".UpdateAuditLog()]", Err.Description End Sub '*** This function updates (creates) an AppInstance record for the specified user Public Sub UpdateUserAppInstance(ByVal strUserId As String, _ ByVal intAppInstanceId As Integer) On Error GoTo ErrorHandler Dim objContext As ObjectContext Dim objUsersDA As ChvCITCUserMgr.clsUsersDA '*** Acquire a reference to the transaction context Set objContext = GetObjectContext() '*** Create the data access object and execute the data access method Set objUsersDA = CreateObject("ChvCITCUserMgr.clsUsersDA") '*** If a user instance profile record does not exist then insert a record If objUsersDA.blnUserAppInstanceExists(strUserId, intAppInstanceId) = False Then objUsersDA.CreateUserAppInstance strUserId, intAppInstanceId End If '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Sub ObjectCleanup: If Not (objUsersDA Is Nothing) Then Set objUsersDA = Nothing Return ErrorHandler: '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort GoSub ObjectCleanup '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".UpdateUserAppInstance()]", Err.Description End Sub '*** This function creates a user attribute record for the specified user Public Sub CreateUser(ByVal strUserId As String, _ ByVal blnExtranetOnly As Boolean, _ ByVal strFirstName As String, _ ByVal strLastName As String, _ ByVal strPhoneNbr As String, _ ByVal strEmail As String, _ ByVal strCompanyName As String, _ ByVal strCountry As String) On Error GoTo ErrorHandler Dim objContext As ObjectContext Dim objUsersDA As ChvCITCUserMgr.clsUsersDA '*** Acquire a reference to the transaction context Set objContext = GetObjectContext() '*** Create the data access object and execute the data access method Set objUsersDA = CreateObject("ChvCITCUserMgr.clsUsersDA") objUsersDA.CreateUser strUserId, IIf(blnExtranetOnly = False, 0, 1), strFirstName, _ strLastName, strPhoneNbr, strEmail, strCompanyName, strCountry '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Sub ObjectCleanup: If Not (objUsersDA Is Nothing) Then Set objUsersDA = Nothing Return ErrorHandler: '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort GoSub ObjectCleanup '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".CreateUser()]", Err.Description End Sub '*** This function deletes the specified user from all eQuest data stores Public Function intDelete(ByVal strAppInstanceAbbr As String, _ ByVal strUserId As String, _ ByVal intAppInstanceId As Integer) As Integer Dim objContext As ObjectContext Dim objUsersDA As clsUsersDA Dim objUsersRO As clsUsersRO Dim objRS As ADODB.Recordset '*** Enable error handling On Error GoTo ErrorHandler '*** Get the MTS Object Context Set objContext = GetObjectContext() '*** Create the data access object Set objUsersRO = CreateObject("ChvCITCUserMgr.clsUsersRO") Set objUsersDA = CreateObject("ChvCITCUserMgr.clsUsersDA") '*** Initialize a successful return code intDelete = 0 '*** Delete the role entries for the user DeleteUserRoles strAppInstanceAbbr, strUserId '*** Delete the MBP ownership entries for the user DeleteUserMBPs strAppInstanceAbbr, strUserId '*** Delete any user publisher views that the user saved DeleteUserPubViews strAppInstanceAbbr, strUserId '*** Delete the user AppInstance record for the user DeleteUserAppInstance strUserId, intAppInstanceId '*** If the the user is no longer assigned to any instances then delete the user from '*** the USER table and from the LDAP Set objRS = objUsersRO.rsGetUserAppInstances(strUserId) If objRS.EOF = True Then objUsersDA.MarkUserForDelete strUserId If objUsersDA.blnUserExistsInLDAP(strUserId) = True Then objUsersDA.DeleteUserFromDLAP strUserId End If End If '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Function ObjectCleanup: If Not (objUsersRO Is Nothing) Then Set objUsersRO = Nothing If Not (objUsersDA Is Nothing) Then Set objUsersDA = Nothing Return ErrorHandler: '*** If there was an error deleting the LDAP record then log, '*** clear the error and resume If Err.Number > dsLowerBound And Err.Number < dsUpperBound Then UpdateAuditLog "", "Delete User", strUserId, "Error deleting LDAP record:" & _ Err.Number & "-" & Err.Description, "", 0 Err.Clear intDelete = 4 Resume Next End If '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort GoSub ObjectCleanup '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".intDelete()]", Err.Description End Function '*** This function deletes an AppInstance record for the specified user Private Sub DeleteUserAppInstance(ByVal strUserId As String, _ ByVal intAppInstanceId As Integer) On Error GoTo ErrorHandler Dim objContext As ObjectContext Dim objUsersDA As ChvCITCUserMgr.clsUsersDA '*** Acquire a reference to the transaction context Set objContext = GetObjectContext() '*** Create the data access object and execute the data access method Set objUsersDA = CreateObject("ChvCITCUserMgr.clsUsersDA") '*** Delete the specified user app instance record objUsersDA.DeleteUserAppInstance strUserId, intAppInstanceId '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Sub ObjectCleanup: If Not (objUsersDA Is Nothing) Then Set objUsersDA = Nothing Return ErrorHandler: '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort GoSub ObjectCleanup '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".DeleteUserAppInstance()]", Err.Description End Sub '*** This function deletes all MBP ownership entries for the specified user Private Sub DeleteUserMBPs(ByVal strAppInstanceAbbr As String, _ ByVal strUserId As String) On Error GoTo ErrorHandler Dim objContext As ObjectContext Dim objUsersDA As ChvCITCUserMgr.clsUsersDA '*** Acquire a reference to the transaction context Set objContext = GetObjectContext() '*** Create the data access object and execute the data access method Set objUsersDA = CreateObject("ChvCITCUserMgr.clsUsersDA") '*** Delete the user MBP entries objUsersDA.DeleteUserMBPs strAppInstanceAbbr, strUserId '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Sub ObjectCleanup: If Not (objUsersDA Is Nothing) Then Set objUsersDA = Nothing Return ErrorHandler: '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort GoSub ObjectCleanup '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".DeleteUserMBPs()]", Err.Description End Sub '*** This function renames the specified user id Public Sub Rename(ByVal strOldUserID As String, _ ByVal strNewUserID As String, _ ByVal blnExtranetOnly As Boolean) On Error GoTo ErrorHandler Dim objContext As ObjectContext '*** Acquire a reference to the transaction context Set objContext = GetObjectContext() '*** Copy the specified user to the new id Copy strOldUserID, strNewUserID, blnExtranetOnly '*** Delete old user id DeleteUserFromAllInstances strOldUserID '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Sub ObjectCleanup: Return ErrorHandler: '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort GoSub ObjectCleanup '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".DeleteUserMBPs()]", Err.Description End Sub '*** This function deletes the specified user pub view entry (for the specified user) Public Sub DeleteUserPubView(ByVal strAppInstanceAbbr As String, _ ByVal lngViewId As String) On Error GoTo ErrorHandler Dim objContext As ObjectContext Dim objUsersDA As ChvCITCUserMgr.clsUsersDA '*** Acquire a reference to the transaction context Set objContext = GetObjectContext() '*** Create the data access object and execute the data access method Set objUsersDA = CreateObject("ChvCITCUserMgr.clsUsersDA") '*** Delete the user pub views objUsersDA.DeleteUserPubView strAppInstanceAbbr, lngViewId '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Sub ObjectCleanup: If Not (objUsersDA Is Nothing) Then Set objUsersDA = Nothing Return ErrorHandler: '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort GoSub ObjectCleanup '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".DeleteUserPubView()]", Err.Description End Sub '*** This function deletes the specified user pub view entry (for the specified user) '*** Adapted from DeleteUserPubView() jggr 11/05/01 Public Sub DeleteUserPubViewsByList(ByVal strAppInstanceAbbr As String, _ ByVal lngViewIdList As String) On Error GoTo ErrorHandler Dim objContext As ObjectContext Dim objUsersDA As ChvCITCUserMgr.clsUsersDA '*** Acquire a reference to the transaction context Set objContext = GetObjectContext() '*** Create the data access object and execute the data access method Set objUsersDA = CreateObject("ChvCITCUserMgr.clsUsersDA") '*** Delete the user pub views objUsersDA.DeleteUserPubViewsByList strAppInstanceAbbr, lngViewIdList '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Sub ObjectCleanup: If Not (objUsersDA Is Nothing) Then Set objUsersDA = Nothing Return ErrorHandler: '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort GoSub ObjectCleanup '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".DeleteUserPubViewsByList()]", Err.Description End Sub '*** This function deletes all role entries for the specified user Private Sub DeleteUserRoles(ByVal strAppInstanceAbbr As String, _ ByVal strUserId As String) On Error GoTo ErrorHandler Dim objContext As ObjectContext Dim objUsersDA As ChvCITCUserMgr.clsUsersDA '*** Acquire a reference to the transaction context Set objContext = GetObjectContext() '*** Create the data access object and execute the data access method Set objUsersDA = CreateObject("ChvCITCUserMgr.clsUsersDA") '*** Delete the user roles objUsersDA.DeleteUserRoles strAppInstanceAbbr, strUserId '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Sub ObjectCleanup: If Not (objUsersDA Is Nothing) Then Set objUsersDA = Nothing Return ErrorHandler: '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort GoSub ObjectCleanup '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".DeleteUserRoles()]", Err.Description End Sub '*** This function deletes a user id from the LDAP Public Sub DeleteUserFromLDAP(ByVal strUserId As String) On Error GoTo ErrorHandler Dim objContext As ObjectContext Dim objUsersDA As ChvCITCUserMgr.clsUsersDA '*** Acquire a reference to the transaction context Set objContext = GetObjectContext() '*** Create the data access object Set objUsersDA = CreateObject("ChvCITCUserMgr.clsUsersDA") '*** Delete the user from the LDAP objUsersDA.DeleteUserFromDLAP (strUserId) '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Sub ObjectCleanup: If Not (objUsersDA Is Nothing) Then Set objUsersDA = Nothing Return ErrorHandler: '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort GoSub ObjectCleanup '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".DeleteUserFromLDAP()]", Err.Description End Sub '*** This function deletes the specified user from all instances Public Sub DeleteUserFromAllInstances(ByVal strUserId As String) On Error GoTo ErrorHandler Dim objContext As ObjectContext Dim objUsersDA As ChvCITCUserMgr.clsUsersDA Dim rsUserAppInstances As ADODB.Recordset '*** Acquire a reference to the transaction context Set objContext = GetObjectContext() '*** Create the data access object Set objUsersDA = CreateObject("ChvCITCUserMgr.clsUsersDA") '*** Create a recordset of all user appinstance assignments Set rsUserAppInstances = objUsersDA.rsGetUserAppInstances(strUserId) '*** If user appinstances are found then delete user from each instance '*** (when being deleted from the last instance they will automatically be deleted completely) If Not (rsUserAppInstances.EOF And rsUserAppInstances.BOF) = True Then While Not rsUserAppInstances.EOF With rsUserAppInstances intDelete .Fields("abbr").Value, strUserId, .Fields("app_instance_id").Value End With rsUserAppInstances.MoveNext Wend Else intDelete "THAILAND", strUserId, 1 End If '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Sub ObjectCleanup: If Not (rsUserAppInstances Is Nothing) Then Set rsUserAppInstances = Nothing If Not (objUsersDA Is Nothing) Then Set objUsersDA = Nothing Return ErrorHandler: '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort GoSub ObjectCleanup '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".DeleteUserFromAllInstances()]", Err.Description End Sub '*** This function deletes all expired users (users who have not logged in in N days) Public Sub DeleteExpiredUsers(ByVal intDays As Integer) On Error GoTo ErrorHandler Dim objContext As ObjectContext Dim objUsersDA As ChvCITCUserMgr.clsUsersDA Dim rsUsers As ADODB.Recordset Dim strExpireDate As String '*** Acquire a reference to the transaction context Set objContext = GetObjectContext() '*** Create the data access object Set objUsersDA = CreateObject("ChvCITCUserMgr.clsUsersDA") '*** Calculate expire date strExpireDate = Format(DateAdd("d", intDays * -1, Date), "mm/dd/yyyy") '*** Create a recordset of all users who have not recently logged in Set rsUsers = objUsersDA.rsGetExpiredUsers(strExpireDate) '*** If expired users are found then delete them If Not (rsUsers.EOF And rsUsers.BOF) = True Then While Not rsUsers.EOF DeleteUserFromAllInstances rsUsers.Fields("user_id").Value rsUsers.MoveNext Wend End If '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Sub ObjectCleanup: If Not (rsUsers Is Nothing) Then Set rsUsers = Nothing If Not (objUsersDA Is Nothing) Then Set objUsersDA = Nothing Return ErrorHandler: '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort GoSub ObjectCleanup '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".DeleteExpiredUsers()]", Err.Description End Sub '*** This function deletes all the user pub view records for the specified user Private Sub DeleteUserPubViews(ByVal strAppInstanceAbbr As String, _ ByVal strUserId As String) On Error GoTo ErrorHandler Dim objContext As ObjectContext Dim objUsersDA As ChvCITCUserMgr.clsUsersDA '*** Acquire a reference to the transaction context Set objContext = GetObjectContext() '*** Create the data access object and execute the data access method Set objUsersDA = CreateObject("ChvCITCUserMgr.clsUsersDA") '*** Delete the user instance profile record objUsersDA.DeleteUserPubViews strAppInstanceAbbr, strUserId '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Sub ObjectCleanup: If Not (objUsersDA Is Nothing) Then Set objUsersDA = Nothing Return ErrorHandler: '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort GoSub ObjectCleanup '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".DeleteUserProfile()]", Err.Description End Sub '*** This function updates the user login data Public Sub UpdateUserLogin(ByVal strUserId As String) On Error GoTo ErrorHandler Dim objContext As ObjectContext Dim objUsersDA As ChvCITCUserMgr.clsUsersDA '*** Acquire a reference to the transaction context Set objContext = GetObjectContext() '*** Create the data access object and execute the data access method Set objUsersDA = CreateObject("ChvCITCUserMgr.clsUsersDA") '*** Update the user login data objUsersDA.UpdateUserLogin strUserId '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Sub ObjectCleanup: If Not (objUsersDA Is Nothing) Then Set objUsersDA = Nothing Return ErrorHandler: '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort GoSub ObjectCleanup '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".UpdateUserLogin()]", Err.Description End Sub '*** This function updates the user table extranet_only field Public Sub UpdateUserExtranetFlag(ByVal strUserId As String, ByVal intFlag As Integer) On Error GoTo ErrorHandler Dim objContext As ObjectContext Dim objUsersDA As ChvCITCUserMgr.clsUsersDA '*** Acquire a reference to the transaction context Set objContext = GetObjectContext() '*** Create the data access object and execute the data access method Set objUsersDA = CreateObject("ChvCITCUserMgr.clsUsersDA") '*** Update the user login data objUsersDA.UpdateUserExtranetFlag strUserId, intFlag '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Sub ObjectCleanup: If Not (objUsersDA Is Nothing) Then Set objUsersDA = Nothing Return ErrorHandler: '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort GoSub ObjectCleanup '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".UpdateUserExtranetFlag()]", Err.Description End Sub '*** This function updates a user role record for the specified user Public Sub UpdateUserMBP(ByVal strAppInstanceAbbr As String, _ ByVal strUserId As String, _ ByVal strMBP As String) On Error GoTo ErrorHandler Dim objContext As ObjectContext Dim objUsersDA As ChvCITCUserMgr.clsUsersDA '*** Acquire a reference to the transaction context Set objContext = GetObjectContext() '*** Create the data access object and execute the data access method Set objUsersDA = CreateObject("ChvCITCUserMgr.clsUsersDA") '*** If a user role record does not exist then insert a record If objUsersDA.blnUserMBPExists(strAppInstanceAbbr, strUserId, strMBP) = False Then objUsersDA.CreateUserMBP strAppInstanceAbbr, strUserId, strMBP End If '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Sub ObjectCleanup: If Not (objUsersDA Is Nothing) Then Set objUsersDA = Nothing Return ErrorHandler: '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort GoSub ObjectCleanup '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".UpdateUserMBP()]", Err.Description End Sub '*** This function creates a user pub view record Public Sub CreateUserPubView(ByVal strAppInstanceAbbr As String, _ ByVal strUserId As String, _ ByVal strViewName As String, _ ByVal strMBPName As String, _ ByVal strMBPType As String, _ ByVal strTabName As String, _ ByVal intTabNumber As Integer, _ ByVal lngRowGroupId As Long, _ ByVal intPageNumber As Integer, _ ByVal intSortColumn As Integer, _ ByVal strSortColumnName As String, _ ByVal strSortDirection As String) On Error GoTo ErrorHandler Dim objContext As ObjectContext Dim objUsersDA As ChvCITCUserMgr.clsUsersDA '*** Acquire a reference to the transaction context Set objContext = GetObjectContext() '*** Create the data access object Set objUsersDA = CreateObject("ChvCITCUserMgr.clsUsersDA") '*** Create the view objUsersDA.CreateUserPubView strAppInstanceAbbr, strUserId, strViewName, strMBPName, strMBPType, _ strTabName, intTabNumber, lngRowGroupId, intPageNumber, intSortColumn, _ strSortColumnName, strSortDirection '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Sub ObjectCleanup: If Not (objUsersDA Is Nothing) Then Set objUsersDA = Nothing Return ErrorHandler: '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort GoSub ObjectCleanup '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".CreateUserPubView()]", Err.Description End Sub '*** This function updates a user pub view record Public Sub UpdateUserPubView(ByVal strAppInstanceAbbr As String, _ ByVal strUserId As String, _ ByVal strViewId As Long, _ ByVal strViewName As String, _ ByVal blnSetAsDefault As Boolean) On Error GoTo ErrorHandler Dim objContext As ObjectContext Dim objUsersDA As ChvCITCUserMgr.clsUsersDA '*** Acquire a reference to the transaction context Set objContext = GetObjectContext() '*** Create the data access object Set objUsersDA = CreateObject("ChvCITCUserMgr.clsUsersDA") '*** If this view is to be set as the default view then first clear all other views (from being the default) If blnSetAsDefault = True Then objUsersDA.ClearDefaultUserPubView strAppInstanceAbbr, strUserId End If '*** Update the view objUsersDA.UpdateUserPubView strAppInstanceAbbr, strViewId, strViewName, IIf(blnSetAsDefault = True, 1, 0) '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Sub ObjectCleanup: If Not (objUsersDA Is Nothing) Then Set objUsersDA = Nothing Return ErrorHandler: '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort GoSub ObjectCleanup '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".UpdateUserPubView()]", Err.Description End Sub '*** This function updates a user role record for the specified user Public Sub UpdateUserRole(ByVal strAppInstanceAbbr As String, _ ByVal strUserId As String, _ ByVal strRole As String) On Error GoTo ErrorHandler Dim objContext As ObjectContext Dim objUsersDA As ChvCITCUserMgr.clsUsersDA '*** Acquire a reference to the transaction context Set objContext = GetObjectContext() '*** Create the data access object and execute the data access method Set objUsersDA = CreateObject("ChvCITCUserMgr.clsUsersDA") '*** If a user role record does not exist then insert a record If objUsersDA.blnUserRoleExists(strAppInstanceAbbr, strUserId, strRole) = False Then objUsersDA.CreateUserRole strAppInstanceAbbr, strUserId, strRole End If '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Sub ObjectCleanup: If Not (objUsersDA Is Nothing) Then Set objUsersDA = Nothing Return ErrorHandler: '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort GoSub ObjectCleanup '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".UpdateUserRole()]", Err.Description End Sub '*** This sub cleans the temporary table, all_user_mbp, used with the Start Page Public Sub DeleteInstancesAndGridsView(ByVal strUserId As String) Dim objContext As ObjectContext Dim objUsersDA As ChvCITCUserMgr.clsUsersDA '*** Acquire a reference to the transaction context Set objContext = GetObjectContext() '*** Create the data access object and execute the data access method Set objUsersDA = CreateObject("ChvCITCUserMgr.clsUsersDA") '*** Execute this function to clear the users entries from the temporary table objUsersDA.DeleteInstancesAndGridsView strUserId '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Sub ObjectCleanup: If Not (objUsersDA Is Nothing) Then Set objUsersDA = Nothing Return ErrorHandler: GoSub ObjectCleanup '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".DeleteInstancesAndGridsView()]", Err.Description End Sub '*** This sub cleans the temporary table, all_user_mbp, used with the Start Page Public Sub DeleteMyViewsCount(ByVal strUserId As String) Dim objContext As ObjectContext Dim objUsersDA As ChvCITCUserMgr.clsUsersDA '*** Acquire a reference to the transaction context Set objContext = GetObjectContext() '*** Create the data access object and execute the data access method Set objUsersDA = CreateObject("ChvCITCUserMgr.clsUsersDA") '*** Execute this function to clear the users entries from the temporary table objUsersDA.DeleteMyViewsCount strUserId '*** Commit the transaction If Not (objContext Is Nothing) Then objContext.SetComplete CommonExit: GoSub ObjectCleanup Exit Sub ObjectCleanup: If Not (objUsersDA Is Nothing) Then Set objUsersDA = Nothing Return ErrorHandler: GoSub ObjectCleanup '*** Abort the transaction If Not (objContext Is Nothing) Then objContext.SetAbort '*** Raise an error to the calling procedure Err.Raise Err.Number, Err.Source & "[" & strMODULE_NAME & ".DeleteMyViewsCount()]", Err.Description End Sub