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="Userfields" script:language="StarBasic">Option Explicit 24cdf0e10cSrcweir'Todo: Controlling Scrollbar via Keyboard 25cdf0e10cSrcweir 26cdf0e10cSrcweirPublic Const SBMAXFIELDINDEX = 14 27cdf0e10cSrcweir 28cdf0e10cSrcweirPublic DlgUserFields as Object 29cdf0e10cSrcweirPublic oDocument as Object 30cdf0e10cSrcweirPublic UserFieldDataType(SBMAXFIELDINDEX,1) as String 31cdf0e10cSrcweirPublic ScrollBarValue as Integer 32cdf0e10cSrcweirPublic UserFieldFamily(0, SBMAXfIELDINDEX) as String 33cdf0e10cSrcweirPublic Const SBTBCOUNT = 9 34cdf0e10cSrcweirPublic oUserDataAccess as Object 35cdf0e10cSrcweirPublic CurFieldIndex as Integer 36cdf0e10cSrcweirPublic FilePath as String 37cdf0e10cSrcweir 38cdf0e10cSrcweirSub StartChangesUserfields 39cdf0e10cSrcweirDim SystemPath as String 40cdf0e10cSrcweir BasicLibraries.LoadLibrary("Tools") 41cdf0e10cSrcweir UserFieldDatatype(0,0) = "COMPANY" 42cdf0e10cSrcweir UserFieldDatatype(0,1) = "o" 43cdf0e10cSrcweir UserFieldDatatype(1,0) = "FIRSTNAME" 44cdf0e10cSrcweir UserFieldDatatype(1,1) = "givenname" 45cdf0e10cSrcweir UserFieldDatatype(2,0) = "LASTNAME" 46cdf0e10cSrcweir UserFieldDatatype(2,1) = "sn" 47cdf0e10cSrcweir UserFieldDatatype(3,0) = "INITIALS" 48cdf0e10cSrcweir UserFieldDatatype(3,1) = "initials" 49cdf0e10cSrcweir UserFieldDatatype(4,0) = "STREET" 50cdf0e10cSrcweir UserFieldDatatype(4,1) = "street" 51cdf0e10cSrcweir UserFieldDatatype(5,0) = "COUNTRY" 52cdf0e10cSrcweir UserFieldDatatype(5,1) = "c" 53cdf0e10cSrcweir UserFieldDatatype(6,0) = "ZIP" 54cdf0e10cSrcweir UserFieldDatatype(6,1) = "postalcode" 55cdf0e10cSrcweir UserFieldDatatype(7,0) = "CITY" 56cdf0e10cSrcweir UserFieldDatatype(7,1) = "l" 57cdf0e10cSrcweir UserFieldDatatype(8,0) = "TITLE" 58cdf0e10cSrcweir UserFieldDatatype(8,1) = "title" 59cdf0e10cSrcweir UserFieldDatatype(9,0) = "POSITION" 60cdf0e10cSrcweir UserFieldDatatype(9,1) = "position" 61cdf0e10cSrcweir UserFieldDatatype(10,0) = "PHONE_HOME" 62cdf0e10cSrcweir UserFieldDatatype(10,1) = "homephone" 63cdf0e10cSrcweir UserFieldDatatype(11,0) = "PHONE_WORK" 64cdf0e10cSrcweir UserFieldDatatype(11,1) = "telephonenumber" 65cdf0e10cSrcweir UserFieldDatatype(12,0) = "FAX" 66cdf0e10cSrcweir UserFieldDatatype(12,1) = "facsimiletelephonenumber" 67cdf0e10cSrcweir UserFieldDatatype(13,0) = "E-MAIL" 68cdf0e10cSrcweir UserFieldDatatype(13,1) = "mail" 69cdf0e10cSrcweir UserFieldDatatype(14,0) = "STATE" 70cdf0e10cSrcweir UserFieldDatatype(14,1) = "st" 71cdf0e10cSrcweir FilePath = GetPathSettings("Config", False) & "/" & "UserData.dat" 72cdf0e10cSrcweir DlgUserFields = LoadDialog("Gimmicks","UserfieldDlg") 73cdf0e10cSrcweir SystemPath = ConvertFromUrl(FilePath) 74cdf0e10cSrcweir DlgUserFields.Model.Label10.Label = ReplaceString(DlgUserFields.Model.Label10.Label, "'" & SystemPath & "'", "<ConfigDir>") 75cdf0e10cSrcweir DlgUserFields.Model.Label10.Label = ReplaceString(DlgUserFields.Model.Label10.Label, GetProductName(), "<PRODUCTNAME>") 76cdf0e10cSrcweir DlgUserFields.Model.cmdSelect.HelpText = ReplaceString(DlgUserFields.Model.cmdSelect.HelpText, GetProductName(), "<PRODUCTNAME>") 77cdf0e10cSrcweir ScrollBarValue = 0 78cdf0e10cSrcweir oUserDataAccess = GetRegistryKeyContent("org.openoffice.UserProfile/Data", True) 79cdf0e10cSrcweir InitializeUserFamily() 80cdf0e10cSrcweir FillDialog() 81cdf0e10cSrcweir DlgUserFields.Execute 82cdf0e10cSrcweir DlgUserFields.Dispose() 83cdf0e10cSrcweirEnd Sub 84cdf0e10cSrcweir 85cdf0e10cSrcweir 86cdf0e10cSrcweirSub FillDialog() 87cdf0e10cSrcweirDim a as Integer 88cdf0e10cSrcweir With DlgUserFields 89cdf0e10cSrcweir For a = 1 To SBTBCount 90cdf0e10cSrcweir .GetControl("Label" & a).Model.Label = UserFieldDataType(a-1,0) 91cdf0e10cSrcweir .GetControl("TextField" & a).Model.Text = UserFieldFamily(CurFieldIndex, a-1) 92cdf0e10cSrcweir Next a 93cdf0e10cSrcweir .Model.ScrollBar1.ScrollValueMax = (SBMAXFIELDINDEX+1) - SBTBCOUNT 94cdf0e10cSrcweir .Model.ScrollBar1.BlockIncrement = SBTBCOUNT 95cdf0e10cSrcweir .Model.ScrollBar1.LineIncrement = 1 96cdf0e10cSrcweir .Model.ScrollBar1.ScrollValue = ScrollBarValue 97cdf0e10cSrcweir End With 98cdf0e10cSrcweirEnd Sub 99cdf0e10cSrcweir 100cdf0e10cSrcweir 101cdf0e10cSrcweirSub ScrollControls() 102cdf0e10cSrcweir ScrollTextFieldInfo(ScrollBarValue) 103cdf0e10cSrcweir ScrollBarValue = DlgUserFields.Model.ScrollBar1.ScrollValue 104cdf0e10cSrcweir If (ScrollBarValue + SBTBCOUNT) >= SBMAXFIELDINDEX + 1 Then 105cdf0e10cSrcweir ScrollBarValue = (SBMAXFIELDINDEX + 1) - SBTBCOUNT 106cdf0e10cSrcweir End If 107cdf0e10cSrcweir FillupTextFields() 108cdf0e10cSrcweirEnd Sub 109cdf0e10cSrcweir 110cdf0e10cSrcweir 111cdf0e10cSrcweirSub ScrollTextFieldInfo(ByVal iScrollValue as Integer) 112cdf0e10cSrcweirDim a as Integer 113cdf0e10cSrcweirDim CurIndex as Integer 114cdf0e10cSrcweir For a = 1 To SBTBCOUNT 115cdf0e10cSrcweir CurIndex = (a-1) + iScrollValue 116cdf0e10cSrcweir UserFieldFamily(CurFieldIndex,CurIndex) = DlgUserFields.GetControl("TextField" & a).Model.Text 117cdf0e10cSrcweir Next a 118cdf0e10cSrcweirEnd Sub 119cdf0e10cSrcweir 120cdf0e10cSrcweir 121cdf0e10cSrcweirSub StopMacro() 122cdf0e10cSrcweir DlgUserFields.EndExecute 123cdf0e10cSrcweirEnd Sub 124cdf0e10cSrcweir 125cdf0e10cSrcweir 126cdf0e10cSrcweirSub SaveSettings() 127cdf0e10cSrcweirDim n as Integer 128cdf0e10cSrcweirDim m as Integer 129cdf0e10cSrcweirDim MaxIndex as Integer 130cdf0e10cSrcweir ScrollTextFieldInfo(DlgUserFields.Model.ScrollBar1.ScrollValue) 131cdf0e10cSrcweir MaxIndex = Ubound(UserFieldFamily(), 1) 132cdf0e10cSrcweir Dim FileStrings(MaxIndex) as String 133cdf0e10cSrcweir For n = 0 To MaxIndex 134cdf0e10cSrcweir FileStrings(n) = "" 135cdf0e10cSrcweir For m = 0 To SBMAXFIELDINDEX 136cdf0e10cSrcweir FileStrings(n) = FileStrings(n) & UserFieldFamily(n,m) & ";" 137cdf0e10cSrcweir Next m 138cdf0e10cSrcweir Next n 139cdf0e10cSrcweir SaveDataToFile(FilePath, FileStrings(), True) 140cdf0e10cSrcweirEnd Sub 141cdf0e10cSrcweir 142cdf0e10cSrcweir 143cdf0e10cSrcweirSub ToggleButtons(ByVal Index as Integer) 144cdf0e10cSrcweirDim i as Integer 145cdf0e10cSrcweir CurFieldIndex = Index 146cdf0e10cSrcweir DlgUserFields.Model.cmdNextUser.Enabled = CurFieldIndex <> Ubound(UserFieldFamily(), 1) 147cdf0e10cSrcweir DlgUserFields.Model.cmdPrevUser.Enabled = CurFieldIndex <> 0 148cdf0e10cSrcweirEnd Sub 149cdf0e10cSrcweir 150cdf0e10cSrcweir 151cdf0e10cSrcweirSub InitializeUserFamily() 152cdf0e10cSrcweirDim FirstIndex as Integer 153cdf0e10cSrcweirDim UserFieldstrings() as String 154cdf0e10cSrcweirDim LocStrings() as String 155cdf0e10cSrcweirDim bFileExists as Boolean 156cdf0e10cSrcweirDim n as Integer 157cdf0e10cSrcweirDim m as Integer 158cdf0e10cSrcweir bFileExists = LoadDataFromFile(GetPathSettings("Config", False) & "/" & "UserData.dat", UserFieldStrings()) 159cdf0e10cSrcweir If bFileExists Then 160cdf0e10cSrcweir FirstIndex = Ubound(UserFieldStrings()) 161cdf0e10cSrcweir ReDim Preserve UserFieldFamily(FirstIndex, SBMAXFIELDINDEX) as String 162cdf0e10cSrcweir For n = 0 To FirstIndex 163cdf0e10cSrcweir LocStrings() = ArrayOutofString(UserFieldStrings(n), ";") 164cdf0e10cSrcweir For m = 0 To SBMAXFIELDINDEX 165cdf0e10cSrcweir UserFieldFamily(n,m) = LocStrings(m) 166cdf0e10cSrcweir Next m 167cdf0e10cSrcweir Next n 168cdf0e10cSrcweir Else 169cdf0e10cSrcweir ReDim Preserve UserFieldFamily(0,SBMAXFIELDINDEX) as String 170cdf0e10cSrcweir For m = 0 To SBMAXFIELDINDEX 171cdf0e10cSrcweir UserFieldFamily(0,m) = oUserDataAccess.GetByName(UserFieldDataType(m,1)) 172cdf0e10cSrcweir Next m 173cdf0e10cSrcweir End If 174cdf0e10cSrcweir ToggleButtons(0) 175cdf0e10cSrcweirEnd Sub 176cdf0e10cSrcweir 177cdf0e10cSrcweir 178cdf0e10cSrcweirSub AddRecord() 179cdf0e10cSrcweirDim i as Integer 180cdf0e10cSrcweirDim MaxIndex as Integer 181cdf0e10cSrcweir For i = 1 To SBTBCount 182cdf0e10cSrcweir DlgUserFields.GetControl("TextField" & i).Model.Text = "" 183cdf0e10cSrcweir Next i 184cdf0e10cSrcweir MaxIndex = Ubound(UserFieldFamily(),1) 185cdf0e10cSrcweir ReDim Preserve UserFieldFamily(MaxIndex + 1, SBMAXFIELDINDEX) as String 186cdf0e10cSrcweir ToggleButtons(MaxIndex + 1, 1) 187cdf0e10cSrcweirEnd Sub 188cdf0e10cSrcweir 189cdf0e10cSrcweir 190cdf0e10cSrcweirSub FillupTextFields() 191cdf0e10cSrcweirDim a as Integer 192cdf0e10cSrcweirDim CurIndex as Integer 193cdf0e10cSrcweir For a = 1 To SBTBCOUNT 194cdf0e10cSrcweir CurIndex = (a-1) + ScrollBarValue 195cdf0e10cSrcweir DlgUserFields.GetControl("Label" & a).Model.Label = UserFieldDataType(CurIndex,0) 196cdf0e10cSrcweir DlgUserFields.GetControl("TextField" & a).Model.Text = UserFieldFamily(CurFieldIndex, CurIndex) 197cdf0e10cSrcweir Next a 198cdf0e10cSrcweirEnd Sub 199cdf0e10cSrcweir 200cdf0e10cSrcweir 201cdf0e10cSrcweirSub StepToRecord(aEvent as Object) 202cdf0e10cSrcweirDim iStep as Integer 203cdf0e10cSrcweir iStep = CInt(aEvent.Source.Model.Tag) 204cdf0e10cSrcweir ScrollTextFieldInfo(ScrollBarValue) 205cdf0e10cSrcweir ToggleButtons(CurFieldIndex + iStep) 206cdf0e10cSrcweir FillUpTextFields() 207cdf0e10cSrcweirEnd Sub 208cdf0e10cSrcweir 209cdf0e10cSrcweir 210cdf0e10cSrcweirSub SelectCurrentFields() 211cdf0e10cSrcweirDim MaxIndex as Integer 212cdf0e10cSrcweirDim i as Integer 213cdf0e10cSrcweir ScrollTextFieldInfo(ScrollBarValue) 214cdf0e10cSrcweir MaxIndex = Ubound(UserFieldFamily(),2) 215cdf0e10cSrcweir For i = 0 To MaxIndex 216cdf0e10cSrcweir oUserDataAccess.ReplaceByName(UserFieldDataType(i,1), UserFieldFamily(CurFieldIndex, i)) 217cdf0e10cSrcweir Next i 218cdf0e10cSrcweir oUserDataAccess.commitChanges() 219cdf0e10cSrcweirEnd Sub 220cdf0e10cSrcweir 221cdf0e10cSrcweir 222cdf0e10cSrcweirSub DeleteCurrentSettings() 223cdf0e10cSrcweirDim n as Integer 224cdf0e10cSrcweirDim m as Integer 225cdf0e10cSrcweirDim MaxIndex as Integer 226cdf0e10cSrcweir MaxIndex = Ubound(UserFieldFamily(),1) 227cdf0e10cSrcweir If CurFieldIndex < MaxIndex Then 228cdf0e10cSrcweir For n = CurFieldIndex To MaxIndex - 1 229cdf0e10cSrcweir For m = 0 To SBMAXFIELDINDEX 230cdf0e10cSrcweir UserFieldFamily(n,m) = UserFieldFamily(n + 1,m) 231cdf0e10cSrcweir Next m 232cdf0e10cSrcweir Next n 233cdf0e10cSrcweir Else 234cdf0e10cSrcweir CurFieldIndex = MaxIndex - 1 235cdf0e10cSrcweir End If 236cdf0e10cSrcweir ReDim Preserve UserFieldFamily(MaxIndex-1, SBMAXfIELDINDEX) as String 237cdf0e10cSrcweir FillupTextFields() 238cdf0e10cSrcweir ToggleButtons(CurFieldIndex) 239*3e02b54dSAndrew RistEnd Sub</script:module> 240