Website Membership: Showing different pages based on specific users

3 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: May 18, 2011   (RSS)

By NigelGordijk - May 17, 2011 - edited: May 17, 2011

I've just set up Website Membership on a construction firm's site and it seems to be working well. There's a Multi Record section that will have pdfs of construction plans. This will only be visible to people who are members and have logged in.

Is it possible to make only certain plans visible to specific members? For example Client A can only see Client A's plans, but not Client B's.

http://www.nithvalley.com/plans.php

Thanks!
Nigel Gordijk

Common Sense Design: User-focused Web design
Tel: 001 519 342 5348 | Web: www.commonsensedesign.net

Re: [NigelGordijk] Website Membership: Showing different pages based on specific users

By gkornbluth - May 17, 2011

Hi Nigel,

I recently did something similar for a site that was offering custom videos.

The first thing that I did (to reduce the eventual clutter) was to create a check box in the account records that said videos_for_sale (in your case it might be plans available)

Then I created a table called "Videos For Sale" with a field for the title of the video, an upload field for the video file itself, a description field, and a list field called videos_for_sale with the List options as “get options from MySQL Query”

and the query as:

SELECT num, last_name
FROM `<?php echo $TABLE_PREFIX ?>accounts`
WHERE video_for_sale='1'


Then for the detail page viewer code I used:
<!-- USER LOGIN FORM -->
<?php if (@$errorsAndAlerts): ?>
<div class="heading-text-13"><br/>
<?php echo $errorsAndAlerts; ?><br/>
</div>
<?php endif ?>

<?php if (!@$CURRENT_USER): ?>

<form action="?" method="post">
<input type="hidden" name="action" value="login" />

<table width="400" border="0" align="center" cellpadding="2" cellspacing="0">
<tr>
<td class="heading-text-13" colspan="2">You must be logged in to access this page.</td></tr><tr>
<td class="body-text-bold-9">Username</td>
<td><input type="text" name="username" value="<?php echo htmlspecialchars(@$_REQUEST['username']); ?>" size="20" /></td>
</tr>
<tr>
<td class="body-text-bold-9">Password</td>
<td><input type="password" name="password" value="<?php echo htmlspecialchars(@$_REQUEST['password']); ?>" size="20" /></td>
</tr>

<tr>
<td colspan="2" align="center">
<br/><input type="submit" name="submit" value="Login" />


</td>
</tr>
<tr>
<td colspan="2" align="left">

<br />
<br /> <a class="special" href="<?php echo $GLOBALS['WEBSITE_LOGIN_REMINDER_URL'] ?>">FORGOT YOUR PASSWORD? CLICK HERE</a> <br /><br />
<span class="body-text-9">If you'd like to become an Aranmore Dance member</span><br />
<a class="special" href="http://www.aranmoredance.com/becomeamember.php">CLICK HERE TO SIGN UP</a>

</td>
</tr>
</table>
</form>
<?php endif ?>
<!-- /USER LOGIN FORM -->

<?php if (@$CURRENT_USER): ?>

<table width="70%" border="0" cellspacing="10" cellpadding="5">
<tr>
<td valign="top" width="75%"><table width="100%" border="0" align="center" cellpadding="5" cellspacing="0">
<tr>
<td colspan="2"><?php foreach ($videos_for_saleRecords as $record): ?><?php if ($CURRENT_USER['num'] == $record['videos_for_sale']): ?>
<span class="heading-text-bold-13">Welcome <?php echo $CURRENT_USER['first_name']; ?>&nbsp;<?php echo $CURRENT_USER['last_name']; ?>,</span><br /><span class="body-text-bold-9">Enjoy your video.</span><br />
<br />
</td>
</tr><tr><td>




<a class="special"href="<?php foreach ($record['video_upload'] as $upload): ?><?php echo $upload['urlPath'] ?><?php endforeach ?>">Click here if you'd prefer to download<br />your personal training video</a><br />
<?PHP endif ?><?php endforeach ?>
<br /></td></tr></table> <?php endif ?>



<?php if (@$CURRENT_USER): ?>

<?php foreach ($videos_for_saleRecords as $record): ?>

<?php if ($CURRENT_USER['num'] == $record['videos_for_sale']): ?>
<table align="center" width="90%" border="0" cellpadding="5">
<tr><td>
<h2 align="center"><?php echo $record['title'] ?></h2><br /></td>
<tr><td align="center">

<div id="container">&nbsp;</div>
<script type="text/javascript">
jwplayer("container").setup({

file: "http://www.aranmoredance.com<?php foreach ($record['video_upload'] as $upload): ?><?php echo $upload['urlPath'] ?><?php endforeach ?>",
height: 420,
width: 510,
<?php if (@$record['background_image']): ?>image: "http://www.aranmoredance.com<?php foreach ($record['background_image'] as $upload): ?><?php echo $upload['thumbUrlPath2'] ?>"<?php endforeach ?>, <?php endif ?>
autostart: true,
modes: [
{ type: "html5" },
{ type: "flash", src: "player.swf" }
]

});
</script>



<br /><br /></td></tr><tr><td class="body-text-9" align="left">
<?php echo $record['description'] ?>
</td></tr></table><?php endif ?><?php endforeach ?> <?php endif ?>


There’s a lot of extra code here because I included a login form on the page, a welcome to the current user, and a description field, but you should be able to use the core idea:
<?php if (@$CURRENT_USER): ?>

<?php foreach ($videos_for_saleRecords as $record): ?>

<?php if ($CURRENT_USER['num'] == $record['videos_for_sale']): ?>

YOUR CODE...

<?php endif ?><?php endforeach ?> <?php endif ?>


Hope that gets you going,

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

Re: [gkornbluth] Website Membership: Showing different pages based on specific users

By NigelGordijk - May 18, 2011

Thanks, Jerry. I'll give this a go.
Nigel Gordijk

Common Sense Design: User-focused Web design
Tel: 001 519 342 5348 | Web: www.commonsensedesign.net