[Issue] Close form by macro - access protection of forms

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
bvdbos
Posts: 11
Joined: Sun Jul 13, 2008 9:07 am
Location: Helmond, Netherlands

[Issue] Close form by macro - access protection of forms

Post by bvdbos »

I want to implement some kind of simple access control on my forms. I have a form which I only want myself to be able to access. When loading the form I check for the OS-username. If the function returns false the form closes. This works well. However, on second attempt to open the document the macro's don't get called on startup. After manually closing and reopening the form the startup macro's do work, fourth they don't etc.

Code: Select all

Sub onloadpersoneelsdossier
if checkpermissionspersoneelsdossier = "false" then
'thisComponent.CurrentController.Frame.close( true )
thisComponent.CurrentController.Frame.dispose()
exit sub
end if   
end Sub

function checkpermissionspersoneelsdossier as string
Dim oForm, oCtrl, oState, oCtrl2, oField, naam
oForm=ThisComponent.Drawpage.Forms.getByName("MainForm")
   If GetGuiType = 1 Then
      naam = Environ( "USERNAME" )   ' Windows
   ElseIf GetGuiType = 4 Then
      naam = Environ( "USER" )   ' Unix, Linux
   Else
      MsgBox "Unknown operating system!", 16           
' Mac OS => GetGuiType = 3
   End If
msgbox("sluiten")
'if naam<>"Bas"  then
checkpermissionspersoneelsdossier="false"
'end if
end function
I suppose this is an error in OOO2.4.1, I've run into somthing similar before. Does anyone have an idea how to accomplish the permissions system per form? Of course, I could just offer the forms and set the permissions on my mysql-database per table (I should do that anyway to prevent other users from reading the data through the tables) but I also want to protect the forms.
Last edited by Hagar Delest on Sat Jul 19, 2008 2:28 pm, edited 1 time in total.
Reason: tagged the thread as Issue (link to a bug report).
User avatar
bvdbos
Posts: 11
Joined: Sun Jul 13, 2008 9:07 am
Location: Helmond, Netherlands

Re: close form by macro - access protection of forms

Post by bvdbos »

No responses here and on oooforum, filed bug 91830.
rmdemi
Posts: 10
Joined: Mon Jun 30, 2008 9:45 pm

Re: [Issue] Close form by macro - access protection of forms

Post by rmdemi »

Hello Bvdbos,

I think your code is buggy :!:

In general, a function is not responsible to access your variables and to chance them. Functions takes variables from calling sub, and some extra variables and They returns soma variables to subs... Take a look some sample function codes, you see this.

But your function tries to reach your dialog and I think to set a label called naam.

So You must try your code (checkpermissionspersoneelsdossier) as sub not a function. And you can create a module level variable checkpermissionspersoneelsdossier="false"

I Think this way is correct way.
OOo 2.4.X on Ms Windows XP + linux-other
User avatar
bvdbos
Posts: 11
Joined: Sun Jul 13, 2008 9:07 am
Location: Helmond, Netherlands

Re: [Issue] Close form by macro - access protection of forms

Post by bvdbos »

Supposing your right, can a sub return have a return-value?

If delete the function and assign the variable "checkpermissionspersoneelsdossier" at the start of the sub the behaviour stays the same.

Code: Select all

Sub onloadpersoneelsdossier
checkpermissionspersoneelsdossier="false"
if checkpermissionspersoneelsdossier = "true" then 
	ResizeWindow
	verbergopmerkingen
	setpersoneelsdossier(true)
       exit sub
end if
'thisComponent.CurrentController.Frame.close( true ) 
thisComponent.CurrentController.Frame.dispose()
end Sub
thanks for helping to solve this.

gr

Bas
rmdemi
Posts: 10
Joined: Mon Jun 30, 2008 9:45 pm

Re: [Issue] Close form by macro - access protection of forms

Post by rmdemi »

Hello Bvdbos,
Supposing your right, can a sub return have a return-value?
Of course a sub can,

Code: Select all

Private booleandossier as String  ' This declaration must be first at module

Sub onloadpersoneelsdossier
checkpermissionspersoneelsdossier
if booleandossier = "false" then
'thisComponent.CurrentController.Frame.close( true )
'Using endExecute disposing method for cleaning memory
'thisComponent.CurrentController.Frame.dispose()
oForm.endExecute()
exit sub
end if   
end Sub

sub checkpermissionspersoneelsdossier
Dim oForm, oCtrl, oState, oCtrl2, oField, naam
oForm=ThisComponent.Drawpage.Forms.getByName("MainForm")
   If GetGuiType = 1 Then
      naam = Environ( "USERNAME" )   ' Windows
   ElseIf GetGuiType = 4 Then
      naam = Environ( "USER" )   ' Unix, Linux
   Else
      MsgBox "Unknown operating system!", 16           
' Mac OS => GetGuiType = 3
   End If
msgbox("sluiten")
'if naam<>"Bas"  then
booleandossier = "false"
'end if
end Sub
So in this way, you can reach this variable. Have a look http://user.services.openoffice.org/en/ ... ose#p16042 this subject about dispose.

Try code...
OOo 2.4.X on Ms Windows XP + linux-other
User avatar
bvdbos
Posts: 11
Joined: Sun Jul 13, 2008 9:07 am
Location: Helmond, Netherlands

Re: [Issue] Close form by macro - access protection of forms

Post by bvdbos »

endExecute() isn't a method of oForm unfortunately...
Post Reply