Results 1 to 4 of 4

Thread: Permission based links

  1. #1
    Join Date
    Feb 2005
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Permission based links

    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

  2. #2
    Join Date
    Mar 2007
    Location
    Tarboro, NC
    Posts
    290
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default

    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.

  3. #3
    Join Date
    Aug 2007
    Location
    Ohio
    Posts
    79
    Thanks
    0
    Thanked 15 Times in 15 Posts

    Default

    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
    Code:
    <?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.

  4. #4
    Join Date
    Feb 2005
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Solution

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •