Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working With Menus? 1

Status
Not open for further replies.

Hurricane766

IS-IT--Management
Nov 30, 2004
34
0
0
CA
Hi,

I'm trying to implement some way of hiding certain menu items based on the users security level.

If I was able to create a user object from a menu, I could give it instance variables where I could store this info. I don't think that this is possible though.

So, I could use the Tag property of each menu item, all I need to be able to do is traverse the menu(s) somehow... like a tree... but I can't find anything like this either.

Any ideas?

Thanks
 
I created a menu service (NVO) based on the PFC for one of my applications to handle this type of situation.

In a nutshell, create your menus with all options enabled (I assume highest security). When a lower level security opens a window put some code in the open (or better your 'post open' event) which:
1) gets the menu options which the user should not see/or are disabled. This should be in the form of <menu item name, string>, <menu option visible, boolean> i.e., m_print FALSE
2) gets a reference to the windows menu via:
Code:
menu    lm_menu, lm_item
n_cst_menu lnv_menu
window  lw_parent

lw_parent = this

lm_menu = lw_parent.MenuID

lnv_menu.of_GetMenuReference (lm_menu, m_print, lm_item)
3) Set the menu option
Code:
lm_item.Visible = FALSE
4) Loop through your other options as appropriate.

If you don't use the PFC I recommend you download the PB10 version (it's open source) and look at the pfc_n_cst_menu object.

Matt

"Nature forges everything on the anvil of time
 
Another method, which is a bit more crude would be to use functions to load the menu. For instance, if you have a FILE menu with 3 items: OPT_1, OPT_2, and OPT_3. In the Selected event of the FILE object, call a function named something like mf_show_file( ). In that function, handle your user security by controlling visibilities of the options.

e.g.
Code:
//function mf_show_file( )
OPT_1.Visible = FALSE
OPT_3.Visible = FALSE
OPT_3.Visible = FALSE

CHOOSE CASE Long( uf_security_level( ) )
    CASE IS < 4  //only option 1 shows if security level is less than 4
        OPT_1.Visible = TRUE
    CASE 4 //option 1&2 show if security level is 4
        OPT_1.Visible = TRUE
        OPT_2.Visible = TRUE
    CASE ELSE //only option 3 shows if security level is greater than 4
        OPT_3.Visible = TRUE
END CHOOSE

Let me know if the example is confusing, and I may be able to explain it a bit better.
 
Thank you for your replies,

I should also mention that menu items may need to be hidden depending on the version of the program as well as on what area of the country the user is in. Also security settings are much more specific than just 1, 2, 3, 4, 5 ect. Security settings are user administrator specific - meaning that an admin at one company might allow users access to different parts of the program than another admin at a different company.

As such I really didn't want to use case/if and then statements to do this because there are so many cases to monitor - it's possible but a little nasty.

I think what I'm going to try is assigning a unique character to each of the following: security options, program version, province. Then in the tag of each menu field I will put the corresponding unique characters. If the user has that version or security setting.

Just after the user logs in I'll create a string of unique characters that is the areas of the program the user can access.

I'll then call a function that traverses the menu (haven't tried it yet but each menu object has an Item[] property which is a list of all it's sub menus) and hide/show menu items based on the tag and the users "access string".

That's the plan anyway, I've yet to implement it. Any ideas?

Thanks


 
Just a quick spit-ball idea, but I'm guessing you're going to have some form of a maintenance application for your admins to control access? If so, then basically you'd be storing two key elements in the DB, user's ID and option ID of some form for what that user has access to. You could retrieve the accessible menu items to a DataStore, and loop through the rows turning on only the items the user has access to.

Hope this helps.
 
In addition to 'thekl0wn'...

You can make your menu itself looking for sucurity level.

Yince PB doesnt gives acess to the create event for menu(items) in the IDE edid mode you can open the sourse in 'edit source mode' to edit the source code directly. There you can add code to the create event eg call a function mf_lookupmysecurity( this.classname()) returning true or false for beeing enabled or disabled. In the on menuname.create in soursecode add this.enabled = mf_lookupmysecurity( this.classname())

so you can handle all security in the mf_lookupmysecurity( ) function... lookup securitylevel in database or elsewhere and set the returnvalue appropriate to securitylevel

this makes it easy to add menuitems in development because all related thins are in one function. the only thing you have to do than when adding some items is to add it to the menu_security_table in database.
eg. you define a table with userid and (varchar) menuacess

userid = "pepe1"
menuacess = "m_main;m_custumor;m_printer_setup;"

userid = "billmurray"
menuacess = "m_main;m_custumor;m_printer_setup;m_add_item;m_print_billing"
etc

add a global variable to your app gs_menu_access
select gs_menu_access for the user and code mf_lookupmysecurity( string as_menu) like this:

if pos( gs_menu_access,as_menu) > 0 then
return TRUE
ELSE
return false
end if
 
Thanks for the ideas.

I really like the idea of editing the source to get at the create event.

Thanks again.
 
bernds44, you're a life-saver! I'm working with a similar issue right now as well, and didn't even think of editing the source... duh! Thanks!
 
Thanks Guys,

but be aware when you edit sourcecode. The feature to att code to the create event is not documented. I only testet it 10 minutes. so much work must be done in testing before deploying!!!!

 
hello,i do as this:
Code:
1\create 2 tables ,sys_module,sys_point 
  and in the 2 tables,save the data just like the base menu
  eg: 
  table1\sys_module: 
        row moudlename
         -----------
         1   file 
         -----------
         2   edit
  table2\sys_point:
         row modulename pointname
          1   file       new
          2   file       open
          3   edit       cut
          4   edit       copy
          5   edit       past
2\create a table sys_menupurview to store someone's menu 
 based on the  security level
 eg: 
 table3\sys_menupurview
         row user modulename pointname bvalid
          1   tom  file       new       Y     
          2   tom  file       open      Y
          3   tom  edit       cut       N
          4   tom  edit       copy      Y
          5   tom  edit       past      N
3\when somebody logining,retrieve it's menu purview where bvalid='Y' and dynamic create the menu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top