Milonic menu that shows options specific to a user

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
djfiii
Beginner
Beginner
Posts: 5
Joined: Fri Apr 13, 2007 12:57 pm

Milonic menu that shows options specific to a user

Post by djfiii »

I have implemented this in asp, if anyone is interested I will post the code. It assumes an existing user login scheme of some sort where user access rights are controlled via the database. All Milonic examples I saw are for static menus where everyone can see every option. Even the database example that comes with the download assumes that all items are to be pulled from the db and displayed in the menu.

This hack basically selects only the relevant items for the user before generating the javascript menu definitions for the milonic menu.
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Post by Ruth »

Hi,

I'm sure someone would really appreciate the post for how to do this. I know it has been done before and there are some posts about it, but I'm not sure how others did it. I believe in some cases it was set to use cookies. I think the examples don't include this because it would require the person to have knowledge of how to implement such things, and that is not something that could be supported here on the forums, unless some nice user, such as yourself :) posts a 'how-to'

I believe for pro licensed users that kind of help is probably provided by Milonic, but here on the forum, it's just us guys and neither John nor I know much about js, though John would probably know about setting up something like this from a database menu. I think he uses CFM and can probably set up 'user' specific types of menus. But, I can't do any of this, and since this is a volunteer forum and ya'll are stuck with what we know ;) and whatever any other helpful user might post

Ruth
djfiii
Beginner
Beginner
Posts: 5
Joined: Fri Apr 13, 2007 12:57 pm

Post by djfiii »

I use sql server and asp, but you could do this with any technology. This post will contain the code, and I will post another that has some explanation.

Table Structure:

Code: Select all

Navitems
   itemid int primary key identity,
   menuid int,
   text varchar,
   url varchar

Navmenus
   id int primary key identity,
   menuname varchar,
   styleid int

Navstyles
   styleid int primary key identity,
   name varchar,
   align varchar,
   bgimage varchar,
   bordercolor varchar,
   ...
   ...
   (I have every possible style as a field and leave the unused blank)

Users
   userid
   username
   ...
   ...
   (whatever other fields you track for your users)

UserAccess
   navID
   userID


Javascript:

Code: Select all

	<script language=JavaScript src="/igs/includes/js/milonic_src.js" type=text/javascript></script>	
	<script language=JavaScript src="/igs/includes/js/mmenudom.js" type=text/javascript></script>
	<script language=javascript type=text/javascript>
		_menuCloseDelay=500;
		_menuOpenDelay=150;
		_subOffsetTop=0;
		_subOffsetLeft=0;
		<% NavBuildStyles() %>
		
		with(milonic=new menuname("IGS Navigation")){
		alwaysvisible=1;
		top=90;
		
		orientation="horizontal";
		style=mmStyle;

		aI("showmenu=IGS Services;text=IGS Services;");
	
		<%
		If chkLog Then
			Navqry = "select distinct(m.menuname), m.id, s.name "
			Navqry = Navqry & "from useraccess u, Navitems i, Navmenus m, Navstyles s "
			Navqry = Navqry & "where u.pID = (select sessPID from Sessions where sessID = '" & request.cookies("sessID") & "') "
			Navqry = Navqry & "and u.navID = i.itemid "
			Navqry = Navqry & "and i.menuid = m.id "
			Navqry = Navqry & "and m.styleid = s.styleid "
				
			set rsNav = server.createobject("ADODB.Recordset")
			rsNav.Open Navqry,strConn
			
			If Not rsNav.EOF Then
				Do While Not rsNav.EOF
					response.write "aI(""showmenu=" & rsNav("menuname") & ";text=" & rsNav("menuname") & """);" & VbCrLf
					rsNav.MoveNext
				Loop
				rsNav.MoveFirst
			End If
		End If
		%>
		}
		
		with(milonic=new menuname("IGS Services")){
			style=mmStyle;
			margin=0;			
			aI("text=Audit Coordination;url=/igs/audits/index.asp;");
			aI("text=Policy Management;url=/igs/comingsoon.asp;");
			aI("text=Risk Management;url=/igs/comingsoon.asp;");
			aI("text=Regulatory Support;url=/igs/comingsoon.asp;");
			aI("text=DSO / DPO Support;url=/igs/comingsoon.asp;");
		}	
		
		<%
		If chkLog Then
			If Not rsNav.EOF Then
				Do While Not rsNav.EOF
					menuname = rsNav("menuname")
					menuid = rsNav("id")
					stylename = rsNav("name")
					
					response.write "with(milonic=new menuname("""&menuname&""")){" & VbCrLf
					response.write "style="&stylename&";" & VbCrLf
					
					Navqry2 = "select i.* "
					Navqry2 = Navqry2 & "from useraccess u, Navitems i, Navmenus m "
					Navqry2 = Navqry2 & "where u.pID = (select sessPID from Sessions where sessID = '" & request.cookies("sessID") & "') "
					Navqry2 = Navqry2 & "and u.navID = i.itemid "
					Navqry2 = Navqry2 & "and i.menuid = m.id "
					Navqry2 = Navqry2 & "and m.id = " & menuid
									
					set rsNav2 = server.createobject("ADODB.Recordset")
					rsNav2.Open Navqry2,strConn
					If Not rsNav2.EOF Then
						Do While Not rsNav2.EOF
							navtext = rsNav2("text")
							navurl = rsNav2("url")
							response.write "aI(""text="&navtext&";url="&navurl&";"");" & VbCrLf
							rsNav2.MoveNext
						Loop
						rsNav2.Close
						set rsNav2 = nothing
					End If
					rsNav.MoveNext
					response.write "}" & VbCrLf & VbCrLf
				Loop
				rsNav.Close
				set rsNav2 = nothing
			End If
		End If				
		%>
		drawMenus()
	</script>


NavBuildStyles Function:

Code: Select all

Function NavBuildStyles()

	cReturn=chr(13)
	cQuote=chr(34)
	
	set rsNavBuild = server.createobject("ADODB.Recordset")
	set rsNavBuild2 = server.createobject("ADODB.Recordset")	

	query="select styleid from Navstyles"
	rsNavBuild2.Open query,strConn
	
	do while not rsNavBuild2.EOF

		query = "select * from Navstyles where styleid = " & rsNavBuild2("styleid")
		rsNavBuild.Open query,strConn
		
		menu = menu & "with("&rsNavBuild("name")&"=new mm_style()){"
		menu=menu&cReturn
		
		For Each f in rsNavBuild.Fields
			menuObjectName=trim(f.name)
			menuObjectValue=trim(f.value)
			if menuObjectName <> "name" and menuObjectName<> "styleid" and menuObjectValue <> "" then
				IF Instr(menuObjectName,"color") then
					menuObjectValue="#"&menuObjectValue
				end if
				menu=menu&menuObjectName & "=" & cQuote& menuObjectValue &cQuote&";"
				menu=menu&cReturn
			end if
		Next
		rsNavBuild.close
		menu = menu & "}"
		menu=menu&cReturn
		
	  rsNavBuild2.MoveNext
	loop
	rsNavBuild2.close

	menu=menu&cReturn
	menu=menu&cReturn
	
	response.write menu
	
End Function
Last edited by djfiii on Fri Apr 13, 2007 8:10 pm, edited 1 time in total.
djfiii
Beginner
Beginner
Posts: 5
Joined: Fri Apr 13, 2007 12:57 pm

Post by djfiii »

Table Explanations:

Navitems has one record for each link in your menus. itemid is the unique identifier for that link. menuid associates that link with a menu in the Navmenus table. text is the text for that link, and url is the url. pretty easy so far.

Navmenus has one record for each menu. id is the unique identifier, menuname is the name, styleid is the id number of the style associated with this menu.

Navstyles has one record for each style you want to use. You probably won't need more than 2. I only use one, because I use the same style for both horizontal and vertical menus. For those of you that use horizStyle and vertStyle as many of the examples do, you would want two records in this table. If you have 10 menus and each one has a different style, then you would want 10 records in this table.

Users - I assume you already have a users table that is defined however is useful to you. The important thing is userid, which relates to the useraccess table.

Useraccess - this table joins users with navigation links. So if there are a total of 10 links in your Navitems table, and I should have access to 4 of them, there would be 4 records for me in the useraccess table. Assume my userid is 23, and I should have access to links with id numbers 1,2,3 and 4. You would have the following records in useraccess:
(1,23)(2,23)(3,23)(4,23)
djfiii
Beginner
Beginner
Posts: 5
Joined: Fri Apr 13, 2007 12:57 pm

Post by djfiii »

Javascript Explanation:


As in the milonic examples, the first two lines are includes to milonic_src.js and mmenudom.js (my users only use IE so I don't use that conditional statement to decide between the IE menudom file and the NS file)

Then these 4 lines, not quite sure what they do but they were in all of the examples:
_menuCloseDelay=500;
_menuOpenDelay=150;
_subOffsetTop=0;
_subOffsetLeft=0;


Then within asp tags I call <% NavBuildStyles() %>, which will be explained in more detail in the next post. Suffice it to say that the basic format of the milonic_data.js file is to declare your styles first, then your menus. That is why this function gets called here, before any menus get generated.

Next up, I start to declare my main menu:

Code: Select all

with(milonic=new menuname("IGS Navigation")){ 
      alwaysvisible=1; 
      top=90; 
       
      orientation="horizontal"; 
      style=mmStyle; 

      aI("showmenu=IGS Services;text=IGS Services;"); 
    
      <% 
      If chkLog Then
I did it this way because, even for users that are not logged in, I want them to see this "IGS Services" menu. After that, I put in some asp code to check if the variable chkLog exists. If it does, I know the user is logged in and I continue with the asp code that queries out all of the relevant links for that user. It runs through a loop that puts out the remaining aI() menu statements if there are any for this user. If the variable chkLog is not set, then none of that ever happens and the user just sees the initial menu "IGS Services".

Finally, call the drawMenus() function and voila - your menu appears.
djfiii
Beginner
Beginner
Posts: 5
Joined: Fri Apr 13, 2007 12:57 pm

Post by djfiii »

NavBuildStyles Explanation:


This basically just selects all of the styles I defined in the database, and loops through them, outputting text in the same format that the milonic_data.js file would be. For me, there is only one style but if I add more I won't have to change any code - this will grab them all.
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Post by Ruth »

Wow, thank you very much. This is really appreciated.

Ruth
Post Reply