2001-04-23 04:46:42 -05:00
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
2001-06-08 08:22:17 -05:00
|
|
|
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
2002-06-26 07:41:33 -05:00
|
|
|
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Correspondence" script:language="StarBasic">Option Explicit
|
2001-04-23 04:46:42 -05:00
|
|
|
|
|
|
|
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
|
2004-05-19 07:23:48 -05:00
|
|
|
Public bTemplate, bDBFields as Boolean
|
2001-04-23 04:46:42 -05:00
|
|
|
|
|
|
|
Sub Main
|
2004-05-19 07:23:48 -05:00
|
|
|
bTemplate = true
|
2001-06-08 08:22:17 -05:00
|
|
|
BasicLibraries.LoadLibrary("Tools")
|
2001-04-23 04:46:42 -05:00
|
|
|
TemplateDialog = LoadDialog("Template", "TemplateDialog")
|
|
|
|
DialogModel = TemplateDialog.Model
|
|
|
|
DialogModel.Step = 2
|
|
|
|
DialogModel.Optmerge.State = True
|
2004-05-19 07:23:48 -05:00
|
|
|
LoadLanguageCorrespondence()
|
2001-06-08 08:22:17 -05:00
|
|
|
TemplateDialog.Execute
|
2002-07-15 10:42:25 -05:00
|
|
|
TemplateDialog.Dispose()
|
2001-04-23 04:46:42 -05:00
|
|
|
End Sub
|
|
|
|
|
|
|
|
|
2004-05-19 07:23:48 -05:00
|
|
|
Sub Placeholder
|
|
|
|
bTemplate = false
|
|
|
|
BasicLibraries.LoadLibrary("Tools")
|
|
|
|
LoadLanguageCorrespondence()
|
|
|
|
bDBFields = false
|
|
|
|
OK()
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
|
|
|
|
Sub Database
|
|
|
|
bTemplate = false
|
|
|
|
BasicLibraries.LoadLibrary("Tools")
|
|
|
|
LoadLanguageCorrespondence()
|
|
|
|
bDBFields = true
|
|
|
|
OK()
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
|
2001-04-23 04:46:42 -05:00
|
|
|
Function LoadLanguageCorrespondence() as Boolean
|
|
|
|
If InitResources("'Template'", "tpl") Then
|
|
|
|
msgNoTextmark$ = GetResText(1303) & Chr(13) & Chr(10) & GetResText(1301)
|
|
|
|
msgError$ = GetResText(1302)
|
2004-05-19 07:23:48 -05:00
|
|
|
If bTemplate Then
|
|
|
|
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)
|
|
|
|
End If
|
2001-04-23 04:46:42 -05:00
|
|
|
LoadLanguageCorrespondence() = True
|
|
|
|
Else
|
2001-06-08 08:22:17 -05:00
|
|
|
msgbox("Warning: Resource could not be loaded!")
|
2001-04-23 04:46:42 -05:00
|
|
|
End If
|
|
|
|
End Function
|
|
|
|
|
|
|
|
|
2001-06-12 08:44:55 -05:00
|
|
|
Function GetFieldName(oFieldKnot as Object, GeneralFieldName as String)
|
2001-06-08 08:22:17 -05:00
|
|
|
If oFieldKnot.HasByName(GeneralFieldName) Then
|
2001-06-20 03:01:20 -05:00
|
|
|
GetFieldName = oFieldKnot.GetByName(GeneralFieldName).AssignedFieldName
|
2001-04-23 04:46:42 -05:00
|
|
|
Else
|
|
|
|
GetFieldName = ""
|
|
|
|
End If
|
|
|
|
End Function
|
|
|
|
|
|
|
|
|
|
|
|
Sub OK
|
|
|
|
Dim ParaBreak
|
|
|
|
Dim sDocLang as String
|
2001-06-08 08:22:17 -05:00
|
|
|
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
|
2001-08-09 08:17:44 -05:00
|
|
|
Dim oAddressPilot as Object
|
2001-06-08 08:22:17 -05:00
|
|
|
Dim oFields as Object
|
|
|
|
Dim oDocSettings as Object
|
2003-03-27 10:59:30 -06:00
|
|
|
Dim oContext as Object
|
|
|
|
Dim bDBvalid as Boolean
|
|
|
|
'On Local Error Goto GENERALERROR
|
2002-06-26 07:41:33 -05:00
|
|
|
|
2004-05-19 07:23:48 -05:00
|
|
|
If bTemplate Then
|
|
|
|
bDBFields = DialogModel.Optmerge.State 'database or placeholder
|
|
|
|
TemplateDialog.EndExecute()
|
|
|
|
DialogExited = TRUE
|
|
|
|
End If
|
|
|
|
|
2001-06-08 08:22:17 -05:00
|
|
|
If bDBFields Then
|
|
|
|
oDBAccess = GetRegistryKeyContent("org.openoffice.Office.DataAccess/AddressBook/")
|
|
|
|
sAddressbook = oDBAccess.DataSourceName
|
2001-10-09 04:37:05 -05:00
|
|
|
|
2003-03-27 10:59:30 -06:00
|
|
|
bDBvalid = false
|
|
|
|
oContext = createUnoService( "com.sun.star.sdb.DatabaseContext" )
|
|
|
|
|
|
|
|
If (not isNull(oContext)) Then
|
|
|
|
'Is the previously assigned address data source still valid?
|
|
|
|
bDBvalid = oContext.hasByName(sAddressbook)
|
|
|
|
end if
|
|
|
|
|
|
|
|
If (bDBvalid = false) Then
|
|
|
|
oAddressPilot = createUnoService("com.sun.star.ui.dialogs.AddressBookSourcePilot")
|
|
|
|
oAddressPilot.execute
|
|
|
|
|
2001-06-08 08:22:17 -05:00
|
|
|
oDBAccess = GetRegistryKeyContent("org.openoffice.Office.DataAccess/AddressBook/")
|
|
|
|
sAddressbook = oDBAccess.DataSourceName
|
|
|
|
If sAddressbook = "" Then
|
|
|
|
MsgBox(GetResText(1301))
|
|
|
|
Exit Sub
|
|
|
|
End If
|
|
|
|
End If
|
|
|
|
oFields = oDBAccess.GetByName("Fields")
|
|
|
|
Table = oDBAccess.GetByName("Command")
|
|
|
|
End If
|
2001-04-23 04:46:42 -05:00
|
|
|
|
2001-06-08 08:22:17 -05:00
|
|
|
ParaBreak = com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK
|
2002-09-02 06:06:12 -05:00
|
|
|
oDocument = ThisComponent
|
2001-06-08 08:22:17 -05:00
|
|
|
If bDBFields Then
|
|
|
|
'set the address db as current db at the document
|
2002-09-02 06:06:12 -05:00
|
|
|
oDocSettings = oDocument.createInstance("com.sun.star.document.Settings")
|
2001-06-08 08:22:17 -05:00
|
|
|
oDocSettings.CurrentDatabaseDataSource = sAddressbook
|
|
|
|
oDocSettings.CurrentDatabaseCommand = Table
|
2001-06-12 08:44:55 -05:00
|
|
|
oDocSettings.CurrentDatabaseCommandType = 0
|
2001-04-23 04:46:42 -05:00
|
|
|
End If
|
2001-06-08 08:22:17 -05:00
|
|
|
oBookmarks = oDocument.Bookmarks
|
|
|
|
oText = oDocument.Text
|
2001-06-12 08:44:55 -05:00
|
|
|
|
2001-06-08 08:22:17 -05:00
|
|
|
oSearchDesc = oDocument.createsearchDescriptor()
|
|
|
|
oSearchDesc.SearchRegularExpression = True
|
|
|
|
oSearchDesc.SearchWords = True
|
|
|
|
oSearchDesc.SearchString = "<[^>]+>"
|
|
|
|
oFoundall = oDocument.FindAll(oSearchDesc)
|
|
|
|
|
|
|
|
'Loop over the foundings
|
2002-09-02 06:06:12 -05:00
|
|
|
For i = oFoundAll.Count -1 To 0 Step -1
|
2001-06-08 08:22:17 -05:00
|
|
|
oFound = oFoundAll.GetByIndex(i)
|
|
|
|
sFoundString = oFound.String
|
|
|
|
'Extract the string inside the brackets
|
|
|
|
sFoundContent = FindPartString(sFoundString,"<",">",1)
|
|
|
|
sFoundContent = LTrim(sFoundContent)
|
|
|
|
' 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 <> "" Then
|
|
|
|
InsertDBField(sAddressbook, Table, sDBField)
|
2001-08-09 08:17:44 -05:00
|
|
|
Else
|
|
|
|
InsertPlaceholder(sFoundContent)
|
2001-06-08 08:22:17 -05:00
|
|
|
End If
|
|
|
|
Else
|
|
|
|
InsertPlaceholder(sFoundContent)
|
|
|
|
End If
|
|
|
|
Next i
|
2001-06-11 03:46:10 -05:00
|
|
|
If bDBFields Then
|
|
|
|
'Open the DB beamer with the right DB
|
|
|
|
Dim oDisp as Object
|
|
|
|
Dim oTransformer
|
|
|
|
Dim aURL as new com.sun.star.util.URL
|
|
|
|
aURL.complete = ".component:DB/DataSourceBrowser"
|
|
|
|
oTransformer = createUnoService("com.sun.star.util.URLTransformer")
|
2001-06-12 08:44:55 -05:00
|
|
|
oTransformer.parseStrict(aURL)
|
2001-06-11 03:46:10 -05:00
|
|
|
oDisp = oDocument.getCurrentController.getFrame.queryDispatch(aURL, "_beamer", com.sun.star.frame.FrameSearchFlag.CHILDREN + com.sun.star.frame.FrameSearchFlag.CREATE)
|
|
|
|
Dim aArgs(3) as new com.sun.star.beans.PropertyValue
|
|
|
|
aArgs(1).Name = "DataSourceName"
|
|
|
|
aArgs(1).Value = sAddressbook
|
|
|
|
aArgs(2).Name = "CommandType"
|
|
|
|
aArgs(2).Value = com.sun.star.sdb.CommandType.TABLE
|
|
|
|
aArgs(3).Name = "Command"
|
|
|
|
aArgs(3).Value = Table
|
|
|
|
oDisp.dispatch(aURL, aArgs())
|
|
|
|
End If
|
2002-09-02 06:06:12 -05:00
|
|
|
|
|
|
|
GENERALERROR:
|
|
|
|
If Err <> 0 Then
|
2002-09-10 02:26:27 -05:00
|
|
|
Msgbox(msgError$,16, GetProductName())
|
2002-09-02 06:06:12 -05:00
|
|
|
Resume LETSGO
|
|
|
|
End If
|
|
|
|
LETSGO:
|
2001-06-12 08:44:55 -05:00
|
|
|
|
2001-04-23 04:46:42 -05:00
|
|
|
End Sub
|
|
|
|
|
|
|
|
|
|
|
|
Sub InsertDBField(sDBName as String, sTableName as String, sColName as String)
|
|
|
|
Dim oFieldMaster, oField as Object
|
|
|
|
If sColname <> "" Then
|
|
|
|
oFieldMaster = oDocument.createInstance("com.sun.star.text.FieldMaster.Database")
|
|
|
|
oField = oDocument.createInstance("com.sun.star.text.TextField.Database")
|
|
|
|
oFieldMaster.DataBaseName = sDBName
|
|
|
|
oFieldMaster.DataBaseName = sDBName
|
|
|
|
oFieldMaster.DataTableName = sTableName
|
|
|
|
oFieldMaster.DataColumnName = sColName
|
|
|
|
oField.AttachTextfieldmaster (oFieldMaster)
|
|
|
|
oBookText.InsertTextContent(oBookMarkCursor, oField, True)
|
|
|
|
oField.Content = "<" & sColName & ">"
|
|
|
|
End If
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
|
2001-06-08 08:22:17 -05:00
|
|
|
Sub InsertPlaceholder(sColName as String)
|
|
|
|
Dim oFieldMaster as Object
|
2001-08-09 08:17:44 -05:00
|
|
|
Dim bCorrectField as Boolean
|
2001-06-08 08:22:17 -05:00
|
|
|
If sColname <> "" Then
|
2001-08-09 08:17:44 -05:00
|
|
|
bCorrectField = True
|
2001-06-08 08:22:17 -05:00
|
|
|
oFieldMaster = oDocument.createInstance("com.sun.star.text.TextField.JumpEdit")
|
|
|
|
Select Case sColName
|
|
|
|
Case "Company"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+1)
|
|
|
|
Case "Department"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+2)
|
|
|
|
Case "FirstName"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+3)
|
|
|
|
Case "LastName"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+4)
|
|
|
|
Case "Street"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+5)
|
|
|
|
Case "Country"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+6)
|
|
|
|
Case "Zip"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+7)
|
|
|
|
Case "City"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+8)
|
|
|
|
Case "Title"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+9)
|
|
|
|
Case "Position"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+10)
|
|
|
|
Case "AddrForm"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+11)
|
|
|
|
Case "Code"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+12)
|
|
|
|
Case "AddrFormMail"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+13)
|
|
|
|
Case "PhonePriv"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+14)
|
|
|
|
Case "PhoneComp"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+15)
|
|
|
|
Case "Fax"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+16)
|
|
|
|
Case "EMail"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+17)
|
|
|
|
Case "URL"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+18)
|
|
|
|
Case "Note"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+19)
|
|
|
|
Case "Altfield1"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+20)
|
|
|
|
Case "Altfield2"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+21)
|
|
|
|
Case "Altfield3"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+22)
|
|
|
|
Case "Altfield4"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+23)
|
|
|
|
Case "Id"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+24)
|
|
|
|
Case "State"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+25)
|
|
|
|
Case "PhoneOffice"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+26)
|
|
|
|
Case "Pager"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+27)
|
|
|
|
Case "PhoneCell"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+28)
|
|
|
|
Case "PhoneOther"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+29)
|
|
|
|
Case "CalendarURL"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+30)
|
|
|
|
Case "InviteParticipant"
|
|
|
|
oFieldMaster.PlaceHolder = getResText(1350+31)
|
|
|
|
Case Else
|
2001-08-09 08:17:44 -05:00
|
|
|
bCorrectField = False
|
2001-06-20 03:01:20 -05:00
|
|
|
End Select
|
2001-08-09 08:17:44 -05:00
|
|
|
If bCorrectField Then
|
|
|
|
oFieldMaster.Hint = getResText(1350)
|
|
|
|
oBookText.InsertTextContent(oBookMarkCursor, oFieldMaster, True)
|
|
|
|
End If
|
2001-06-08 08:22:17 -05:00
|
|
|
End If
|
2001-04-23 04:46:42 -05:00
|
|
|
End Sub
|
2001-12-12 06:48:38 -06:00
|
|
|
</script:module>
|