Membership: List CURRENT USER items only

25 posts by 6 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: August 4, 2011   (RSS)

By Toledoh - March 4, 2010

Hi Guys,

This should be straight forward, but I can't seem to get it.

I've got a "multi-record" section called "Client Area". Within this, I've got a field "account" with is a pick list from the user accounts table.

On the list page, I want to show only records that relate to the current user.

So at the top of the page, I need to have something like;

list($l_client_areaRecords, $l_client_areaMetaData) = getRecords(array(
'tableName' => 'l_client_area',
'where' =>'account = $CURRENT_USER['num']

));


but that doesn't work.... can you help?
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] Membership: List CURRENT USER items only

By gkornbluth - March 7, 2010 - edited: March 7, 2010

Hi Tim,

I haven't really played with this a lot but will be in a few days.

For now, here are some notes (from Chris) that I found in the Plugin section of my CMSB Cookbook thecmsbcookbook.com

To determine if the current user is logged in, you can test with:

<?php if (current_user): ?>
only logged in user will see this...
<? php endif ?>


You could set up a separate (text or check box) field in the user accounts editor and assign it a value for that particular class of users. Then test with:

<?php if ($CURRENT_USER['your_field'] == "your_value"): ?>Current user will be able to see this<?php endif ?>

Only user(s) who have that value entered/selected in their user record will be able to view the protected information on the web page.

To determine if the current user is the "author" of a record, you can test with:

<?php if ($record['createdByUserNum'] == $CURRENT_USER['num']): ?>Only the author will be able to see this<?php endif ?>

You may want to also allow admins to see your protected information:

<?php if ($record['createdByUserNum'] == $CURRENT_USER['num'] || $CURRENT_USER['isAdmin']): ?>Author and administrators will be able to see this<?php endif ?>

Hope that helps to gets you where you need to go.

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

Re: [Dave] Membership: List CURRENT USER items only

By Toledoh - March 8, 2010

Not working yet Dave... maybe I'm doing something wrong?

I've got a demo login: username/password client1/client1

I've got 2 pages:
http://www.forrest.id.au/test/clientList.php
http://www.forrest.id.au/test/clientList_A.php

The only difference between the 2 is;
'where' => mysql_escapef(" client_list = ? ", $CURRENT_USER['num'] ),

and "A" has;
'where' => mysql_escapef(" client_list != ? ", $CURRENT_USER['num'] ),


You can see that the second record has the client_name as "4" and the current user as "4", so shouldn't the first version of the page show that result?
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] Membership: List CURRENT USER items only

By Chris - March 9, 2010

Hi Tim,

Can you please post the complete PHP source code for clientList.php? Also, how exactly is your "client_list" field configured? Is it a Multi-Value list field, perchance?
All the best,
Chris

Re: [chris] Membership: List CURRENT USER items only

By Toledoh - March 9, 2010 - edited: March 9, 2010

Hi Chris.


client_list is a pick list from the user table. So basically, as soon as I have someone sign-up, they are added to the list for a potential "client area".

Attached is the file.
Cheers,

Tim (toledoh.com.au)
Attachments:

clientlist.php 4K

Re: [Toledoh] Membership: List CURRENT USER items only

By Chris - March 9, 2010 - edited: March 9, 2010

Hi Tim,

Please try changing this:

'where' => mysql_escapef(" client_list = ? ", $CURRENT_USER['num'] ),

to this:

'where' => mysql_escapef(" client_list LIKE ? ", "%\t".$CURRENT_USER['num']."\t%" ),

Does that solve the problem? Please let me know.
All the best,
Chris

Re: [chris] Membership: List CURRENT USER items only

By Toledoh - March 9, 2010

Sorry Chris,

I'm now getting an error:
MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' %' ) ORDER BY client_list' at line 3

Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] Membership: List CURRENT USER items only

By Chris - March 9, 2010

Hi Tim,

Sorry about that. Please try this instead:

'where' => mysql_escapef(" client_list LIKE ? ", "%\t".$CURRENT_USER['num']."\t%" ),

(I've edited my above post to be correct also.)
All the best,
Chris

Re: [chris] Membership: List CURRENT USER items only

By Toledoh - March 9, 2010

Excellent! Thanks heaps.
Cheers,

Tim (toledoh.com.au)