Domino Code Fragment

Code Name*
EKDOCLOC.LSS - Function Library
Date*
04/19/2000
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.
Description*
EKDOCLOC.LSS - Function Library
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
related Notes: MSC Design Library, MSC Design Library
%REM
----------------------------------------------------------------------------
FILE:    EKDOCLOC.LSS - Function Library
UPDATED: April 1997
AUTHOR:  Eric Koeler
       
mailto:ekoeler@panix.com
       
http://www.panix.com/~ekoeler
NOTE:    Copyright (C) 1997 by Eric Koeler, this file is protected by the
        GNU General Public License
----------------------------------------------------------------------------
In the Declarations section of the script in which you plan to use these
functions, add the following line:


     %INCLUDE "FILEPATH\EKDOCLOC.LSS"

Where FILEPATH is the OS-specific, fully qualified path to the location
where you saved this file.
----------------------------------------------------------------------------
%ENDREM


' Function declarations
Declare Function DocLockCheck (doc    As NotesDocument, _
                              prompt As Integer)       As Integer
Declare Function DocLockCreate(doc    As NotesDocument) As Integer
Declare Function DocLockRemove(doc    As NotesDocument) As Integer


' Fields used for document locking
Const LOCKFIELD   = "$LockEdit"
Const LOCKFIELDTD = "$LockEditTime"


'----------------------------------------------------------------------------

Function DocLockCheck(doc As NotesDocument, prompt As Integer) As Integer
 
    On Error Goto ErrorHandler
    DocLockCheck = False


     Dim sess     As New NotesSession
    Dim thisUser As     String
    Dim thatUser As     String


     '----- Get the user names
    thisUser = sess.CommonUserName
    If doc.HasItem(LOCKFIELD) Then
         thatUser = doc.GetFirstItem(LOCKFIELD).Text
    Else
         thatUser = ""
    End if


     '----- Check if this document is already locked
    If Strcomp(thatUser, thisUser) And Strcomp(thatUser, "") Then
         DocLockCheck = True
         If (prompt) Then
              Msgbox thatUser & " is currently viewing or editing this document. " & _
              "You will not be able to edit this document until this user is finished.", 0, _
              "Edit Lock"
        End If
    End If
   
TheEnd:
    Exit Function
   
ErrorHandler:
    Print Trim$(Str(Err)) & ": " & Error$
    Resume TheEnd


End Function

'----------------------------------------------------------------------------

Function DocLockCreate(doc As NotesDocument) As Integer

     On Error Goto   ErrorHandler
    Dim sess As New NotesSession
    DocLockCreate = False


     '----- Check if this user is locked out
    If DocLockCheck(doc, True) Then Goto TheEnd


     '----- Otherwise, lock this document  
    Call doc.ReplaceItemValue(LOCKFIELD,   sess.CommonUserName)
    Call doc.ReplaceItemValue(LOCKFIELDTD, Now)
    DocLockCreate = doc.Save(True, True)
   
TheEnd:
    Exit Function
   
ErrorHandler:
    Print Trim$(Str(Err)) & ": " & Error$
    Resume TheEnd


End Function

'---------------------------------------------------------------------------

Function DocLockRemove(doc As NotesDocument) As Integer

     On Error Goto   ErrorTime
    DocLockRemove = False
         
    '----- Check if this user is locked out, but don't prompt
    If DocLockCheck(doc, False) Then Goto TheEnd


     '----- This user had the lock, so remove it now
    Call doc.RemoveItem(LOCKFIELD)
    Call doc.RemoveItem(LOCKFIELDTD)
    DocLockRemove = doc.Save(True, True)


TheEnd:
    Exit Function


ErrorTime:

     '----- Print the error to the status bar
    Print Trim$(Str$(Err)) & ": " & Error$
    Resume TheEnd

End Function