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