($Inbox) Folder in the Mail File
Sub Postopen(Source As Notesuiview)
Dim session As New NotesSession
Dim db As NotesDatabase
Dim db_nab As New NotesDatabase("","")
Dim view_user As NotesView
Dim doc_user As NotesDocument
Dim date_silent As Variant
Dim date_full As Variant
Dim date_latest As Variant
Dim date_popup As Variant
Dim date_silent_valid As Integer
Dim date_full_valid As Integer
Dim string_ini As String
Dim local_mail_server As String
Dim nab_mail_server As String
Dim server_name As String
Dim flag As Integer
Dim msg_title As String
Dim msg_body As String
Dim nb_hour As Long
On Error Resume Next
' # Pseudo Constants
nb_hour = 3 ' Number hour between two popup windows
msg_title = "You need to restart your Notes client"
msg_body = "Your Mail Server have been modified" + Chr(10) + "Please restart your Notes client now"
' # We don't want to go further
string_ini = session.GetEnvironmentString("$DskMgrNoPopup",True)
If string_ini = "1" Then Exit Sub
' # Get Latest Warning Popup date
string_ini = session.GetEnvironmentString("$DskMgrPreviousPopup",True)
If Len(string_ini) > 8 Then
date_popup = Cdat(string_ini)
' # We wait at least X hours between two warnings
If Clng(((Cdbl(Now) - Cdbl(date_popup)) * 24)) < nb_hour Then Exit Sub
End If
' # Get Latest Desktop Manager execution date
string_ini = session.GetEnvironmentString("$DskMgrPreviousFull",True)
If Len(string_ini) > 8 Then
date_full = Cdat(string_ini)
date_full_valid = 1
End If
string_ini = session.GetEnvironmentString("$DskMgrPreviousSilent",True)
If Len(string_ini) > 8 Then
date_silent = Cdat(string_ini)
date_silent_valid = 1
End If
' # Is Desktop Manager installed ?
If date_full_valid = 0 And date_silent_valid = 0 Then Exit Sub
' # Get Latest date of Desktop Manager Run
If date_full_valid = 1 And date_silent_valid = 0 Then
date_latest = date_full
Elseif date_full_valid = 0 And date_silent_valid = 1 Then
date_latest = date_silent
Else
If date_full > date_silent Then
date_latest = date_full
Else
date_latest = date_silent
End If
End If
' ## We have to check if this user has changed its mail server on the NAB
server_name = db.Server
If server_name = "" Then
' # We use the MailServer from the Notes.ini = MailServer define in the Location document
server_name = session.GetEnvironmentString("MailServer",True)
If server_name = "" Then
' # We use the $DskMgrServer variable from the Notes.ini
server_name = session.GetEnvironmentString("$DskMgrServer",True)
End If
End If
flag = db_nab.Open(server_name,"names.nsf")
If flag = True Then
Set view_user = db_nab.GetView("($Users)")
If Not (view_user Is Nothing) Then
Set doc_user = view_user.GetDocumentByKey(session.UserName)
If Not (doc_user Is Nothing) Then
nab_mail_server = doc_user.MailServer(0)
End If
End If
End If
' # Display Popup for the User
local_mail_server = session.GetEnvironmentString("MailServer",True)
If nab_mail_server <> "" And Ucase$(nab_mail_server) <> Ucase$(local_mail_server) Then
Messagebox msg_body, 64, msg_title
End If
' # New 'Latest Popup' time / date
Call session.SetEnvironmentVar("$DskMgrPreviousPopup",Cstr(Now),True)
End Sub
Mail File QueryClose
REM {Default Path for Desktop Manager database and Server};
default_dskmgr_database := "";
default_dskmgr_server := "";
REM {Get the path of the Desktop Manager database on the server};
dskmgr_database := @If(@Environment("DskMgrDatabase") = ""; default_dskmgr_database; @Environment("DskMgrDatabase"));
dskmgr_server := @If(@Environment("DskMgrServer") = ""; default_dskmgr_server; @Environment("DskMgrServer"));
REM {Build a unique Key forn this user};
unique_userkey := @Right(@ReplaceSubstring(@UpperCase(@Name([CN];@UserName));" ";"_");10);
REM {First time we have used this PC};
dskmgr_first := @Environment("DskMgrUseFirst_"+unique_userkey);
@If(dskmgr_first = ""; @SetEnvironment("DskMgrUseFirst_"+unique_userkey; @Text(@Now)); @Success);
dskmgr_first = @Environment("DskMgrUseFirst_"+unique_userkey);
dskmgr_first_nb := @Year(@TextToTime(dskmgr_first))*10000 + @Month(@TextToTime(dskmgr_first))*100 + @Day(@TextToTime(dskmgr_first));
REM {Last time we have used this PC};
dskmgr_last := @Environment("DskMgrUseLast_"+unique_userkey);
@If(dskmgr_last = ""; @SetEnvironment("DskMgrUseLast_"+unique_userkey;@Text(@Now));@Success);
dskmgr_last = @Environment("DskMgrUseLast_"+unique_userkey);
dskmgr_last_nb := @Year(@TextToTime(dskmgr_last))*10000 + @Month(@TextToTime(dskmgr_last))*100 + @Day(@TextToTime(dskmgr_last));
REM {Today time};
today_nb := @Year(@Now)*10000 + @Month(@Now)*100 + @Day(@Now);
days_nb := @If(today_nb = dskmgr_first_nb; 1 ; (@Today - @Date(@TextToTime(dskmgr_first)))/86400);
REM {Check how often we have used this PC};
dskmgr_frequency_text := @Environment("DskMgrUse_"+unique_userkey);
dskmgr_frequency := @If(dskmgr_frequency_text = ""; 1; @TextToNumber(dskmgr_frequency_text));
REM {Increment the frequency if needed (just once a day)};
dskmgr_new_frequency := dskmgr_frequency + @If(today_nb != dskmgr_last_nb;1;0);
@SetEnvironment("DskMgrUse_"+unique_userkey;@Text(dskmgr_new_frequency));
@SetEnvironment("DskMgrUseLast_"+unique_userkey;@Text(@Now));
REM {Define if it is the regular User's PC or a temporary one : used at least 15% of the time};
dskmgr_adjust_frequency := dskmgr_new_frequency * 1,5;
usage := @Integer(100 * @If(dskmgr_adjust_frequency > days_nb; days_nb; dskmgr_adjust_frequency) / @If(days_nb=0;1;days_nb));
regular_pc := @If(dskmgr_new_frequency < 2; 0;
days_nb < 2; 0;
usage < 15; 0;
1);
REM {We can't find the DskMgrStart database, so we force the Desktop Manager database on the server};
@If(@DbExists("":"DskMgrStart.nsf") | dskmgr_database = "" | regular_pc = 0;
@Success;
@Command([FileOpenDatabase];dskmgr_server:dskmgr_database;"";"";"1")
)
Mail File QueryClose
REM {Compute the last time Desktop Manager has run};
previous_fullmode := @Environment("DskMgrPreviousFull");
previous_silentmode := @Environment("DskMgrPreviousSilent");
previous_fullmode_nb := @If(previous_fullmode = ""; 0; @Year(@TextToTime(previous_fullmode))*10000 + @Month(@TextToTime(previous_fullmode))*100 + @Day(@TextToTime(previous_fullmode)));
previous_silentmode_nb := @If(previous_silentmode = ""; 0; @Year(@TextToTime(previous_silentmode))*10000 + @Month(@TextToTime(previous_silentmode))*100 + @Day(@TextToTime(previous_silentmode)));
today_nb := @Year(@Today)*10000 + @Month(@Today)*100 + @Day(@Today);
fullmode_delta := @If(previous_fullmode_nb = 0; today_nb - previous_fullmode_nb; (@Today - @Date(@TextToTime(previous_fullmode)))/86400);
silentmode_delta := @If(previous_silentmode_nb = 0; today_nb - previous_silentmode_nb; (@Today - @Date(@TextToTime(previous_silentmode)))/86400);
REM {Force to run if the lastest run was 2 days or more};
run_dskmgr := @If(silentmode_delta > 2 & fullmode_delta > 2; 1; 0);
REM {Desktop Manager Database Location};
db_name := @If(@Environment("DskMgrDatabase") = ""; ""; @Environment("DskMgrDatabase"));
server_name := @If(@Environment("DskMgrServer") = ""; ""; @Environment("DskMgrServer"));
REM {Start Desktop Manager in FullMode = "1", in Silent Mode = "2"};
@SetEnvironment("DskMgrAutoStart"; "2");
REM {Open the Desktop Manager database};
@If(@Environment("DskMgrDatabase") = "" & @Environment("DskMgrServer") = "";
@SetEnvironment("DskMgrAutoStart";"");
run_dskmgr = 1;
@If(@IsError(@DbExists(server_name:db_name)) | @DbExists(server_name:db_name) = 0;
@Success;
@PostedCommand([FileOpenDatabase];server_name:db_name));
@Success)
Back to Top
Commentaires
0 commentaire
Cet article n'accepte pas de commentaires.