PDA

View Full Version : Permission based links



dmelosi
01-27-2008, 03:11 PM
Permission based links

http://www.dealermanage.net/dropnav.htm

I have an application that people need to log in. There is an admin in each location that will set what each individual can see. I am using the Top Navigational Bar III v3.5 by BrotherCake.
Here is a little sample of the code.



addMainItem("/main/welcome.asp","",81,"center","","",0,0,"","","","","");

defineSubmenuProperties(135,"center","center",-3,0,"","","","","","","");

addSubmenuItem("/main/welcome.asp","Personal Dash","");

addSubmenuItem("/MgmtTools/welcomeDash.asp","Dock Dash","");


I am wanting to call from a database to see if that person who logs in has permission to get to that page (which is set by the admin). How would i put the code around each link to see if that link needs to be enabled for that particular person who has logged in to see in the drop down menu? Can that be done?

Thanks,
Dave

TimFA
01-27-2008, 06:07 PM
No, as far as I know JavaScript cannot call into a database. Ajax perhaps? I don't know Ajax though. Hope you get your help.

Tim

EDIT: You may try PHP. Its fairly easy.

jackbenimble4
01-27-2008, 06:10 PM
Calling the database and determining which links should be displayed should be logic on the server side. What you could do is have a file, userlinks.asp for example, which outputs as a javascript file. I'm not familiar with ASP so I couldn't help you with this, but in PHP I'd have a file that looked something like this ( majority commented for brevity ):

userlinks.php



<?php

// set the Content type to javascript, so the browser knows how to treat it
header("Content-type: application/x-javascript");

?>

<script type="text/javascript">
<?php

// query the database for the links, and store them in an associative array, $links

foreach($links as $link) {

// determine which link we need and then output... for example:
echo "addSubmenuItem(\"".$link['path']."\",\"".$link['name']."\",\"\");";

}

?>
</script>

Your javascript could then always rely on that file to setup the links for you. It's important to remember that Javascript is on the client side. Therefore, it doesn't have access to the database on your server. The only way the javascript could gain access is through ajax, but that would be very poor design and a waste of resources.

dmelosi
01-27-2008, 08:26 PM
Thank you all for your help.

It works when I put the value of the permission, True or False in the .js file and set the permissions in session.

If I set the field name dashSalMan as True in the database, then set that in session when the person logs in, this code works in the custom.js file

<% if (session("dashSalMan") = "True") then %>
addSubmenuItem("/MgmtTools/welcomeDash.asp?wherefrom=salesMan","Sales Manage Dash","");
<% end if %>


The link in the drop down shows up fine.

Thank you again for your responses.

Dave