Public Class GroupManager
'=properties
Public Session As NotesSession
Public CurrentDatabase As NotesDatabase
Public AddressBook As NotesDatabase
Public AddressBookView As NotesView
'=constructor
Public Sub New
On Error Goto processError
Set Session = New NotesSession
Set CurrentDatabase = Session.CurrentDatabase
Set AddressBook = Session.GetDatabase(CurrentDatabase.Server, "names.nsf", False)
If AddressBook Is Nothing Then Error 1984, "Невозможно получить адресную книгу!"
Set AddressBookView = AddressBook.GetView("($ServerAccess)")
If AddressBookView Is Nothing Then Error 1984, "Невозможно получить представление в адресной книге!"
Call AddressBookView.Refresh()
AddressBookView.AutoUpdate = False
Exit Sub
processError:
Error Err, "-> CLASS: " + Typename(Me) + "-> " + Cstr(Getthreadinfo(1)) + " (" + Cstr(Erl) + ") " + Error$
End Sub
'=methods
Public Function GetGroupsForUser(UserName As String) As Variant
Dim nn As Variant
Dim AllGroups As Variant
Dim k As Integer
Dim dcol As NotesDocumentCollection
Dim doc As NotesDocument
On Error Goto processError
GetGroupsForUser = Split("", "")
nn = Trim(Cstr(UserName))
If nn = "" Then nn = Session.UserName
Set nn = New NotesName(nn)
nn = Trim(Cstr(nn.Canonical))
AllGroups = Split("", "")
AllGroups = Arrayunique(Fulltrim(Arrayappend(AllGroups, nn)), 5)
k = -1
Do
k = k + 1
Set dcol = AddressBookView.GetAllDocumentsByKey(AllGroups(k), True)
If dcol.Count > 0 Then
Set doc = dcol.GetFirstDocument()
Do While Not doc Is Nothing
If Not Isnull(Arraygetindex(doc.Members, AllGroups(k), 5)) Then AllGroups = Arrayunique(Fulltrim(Arrayappend(AllGroups, doc.ListName)), 5)
Set doc = dcol.GetNextDocument(doc)
Loop
End If
Loop While k < Ubound(AllGroups)
GetGroupsForUser = Fulltrim(Arrayreplace(AllGroups, AllGroups(0), ""))
ENDING:
GetGroupsForUser = Arrayunique(Fulltrim(GetGroupsForUser), 5)
Exit Function
processError:
Error Err, "-> CLASS: " + Typename(Me) + "-> " + Cstr(Getthreadinfo(1)) + " (" + Cstr(Erl) + ") " + Error$
End Function
End Class