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=
"Correspondence" script:
language=
"StarBasic">Option Explicit
5 Public msgNoTextmark$, msgError$
8 Public sCompany$, sFirstName$, sLastName$, sStreet$, sPostalCode$, sCity$, sState$, sInitials$, sPosition$
10 Public oDocument, oText, oBookMarks, oBookMark, oBookMarkCursor, oBookText as Object
11 Public bTemplate, bDBFields as Boolean
15 BasicLibraries.LoadLibrary(
"Tools
")
16 TemplateDialog = LoadDialog(
"Template
",
"TemplateDialog
")
17 DialogModel = TemplateDialog.Model
19 DialogModel.Optmerge.State = True
20 LoadLanguageCorrespondence()
21 TemplateDialog.Execute
22 TemplateDialog.Dispose()
28 BasicLibraries.LoadLibrary(
"Tools
")
29 LoadLanguageCorrespondence()
37 BasicLibraries.LoadLibrary(
"Tools
")
38 LoadLanguageCorrespondence()
44 Function LoadLanguageCorrespondence() as Boolean
45 If InitResources(
"'Template
'",
"tpl
") Then
46 msgNoTextmark$ = GetResText(
1303)
& Chr(
13)
& Chr(
10)
& GetResText(
1301)
47 msgError$ = GetResText(
1302)
49 DialogModel.Title = GetResText(
1303+
3)
50 DialogModel.CmdCancel.Label = GetResText(
1102)
51 DialogModel.CmdCorrGoOn.Label = GetResText(
1103)
52 DialogModel.OptSingle.Label = GetResText(
1303 +
1)
53 DialogModel.Optmerge.Label = GetResText(
1303 +
2)
54 DialogModel.FrmLetter.Label = GetResText(
1303)
56 LoadLanguageCorrespondence() = True
58 msgbox(
"Warning: Resource could not be loaded!
")
63 Function GetFieldName(oFieldKnot as Object, GeneralFieldName as String)
64 If oFieldKnot.HasByName(GeneralFieldName) Then
65 GetFieldName = oFieldKnot.GetByName(GeneralFieldName).AssignedFieldName
67 GetFieldName =
""
74 Dim sDocLang as String
75 Dim oSearchDesc as Object
76 Dim oFoundAll as Object
78 Dim sFoundContent as String
79 Dim sFoundString as String
80 Dim sDBField as String
82 Dim oDBAccess as Object
83 Dim oAddressDialog as Object
84 Dim oAddressPilot as Object
86 Dim oDocSettings as Object
87 Dim oContext as Object
88 Dim bDBvalid as Boolean
89 'On Local Error Goto GENERALERROR
92 bDBFields = DialogModel.Optmerge.State
'database or placeholder
93 TemplateDialog.EndExecute()
98 oDBAccess = GetRegistryKeyContent(
"org.openoffice.Office.DataAccess/AddressBook/
")
99 sAddressbook = oDBAccess.DataSourceName
102 oContext = createUnoService(
"com.sun.star.sdb.DatabaseContext
" )
104 If (not isNull(oContext)) Then
105 'Is the previously assigned address data source still valid?
106 bDBvalid = oContext.hasByName(sAddressbook)
109 If (bDBvalid = false) Then
110 oAddressPilot = createUnoService(
"com.sun.star.ui.dialogs.AddressBookSourcePilot
")
111 oAddressPilot.execute
113 oDBAccess = GetRegistryKeyContent(
"org.openoffice.Office.DataAccess/AddressBook/
")
114 sAddressbook = oDBAccess.DataSourceName
115 If sAddressbook =
"" Then
116 MsgBox(GetResText(
1301))
120 oFields = oDBAccess.GetByName(
"Fields
")
121 Table = oDBAccess.GetByName(
"Command
")
124 ParaBreak = com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK
125 oDocument = ThisComponent
127 'set the address db as current db at the document
128 oDocSettings = oDocument.createInstance(
"com.sun.star.document.Settings
")
129 oDocSettings.CurrentDatabaseDataSource = sAddressbook
130 oDocSettings.CurrentDatabaseCommand = Table
131 oDocSettings.CurrentDatabaseCommandType =
0
133 oBookmarks = oDocument.Bookmarks
134 oText = oDocument.Text
136 oSearchDesc = oDocument.createsearchDescriptor()
137 oSearchDesc.SearchRegularExpression = True
138 oSearchDesc.SearchWords = True
139 oSearchDesc.SearchString =
"<[^
>]+
>"
140 oFoundall = oDocument.FindAll(oSearchDesc)
142 'Loop over the foundings
143 For i = oFoundAll.Count -
1 To
0 Step -
1
144 oFound = oFoundAll.GetByIndex(i)
145 sFoundString = oFound.String
146 'Extract the string inside the brackets
147 sFoundContent = FindPartString(sFoundString,
"<",
">",
1)
148 sFoundContent = LTrim(sFoundContent)
149 ' Define the Cursor and place it on the founding
150 oBookmarkCursor = oFound.Text.CreateTextCursorbyRange(oFound)
151 oBookText = oFound.Text
153 sDBField = GetFieldname(oFields, sFoundContent)
154 If sDBField
<> "" Then
155 InsertDBField(sAddressbook, Table, sDBField)
157 InsertPlaceholder(sFoundContent)
160 InsertPlaceholder(sFoundContent)
164 'Open the DB beamer with the right DB
167 Dim aURL as new com.sun.star.util.URL
168 aURL.complete =
".component:DB/DataSourceBrowser
"
169 oTransformer = createUnoService(
"com.sun.star.util.URLTransformer
")
170 oTransformer.parseStrict(aURL)
171 oDisp = oDocument.getCurrentController.getFrame.queryDispatch(aURL,
"_beamer
", com.sun.star.frame.FrameSearchFlag.CHILDREN + com.sun.star.frame.FrameSearchFlag.CREATE)
172 Dim aArgs(
3) as new com.sun.star.beans.PropertyValue
173 aArgs(
1).Name =
"DataSourceName
"
174 aArgs(
1).Value = sAddressbook
175 aArgs(
2).Name =
"CommandType
"
176 aArgs(
2).Value = com.sun.star.sdb.CommandType.TABLE
177 aArgs(
3).Name =
"Command
"
178 aArgs(
3).Value = Table
179 oDisp.dispatch(aURL, aArgs())
183 If Err
<> 0 Then
184 Msgbox(msgError$,
16, GetProductName())
192 Sub InsertDBField(sDBName as String, sTableName as String, sColName as String)
193 Dim oFieldMaster, oField as Object
194 If sColname
<> "" Then
195 oFieldMaster = oDocument.createInstance(
"com.sun.star.text.FieldMaster.Database
")
196 oField = oDocument.createInstance(
"com.sun.star.text.TextField.Database
")
197 oFieldMaster.DataBaseName = sDBName
198 oFieldMaster.DataBaseName = sDBName
199 oFieldMaster.DataTableName = sTableName
200 oFieldMaster.DataColumnName = sColName
201 oField.AttachTextfieldmaster (oFieldMaster)
202 oBookText.InsertTextContent(oBookMarkCursor, oField, True)
203 oField.Content =
"<" & sColName
& ">"
208 Sub InsertPlaceholder(sColName as String)
209 Dim oFieldMaster as Object
210 Dim bCorrectField as Boolean
211 If sColname
<> "" Then
213 oFieldMaster = oDocument.createInstance(
"com.sun.star.text.TextField.JumpEdit
")
215 Case
"Company
"
216 oFieldMaster.PlaceHolder = getResText(
1350+
1)
217 Case
"Department
"
218 oFieldMaster.PlaceHolder = getResText(
1350+
2)
219 Case
"FirstName
"
220 oFieldMaster.PlaceHolder = getResText(
1350+
3)
221 Case
"LastName
"
222 oFieldMaster.PlaceHolder = getResText(
1350+
4)
223 Case
"Street
"
224 oFieldMaster.PlaceHolder = getResText(
1350+
5)
225 Case
"Country
"
226 oFieldMaster.PlaceHolder = getResText(
1350+
6)
228 oFieldMaster.PlaceHolder = getResText(
1350+
7)
229 Case
"City
"
230 oFieldMaster.PlaceHolder = getResText(
1350+
8)
231 Case
"Title
"
232 oFieldMaster.PlaceHolder = getResText(
1350+
9)
233 Case
"Position
"
234 oFieldMaster.PlaceHolder = getResText(
1350+
10)
235 Case
"AddrForm
"
236 oFieldMaster.PlaceHolder = getResText(
1350+
11)
237 Case
"Code
"
238 oFieldMaster.PlaceHolder = getResText(
1350+
12)
239 Case
"AddrFormMail
"
240 oFieldMaster.PlaceHolder = getResText(
1350+
13)
241 Case
"PhonePriv
"
242 oFieldMaster.PlaceHolder = getResText(
1350+
14)
243 Case
"PhoneComp
"
244 oFieldMaster.PlaceHolder = getResText(
1350+
15)
246 oFieldMaster.PlaceHolder = getResText(
1350+
16)
247 Case
"EMail
"
248 oFieldMaster.PlaceHolder = getResText(
1350+
17)
250 oFieldMaster.PlaceHolder = getResText(
1350+
18)
251 Case
"Note
"
252 oFieldMaster.PlaceHolder = getResText(
1350+
19)
253 Case
"Altfield1
"
254 oFieldMaster.PlaceHolder = getResText(
1350+
20)
255 Case
"Altfield2
"
256 oFieldMaster.PlaceHolder = getResText(
1350+
21)
257 Case
"Altfield3
"
258 oFieldMaster.PlaceHolder = getResText(
1350+
22)
259 Case
"Altfield4
"
260 oFieldMaster.PlaceHolder = getResText(
1350+
23)
262 oFieldMaster.PlaceHolder = getResText(
1350+
24)
263 Case
"State
"
264 oFieldMaster.PlaceHolder = getResText(
1350+
25)
265 Case
"PhoneOffice
"
266 oFieldMaster.PlaceHolder = getResText(
1350+
26)
267 Case
"Pager
"
268 oFieldMaster.PlaceHolder = getResText(
1350+
27)
269 Case
"PhoneCell
"
270 oFieldMaster.PlaceHolder = getResText(
1350+
28)
271 Case
"PhoneOther
"
272 oFieldMaster.PlaceHolder = getResText(
1350+
29)
273 Case
"CalendarURL
"
274 oFieldMaster.PlaceHolder = getResText(
1350+
30)
275 Case
"InviteParticipant
"
276 oFieldMaster.PlaceHolder = getResText(
1350+
31)
278 bCorrectField = False
280 If bCorrectField Then
281 oFieldMaster.Hint = getResText(
1350)
282 oBookText.InsertTextContent(oBookMarkCursor, oFieldMaster, True)