[thelist] Looking for dynamic menus for ASP pages

Rob Smith rob.smith at THERMON.com
Tue Jul 27 09:23:30 CDT 2004


> allow me to populate each user's menu based on the 
> user's permission level.  

Although I cannot provide a link, I can offer some experience as this is how
I did it...

I used the native Windows NTFS as a foundation for the design criteria. We
have 3 basic levels for permissions.

Level 1 
Accessible by all employees' information contained here must be suitable for
all employees. A prime example of this group would be anyone who has access
to the Intranet. This information is generic in nature. 

Level 2 
Region Specific: Accessibility determined by the employees 'location' within
the company

Level 3 
Special Projects: Accessible to specific groups of employees as determined
by project requirements. 

So. A level 1 group is everyone or DOMAIN_USERS\Everyone. A level 2 group
would be Texas. A level 3 group would be The Accounting Dept in Texas. 

Now. You have all these different groups (Accounting, Texas, everyone, etc.)
and each as a right to see certain pages.

Now. You have pages that can be seen by only certain people right. How do
you fit this mess together to provide a highly customizable menu system for
each person? I used comma delimited lists. There are other ways I'm sure,
but this sounded most straight forward to me.

For example:

Pages		Users
-----		-----
  A		  1
  B		  2
  C     	  3
  D           4

Page A can be seen by 1,2
Page B can be seen by 2,3,4
Page C can be seen by 1,2,3
Page D can only be seen by 3
and
User 1 can see A,C
User 2 can see A,B,C
User 3 can see B,C,D
User 4 can see B only

  So now put your shoes into User 3. I'm surfing around on the site, 
  and I have three menu choices: B,C,D. That's it.

Get the group by the identity of the user:
------------------------------------------
  Recordset1.Source = "SELECT userGroup FROM Users where userID 
  like '%" &session("userID") & "%'"

Split the userGroup into an array
-----------------------------
  session("level") = Recordset1.fields.item("userGroup").value
  levels = split(session("level"),",") ' ex: 1,3,5,9,15,29
  levelcount = uBound(levels)

Get the Menu item into an array
--------------------------
  Sample Rows:
  ID  Subject  URL                        AccessLevel NameState
  65	Travel   <a href="#">Jamaica</a>	2,3	      top
  66	Travel   <a href="#">Bahamas</a>	1,3,9	      top
  67	Travel   <a href="#">Cuba</a>		3	      top
  68	Travel   <a href="#">Africa</a>	1,2,10	top
  69	Travel   <a href="#">Kenya</a>	10,15	      Africa
  70	Travel   <a href="#">Congo</a>	10,15	      Africa

  Navigation.Source = "SELECT AccessLevel FROM Menu WHERE Subject = 'Travel'
AND NameState = 'top' ORDER BY ID" ' or whatever the subject is for that
navigation root topic.
  
  When and if you want sub menus, in this example, change NameState in the
query to be that of the sub department. This is a semi-recursive navigation
technique.

  In this example, If my access level was 2,5,7, I would see this as my
navigation:

  Jamaica
  Africa

The mesh is solved by nested for loops:
---------------------------------------
Although these iterations can be costly in a highly complex navigation
system. However, the amount of repetitions per evolution are negligible to
date.

While Not Navigation.EOF
    page = split(Navigation.fields.item("AccessLevel").value,",")
	flag="no"
	for i=0 to uBound(AccessLevel)
	   for j=0 to uBound(page)
	      if AccessLevel(i) = page(j) then
		     flag="yes" 'user can see the page.
		end if
	   next
	next ' finished comparing lists

	if flag="yes" then ' if the user can, then display it.
	   response.write ((Navigation.fields.item("URL").value) & vbCRLF)
	End If
	nav.moveNext
Wend

Now All you have to do is find the code for a top-level drop down menu
system and replace the static instances with this loop. If you want sub
menus in drop down's, I'm sure that can be solved to.

There is one thing I do hate about this system, although the frequency is
about once in a blue moon it's still annoying, is when a menu item gets
inserted or removed. I have to export the table into Excel, change it
around, delete the contents of the SQL table, and import the new data. I
know a way around this, but I'm too busy to fix it.

Rob.

p.s. I should publish an article on this on Evolt. It's a working system for
nearly two and a half years with NO complaints!




More information about the thelist mailing list