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

Creating a macro - Writing a Script - Using the API

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

Postby bvdbos » Sun Jul 13, 2008 9:41 am

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   Expand viewCollapse view
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

Postby bvdbos » Sat Jul 19, 2008 9:09 am

No responses here and on oooforum, filed bug 91830.
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

Postby rmdemi » Sun Jul 20, 2008 11:17 pm

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
rmdemi
 
Posts: 10
Joined: Mon Jun 30, 2008 9:45 pm

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

Postby bvdbos » Mon Jul 21, 2008 7:29 am

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   Expand viewCollapse view
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
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

Postby rmdemi » Mon Jul 21, 2008 6:12 pm

Hello Bvdbos,

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


Of course a sub can,

Code: Select all   Expand viewCollapse view
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/forum/viewtopic.php?f=20&t=3584&p=16042&hilit=dispose#p16042 this subject about dispose.

Try code...
OOo 2.4.X on Ms Windows XP + linux-other
rmdemi
 
Posts: 10
Joined: Mon Jun 30, 2008 9:45 pm

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

Postby bvdbos » Mon Jul 21, 2008 8:54 pm

endExecute() isn't a method of oForm unfortunately...
User avatar
bvdbos
 
Posts: 11
Joined: Sun Jul 13, 2008 9:07 am
Location: Helmond, Netherlands


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 10 guests