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