1*b1cdbd2cSJim Jagielski<?xml version="1.0" encoding="UTF-8"?> 2*b1cdbd2cSJim Jagielski<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3*b1cdbd2cSJim Jagielski<!--*********************************************************** 4*b1cdbd2cSJim Jagielski * 5*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one 6*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file 7*b1cdbd2cSJim Jagielski * distributed with this work for additional information 8*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file 9*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the 10*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance 11*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at 12*b1cdbd2cSJim Jagielski * 13*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0 14*b1cdbd2cSJim Jagielski * 15*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing, 16*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an 17*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the 19*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations 20*b1cdbd2cSJim Jagielski * under the License. 21*b1cdbd2cSJim Jagielski * 22*b1cdbd2cSJim Jagielski ***********************************************************--> 23*b1cdbd2cSJim Jagielski<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Correspondence" script:language="StarBasic">Option Explicit 24*b1cdbd2cSJim Jagielski 25*b1cdbd2cSJim JagielskiPublic msgNoTextmark$, msgError$ 26*b1cdbd2cSJim JagielskiPublic sAddressbook$ 27*b1cdbd2cSJim JagielskiPublic Table 28*b1cdbd2cSJim JagielskiPublic sCompany$, sFirstName$, sLastName$, sStreet$, sPostalCode$, sCity$, sState$, sInitials$, sPosition$ 29*b1cdbd2cSJim JagielskiPublic DialogExited 30*b1cdbd2cSJim JagielskiPublic oDocument, oText, oBookMarks, oBookMark, oBookMarkCursor, oBookText as Object 31*b1cdbd2cSJim JagielskiPublic bTemplate, bDBFields as Boolean 32*b1cdbd2cSJim Jagielski 33*b1cdbd2cSJim JagielskiSub Main 34*b1cdbd2cSJim Jagielski bTemplate = true 35*b1cdbd2cSJim Jagielski BasicLibraries.LoadLibrary("Tools") 36*b1cdbd2cSJim Jagielski TemplateDialog = LoadDialog("Template", "TemplateDialog") 37*b1cdbd2cSJim Jagielski DialogModel = TemplateDialog.Model 38*b1cdbd2cSJim Jagielski DialogModel.Step = 2 39*b1cdbd2cSJim Jagielski DialogModel.Optmerge.State = True 40*b1cdbd2cSJim Jagielski LoadLanguageCorrespondence() 41*b1cdbd2cSJim Jagielski TemplateDialog.Execute 42*b1cdbd2cSJim Jagielski TemplateDialog.Dispose() 43*b1cdbd2cSJim JagielskiEnd Sub 44*b1cdbd2cSJim Jagielski 45*b1cdbd2cSJim Jagielski 46*b1cdbd2cSJim JagielskiSub Placeholder 47*b1cdbd2cSJim Jagielski bTemplate = false 48*b1cdbd2cSJim Jagielski BasicLibraries.LoadLibrary("Tools") 49*b1cdbd2cSJim Jagielski LoadLanguageCorrespondence() 50*b1cdbd2cSJim Jagielski bDBFields = false 51*b1cdbd2cSJim Jagielski OK() 52*b1cdbd2cSJim JagielskiEnd Sub 53*b1cdbd2cSJim Jagielski 54*b1cdbd2cSJim Jagielski 55*b1cdbd2cSJim JagielskiSub Database 56*b1cdbd2cSJim Jagielski bTemplate = false 57*b1cdbd2cSJim Jagielski BasicLibraries.LoadLibrary("Tools") 58*b1cdbd2cSJim Jagielski LoadLanguageCorrespondence() 59*b1cdbd2cSJim Jagielski bDBFields = true 60*b1cdbd2cSJim Jagielski OK() 61*b1cdbd2cSJim JagielskiEnd Sub 62*b1cdbd2cSJim Jagielski 63*b1cdbd2cSJim Jagielski 64*b1cdbd2cSJim JagielskiFunction LoadLanguageCorrespondence() as Boolean 65*b1cdbd2cSJim Jagielski If InitResources("'Template'", "tpl") Then 66*b1cdbd2cSJim Jagielski msgNoTextmark$ = GetResText(1303) & Chr(13) & Chr(10) & GetResText(1301) 67*b1cdbd2cSJim Jagielski msgError$ = GetResText(1302) 68*b1cdbd2cSJim Jagielski If bTemplate Then 69*b1cdbd2cSJim Jagielski DialogModel.Title = GetResText(1303+3) 70*b1cdbd2cSJim Jagielski DialogModel.CmdCancel.Label = GetResText(1102) 71*b1cdbd2cSJim Jagielski DialogModel.CmdCorrGoOn.Label = GetResText(1103) 72*b1cdbd2cSJim Jagielski DialogModel.OptSingle.Label = GetResText(1303 + 1) 73*b1cdbd2cSJim Jagielski DialogModel.Optmerge.Label = GetResText(1303 + 2) 74*b1cdbd2cSJim Jagielski DialogModel.FrmLetter.Label = GetResText(1303) 75*b1cdbd2cSJim Jagielski End If 76*b1cdbd2cSJim Jagielski LoadLanguageCorrespondence() = True 77*b1cdbd2cSJim Jagielski Else 78*b1cdbd2cSJim Jagielski msgbox("Warning: Resource could not be loaded!") 79*b1cdbd2cSJim Jagielski End If 80*b1cdbd2cSJim JagielskiEnd Function 81*b1cdbd2cSJim Jagielski 82*b1cdbd2cSJim Jagielski 83*b1cdbd2cSJim JagielskiFunction GetFieldName(oFieldKnot as Object, GeneralFieldName as String) 84*b1cdbd2cSJim Jagielski If oFieldKnot.HasByName(GeneralFieldName) Then 85*b1cdbd2cSJim Jagielski GetFieldName = oFieldKnot.GetByName(GeneralFieldName).AssignedFieldName 86*b1cdbd2cSJim Jagielski Else 87*b1cdbd2cSJim Jagielski GetFieldName = "" 88*b1cdbd2cSJim Jagielski End If 89*b1cdbd2cSJim JagielskiEnd Function 90*b1cdbd2cSJim Jagielski 91*b1cdbd2cSJim Jagielski 92*b1cdbd2cSJim JagielskiSub OK 93*b1cdbd2cSJim JagielskiDim ParaBreak 94*b1cdbd2cSJim JagielskiDim sDocLang as String 95*b1cdbd2cSJim JagielskiDim oSearchDesc as Object 96*b1cdbd2cSJim JagielskiDim oFoundAll as Object 97*b1cdbd2cSJim JagielskiDim oFound as Object 98*b1cdbd2cSJim JagielskiDim sFoundContent as String 99*b1cdbd2cSJim JagielskiDim sFoundString as String 100*b1cdbd2cSJim JagielskiDim sDBField as String 101*b1cdbd2cSJim JagielskiDim i as Integer 102*b1cdbd2cSJim JagielskiDim oDBAccess as Object 103*b1cdbd2cSJim JagielskiDim oAddressDialog as Object 104*b1cdbd2cSJim JagielskiDim oAddressPilot as Object 105*b1cdbd2cSJim JagielskiDim oFields as Object 106*b1cdbd2cSJim JagielskiDim oDocSettings as Object 107*b1cdbd2cSJim JagielskiDim oContext as Object 108*b1cdbd2cSJim JagielskiDim bDBvalid as Boolean 109*b1cdbd2cSJim Jagielski 'On Local Error Goto GENERALERROR 110*b1cdbd2cSJim Jagielski 111*b1cdbd2cSJim Jagielski If bTemplate Then 112*b1cdbd2cSJim Jagielski bDBFields = DialogModel.Optmerge.State 'database or placeholder 113*b1cdbd2cSJim Jagielski TemplateDialog.EndExecute() 114*b1cdbd2cSJim Jagielski DialogExited = TRUE 115*b1cdbd2cSJim Jagielski End If 116*b1cdbd2cSJim Jagielski 117*b1cdbd2cSJim Jagielski If bDBFields Then 118*b1cdbd2cSJim Jagielski oDBAccess = GetRegistryKeyContent("org.openoffice.Office.DataAccess/AddressBook/") 119*b1cdbd2cSJim Jagielski sAddressbook = oDBAccess.DataSourceName 120*b1cdbd2cSJim Jagielski 121*b1cdbd2cSJim Jagielski bDBvalid = false 122*b1cdbd2cSJim Jagielski oContext = createUnoService( "com.sun.star.sdb.DatabaseContext" ) 123*b1cdbd2cSJim Jagielski 124*b1cdbd2cSJim Jagielski If (not isNull(oContext)) Then 125*b1cdbd2cSJim Jagielski 'Is the previously assigned address data source still valid? 126*b1cdbd2cSJim Jagielski bDBvalid = oContext.hasByName(sAddressbook) 127*b1cdbd2cSJim Jagielski end if 128*b1cdbd2cSJim Jagielski 129*b1cdbd2cSJim Jagielski If (bDBvalid = false) Then 130*b1cdbd2cSJim Jagielski oAddressPilot = createUnoService("com.sun.star.ui.dialogs.AddressBookSourcePilot") 131*b1cdbd2cSJim Jagielski oAddressPilot.execute 132*b1cdbd2cSJim Jagielski 133*b1cdbd2cSJim Jagielski oDBAccess = GetRegistryKeyContent("org.openoffice.Office.DataAccess/AddressBook/") 134*b1cdbd2cSJim Jagielski sAddressbook = oDBAccess.DataSourceName 135*b1cdbd2cSJim Jagielski If sAddressbook = "" Then 136*b1cdbd2cSJim Jagielski MsgBox(GetResText(1301)) 137*b1cdbd2cSJim Jagielski Exit Sub 138*b1cdbd2cSJim Jagielski End If 139*b1cdbd2cSJim Jagielski End If 140*b1cdbd2cSJim Jagielski oFields = oDBAccess.GetByName("Fields") 141*b1cdbd2cSJim Jagielski Table = oDBAccess.GetByName("Command") 142*b1cdbd2cSJim Jagielski End If 143*b1cdbd2cSJim Jagielski 144*b1cdbd2cSJim Jagielski ParaBreak = com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK 145*b1cdbd2cSJim Jagielski oDocument = ThisComponent 146*b1cdbd2cSJim Jagielski If bDBFields Then 147*b1cdbd2cSJim Jagielski 'set the address db as current db at the document 148*b1cdbd2cSJim Jagielski oDocSettings = oDocument.createInstance("com.sun.star.document.Settings") 149*b1cdbd2cSJim Jagielski oDocSettings.CurrentDatabaseDataSource = sAddressbook 150*b1cdbd2cSJim Jagielski oDocSettings.CurrentDatabaseCommand = Table 151*b1cdbd2cSJim Jagielski oDocSettings.CurrentDatabaseCommandType = 0 152*b1cdbd2cSJim Jagielski End If 153*b1cdbd2cSJim Jagielski oBookmarks = oDocument.Bookmarks 154*b1cdbd2cSJim Jagielski oText = oDocument.Text 155*b1cdbd2cSJim Jagielski 156*b1cdbd2cSJim Jagielski oSearchDesc = oDocument.createsearchDescriptor() 157*b1cdbd2cSJim Jagielski oSearchDesc.SearchRegularExpression = True 158*b1cdbd2cSJim Jagielski oSearchDesc.SearchWords = True 159*b1cdbd2cSJim Jagielski oSearchDesc.SearchString = "<[^>]+>" 160*b1cdbd2cSJim Jagielski oFoundall = oDocument.FindAll(oSearchDesc) 161*b1cdbd2cSJim Jagielski 162*b1cdbd2cSJim Jagielski 'Loop over the foundings 163*b1cdbd2cSJim Jagielski For i = oFoundAll.Count -1 To 0 Step -1 164*b1cdbd2cSJim Jagielski oFound = oFoundAll.GetByIndex(i) 165*b1cdbd2cSJim Jagielski sFoundString = oFound.String 166*b1cdbd2cSJim Jagielski 'Extract the string inside the brackets 167*b1cdbd2cSJim Jagielski sFoundContent = FindPartString(sFoundString,"<",">",1) 168*b1cdbd2cSJim Jagielski sFoundContent = LTrim(sFoundContent) 169*b1cdbd2cSJim Jagielski ' Define the Cursor and place it on the founding 170*b1cdbd2cSJim Jagielski oBookmarkCursor = oFound.Text.CreateTextCursorbyRange(oFound) 171*b1cdbd2cSJim Jagielski oBookText = oFound.Text 172*b1cdbd2cSJim Jagielski If bDBFields Then 173*b1cdbd2cSJim Jagielski sDBField = GetFieldname(oFields, sFoundContent) 174*b1cdbd2cSJim Jagielski If sDBField <> "" Then 175*b1cdbd2cSJim Jagielski InsertDBField(sAddressbook, Table, sDBField) 176*b1cdbd2cSJim Jagielski Else 177*b1cdbd2cSJim Jagielski InsertPlaceholder(sFoundContent) 178*b1cdbd2cSJim Jagielski End If 179*b1cdbd2cSJim Jagielski Else 180*b1cdbd2cSJim Jagielski InsertPlaceholder(sFoundContent) 181*b1cdbd2cSJim Jagielski End If 182*b1cdbd2cSJim Jagielski Next i 183*b1cdbd2cSJim Jagielski If bDBFields Then 184*b1cdbd2cSJim Jagielski 'Open the DB beamer with the right DB 185*b1cdbd2cSJim Jagielski Dim oDisp as Object 186*b1cdbd2cSJim Jagielski Dim oTransformer 187*b1cdbd2cSJim Jagielski Dim aURL as new com.sun.star.util.URL 188*b1cdbd2cSJim Jagielski aURL.complete = ".component:DB/DataSourceBrowser" 189*b1cdbd2cSJim Jagielski oTransformer = createUnoService("com.sun.star.util.URLTransformer") 190*b1cdbd2cSJim Jagielski oTransformer.parseStrict(aURL) 191*b1cdbd2cSJim Jagielski oDisp = oDocument.getCurrentController.getFrame.queryDispatch(aURL, "_beamer", com.sun.star.frame.FrameSearchFlag.CHILDREN + com.sun.star.frame.FrameSearchFlag.CREATE) 192*b1cdbd2cSJim Jagielski Dim aArgs(3) as new com.sun.star.beans.PropertyValue 193*b1cdbd2cSJim Jagielski aArgs(1).Name = "DataSourceName" 194*b1cdbd2cSJim Jagielski aArgs(1).Value = sAddressbook 195*b1cdbd2cSJim Jagielski aArgs(2).Name = "CommandType" 196*b1cdbd2cSJim Jagielski aArgs(2).Value = com.sun.star.sdb.CommandType.TABLE 197*b1cdbd2cSJim Jagielski aArgs(3).Name = "Command" 198*b1cdbd2cSJim Jagielski aArgs(3).Value = Table 199*b1cdbd2cSJim Jagielski oDisp.dispatch(aURL, aArgs()) 200*b1cdbd2cSJim Jagielski End If 201*b1cdbd2cSJim Jagielski 202*b1cdbd2cSJim Jagielski GENERALERROR: 203*b1cdbd2cSJim Jagielski If Err <> 0 Then 204*b1cdbd2cSJim Jagielski Msgbox(msgError$,16, GetProductName()) 205*b1cdbd2cSJim Jagielski Resume LETSGO 206*b1cdbd2cSJim Jagielski End If 207*b1cdbd2cSJim Jagielski LETSGO: 208*b1cdbd2cSJim Jagielski 209*b1cdbd2cSJim JagielskiEnd Sub 210*b1cdbd2cSJim Jagielski 211*b1cdbd2cSJim Jagielski 212*b1cdbd2cSJim JagielskiSub InsertDBField(sDBName as String, sTableName as String, sColName as String) 213*b1cdbd2cSJim JagielskiDim oFieldMaster, oField as Object 214*b1cdbd2cSJim Jagielski If sColname <> "" Then 215*b1cdbd2cSJim Jagielski oFieldMaster = oDocument.createInstance("com.sun.star.text.FieldMaster.Database") 216*b1cdbd2cSJim Jagielski oField = oDocument.createInstance("com.sun.star.text.TextField.Database") 217*b1cdbd2cSJim Jagielski oFieldMaster.DataBaseName = sDBName 218*b1cdbd2cSJim Jagielski oFieldMaster.DataBaseName = sDBName 219*b1cdbd2cSJim Jagielski oFieldMaster.DataTableName = sTableName 220*b1cdbd2cSJim Jagielski oFieldMaster.DataColumnName = sColName 221*b1cdbd2cSJim Jagielski oField.AttachTextfieldmaster (oFieldMaster) 222*b1cdbd2cSJim Jagielski oBookText.InsertTextContent(oBookMarkCursor, oField, True) 223*b1cdbd2cSJim Jagielski oField.Content = "<" & sColName & ">" 224*b1cdbd2cSJim Jagielski End If 225*b1cdbd2cSJim JagielskiEnd Sub 226*b1cdbd2cSJim Jagielski 227*b1cdbd2cSJim Jagielski 228*b1cdbd2cSJim JagielskiSub InsertPlaceholder(sColName as String) 229*b1cdbd2cSJim JagielskiDim oFieldMaster as Object 230*b1cdbd2cSJim JagielskiDim bCorrectField as Boolean 231*b1cdbd2cSJim Jagielski If sColname <> "" Then 232*b1cdbd2cSJim Jagielski bCorrectField = True 233*b1cdbd2cSJim Jagielski oFieldMaster = oDocument.createInstance("com.sun.star.text.TextField.JumpEdit") 234*b1cdbd2cSJim Jagielski Select Case sColName 235*b1cdbd2cSJim Jagielski Case "Company" 236*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+1) 237*b1cdbd2cSJim Jagielski Case "Department" 238*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+2) 239*b1cdbd2cSJim Jagielski Case "FirstName" 240*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+3) 241*b1cdbd2cSJim Jagielski Case "LastName" 242*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+4) 243*b1cdbd2cSJim Jagielski Case "Street" 244*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+5) 245*b1cdbd2cSJim Jagielski Case "Country" 246*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+6) 247*b1cdbd2cSJim Jagielski Case "Zip" 248*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+7) 249*b1cdbd2cSJim Jagielski Case "City" 250*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+8) 251*b1cdbd2cSJim Jagielski Case "Title" 252*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+9) 253*b1cdbd2cSJim Jagielski Case "Position" 254*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+10) 255*b1cdbd2cSJim Jagielski Case "AddrForm" 256*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+11) 257*b1cdbd2cSJim Jagielski Case "Code" 258*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+12) 259*b1cdbd2cSJim Jagielski Case "AddrFormMail" 260*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+13) 261*b1cdbd2cSJim Jagielski Case "PhonePriv" 262*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+14) 263*b1cdbd2cSJim Jagielski Case "PhoneComp" 264*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+15) 265*b1cdbd2cSJim Jagielski Case "Fax" 266*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+16) 267*b1cdbd2cSJim Jagielski Case "EMail" 268*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+17) 269*b1cdbd2cSJim Jagielski Case "URL" 270*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+18) 271*b1cdbd2cSJim Jagielski Case "Note" 272*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+19) 273*b1cdbd2cSJim Jagielski Case "Altfield1" 274*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+20) 275*b1cdbd2cSJim Jagielski Case "Altfield2" 276*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+21) 277*b1cdbd2cSJim Jagielski Case "Altfield3" 278*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+22) 279*b1cdbd2cSJim Jagielski Case "Altfield4" 280*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+23) 281*b1cdbd2cSJim Jagielski Case "Id" 282*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+24) 283*b1cdbd2cSJim Jagielski Case "State" 284*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+25) 285*b1cdbd2cSJim Jagielski Case "PhoneOffice" 286*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+26) 287*b1cdbd2cSJim Jagielski Case "Pager" 288*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+27) 289*b1cdbd2cSJim Jagielski Case "PhoneCell" 290*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+28) 291*b1cdbd2cSJim Jagielski Case "PhoneOther" 292*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+29) 293*b1cdbd2cSJim Jagielski Case "CalendarURL" 294*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+30) 295*b1cdbd2cSJim Jagielski Case "InviteParticipant" 296*b1cdbd2cSJim Jagielski oFieldMaster.PlaceHolder = getResText(1350+31) 297*b1cdbd2cSJim Jagielski Case Else 298*b1cdbd2cSJim Jagielski bCorrectField = False 299*b1cdbd2cSJim Jagielski End Select 300*b1cdbd2cSJim Jagielski If bCorrectField Then 301*b1cdbd2cSJim Jagielski oFieldMaster.Hint = getResText(1350) 302*b1cdbd2cSJim Jagielski oBookText.InsertTextContent(oBookMarkCursor, oFieldMaster, True) 303*b1cdbd2cSJim Jagielski End If 304*b1cdbd2cSJim Jagielski End If 305*b1cdbd2cSJim JagielskiEnd Sub 306*b1cdbd2cSJim Jagielski</script:module> 307