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 accessadministratorsto view particular navigation links.

Make Elements Conditional

Because we want the conditional display to be a part of every page in the applicationincluding those already builtthe 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.

Note

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 elementshere, two rows of a table used for navigationprior to applying the code.

1.

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

Choose the userlogin template for your server model.

2.

Click 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].

r1-13.


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 their 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.

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

Before:

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


After:

<% end if %>


Before:

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


After:

<% } %>


Before:

[View full width]

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


After:

</cfif>


Before:

[View full width]

<?php if (isset($_SESSION['MM_UserGroup']) && ($_SESSION['MM_UserGroup']=="1")) { ?>


After:

<?php } ?>


The code snippet checks to see whether 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 8 Recipes
Macromedia Dreamweaver 8 Recipes
ISBN: 0321393910
EAN: 2147483647
Year: 2003
Pages: 121

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