CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> Archive -> GotoCode Archive

 Menu visibility dependant on security level (ASP)

Print topic Send  topic

Author Message
jrp1946
Posted: 02/22/2002, 12:22 PM

I am trying to find out how to display menus depending on whether a user has a security level of 1, 2, 3 or none. I assume these four menus will go into the Header page. From examination of other postings here, I have learned how to achieve this for two menus based on something like ...

if Session("UserRights") = 1
then SetVar "FormMenu_1",""
exit sub
end if

... but I can't work out the logic for extending this to display only one of four menus according to the user's security level, or where to place the code - in the Header Page Open event, or somewhere in the individual menu form Open events?

Thanks to all for previous help. It's a steep learning curve for an amateur, but stimulating.
Andrew B
Posted: 02/22/2002, 3:25 PM

Well, I have never tested for 'not logged in' so I'm not sure how you will do that (probably isempty(session("userrights"))?

The way I do it is just stick the same code you are using in the open event for each form... You are going to want to change the "=" to a not equals ("<>") so that it will hide the code every time the security level is NOT what that form is supposed to display for. Othewise it gets messy.

If (Session("UserRights") <> "1") then
SetVar "FormMenuLevel1", ""
exit sub
end if

p.s. A simplery way to do it may be to put code like this in the page open event, but it just makes the IF() smipler

dim iSecLevel 'variable holds the numeric equiv. of the security level
if (isNumeric(Session("UserRights"))) then
iSecLevel = -1
else
iSecLevel = CLng(Session("UserRights"))
end if

and then change the if statement to
if (iSecLevel = 1) ' for user
if (iSecLevel = -1) ' for not logged in

You could even put this code in the global and use it on eveyr page. The thing I do is define SEC_NOTLOGGEDIN, SEC_USER, SEC_MANAGER, SEC_ADMIN in the globals and then use those on all the pages. Just in case i need to change sec. levels tometime later.

Sorry for bein so verbose.
jrp1946
Posted: 02/23/2002, 9:50 PM

Thank you, Andrew. The <> did the trick. And testing for a user with no rights turned out to just as simple, e.g.:

if (Session("UserRights") <> "")
then SetVar "FormMenuMenuLevel_0",""


kenlyle
Posted: 02/25/2002, 1:36 PM

That was a great reply, Jeremy!

I just happened to find this in some CC generated code:

if(get_session("UserID") == "")
{
//-------------------------------
// User is not logged in

So that is apparently the best way to test for "not logged in"
dava133
Posted: 02/27/2002, 3:59 PM

I have just tried doing exactly the same thing but I end up with all 3 menu forms displayed in the header!!! Am I doing something stupid?! cheers

David
RobertF
Posted: 02/28/2002, 12:28 AM

Make sure that you are placing the code in the open event for the menu, and that you have only the code that applies to that menu. Basically, this causes the ShowMenu sub to be exited and hence, not shown, based upon security levels.

For example, if you have two menus.... one for UserRights = 1 called MenuLevel_1, and another for UserRights = 2 called Menu_2 then you do as follows:

In the open event for MenuLevel_1 you would put:

if Session("userrights") <> "1" then
SetVar "FormMenuLevel_1",""
exit sub
end if

In the open event for MenuLevel_2 you would put:

if Session("userrights") <> "2" then
SetVar "FormMenuLevel_2",""
exit sub
end if


This works for me. I initially got the same thing you did .... all menus displaying. Took some time reading the generated code to figure out what was happening. Others please jump in if I'm off-base.
marco
Posted: 02/28/2002, 1:19 AM

in on open event:

a=Session("UserRights")

If a=1 then
FormMenuLevel1="FormMenuLevel1"
FormMenuLevel2=""
exit sub
end if

If a=2 then
FormMenuLevel2="FormMenuLevel2"
FormMenuLevel1=""
exit sub
end if

that is all.

regards,
marco
www.adenin.nl / www.adenin.com
dava133
Posted: 02/28/2002, 8:47 AM

Thanks for all the help but still cant get it too work, ive put the code up for my header page at http://homepage.ntlworld.com/dava133/Header.txt

I have a header page with 3 very similar menu forms on it named nav0, nav2, nav3, this is right isnt it?? cheers

dava133
Posted: 02/28/2002, 9:12 AM

OK im stupid i wasnt putting Form before the formname!!!So forget the last post! thanks for the help everyone!

   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.