office-gobmx/wizards/source/template/Correspondence.xba

218 lines
No EOL
7.7 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Correspondence" script:language="StarBasic">Option Explicit
Public msgNoTextmark$, msgError$
Public sAddressbook$
Public Table
Public sCompany$, sFirstName$, sLastName$, sStreet$, sPostalCode$, sCity$, sState$, sInitials$, sPosition$
Public DialogExited
Public oDocument, oText, oBookMarks, oBookMark, oBookMarkCursor, oBookText as Object
Sub Main
BasicLibraries.LoadLibrary(&quot;Tools&quot;)
TemplateDialog = LoadDialog(&quot;Template&quot;, &quot;TemplateDialog&quot;)
DialogModel = TemplateDialog.Model
DialogModel.Step = 2
DialogModel.Optmerge.State = True
LoadLanguageCorrespondence()
TemplateDialog.Execute
End Sub
Function LoadLanguageCorrespondence() as Boolean
If InitResources(&quot;&apos;Template&apos;&quot;, &quot;tpl&quot;) Then
msgNoTextmark$ = GetResText(1303) &amp; Chr(13) &amp; Chr(10) &amp; GetResText(1301)
msgError$ = GetResText(1302)
DialogModel.Title = GetResText(1303+3)
DialogModel.CmdCancel.Label = GetResText(1102)
DialogModel.CmdCorrGoOn.Label = GetResText(1103)
DialogModel.OptSingle.Label = GetResText(1303 + 1)
DialogModel.Optmerge.Label = GetResText(1303 + 2)
DialogModel.FrmLetter.Label = GetResText(1303)
LoadLanguageCorrespondence() = True
Else
msgbox(&quot;Warning: Resource could not be loaded!&quot;)
End If
End Function
Function GetFieldName(oFieldKnot as Object, GeneralFieldName as String)
If oFieldKnot.HasByName(GeneralFieldName) Then
GetFieldName = oFieldKnot.GetByName(GeneralFieldName).FieldName
Else
GetFieldName = &quot;&quot;
End If
End Function
Sub OK
Dim ParaBreak
Dim sDocLang as String
Dim bDBFields as Boolean
Dim oSearchDesc as Object
Dim oFoundAll as Object
Dim oFound as Object
Dim sFoundContent as String
Dim sFoundString as String
Dim sDBField as String
Dim i as Integer
Dim oDBAccess as Object
Dim oAddressDialog as Object
Dim oFields as Object
Dim oDocSettings as Object
bDBFields = DialogModel.Optmerge.State &apos;db oder PLatzhalter
If bDBFields Then
oDBAccess = GetRegistryKeyContent(&quot;org.openoffice.Office.DataAccess/AddressBook/&quot;)
sAddressbook = oDBAccess.DataSourceName
If sAddressbook = &quot;&quot; Then
oAddressDialog = CreateUnoService(&quot;com.sun.star.ui.AddressBookSourceDialog&quot;)
oAddressDialog.Execute
oDBAccess = GetRegistryKeyContent(&quot;org.openoffice.Office.DataAccess/AddressBook/&quot;)
sAddressbook = oDBAccess.DataSourceName
If sAddressbook = &quot;&quot; Then
MsgBox(GetResText(1301))
Exit Sub
End If
End If
oFields = oDBAccess.GetByName(&quot;Fields&quot;)
Table = oDBAccess.GetByName(&quot;Command&quot;)
End If
TemplateDialog.EndExecute()
DialogExited = TRUE
ParaBreak = com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK
oDocument = StarDesktop.ActiveFrame.Controller.Model
If bDBFields Then
&apos;set the address db as current db at the document
oDocSettings = oDocument.createInstance(&quot;com.sun.star.document.DocumentSettings&quot;)
oDocSettings.CurrentDatabaseDataSource = sAddressbook
oDocSettings.CurrentDatabaseCommand = Table
oDocSettings.CurrentDatabaseCommandType = 0
End If
oBookmarks = oDocument.Bookmarks
oText = oDocument.Text
oSearchDesc = oDocument.createsearchDescriptor()
oSearchDesc.SearchRegularExpression = True
oSearchDesc.SearchWords = True
oSearchDesc.SearchString = &quot;&lt;[^&gt;]+&gt;&quot;
oFoundall = oDocument.FindAll(oSearchDesc)
&apos;Loop over the foundings
For i = 0 To oFoundAll.Count - 1
oFound = oFoundAll.GetByIndex(i)
sFoundString = oFound.String
&apos;Extract the string inside the brackets
sFoundContent = FindPartString(sFoundString,&quot;&lt;&quot;,&quot;&gt;&quot;,1)
sFoundContent = LTrim(sFoundContent)
&apos; Define the Cursor and place it on the founding
oBookmarkCursor = oFound.Text.CreateTextCursorbyRange(oFound)
oBookText = oFound.Text
If bDBFields Then
sDBField = GetFieldname(oFields, sFoundContent)
If sDBField &lt;&gt; &quot;&quot; Then
InsertDBField(sAddressbook, Table, sDBField)
End If
Else
InsertPlaceholder(sFoundContent)
End If
Next i
End Sub
Sub InsertDBField(sDBName as String, sTableName as String, sColName as String)
Dim oFieldMaster, oField as Object
If sColname &lt;&gt; &quot;&quot; Then
oFieldMaster = oDocument.createInstance(&quot;com.sun.star.text.FieldMaster.Database&quot;)
oField = oDocument.createInstance(&quot;com.sun.star.text.TextField.Database&quot;)
oFieldMaster.DataBaseName = sDBName
oFieldMaster.DataBaseName = sDBName
oFieldMaster.DataTableName = sTableName
oFieldMaster.DataColumnName = sColName
oField.AttachTextfieldmaster (oFieldMaster)
oBookText.InsertTextContent(oBookMarkCursor, oField, True)
oField.Content = &quot;&lt;&quot; &amp; sColName &amp; &quot;&gt;&quot;
End If
End Sub
Sub InsertPlaceholder(sColName as String)
Dim oFieldMaster as Object
If sColname &lt;&gt; &quot;&quot; Then
oFieldMaster = oDocument.createInstance(&quot;com.sun.star.text.TextField.JumpEdit&quot;)
Select Case sColName
Case &quot;Company&quot;
oFieldMaster.PlaceHolder = getResText(1350+1)
Case &quot;Department&quot;
oFieldMaster.PlaceHolder = getResText(1350+2)
Case &quot;FirstName&quot;
oFieldMaster.PlaceHolder = getResText(1350+3)
Case &quot;LastName&quot;
oFieldMaster.PlaceHolder = getResText(1350+4)
Case &quot;Street&quot;
oFieldMaster.PlaceHolder = getResText(1350+5)
Case &quot;Country&quot;
oFieldMaster.PlaceHolder = getResText(1350+6)
Case &quot;Zip&quot;
oFieldMaster.PlaceHolder = getResText(1350+7)
Case &quot;City&quot;
oFieldMaster.PlaceHolder = getResText(1350+8)
Case &quot;Title&quot;
oFieldMaster.PlaceHolder = getResText(1350+9)
Case &quot;Position&quot;
oFieldMaster.PlaceHolder = getResText(1350+10)
Case &quot;AddrForm&quot;
oFieldMaster.PlaceHolder = getResText(1350+11)
Case &quot;Code&quot;
oFieldMaster.PlaceHolder = getResText(1350+12)
Case &quot;AddrFormMail&quot;
oFieldMaster.PlaceHolder = getResText(1350+13)
Case &quot;PhonePriv&quot;
oFieldMaster.PlaceHolder = getResText(1350+14)
Case &quot;PhoneComp&quot;
oFieldMaster.PlaceHolder = getResText(1350+15)
Case &quot;Fax&quot;
oFieldMaster.PlaceHolder = getResText(1350+16)
Case &quot;EMail&quot;
oFieldMaster.PlaceHolder = getResText(1350+17)
Case &quot;URL&quot;
oFieldMaster.PlaceHolder = getResText(1350+18)
Case &quot;Note&quot;
oFieldMaster.PlaceHolder = getResText(1350+19)
Case &quot;Altfield1&quot;
oFieldMaster.PlaceHolder = getResText(1350+20)
Case &quot;Altfield2&quot;
oFieldMaster.PlaceHolder = getResText(1350+21)
Case &quot;Altfield3&quot;
oFieldMaster.PlaceHolder = getResText(1350+22)
Case &quot;Altfield4&quot;
oFieldMaster.PlaceHolder = getResText(1350+23)
Case &quot;Id&quot;
oFieldMaster.PlaceHolder = getResText(1350+24)
Case &quot;State&quot;
oFieldMaster.PlaceHolder = getResText(1350+25)
Case &quot;PhoneOffice&quot;
oFieldMaster.PlaceHolder = getResText(1350+26)
Case &quot;Pager&quot;
oFieldMaster.PlaceHolder = getResText(1350+27)
Case &quot;PhoneCell&quot;
oFieldMaster.PlaceHolder = getResText(1350+28)
Case &quot;PhoneOther&quot;
oFieldMaster.PlaceHolder = getResText(1350+29)
Case &quot;CalendarURL&quot;
oFieldMaster.PlaceHolder = getResText(1350+30)
Case &quot;InviteParticipant&quot;
oFieldMaster.PlaceHolder = getResText(1350+31)
Case Else
oFieldMaster.PlaceHolder = sColName
End Select
oFieldMaster.Hint = getResText(1350)
oBookText.InsertTextContent(oBookMarkCursor, oFieldMaster, True)
End If
End Sub
</script:module>