-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMisc_Setfield325.lss
3680 lines (3269 loc) · 119 KB
/
Misc_Setfield325.lss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Option Public
Option Declare
Const SETFIELDVER$ = "Misc Setfield V3.25 13/09/2017"
Const LOOKUP$ = "lookup.nsf"
Const LOOKUPVIEWALIAS$ = "D1"
Const LOOKUPKEY$ = "MISCSETFIELD"
Const BROWSERPATH$ = "C:\Program Files\Internet Explorer\IEXPLORE.EXE"
Const TEXTEDITORPATH$ = "NOTEPAD.EXE"
Const HTTPS$ = "https://"
Const NOTES$ = "notes://"
Const VIEWLINK$ = "VIEW"
Const DBLINK$ = "DB"
Const ONSDOMAIN$ = "domapp001.ons.statistics.gov.uk" ' Updated V3.08 10/04/2015
Const ARIAL$ = "Arial"
Const TIMESNR$ = "Times New Roman"
Const FS1$ = "9"
Const FS2$ = "12"
Const BC$ = "#CCCCCC" ' Grey
Const AUTHORSCOL$ = "#99FF33" ' Pale Green
Const READERSCOL$ = "#FFFF00" ' Yellow
Const NAMESCOL$ = "#00FFFF" ' Pale Blue
Const PROHIBITCOL$ = "#99FF33" ' Pale Green
Const RTMAXLEN% = 500 ' V3.16
Const RTLIMITSPIEL$ = " . . . (Only showing first " & RTMAXLEN% & " chars)" ' V3.16
Const NOVAL$ = "~ NO VALUE ASSIGNED ~" ' V3.16
Dim ws As NotesUIWorkspace
Dim sess As NotesSession
Dim db As NotesDatabase
Dim lookupdb As NotesDatabase
Dim lookupview As NotesView
Dim view As NotesView
Dim uiview As NotesUIView ' V3.02 change agent properties to act on None
Dim dc As NotesDocumentCollection
Dim popup As NotesDocument
Dim lookupdoc As NotesDocument
Dim uidoc As NotesUIDocument
Dim agent As NotesAgent
Dim rtitem As NotesRichTextItem
Dim item As NotesItem
Dim sourceitem As NotesItem
Dim formitems() As String
Dim formitemsexp() As String
Dim bareformitems() As String
Dim formvals() As String
Dim formitemtypes() As String
Dim prohibit() As String
Dim changelog() As String
Dim agentlist() As String
Dim exist As String
Dim prohibitmess As String
Dim filenamexls As String
Dim fieldname As String
Dim fieldtype As String
Dim listtype As String
Dim newfieldname As String
Dim source As String
Dim target As String
Dim rename As String
Dim tempitem As String
Dim tempval As String
Dim tempitemtype As String
Dim tempbareformitems As String
Dim itemdesc As String
Dim targetserver As String
Dim targetdbpath As String
Dim filename As String
Dim tempdir As String
Dim mydate As String
Dim mytime As String
Dim Inshold As String
Dim sorttype As String
Dim holdvalue As String
Dim prohibitcnt As Long
Dim t As Long
Dim m As Long
Dim v As Long
Dim x As Long
Dim y As Long
Dim z As Long
Dim sortcounter As Long
Dim updcnt As Long
Dim choice As Long
Dim itemtype As Long
Dim fieldvalueint As Long
Dim tempdbl() As Double
Dim fieldvaluefp As Double
Dim fieldvalue As Variant
Dim selval As Variant
Dim SortedArray As Variant
Dim heapsortvar As Variant
Dim wsObject As Variant
Dim fr_retval As Variant
Dim cursel As Variant
Dim valvar As Variant
Dim retval As Variant
Dim datevar As Variant
Dim filenamevar As Variant
Dim removeprohibit As Boolean
Declare Private Function W32GetActiveWindow Lib "user32" Alias "GetActiveWindow" ( ) As Long
Declare Private Function W32OpenClipboard Lib "user32" Alias "OpenClipboard" (ByVal hWnd As Long) As Long
Declare Private Function W32CloseClipboard Lib "user32" Alias "CloseClipboard" ( ) As Long
Declare Private Function W32EmptyClipboard Lib "user32" Alias "EmptyClipboard" ( ) As Long
Declare Private Function W32GetClipboardData Lib "user32" Alias "GetClipboardData" (ByVal wFormat As Long) As Long
Declare Private Function W32SetClipboardData Lib "user32" Alias "SetClipboardData" (ByVal wFormat As Long, ByVal hMem As Long) As Long
Declare Private Function W32IsClipboardFormatAvailable Lib "user32" Alias "IsClipboardFormatAvailable" ( ByVal wFormat As Long) As Long
Declare Private Function W32GlobalLock Lib "kernel32" Alias "GlobalLock" (ByVal hMem As Long) As Long
Declare Private Function W32GlobalUnlock Lib "kernel32" Alias "GlobalUnlock" (ByVal hMem As Long) As Long
Declare Private Function W32GlobalAllocate Lib "kernel32" Alias "GlobalAlloc" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Declare Private Function W32WriteMemoryToString Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As Any) As Long
Declare Private Function W32WriteStringToMemory Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As Long, ByVal lpString2 As String) As Long
Sub Initialize
'To roll-out the changes to all current templates use Agent A. MSF_Copy
'Misc Setfield Changelog
ReDim changelog(40) ' Global
changelog(40) = "V3.25 13/09/2017 - Changes to List Design funcrionality - count form fields"
changelog(39) = "V3.24 24/04/2017 - Incremental code improvements such as DBQueryAccess Function, New sorting algorithm"
changelog(38) = "V3.23 05/04/2017 - Export and Import Private Views using DXL"
changelog(37) = "V3.22 03/11/2016 - Change case"
changelog(36) = "V3.21 12/04/2016 - Fixed zero-divide bug with Copy Docs to other DB"
changelog(35) = "V3.20 26/02/2016 - Tidy up of some issues caused by changing the rollout approach"
changelog(34) = "V3.19 10/02/2016 - Inherit from template idea, removed the version in the name, exempt BDB option in MSF_Copy and added Copy ACL Roles"
changelog(33) = "V3.18 18/01/2016 - Compare two documents, some code rationalisation and consistency changes V018 of MSF Template"
changelog(32) = "V3.17 06/01/2016 - Copy View and DB URL, Run background Agent , more improvements to RT Field handling & Release Native Notes Lock V017 of MSF Template"
changelog(31) = "V3.16 22/12/2015 - Sign Document, Copy Documents, improved RT Field handling V016 of MSF Template"
changelog(30) = "V3.15 01/10/2015 - Sorting changes, Added Heapsort, changed Quicksort and Insertion Sort, improved Dominic Spy V015 of MSF Template"
changelog(29) = "V3.14 29/08/2015 - Changed nearly all integers to long data type to raise limit on selected documents from 32767. V014 of MSF Template"
changelog(28) = "V3.13 20/08/2015 - Delete Document ACL check override facility, Correct BDB Version (experimental) V013 of MSF Template"
changelog(27) = "V3.12 31/07/2015 - Added Delete Document which bypasses various deletion prevention methods. V012 of MSF Template"
changelog(26) = "V3.11 30/07/2015 - Took limitations off Release Notes Lock, added remove EDRMS Declaration, added changelog display, added Find/Replace Substring. Fixed delete field bug. V011 of MSF Template"
changelog(25) = "V3.10 18/06/2015 - Improved copy profile doc and release native notes lock V010 of MSF Template"
changelog(24) = "V3.09 15/05/2015 - Improved set integer to cope with Long values V008 of MSF Template"
changelog(23) = "V3.08 21/04/2014 - Fixed Copy URL, added Copy Profile - V007 of MSF Template"
changelog(22) = "V3.07 05/03/2015 - Copy URL to clipboard, Makeresponse - This is V006 of MSF Template"
changelog(21) = "V3.06 13/02/2015 - RemoveERMS list expanded to cope with new fields found."
changelog(20) = "V3.05 03/02/2015 - Various bugfixes mainly to do with conflicts between ui and not ui"
changelog(19) = "V3.04 26/01/2015 - Revised selection again to avoid the annoying ticking of one doc"
changelog(18) = "V3.03 15/01/2015 - Added removeerms, fixed bug about working on uidoc"
changelog(17) = "V3.02 13/01/2015 - Worked out how to have the agent work on No docs selected, _popup renamed to _msfpopup"
changelog(16) = "V3.01 10/01/2015 - Create Document option added and changed the aliases of the field 'exist' to deal with logical issues"
changelog(15) = "V3.00 22/12/2014 - Changed the selection method in the popup form to combobox to give more room, reinstated remove Notes lock. added unique, sort and trim text type arrays, rename field, delete profile"
changelog(14) = "V2.94 21/11/2014 - Changed the code quite considerably to allow back-end display and update of profile documents, new copy button. Refinement to copy button on 01/12/2014."
changelog(13) = "V2.93 01/05/2014 - Added a find/replace feature replacing the release Notes Lock"
changelog(12) = "V2.92 12/03/2014 - Found serious bug when changing type to text - the code is in sub checktype suitably commented - subsequently found a minor bug in findprohibit fixed on 05/04/2014, not versioned but rolled out."
changelog(11) = "V2.91 12/02/2014 - Coding rationalisation in particular the main Select Case, Added release Native Notes Lock"
changelog(10) = "V2.9 20/01/2014 - Added Display Notes.ini and Export to Excel"
changelog(9) = "V2.8 10/01/2014 - Added Edit Profiles feature"
changelog(8) = "V2.7 23/12/2013 - Reordered radio buttons, Added floating point option to setting/appending/new values, bugfixes, analyse forms"
changelog(7) = "V2.63 18/12/2013 - Added list design elements"
changelog(6) = "V2.62 11/12/2013 - Added Find prohibit refresh"
changelog(5) = "V2.61 16/11/2013 - Small change to Dominic Spy feature, not worth a rollout"
changelog(4) = "V2.6 16/10/2013 - Domino Spy type feature added"
changelog(3) = "V2.5 22/08/2013 - Fixed the bugs with append of numbers and dates including multi-value"
changelog(2) = "V2.4 13/08/2013 - Improvements to CopyACL"
changelog(1) = "V2.3 23/11/2012 - Added CopyACL. SEE DECLARATIONS FOR CONSTANTS"
changelog(0) = "V2.2 Security feature added where it looks up the D1 Keyword values view of lookup.nsf for a key of 'MISCSETFIELD'"
Dim doc As NotesDocument
Set ws = New NotesUIWorkspace
Set sess = New NotesSession
Set db = sess.currentdatabase
'%REM FOR OPENNTF Comment out my security feature that prevents unauthorised usage within my organisation
If security = "NO" Then ' ACCESS CHECK WITHIN ONS
Exit Sub
End If
'%END REM
Set uiview = ws.Currentview ' V3.02 change agent properties to act on None
If Not uiview Is Nothing Then ' V3.03
Set view = uiview.view ' V3.07
Set dc = uiview.Documents ' V3.02 change agent properties to act on None
updcnt = 0
If dc.count > 0 Then ' V3.02 change agent properties to act on None
Set doc = dc.getfirstdocument
Else ' V3.02 change agent properties to act on None
Set dc = db.Unprocesseddocuments
If dc.count > 0 Then
Set doc = dc.getfirstdocument ' V3.04
Else
Set doc = New NotesDocument(db) ' V3.02 change agent properties to act on None
doc.nodocselected = "Running in no document selected mode" ' V3.02 change agent properties to act on None
End If
End If ' V3.02 change agent properties to act on None
Else
Set doc = ws.Currentdocument.Document ' V3.03
End If
' The main block of code that populates the popup and controls the operations moved to this new sub mainlogic
' so that the contents can be replaced if required V2.94 DJS 21/11/2014
Set popup = New NotesDocument(db) ' Put back here V3.05
Call A_MainLogic(doc) ' GO HERE FIRST TO SEE PROGRAM STRUCTURE
DeSelect ' V3.16
If exist <> "" Then
If exist < "A" Then
Print Time$ & " : " & SETFIELDVER & " Agent ended OK, updated " & CStr(updcnt) & " documents. Field " & fieldname & " Datatype " & fieldtype & " Action " & exist
End If
End If
End Sub
Sub NotesIni
Dim dummy As Long
Dim eval As Variant
Dim retval As Variant
Dim inidoc As New NotesDocument(db)
eval = Evaluate(|@ConfigFile|, inidoc)
dummy = Shell(TEXTEDITORPATH & " " & eval(0),1)
Print Time$ & " : " & SETFIELDVER & " Agent Ends OK, Notes.ini opened"
End Sub
Sub DeleteDocument(doc As NotesDocument)
' V3.12 31/07/2015
Dim deldoc As NotesDocument
Dim uidocdel As NotesUIDocument
Dim unid As String
Dim iChoice As Long
Dim docselected As Long
retry:
' If Not dbdeleteaccess Then ' prior to V3.24 - questionable reliability
If Not (DBQueryAccess And DBACL_DELETE_DOCUMENTS) > 0 Then ' V3.24 - see function DBQueryAccess for calling details
' 3 Abort IDABORT
' 4 Retry IDRETRY
' 5 Ignore IDIGNORE
iChoice = MessageBox ("Testing the ACL suggests that you do not have Delete access on this database ACL", 18, "ACL Test " & SETFIELDVER)
Select Case iChoice
Case 3 : Print Time$ & " : " & SETFIELDVER & " Exiting"
Exit Sub
Case 4 : Print Time$ & " : " & SETFIELDVER & " Retrying"
GoTo retry
Case 5 : Print Time$ & " : " & SETFIELDVER & " Ignoring"
End Select
End If
If dc Is Nothing Then
docselected = 1
Else
docselected = dc.count
End If
Choice = MessageBox ("Continuing will delete the " & CStr(docselected) & " selected document(s), is this OK", 36, "Confirmation of deletion " & SETFIELDVER)
If(choice = 7) Then
MessageBox "Aborting As Requested",16,"Exiting " & SETFIELDVER
Exit Sub
End If
If dc Is Nothing Then
Dim wsdel As New NotesUIWorkspace
Set uidocdel = wsdel.currentdocument
If Not uidocdel Is Nothing Then ' Deleting the backend open doc is tricky so here goes
unid = doc.Universalid
Call uidocdel.close
Delete doc
Set deldoc = db.Getdocumentbyunid(unid)
Call deldoc.RemovePermanently(True)
Call wsdel.Viewrefresh()
Else
Call doc.RemovePermanently(True)
End If
Else
Call dc.Removeall(True)
End If
Print Time$ & " : " & SETFIELDVER & " Deleted " & CStr(docselected) & " document(s) from " & db.Title
End Sub
Sub A_MainLogic(doc As NotesDocument)
Dim dccount As Long
Call A_InitVariables(doc) ' V3.18 Get the form items and corresponding values
popup.formitems = formitems
popup.formvals = formvals
popup.chooser = ""
popup.selval = ""
popup.newfieldname = ""
popup.newval = ""
popup.fieldtype = "Text"
popup.listtype = "Single"
popup.exist = "Replace Value(s)"
popup.target = ""
popup.rename = ""
popup.targetdbpath = ""
popup.targetserver = "" ' Noticed missing V3.08 when adding copyprofile
popup.targetserverbackend = "" ' V3.10
' ADDED EXPORT FIELDS
popup.formitemsexp = formitems
popup.chooserexp = ""
popup.chosen = ""
popup.delimeter = ","
tempdir=Environ("Temp")
If tempdir="" Then
tempdir=Environ("Tmp")
If tempdir="" Then
MessageBox "No 'TEMP'-directory in your environment"
tempdir = "H:\ndata"
End If
End If
mydate = Format$( Date$ , "yyyymmdd" )
mytime = Format$( Time$ , "hhnn" )
filename = tempdir & "\" & db.title & "_export_" & mydate & "_" & mytime & ".csv"
filenamexls = tempdir & "\" & db.title & "_export_" & mydate & "_" & mytime & ".xls"
popup.filename = filename
filenamevar = Evaluate(|@ReplaceSubstring( filename ; " " ; "_" )|,popup)
filenamevar = Evaluate(|@ReplaceSubstring( filename ; "\\" ; "_" )|,popup)
filenamevar = Evaluate(|@ReplaceSubstring( filename ; "/" ; "_" )|,popup)
popup.filename = filenamevar(0)
If dc Is Nothing Then ' V2.94 21/11/2014
dccount = 1
Else
dccount = dc.count
End If
retval = ws.DialogBox("msfpopup", True, True, False, False, False, False, SETFIELDVER & " : Choose the field and new value or action : " & CStr(dccount) & " documents selected",popup)
If Not retval Then
Print Time$ & " : " & SETFIELDVER & " Cancel Pressed, exiting" ' Changed V2.7 DJS 23/12/2013
Exit Sub
End If
fieldvalue = popup.newval
If(Len(popup.chooser(0)) > 0) Then
fieldname = Left(popup.chooser(0),InStr(popup.chooser(0)," ") - 1)
End If
newfieldname = popup.newfieldname(0)
fieldtype = popup.fieldtype(0)
listtype = popup.listtype(0)
exist = popup.exist(0)
selval = popup.selval
target = popup.target(0)
rename = popup.rename(0)
targetdbpath = popup.targetdbpath(0)
targetserver = popup.targetserverbackend(0) ' Solving a problem V3.10
If(Len(popup.source(0)) > 0) Then
source = Left(popup.source(0),InStr(popup.source(0)," ") - 1)
target = Left(popup.target(0),InStr(popup.target(0)," ") - 1)
End If
If(fieldname = "" And fieldvalue(0) = "" And newfieldname = "" And fieldtype <> "5" And target = "" And targetdbpath = "" And exist <> "B") Then
MessageBox "Nothing Returned",16,"Exiting " & SETFIELDVER
Exit Sub
End If
If(fieldtype = "Integer (Long)" And fieldvalue(0) <> "") Then
fieldvalueint = CLng(fieldvalue(0)) ' NOT DEALING WITH FLOAT ETC
Else
If(fieldtype = "Floating Point" And fieldvalue(0) <> "") Then
fieldvaluefp = CDbl(fieldvalue(0))
End If
End If
Select Case exist
Case "1" : ' REPLACE VALUES
Call ReplaceVals(doc)
Case "2" : ' APPEND VALUES
Call AppendVals(doc)
Case "3" : ' NEW FIELD
Call NewField(doc)
Case "4" : ' DELETE FIELD
Call DeleteField(doc)
Case "5" ' CHANGE FIELD TYPE
Call ChangeFieldType(doc)
Case "6" ' SET ONE FIELD TO ANOTHER
Call SetFieldToAnother(doc)
Case "7" ' REMOVE ERMS DECLARATION V3.03 15/01/2015, List updated V3.09+
Call RemoveObsoleteERMS(doc)
Case "8" ' MAKE ONE DOC A RESPONSE TO ANOTHER V3.07
Call makeresponse(doc)
Case "9" ' REMOVE EDRMS DECLARATION V3.11 24/07/2015
Call RemoveEDRMS(doc)
Case "10" ' RELEASE NATIVE NOTES LOCK - Moved into the numerical range at V3.11
Call ReleaseNotesLock(doc) ' Reinstated at V3.00 Made Multi-doc at V3.11
Case "11" ' FIND/REPLACE SUBSTRING V3.11
Call findreplacesubstring(doc)
Case "12" ' DELETE DOCUMENT V3.12
Call deletedocument(doc)
Case "13" ' FIX BDB VERSION ISSUE V3.13
Call fixbdbdocversion(doc)
Case "14" ' SIGN DOCUMENT V3.16
Call signdocument(doc)
Case "15" ' To Lower Case V3.22
Call ChangeCase(doc,"LOWER")
Case "16" ' To Upper Case V3.22
Call ChangeCase(doc,"UPPER")
Case "18" ' FIND/REPLACE - replaces a matching multi-value array element with another value - not a substring that is find_replace_substring - Reinstated in V3.14
Call findreplace(doc)
Case "19" ' RENAME FIELD
Call renamefield(doc) ' V3.00
Case "20" ' SORT TEXT FIELD
Call sorttextfield(doc) ' V3.00
Case "21" ' TRIM TEXT FIELD
Call trimtextfield(doc) ' V3.00
Case "22" ' UNIQUE TEXT FIELD
Call uniquetextfield(doc) ' V3.00
Case "23" ' CREATE DOCUMENT
If Not uiview Is Nothing Then
Call UIView.DeselectAll
Call createdocument ' V3.00
End If
' The actions that (mainly) don't act on a document selection have been relabelled as letters to make the
' print statement code at the end of initialize summarising what was done easier
Case "A" ' REFRESH ALL FIELDS - be aware this might change the docs in unintended ways
Call RefreshAll(doc)
Case "B" ' COPY ACL
Call copyacl(targetserver,targetdbpath)
Case "C" ' DOMINIC SPY - show all fields/types/values in a browser - only works on one document regardless of collection
Call dominicspy( doc, bareformitems, formvals, formitemtypes)
Case "D" ' FIND PROHIBIT REFRESH DESIGN ELEMENTS
Call findprohibit(False,True) ' Set param 1 to True if we ever allow removal - new form option though
Case "E" ' LIST DESIGN
Call designelements
Case "F" ' ANALYSE FORMS
Call analyseforms
Case "G" ' EDIT PROFILES
If Not uiview Is Nothing Then
Call UIView.DeselectAll
End If
Call editprofiles
Case "H" ' DELETE PROFILE DOC
If Not uiview Is Nothing Then
Call UIView.DeselectAll
End If
Call deleteprofile ' V3.00
Case "I" ' ' EXPORT SELECTED DOCS TO EXCEL
Call export(popup)
Case "J" ' DISPLAY NOTES.INI
Call notesini
Case "L" ' Copy field to clipboard
Call CopyVals(doc)
Case "M" ' Copy URL to clipboard V3.07
Call CopyURL(doc)
Case "N" ' Copy Profile document to another database V3.08
Call copyprofile
Case "O" ' Display changelog
Call changelogdisplay
Case "P" ' COPY DOCUMENTS V3.16
Call copydocs(targetserver,targetdbpath,doc)
Case "Q" ' RUN AGENT V3.17
Call runagent
Case "R" ' COPY DB URL TO CLIPBOARD V3.17
Call CopyDBURL(DBLINK$)
Case "S" ' COPY View URL TO CLIPBOARD V3.17
Call CopyDBURL(VIEWLINK$)
Case "T" ' Compare 2 documents V3.18
Call CompareDocs(doc)
Case "U" ' COPY ACL ROLES V3.19
Call CopyRoles(targetserver,targetdbpath)
Case "V" ' EXPORT VIEW DESIGN TO DXL V3.23
Call ExportViewDXL
Case "W" ' IMPORT VIEW DESIGN FROM DXL V3.23
Call ImportViewDXL
End Select
End Sub
Public Function QuickSort(sArray As Variant, sortorder As String)
Dim sA() As String
Dim j As Long
Dim bottom As Long
Dim top As Long
bottom = LBound ( sArray )
top = UBound ( sArray )
ReDim sA( bottom To top ) As String
For j = bottom To top
sA ( j ) = sArray ( j )
Next
' DoQS does a QuickSort if the Sublist is longer than 10 elements
' Thus, when DoQS finishes, all elements are within 10 spots of their correct location.
' For lists that are close to being in order, an Insertion Sort is much faster than a QuickSort, so we
' run through the whole thing once doing an Insertion Sort to finish tidying up the order.
Call QuickSortMain( sA, bottom, top )
Call InsertionSort ( sA, sortorder )
SortedArray = sA
End Function
Sub HeapSiftUp(pavIn As Variant, piStart As Integer, piEnd As Integer)
' Used to sort DESC
Dim liRoot As Integer
dim liChild As Integer
Dim lvTemp As Variant
liRoot = piStart
While liRoot *2 + 1 <= piEnd
liChild = liRoot *2 + 1
If liChild +1 <= piEnd Then ' You cannot combine this test and the next one on the same line as if this is false you will error testing the next line DJS
If pavIn(liChild) > pavIn(liChild + 1) Then
liChild = liChild + 1
End If
End If
If pavIn(liRoot) > pavIn(liChild) Then
lvTemp = pavIn(liRoot)
pavIn(liRoot) = pavIn(liChild)
pavIn(liChild) = lvTemp
liRoot = liChild
Else
Exit Sub
End If
Wend
End Sub
Function DBDeleteAccess As Boolean ' V3.12
' Evaluating @Useraccess seems to produce quite unreliable results until I happened to run it twice in the same code with different parameters, very strange
' The Full call is @UserAccess(server:path) with no params which returns
' [AccessLevel] : [CreateDocuments] : [DeleteDocuments] : [CreatePersonalAgents] : [CreatePersonalFoldersAndViews] : [CreateSharedFoldersAndViews] : [CreateLotusScriptJavaAgents] : [ReadPublicDocuments] : [WritePublicDocuments]
' Text Values 6; 1; 1; 1; 1; 1; 1; 1; 1 assuming Manager with every permission, delete docs is return val position 3 array subscript 2 because it starts at zero
Dim accstring As String
Dim i As Long
Dim Result As Variant
Dim testdeletiondoc As New NotesDocument(db)
dbdeleteaccess = False
testdeletiondoc.server = db.Server
testdeletiondoc.path = db.FilePath
Result=Evaluate("@UserAccess(server:path)",testdeletiondoc)
For i = LBound(result) To UBound(result)
accstring = accstring & " " & CStr(i) & " = " & result(i) & " ; "
Next
Print Time$ & " : " & SETFIELDVER & " Current user access to " & db.title & " is " & accstring
Result=Evaluate("@UserAccess(server:path; [DELETEDOCUMENTS] )",testdeletiondoc)
Print Time$ & " : " & SETFIELDVER & " Current user delete access to " & db.title & " is " & result(0) & " (where 0 is no delete access, 1 is delete access)"
If(Result(0) = "1") Then ' USER HAS DELETE ACCESS TO CURRENT DB
dbdeleteaccess = True
End If
End Function
Sub SetFieldToAnother(doc As NotesDocument)
fieldname = target ' V3.00 this is to give a meaningful print message at the termination of the code
While Not doc Is Nothing
Set sourceitem = doc.getfirstitem(source)
Set item = doc.ReplaceItemValue( target,sourceitem.values)
Call doc.Save( True, True )
updcnt = updcnt + 1
If dc Is Nothing Then ' V2.94 21/11/2014
Exit Sub
End If
Set doc = dc.getnextdocument(doc)
Wend
End Sub
Sub HeapSiftDown(pavIn As Variant, piStart As Integer, piEnd As Integer)
' Used to sort ASC
Dim liRoot As Integer
Dim liChild As Integer
Dim lvTemp As Variant
liRoot = piStart
While liRoot *2 + 1 <= piEnd
liChild = liRoot *2 + 1
If liChild +1 <= piEnd Then ' You cannot combine this test and the next one on the same line as if this is false you will error testing the next line DJS
If pavIn(liChild) < pavIn(liChild + 1) Then
liChild = liChild + 1
End If
End If
If pavIn(liRoot) < pavIn(liChild) Then
lvTemp = pavIn(liRoot)
pavIn(liRoot) = pavIn(liChild)
pavIn(liChild) = lvTemp
liRoot = liChild
Else
Exit Sub
End If
Wend
End Sub
Sub SignDocument(doc As NotesDocument)
While Not doc Is Nothing
Call doc.sign
Call doc.Save( True, True )
updcnt = updcnt + 1
If dc Is Nothing Then
Exit Sub
End If
Set doc = dc.getnextdocument(doc)
Wend
End Sub
Sub CopyURL(doc As NotesDocument) 'Sub added at V3.07
Dim nc As NotesNoteCollection
Dim ncdoc As NotesDocument
Dim URLchoice(1) As String
Dim URL As String
Dim nid As String
Dim nextid As String
Dim viewname As String
Dim i As Long
Dim returnvar As Variant
URLchoice(0) = NOTES$
URLchoice(1) = HTTPS$
Dim sn As New NotesName(db.server)
If Not dc Is Nothing Then
If dc.count <> 1 Then
MessageBox "This only works on one document at a time",16,SETFIELDVER$ &" Error"
Exit Sub
End If
End If
If view Is Nothing Then
Set nc = db.CreateNoteCollection(False)
Call nc.SelectAllDesignElements(False)
Call nc.SelectAllIndexElements(False)
nc.SelectViews = True
Call nc.BuildCollection
nid = nc.GetFirstNoteId
For i = 1 To nc.Count
Set ncdoc = db.GetDocumentByID(nid)
If InStr(ncdoc.~$Flags(0),"d") Then
If(InStr(ncdoc.~$TITLE(0),"|") > 0) Then
viewname = Left(ncdoc.~$TITLE(0),InStr(ncdoc.~$TITLE(0),"|")-1)
Else
viewname = ncdoc.~$TITLE(0)
End If
Set view = db.GetView(viewname)
Exit For
End If
nid = nc.GetNextNoteId(nid)
Next
End If
If view Is Nothing Then
MessageBox "Cannot find a default view for this database, select the doc at the view level and try again",16,SETFIELDVER$ &" Error"
Exit Sub
End If
returnvar = ws.Prompt( PROMPT_OKCANCELCOMBO, SETFIELDVER$ &" URL Type Dialog", "What kind of URL do you want?",URLchoice(0) , URLchoice )
If returnvar = URLchoice(0) Then
URL = NOTES$ & sn.common & "/" & db.ReplicaID & "/" & view.UniversalID & "/" & doc.universalID
Else
URL = HTTPS$ & ONSDOMAIN$ & "/" & db.ReplicaID & "/" & view.UniversalID & "/" & doc.universalID ' Updated V3.08 10/04/2015
End If
Call setClipboardText(URL)
Print Time$ & " : " & SETFIELDVER & " Agent ended OK, copied URL " & URL & " to clipboard"
End Sub
Sub FindReplace(doc As NotesDocument)
' Prompt using values of the selected field, ignore Single/Multi field, always figure that out as and when
Dim docitem As NotesItem
Dim holdvals() As String
Dim replacestring As String
Dim dccount As Long
Dim w As Long
Dim y As Long
Dim z As Long
Dim s As Long
Dim changed As Long
Dim arresult As Variant
If dc Is Nothing Then
dccount = 1
Else
dccount = dc.count
End If
GoSub getholdvals ' Have to do it with strings
' PROMPT_OK (1) PROMPT_OKCANCELCOMBO (5) PROMPT_OKCANCELEDIT (3) PROMPT_OKCANCELEDITCOMBO (6) PROMPT_OKCANCELLIST (4)
' PROMPT_OKCANCELLISTMULT (7) PROMPT_PASSWORD (10) PROMPT_YESNO (2) PROMPT_YESNOCANCEL (11)
fr_retval = ws.prompt(6,SETFIELDVER & " Find/Replace Interface " & CStr(dccount) & " selected","Select Value to Replace in field " & fieldname,"",holdvals)
If IsEmpty(fr_retval) Then
MessageBox "Cancelling as requested",64,SETFIELDVER & " Find/Replace Interface"
Exit Sub
End If
replacestring = InputBox("Input value you want to replace " & fr_retval & " with in field " & fieldname ,SETFIELDVER & " Find/Replace Interface " & CStr(dccount) & " selected",fieldvalue(0))
Print Time$ & " : " & SETFIELDVER & " Replace value " & fr_retval & " with " & replacestring
If replacestring = "" Then
MessageBox "Cancelling as requested",64,SETFIELDVER & " Find/Replace Interface"
Exit Sub
End If
While Not doc Is Nothing
GoSub getholdvals
arresult = ArrayReplace( holdvals, fr_retval, replacestring)
changed = 0
For s = LBound(holdvals) To UBound(holdvals)
If(holdvals(s) <> arresult(s)) Then
changed = 1
Exit For
End If
Next
If(changed = 1) Then
Select Case fieldtype
Case "Integer (Long)", "Floating Point" :
ReDim tempdbl(UBound(arresult))
For t = LBound(arresult) To UBound(arresult)
tempdbl(t) = CDbl(arresult(t))
Next
Set item = doc.ReplaceItemValue( fieldname, tempdbl) ' DJS 21/08/2013
Case "Date":
Set item = doc.ReplaceItemValue(fieldname, CDat(arresult(0)))
For t = LBound(arresult)+1 To UBound(arresult)
Call doc.ReplaceItemValue(fieldname, ArrayAppend(item.Values,CDat(arresult(t))))
Next
Case Else:
Set item = doc.ReplaceItemValue( fieldname, arresult) ' TEXT
Call checktype(doc)
End Select
Call doc.Save( True, True )
updcnt = updcnt + 1
End If
If dc Is Nothing Then ' V2.94 21/11/2014
Exit Sub
End If
Set doc = dc.getnextdocument(doc)
Wend
Exit Sub
getholdvals: ' NEED TO CONVERT TO STRINGS TO WORK CORRECTLY
y = 0
z = 1
Set docitem = doc.getfirstitem(fieldname)
selval = docitem.text
Stop
ReDim holdvals(y)
For w = 1 To Len(selval)
If(Mid(selval,w,1) = ";") Then
ReDim Preserve holdvals(y)
holdvals(y) = Mid(selval, z,w-z)
z = w + 1
y = y + 1
End If
Next
' GET THE LAST VALUE IF EXISTS
If (w > z) Then
ReDim Preserve holdvals(y)
holdvals(y) = Mid(selval,z,w-z)
End If
Return
End Sub
Sub AnalyseForms
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim deldoc As NotesDocument
Dim forms() As String
Dim formscounts() As String
Dim mess As String
Dim deleteempty As String
Dim formscnt() As Long
Dim formsbytes() As Single ' V3.02
Dim total As Long
Dim profiletotal As Long
Dim i As Long
Dim delmkr As Long
Dim a As Long
Dim b As Long
Dim x As Variant
Print Time$ & " : " & SETFIELDVER & " Analyseforms Starts"
deleteempty = InputBox$("Delete documents with no formname? Y/N", SETFIELDVER$ & " Remove documents?","N")
deleteempty = UCase(deleteempty)
Set dc = db.Alldocuments
total = dc.count
GoSub countforms
Set dc = db.GetProfileDocCollection
profiletotal = dc.count
If(profiletotal > 0) Then
mess = mess & Chr(10) & "========================" & Chr(10) & "Profile Document Summary" & Chr(10) & "========================" & Chr(10)
GoSub countforms
End If
Print Time$ & " : " & SETFIELDVER & " Agent Ends OK Analyseforms Ends"
MessageBox mess,64,SETFIELDVER$ &" Documents By Form - Total " & CStr(total + profiletotal)
Exit Sub
countforms:
i = 0
ReDim forms(i)
ReDim formscnt(i)
ReDim formsbytes(i) ' V3.02
Set doc = dc.getfirstdocument
While Not doc Is Nothing
If(doc.form(0) = "" And doc.nameofprofile = "" And deleteempty = "Y") Then
Set deldoc = doc
delmkr = 1
Else
If(doc.form(0) = "") Then
x = ArrayGetIndex(forms, doc.nameofprofile,5)
Else
x = ArrayGetIndex(forms,doc.form(0),5)
End If
If IsNull(x) Then
ReDim Preserve forms(i)
ReDim Preserve formscnt(i)
ReDim Preserve formsbytes(i) ' V3.02
If(doc.form(0) = "") Then
forms(i) = doc.nameofprofile
Else
forms(i) = doc.form(0)
End If
formscnt(i) = 1
formsbytes(i) = doc.size ' V3.02
i = i + 1
Else
formscnt(x) = formscnt(x) + 1
formsbytes(x) = formsbytes(x) + doc.size ' V3.02
End If
End If
Set doc = dc.getnextdocument(doc)
If (delmkr = 1) Then
Call deldoc.Remove(True)
delmkr = 0
End If
Wend
ReDim formscounts(UBound(forms))
For b = LBound(forms) To UBound(forms)
formscounts(b) = forms(b) & UString$(50 - Len(forms(b))," ") & formscnt(b) & " (No.) " & Format(formsbytes(b),"General Number") & " (Bytes)" ' V3.02
Next
Call quicksort(formscounts,"ASC") ' Sortorder parameter V3.00
For a = LBound(sortedarray) To UBound(sortedarray)
mess = mess & sortedarray(a) & Chr(10)
Next
Return
End Sub
Sub CopyDBURL(link as String) 'Sub added at V3.17
Dim uiview As NotesUIView
Dim URLchoice(1) As String
Dim URL As String
Dim returnvar As Variant
URLchoice(0) = NOTES$
URLchoice(1) = HTTPS$
Dim sn As New NotesName(db.server)
If (link = VIEWLINK$) then
Set uiview = ws.CurrentView
Set view = db.GetView(uiview.Viewname)
End if
returnvar = ws.Prompt( PROMPT_OKCANCELCOMBO, SETFIELDVER$ &" URL Type Dialog", "What kind of URL do you want?",URLchoice(0) , URLchoice )
If returnvar = URLchoice(0) Then
URL = NOTES$ & sn.common & "/" & db.ReplicaID
Else
URL = HTTPS$ & ONSDOMAIN$ & "/" & db.ReplicaID
End If
If (link = VIEWLINK$) Then
URL = URL & "/" & view.UniversalID
End if
Call setClipboardText(URL)
Print Time$ & " : " & SETFIELDVER & " Agent ended OK, copied URL " & URL & " to clipboard"
End Sub
Function ReplaceSubstring( ByVal astring As String, substring As String, newsubstring As String) As String
Dim index As Long
index = InStr( astring, substring)
Do While index > 0
replaceSubstring = Left$( astring, index - 1) & newsubstring
astring = Right$( astring, Len(astring) - index - Len( substring) + 1 )
index = InStr( astring, substring)
Loop
replaceSubstring = replaceSubstring & astring
End Function
Sub CompareDocs(doc As NotesDocument)
Dim path As String
Dim filename As String
Dim noteid As String
Dim holdnoteid As string
Dim filenum As Integer
Dim dummy As Long
Dim i As Long
Dim c As Long
Dim r As Long
Dim holdcreated As Variant
Dim holdlastmod As Variant
Dim holdformvals As Variant
Dim holdbareformitems As Variant
Dim retval As Variant
If dc.count <> 2 Then
MessageBox "This function only works for two selected documents, exiting",16,"Exiting " & SETFIELDVER
Exit sub
End If
holdformvals = formvals
holdbareformitems = bareformitems
holdcreated = doc.Created
holdlastmod = doc.Lastmodified
holdnoteid = "NT" & UString$ ( 8 - Len(doc.Noteid) , "0") & doc.Noteid
For c = LBound(holdbareformitems) To UBound(holdbareformitems)
r = InStr(holdbareformitems(c), " ")
If r > 0 Then
holdbareformitems(c) = Left(holdbareformitems(c),r-1)
End If
Next
Set doc = dc.getnextdocument(doc)
If doc Is nothing Then
MessageBox "Cannot get the second document, exiting",16,"Exiting " & SETFIELDVER
Exit Sub
End If
Call A_InitVariables(doc) ' V3.18 Get the form items and corresponding values End If
noteid = "NT" & UString$ ( 8 - Len(doc.Noteid) , "0") & doc.Noteid
For c = LBound(bareformitems) To UBound(bareformitems)
r = InStr(bareformitems(c), " ")
If r > 0 Then
bareformitems(c) = Left(bareformitems(c),r-1)
End If
Next
GoSub createfile
For c = LBound(bareformitems) To UBound(bareformitems) ' Check current doc (2) against the previous doc (1)
retval = ArrayGetIndex(holdbareformitems, bareformitems(c), 5 )
If IsNull(retval) Then
Print # FileNum, "Field " & bareformitems(c) & " in document last modified " & doc.Lastmodified & " (" & noteid & ") does not exist in document last modified " & holdlastmod & " (" & holdnoteid & ")"
Else
If holdformvals(retval) <> formvals(c) Then
Print # FileNum, "Field " & bareformitems(c) & " in document last modified " & doc.Lastmodified & " (" & noteid & ") has value " & formvals(c)
Print # FileNum, "Field " & holdbareformitems(retval) & " in document last modified " & holdlastmod & " (" & holdnoteid & ") has value " & holdformvals(retval)
End If
End If
Next
For c = LBound(holdbareformitems) To UBound(holdbareformitems) ' Check previous doc (1) against the current doc (2) - only interested in fields not present now
retval = ArrayGetIndex(bareformitems, holdbareformitems(c), 5 )
If IsNull(retval) Then
Print # FileNum, "Field " & holdbareformitems(c) & " in document last modified " & holdlastmod & " (" & holdnoteid & ") does not exist in document last modified " & doc.Lastmodified & " (" & noteid & ")"
End If
Next
Close #FileNum
dummy = Shell(TEXTEDITORPATH & " " & filename,1)
Print Time$ & " : " & SETFIELDVER & " Agent ended OK - wrote compare log"
Exit Sub
createfile:
' FIND CORRECT LOCAL PROFILE DIR
tempdir=Environ("Temp")
If tempdir="" Then
tempdir=Environ("Tmp")