SETTING UP PRIVATE AREAS FOR USERS - Aug 21st, 2011


User gsfriend said: I'm setting up a site for a custom home builder and they want a private area where customers can
login and see pictures of their home during the construction process and we as a place they can access documents that
relate to that customer only.

My question is, can the membership plugin be easily configured to display UNIQUE content to the current member logged
in? In my case, each customer would have their own unique files that I would only want them to have access to, not other
clients.

Dave at Interactive Tools came back with:

“What the plugin does is make a global available on every page called $CURRENT_USER that has the record of the
currently logged in user.

So a simple implementation would be to have a section called "homes" with a field called "ownerUserNum" which was a
pulldown of customer names (with user num stored as the value in the database).”

Then in your homes viewer you could have something like:



'where' => " ownerUserNum = {$CURRENT_USER['num']} ",



And only homes assigned to the currently logged in user would be shown.

Dave suggested setting up a multi record section called “Homes” with a pulldown field showing all users to the
"Homes" section like this:

Go to: Admin > Section Editors > Homes > Add Field
Field Label: Owner
Field Name: ownerUserNum
Field Type: list

Display As: Pulldown
List Options: Get options from database (advanced)
Section Tablename: Accounts
Values Field: num
Labels Field: fullname

Gsfriend added fields for Title, Name, Content, File Uploads for Images, etc., to the section.

The resulting viewer code was:



<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php if (!@$GLOBALS['WEBSITE_MEMBERSHIP_PLUGIN']) { die("You must activate the Website Membership plugin before you can
access this page."); } ?>
<?php if (!$CURRENT_USER) { websiteLogin_redirectToLogin(); } ?>

<?php
require_once "/home/ekfriend/public_html/cms/lib/viewer_functions.php";

list(
$homeownersRecords, $homeownersMetaData) = getRecords(array(
'tableName' => 'homeowners',
'where' => " (ownerUserNum = '{$CURRENT_USER['num']}') OR '{$CURRENT_USER['isAdmin']}' ",
'limit' => '1',
));
$homeownersRecord = @$homeownersRecords[0]; // get first record

list($settingsRecords, $settingsMetaData) = getRecords(array(
'tableName' => 'settings',
'limit' => '1',
));



If you wanted to also allow admins to view the records, you’d change the where statement to:



'where' => " (ownerUserNum = '{$CURRENT_USER['num']}') OR '{$CURRENT_USER['isAdmin']}' ",



According to Jason Sauchuk of Interactive Tools:

If
you're searching as part of a multi-select list, you need to use the LIKE operator and put tab characters before and
after your search option. Try this:



'where' => "ownerUserNum LIKE '%\t". intval($CURRENT_USER['num'])."\t%'",




The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service