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