1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Userfields" script:language="StarBasic">Option Explicit
4&apos;Todo: Controlling Scrollbar via Keyboard
5
6Public Const SBMAXFIELDINDEX = 14
7
8Public DlgUserFields as Object
9Public oDocument as Object
10Public UserFieldDataType(SBMAXFIELDINDEX,1) as String
11Public ScrollBarValue as Integer
12Public UserFieldFamily(0, SBMAXfIELDINDEX) as String
13Public Const SBTBCOUNT = 9
14Public oUserDataAccess as Object
15Public CurFieldIndex as Integer
16Public FilePath as String
17
18Sub StartChangesUserfields
19Dim SystemPath as String
20	BasicLibraries.LoadLibrary(&quot;Tools&quot;)
21	UserFieldDatatype(0,0) = &quot;COMPANY&quot;
22	UserFieldDatatype(0,1) = &quot;o&quot;
23	UserFieldDatatype(1,0) = &quot;FIRSTNAME&quot;
24	UserFieldDatatype(1,1) = &quot;givenname&quot;
25	UserFieldDatatype(2,0) = &quot;LASTNAME&quot;
26	UserFieldDatatype(2,1) = &quot;sn&quot;
27	UserFieldDatatype(3,0) = &quot;INITIALS&quot;
28	UserFieldDatatype(3,1) = &quot;initials&quot;
29	UserFieldDatatype(4,0) = &quot;STREET&quot;
30	UserFieldDatatype(4,1) = &quot;street&quot;
31	UserFieldDatatype(5,0) = &quot;COUNTRY&quot;
32	UserFieldDatatype(5,1) = &quot;c&quot;
33	UserFieldDatatype(6,0) = &quot;ZIP&quot;
34	UserFieldDatatype(6,1) = &quot;postalcode&quot;
35	UserFieldDatatype(7,0) = &quot;CITY&quot;
36	UserFieldDatatype(7,1) = &quot;l&quot;
37	UserFieldDatatype(8,0) = &quot;TITLE&quot;
38	UserFieldDatatype(8,1) = &quot;title&quot;
39	UserFieldDatatype(9,0) = &quot;POSITION&quot;
40	UserFieldDatatype(9,1) = &quot;position&quot;
41	UserFieldDatatype(10,0) = &quot;PHONE_HOME&quot;
42	UserFieldDatatype(10,1) = &quot;homephone&quot;
43	UserFieldDatatype(11,0) = &quot;PHONE_WORK&quot;
44	UserFieldDatatype(11,1) = &quot;telephonenumber&quot;
45	UserFieldDatatype(12,0) = &quot;FAX&quot;
46	UserFieldDatatype(12,1) = &quot;facsimiletelephonenumber&quot;
47	UserFieldDatatype(13,0) = &quot;E-MAIL&quot;
48	UserFieldDatatype(13,1) = &quot;mail&quot;
49	UserFieldDatatype(14,0) = &quot;STATE&quot;
50	UserFieldDatatype(14,1) = &quot;st&quot;
51	FilePath = GetPathSettings(&quot;Config&quot;, False) &amp; &quot;/&quot; &amp; &quot;UserData.dat&quot;
52	DlgUserFields = LoadDialog(&quot;Gimmicks&quot;,&quot;UserfieldDlg&quot;)
53	SystemPath = ConvertFromUrl(FilePath)
54	DlgUserFields.Model.Label10.Label = ReplaceString(DlgUserFields.Model.Label10.Label, &quot;&apos;&quot; &amp; SystemPath &amp; &quot;&apos;&quot;, &quot;&lt;ConfigDir&gt;&quot;)
55	DlgUserFields.Model.Label10.Label = ReplaceString(DlgUserFields.Model.Label10.Label, GetProductName(), &quot;&lt;PRODUCTNAME&gt;&quot;)
56	DlgUserFields.Model.cmdSelect.HelpText = ReplaceString(DlgUserFields.Model.cmdSelect.HelpText, GetProductName(), &quot;&lt;PRODUCTNAME&gt;&quot;)
57	ScrollBarValue = 0
58	oUserDataAccess = GetRegistryKeyContent(&quot;org.openoffice.UserProfile/Data&quot;, True)
59	InitializeUserFamily()
60	FillDialog()
61	DlgUserFields.Execute
62	DlgUserFields.Dispose()
63End Sub
64
65
66Sub FillDialog()
67Dim a as Integer
68	With DlgUserFields
69		For a = 1 To SBTBCount
70			.GetControl(&quot;Label&quot; &amp; a).Model.Label = UserFieldDataType(a-1,0)
71			.GetControl(&quot;TextField&quot; &amp; a).Model.Text = UserFieldFamily(CurFieldIndex, a-1)
72		Next a
73		.Model.ScrollBar1.ScrollValueMax = (SBMAXFIELDINDEX+1) - SBTBCOUNT
74		.Model.ScrollBar1.BlockIncrement = SBTBCOUNT
75		.Model.ScrollBar1.LineIncrement = 1
76		.Model.ScrollBar1.ScrollValue = ScrollBarValue
77	End With
78End Sub
79
80
81Sub ScrollControls()
82	ScrollTextFieldInfo(ScrollBarValue)
83	ScrollBarValue = DlgUserFields.Model.ScrollBar1.ScrollValue
84	If (ScrollBarValue + SBTBCOUNT) &gt;= SBMAXFIELDINDEX + 1 Then
85		ScrollBarValue = (SBMAXFIELDINDEX + 1) - SBTBCOUNT
86	End If
87	FillupTextFields()
88End Sub
89
90
91Sub ScrollTextFieldInfo(ByVal iScrollValue as Integer)
92Dim a as Integer
93Dim CurIndex as Integer
94	For a = 1 To SBTBCOUNT
95		CurIndex = (a-1) + iScrollValue
96		UserFieldFamily(CurFieldIndex,CurIndex) = DlgUserFields.GetControl(&quot;TextField&quot; &amp; a).Model.Text
97	Next a
98End Sub
99
100
101Sub StopMacro()
102	DlgUserFields.EndExecute
103End Sub
104
105
106Sub SaveSettings()
107Dim n as Integer
108Dim m as Integer
109Dim MaxIndex as Integer
110	ScrollTextFieldInfo(DlgUserFields.Model.ScrollBar1.ScrollValue)
111	MaxIndex = Ubound(UserFieldFamily(), 1)
112	Dim FileStrings(MaxIndex) as String
113	For n = 0 To MaxIndex
114		FileStrings(n) = &quot;&quot;
115		For m = 0 To SBMAXFIELDINDEX
116			FileStrings(n) = FileStrings(n) &amp; UserFieldFamily(n,m) &amp; &quot;;&quot;
117		Next m
118	Next n
119	SaveDataToFile(FilePath, FileStrings(), True)
120End Sub
121
122
123Sub ToggleButtons(ByVal Index as Integer)
124Dim i as Integer
125	CurFieldIndex = Index
126	DlgUserFields.Model.cmdNextUser.Enabled = CurFieldIndex &lt;&gt; Ubound(UserFieldFamily(), 1)
127	DlgUserFields.Model.cmdPrevUser.Enabled = CurFieldIndex &lt;&gt; 0
128End Sub
129
130
131Sub InitializeUserFamily()
132Dim FirstIndex as Integer
133Dim UserFieldstrings() as String
134Dim LocStrings() as String
135Dim bFileExists as Boolean
136Dim n as Integer
137Dim m as Integer
138	bFileExists = LoadDataFromFile(GetPathSettings(&quot;Config&quot;, False) &amp; &quot;/&quot; &amp; &quot;UserData.dat&quot;, UserFieldStrings())
139	If bFileExists Then
140		FirstIndex = Ubound(UserFieldStrings())
141		ReDim Preserve UserFieldFamily(FirstIndex, SBMAXFIELDINDEX) as String
142		For n = 0 To FirstIndex
143			LocStrings() = ArrayOutofString(UserFieldStrings(n), &quot;;&quot;)
144			For m = 0 To SBMAXFIELDINDEX
145				UserFieldFamily(n,m) = LocStrings(m)
146			Next m
147		Next n
148	Else
149		ReDim Preserve UserFieldFamily(0,SBMAXFIELDINDEX) as String
150		For m = 0 To SBMAXFIELDINDEX
151			UserFieldFamily(0,m) = oUserDataAccess.GetByName(UserFieldDataType(m,1))
152		Next m
153	End If
154	ToggleButtons(0)
155End Sub
156
157
158Sub AddRecord()
159Dim i as Integer
160Dim MaxIndex as Integer
161	For i = 1 To SBTBCount
162		DlgUserFields.GetControl(&quot;TextField&quot; &amp; i).Model.Text = &quot;&quot;
163	Next i
164	MaxIndex = Ubound(UserFieldFamily(),1)
165	ReDim Preserve UserFieldFamily(MaxIndex + 1, SBMAXFIELDINDEX) as String
166	ToggleButtons(MaxIndex + 1, 1)
167End Sub
168
169
170Sub FillupTextFields()
171Dim a as Integer
172Dim CurIndex as Integer
173	For a = 1 To SBTBCOUNT
174		CurIndex = (a-1) + ScrollBarValue
175		DlgUserFields.GetControl(&quot;Label&quot; &amp; a).Model.Label = UserFieldDataType(CurIndex,0)
176		DlgUserFields.GetControl(&quot;TextField&quot; &amp; a).Model.Text = UserFieldFamily(CurFieldIndex, CurIndex)
177	Next a
178End Sub
179
180
181Sub StepToRecord(aEvent as Object)
182Dim iStep as Integer
183	iStep = CInt(aEvent.Source.Model.Tag)
184	ScrollTextFieldInfo(ScrollBarValue)
185	ToggleButtons(CurFieldIndex  + iStep)
186	FillUpTextFields()
187End Sub
188
189
190Sub SelectCurrentFields()
191Dim MaxIndex as Integer
192Dim i as Integer
193	ScrollTextFieldInfo(ScrollBarValue)
194	MaxIndex = Ubound(UserFieldFamily(),2)
195	For i = 0 To MaxIndex
196		oUserDataAccess.ReplaceByName(UserFieldDataType(i,1), UserFieldFamily(CurFieldIndex, i))
197	Next i
198	oUserDataAccess.commitChanges()
199End Sub
200
201
202Sub DeleteCurrentSettings()
203Dim n as Integer
204Dim m as Integer
205Dim MaxIndex as Integer
206	MaxIndex = Ubound(UserFieldFamily(),1)
207	If CurFieldIndex &lt; MaxIndex Then
208		For n = CurFieldIndex To MaxIndex - 1
209			For m = 0 To SBMAXFIELDINDEX
210				UserFieldFamily(n,m) = UserFieldFamily(n + 1,m)
211			Next m
212		Next n
213	Else
214		CurFieldIndex = MaxIndex - 1
215	End If
216	ReDim Preserve UserFieldFamily(MaxIndex-1, SBMAXfIELDINDEX) as String
217	FillupTextFields()
218	ToggleButtons(CurFieldIndex)
219End Sub</script:module>