Sub Postopen(Source As Notesuidatabase)
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim thisdb As NotesDatabase
Dim profileview As NotesView
Dim profiledoc As NotesDocument
Dim User As String
User = session.commonusername
Set thisdb = session.CurrentDatabase
Set profileView = thisdb.GetView("User Profiles")
Set profileDoc = profileView.GetDocumentByKey(User, True)
If profiledoc Is Nothing Then
'__________Create profile doc since none currently exists__________
Set profileDoc = thisdb.CreateDocument
profileDoc.form = "User Profile"
profileDoc.up_username = User
profileDoc.up_AddedDate = Now
profileDoc.up_sessions = 1
profileDoc.up_LastSession = Now
Else
'__________Profile exists, update session tracking info____________
'<<<<<<<<<<<<Counter for Sessions, check if field exists<<<<<<<<<<<<<<<
Dim itemcheck As NotesItem
Set itemcheck = profileDoc.GetFirstItem( "up_sessions" )
If itemcheck Is Nothing Then
profileDoc.up_sessions = 1
Else
profileDoc.up_sessions = profileDoc.up_sessions(0) + 1
End If
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
' <<<<<<<<<<<<<<<<<<<<<<<<SESSION HISTORY<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Dim item As NotesItem
Set item = profileDoc.GetFirstItem( "up_sessionhistory" )
If item Is Nothing Then
profileDoc.up_sessionhistory = ""
Set item = profileDoc.GetFirstItem( "up_sessionhistory" )
End If
If Ubound(profileDoc.up_sessionhistory) >= 9 Then
'<<<<<<<<<<<<retrieve, clear & repopulate last 10 values only<<<<<<<<<<<<<<<<<
Dim J As Integer
Dim X As Integer
'________STEP 1 - Gather Info from original field___________
Dim sourcearray() As String
Redim sourcearray((Ubound(profileDoc.up_sessionhistory)-8) To Ubound(profileDoc.up_sessionhistory)) As String
For J = (Ubound(profileDoc.up_sessionhistory)-8) To Ubound(profileDoc.up_sessionhistory)
sourceArray(J) = profileDoc.up_sessionhistory(J)
Next J
'________STEP 2 - Clear out field______________________
profileDoc.up_sessionhistory = ""
'________STEP 3 - Repopulate field with new values_______
For x = (Ubound(SourceArray)-8) To Ubound(SourceArray)
If profileDoc.up_sessionhistory(0) = "" Then
profileDoc.up_sessionhistory = SourceArray(x)
Else
Set item = profileDoc.GetFirstItem( "up_sessionhistory" )
Call item.AppendToTextList(Cstr(SourceArray(x)))
End If
Next x
'________STEP 4 - Append Last value for this session "Now"_______
Call item.AppendToTextList(Cstr(Now))
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Else
'_______There are less than 9 values, just append__________
Call item.AppendToTextList(Cstr(Now))
End If
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
End If
'_____________Update Last Session field and save__________________
profileDoc.up_LastSession = Cstr(Now)
Call profileDoc.Save( True, True )
End Sub