Membership Listing Qtn

3 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: June 1, 2010   (RSS)

By (Deleted User) - May 29, 2010

Hello,

I am currently building a site for a gym. I would like to create a site that gives members different experiences depending on their membership level.

You mention in the readme file:


<?php if ($CURRENT_USER['gold']): ?>
Only gold members would see this.
<?php endif ?>


How can I set it so that there are say 4 levels of membership

Registered
Bronze
Silver
Gold

When people register they are auto added as Registered. In the Admin a member of the gym staff can give a higher membership level.

Thanks Jono

Re: [jonoc73] Membership Listing Qtn

By gkornbluth - May 31, 2010

Hi jonoc73,

You could approach this in 2 similar ways, by restricting folder access and by restricting document access.

Here's an excerpt from my CMSB Cookbook thecmsbcookbook.com that should explain how to implement this idea.

You can use these approaches in menus as well so you can really customize your user’s experience.

Limiting Directory Access and Protecting Directories
Thanks to Dave Edis for this part.

Since all the files are PHP they are executed server side and protected from prying eyes by default.

1) In your user accounts editor, create a multi value list field called allowedFolders
The values I used are:

board_access
committee_access
general_access

Go into the User Accounts list and check some values in your account to authorize access to some of those folders.

2) In the root directory of your site create 3 folders:
board_access
committee_access
general_access

3) In each folder upload a test file called access.php

the code in each of the access.php files is:

<?php
require_once "../cmsAdmin/lib/viewer_functions.php";
if (!@$GLOBALS['WEBSITE_MEMBERSHIP_PLUGIN']) { die("You must activate the Website Membership plugin before you can access this page."); }
if (!$CURRENT_USER) { websiteLogin_redirectToLogin(); }

//
$folderName = basename(dirname(__FILE__));
$allowAccess = preg_match("/\t$folderName\t/", $CURRENT_USER['allowedFolders']);
if (!$allowAccess) { die("You don't have access to this folder!"); }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Access Test</title>
</head>

<body>
<?php echo $CURRENT_USER['allowedFolders'] ?>
</body>
</html>


The code in the body just prints out the directories that the particular member is authorized to view.

After you’ve got the basic code working, you can paste the code required into an existing page, upload it to one of those directories, and make sure it all works as planned.

Limiting File Access and Protecting Individual Files
If you’ve only got a few files to protect, you can use something like this:

Set up a single value list field in the user accounts table with the membership levels required, for example:

General
Committee
Board

Assign access to one of these levels to your user account.

Then use code similar to this to protect whole pages or portions of a page. If the user is not logged in, line 3 in the code will force them to log in before they can access this page:

<?php require_once "cmsAdmin/lib/viewer_functions.php"; ?>
if (!@$GLOBALS['WEBSITE_MEMBERSHIP_PLUGIN']) { die("You must activate the Website Membership plugin before you can access this page."); }
if (!$CURRENT_USER) { websiteLogin_redirectToLogin(); }

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Information Access Test</title>
</head>

<body>
<?php if ($CURRENT_USER['membership_level'] == "Committee"): ?>You are logged in and are authorized to see this Committee level information.
<?php elseif ($CURRENT_USER['membership_level'] == "Board"): ?>You Are Logged in and are authorized to see this Board of Directors level information.
<?php elseif ($CURRENT_USER['membership_level'] == "General"): ?>You Are Logged in and are authorized to see this General membership level information.
<?PHP else: ?> You must log in before you can see the information that is authorized for your level of membership.
<?PHP endif ?>

</body>
</html>


If you’re using a multi value list to define your authorization levels, you can’t use the == test, since your field can actually contain more than just an exact match. You can however use the strpos function to determine if a particular membership level is contained in the list.

Theoretically the strpos function returns the numeric position of the first occurrence of the pattern that you’re searching for, however, before it can do that it has to decide if the pattern exists in the string.

Here’s the code:

<?php if (strpos($CURRENT_USER['membership_level'], 'committee_access')): ?>
You Are Logged in and are authorized to see committee level level information.
<?PHP endif ?>


Hope that gets you off in the right direction.

Best,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php