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