End User Recipe: Conditional Display

Just as we protected any number of pages from unauthorized viewing, we can protect parts of those pages. With group access levels deployed, any page element can be modified so that it is seen only by members of certain groups. In this recipe, we will allow only those with the highest level of access administrators to view particular navigation links.

Make Elements Conditional

Because we want the conditional display to be a part of every page in the application including those already built the application template must be modified. Dreamweaver maintains a connection to all files derived from a template, so changes can be propagated automatically to affected documents. If you've already posted some files to your remote server, you'll need to upload them again after the template changes are applied.

Warning

Although you should exercise care when making changes to any document, you need to be extra careful when applying alterations to templates because of the potential ramifications for numerous files.


In this step, we'll select the page elements here, two rows of a table used for navigation prior to applying the code.

  1. From the Templates category of the Assets panel, select the template to be used for the login application.

    graphics/book.gif Choose the userlogin template for your server model.

  2. Select the Edit button on the bottom of the Assets panel, or double-click the file.

  3. In Design view, select the lower two rows of the navigation links on the left side of the page [r1-13].


    Figure r1-13.

    graphics/03fig13.jpg


    The links within these rows are associated with administration functions: User Manager and User Statistics.

  4. Switch to Code view, where you'll note that only the individual cells have been selected, not the containing rows (the <tr> tags). Adjust the selection so that both rows containing the cells are highlighted.

    If you attempt the next step (applying a snippet) with just the cells selected, Dreamweaver will wrap the code around the entire table which is not the desired effect.

  5. Wrap the following code around the selection.

    graphics/book.gif From the Snippets panel, open the Recipes > UserLogin > Custom Code folder for your server model and insert the Conditional Display snippet.

    Before:

    graphics/vb.gif

     <% if (cStr(Session("MM_UserAuthorization"))="1")  { %> 

    After:

     
     <% end if %> 
     

    Before:

    graphics/js.gif

     <% if (String(Session("MM_UserAuthorization"))=="1")  { %> 

    After:

     
     <% } %> 
     

    Before:

    graphics/cf.gif

     <cfif IsDefined("Session.MM_UserAuthorization") AND Session.MM_UserAuthorization EQ "1"> 

    After:

     
     </cfif> 
     

    Before:

    graphics/php.gif

     <?php if ($_Session["MM_UserGroup"]=="1") { ?> 

    After:

     
     <?php } ?> 
     

The code snippet checks to see if the session object MM_UserAuthorization (MM_UserGroup for PHP) is set to 1, the administrator designation as defined in the data source. The resulting effect is that the links to administrative pages are visible only by administrators.

Be sure to save your template and update all derived documents.



Macromedia Dreamweaver MX 2004 Web Application Recipes
Macromedia Dreamweaver MX 2004 Web Application Recipes
ISBN: 0735713200
EAN: 2147483647
Year: 2003
Pages: 131

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net