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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem on enabling and disabling menu bar

Status
Not open for further replies.

gutay008

Programmer
Nov 9, 2015
34
PH
Good Day!

i dont know if what is the problem on my code, im trying to disable some of my menu bar when the user account change. For example, if the user which is currently logged is admin, all menu and menu bar will be enable, then if a another user account logged in like guest there will be certain menu he/she can access.
here is my code in my login module:

SELECT user
SET ORDER TO id
LOCATE FOR user.username = ALLTRIM(thisform.txtUsername.Value) AND user.password = thisform.text2.Value
IF found()
SET SKIP OF MENU _msysmenu .f.
thisform.text3.Value = user.role

IF user.admin = "S" *** for guest account
SET SKIP OF BAR 1 OF file .f.
SET SKIP OF BAR 2 OF file .t.
SET SKIP OF BAR 2 OF department .t.
_screen.Caption = "BGHsystem v1.0" +" "+"(WELCOME:"+" "+ALLTRIM(user.fullname)+")"
DEFINE BAR 3 OF File PROMPT "L\<og Out" +" "+ ALLTRIM(user.username)+"..."
ELSE
IF user.admin = "T" *** for admin account
SET SKIP OF BAR 1 OF file .f.
SET SKIP OF BAR 2 OF file .f.
SET SKIP OF BAR 2 OF department .f.
_screen.Caption = "BGHsystem v1.0" +" "+"(WELCOME:"+" "+ALLTRIM(user.fullname)+")"
DEFINE BAR 3 OF File PROMPT "L\<og Out" +" "+ ALLTRIM(user.username)+"..."
ENDIF
ENDIF

attached here is the image of my setup menu items..

thank you in advence
 
 http://files.engineering.com/getfile.aspx?folder=bf04dfb4-4c75-4a42-846b-3a800ffd4dd2&file=under_file_menu.png
And what doesn't work? Did you compare bar numnbers with the menu definiton? Is the menu established already, when you run this?

Bye, Olaf.
 
yes, i already double checked the name of the menu and the bar number. the problem is if i logged the guest account all the menu and menu bar was enabled and if i logged the admin account just the same as if nothing happens. it always enabled all my menu bar.
 
What value is user.admin? Could you set a breakpoint and check that out?

Also please try the following: Enter a username, then empty the password textbox via CTRl+A and CTRL+X, can you login this way?

Bye, Olaf.
 
Hi,
First there is one ENDIF missing in your code. Furthermore you don't have code when you cannot "locate" the user.

Code:
SELECT user
SET ORDER TO id
LOCATE FOR user.username = ALLTRIM(thisform.txtUsername.Value) AND user.password = thisform.text2.Value
[highlight #FCE94F]IF found()[/highlight]
SET SKIP OF MENU _msysmenu .f.
thisform.text3.Value = user.role

[highlight #FCE94F]IF user.admin = "S" *** for guest account[/highlight]
SET SKIP OF BAR 1 OF file .f.
SET SKIP OF BAR 2 OF file .t.
SET SKIP OF BAR 2 OF department .t.
_screen.Caption = "BGHsystem v1.0" +" "+"(WELCOME:"+" "+ALLTRIM(user.fullname)+")"
DEFINE BAR 3 OF File PROMPT "L\<og Out" +" "+ ALLTRIM(user.username)+"..."
[highlight #FCE94F]ELSE[/highlight]
[highlight #FCE94F]IF user.admin = "T" *** for admin account[/highlight]
SET SKIP OF BAR 1 OF file .f.
SET SKIP OF BAR 2 OF file .f.
SET SKIP OF BAR 2 OF department .f.
_screen.Caption = "BGHsystem v1.0" +" "+"(WELCOME:"+" "+ALLTRIM(user.fullname)+")"
DEFINE BAR 3 OF File PROMPT "L\<og Out" +" "+ ALLTRIM(user.username)+"..."
[highlight #FCE94F]ENDIF[/highlight]
[highlight #FCE94F]ENDIF[/highlight]

And I think you are confusing BAR and PAD - (from Hacker's Guide to VFP7)

Here's another command that's easy to confuse. SET SKIP OF is about menus. SET SKIP TO is about relations. We're interested in menus right now.

SET SKIP OF lets you turn individual menu components on and off. When a component is turned off, its prompt dims and the user can't choose it—sort of. SKPBAR() and SKPPAD() tell you the status of individual bars and pads.

Usage
SET SKIP OF MENU MenuName lSkipIt
SET SKIP OF PAD PadName OF MenuName lSkipIt
SET SKIP OF POPUP PopupName lSkipIt
SET SKIP OF BAR nBar OF PopupName lSkipIt

These commands work inside out—when you SET SKIP of some component to .T., it gets disabled. In fact, it works the same way as the SKIP FOR clause of the various DEFINE commands for menu components. Like SET DELETED, it's just one of those things that's backward. Consider it sort of a Disabled property—then the double negatives make some sense!

Like so many other menu commands, the MENU and POPUP versions of this one propagate downward. SET SKIP OF a popup to .T. and every bar on the popup is disabled. You can then enable individual bars with SET SKIP OF BAR.

Unlike SKIP FOR, SET SKIP OF is not dynamically evaluated. That is, lSkipIt is evaluated when you issue the command and the item's status is set accordingly. But changes to lSkipIt after that do not affect that menu item. Use SKIP FOR to set up conditions that are evaluated repeatedly. (You can refresh the menu and update the SKIP status by issuing ACTIVATE MENU MenuName NOWAIT.)


In the system menu, disabling a pad prevents you from opening that pad, so you can't get to the items on the pad's associated popup. In non-system menus, that's not the case. To disable all the items below a pad, you have to SET SKIP OF the pad and of the popup associated with it.


Example
* Turn off the view menu
SET SKIP OF PAD _MSM_View OF _MSysMenu .T.

Usage
lIsSkipped = SKPBAR( cPopupName, nBar )
lIsSkipped = SKPPAD( cMenuName, cPadName )

When you need to know if a menu item is available at the moment, these two are the ticket. The results are changed by the SET SKIP OF commands and the SKIP FOR clause of the various DEFINE commands.

hth

MK

 
I think it's easier to use the SKIP FOR clause in the DEFINE BAR command (or in the Menu Designer, which is how I'd normally do this). Then, you simply have to provide a mechanism for ensuring that the data that determines whether to disable is available.

So you'd simply define the bar with, say:

SKIP FOR NOT (User.Admin == "T")

to make it available only to admins.

Tamar
 
@ sir Olaf, trying what your suggestion give me error, either emptying or putting value which not equal to exact value of my password or username. locating the user account has no problem, it works fine but in the menu part, there was nothing happens, all the bar on my menu was enabled. Also the code which i used to enable and disable the bar are well functioned on my previous projects. I just dont figure out which part i do wrong. The value of my admin is eaither, T for admin account and S for guest account.

@ sir mjcmkrsr, sorry but in my code there was last ENDIF which i did not included in the post.

@ sir tamar, i tried your suggestion but when im trying to verify the code it display error telling syntax error. Also i cannot add my database.


also aside the code on my login form i have here code on my main program:

PUSH MENU _msysmenu
DEACTIVATE WINDOW standard
DO C:\BGHSystem\Menu\sample.MPR
SET SKIP OF MENU _msysmenu .f.
DO FORM C:\BGHSystem\Menu\log

This code from my main program works well on my previous programs.
 
******UPDATE

my mistake on my login form that's why my menu wont work. i accidentally change window type to modal instead of modeless. that's all..


thank you for the advise and suggestions
 
Well, if you have SET EXACT OFF (which is the default) and empty the password textbox, you will locate the user and that's WRONG. It's wrong aside of the non changing menu, it's wrong to store the password in clear text, but aside of that its wrong to not compare Alltrim(password)==Alltrim(txtPassword.Value). = is only comparing partial strings and everything equals "", check for yourself at the command window try [tt]? "secretpassword"=""[/tt]. It's .T.

You still have no code for the case NOT FOUND(), when the login should fail because username and/or password not matching, you do nothing, so you keep the menu as is.

You say yourself: locating the user account has no problem, it works fine, well you find a user record, when you shouldn't because of no matching password and that in itself should have alarmed you, that this login mechanism should be corrected.

Bye, Olaf.
 
Hi,

In addition to Olaf's comments and Tamar's suggestions, you may want to reread this paragraph from VFP HG

[highlight #FCE94F]Unlike SKIP FOR, SET SKIP OF is not dynamically evaluated.[/highlight] That is, lSkipIt is evaluated when you issue the command and the item's status is set accordingly. But changes to lSkipIt after that do not affect that menu item. Use SKIP FOR to set up conditions that are evaluated repeatedly. [highlight #FCE94F](You can refresh the menu and update the SKIP status by issuing ACTIVATE MENU MenuName NOWAIT.)[/highlight]

hth

MK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top