Forums

Show User data only OR all for admin

BigStef 28 Feb, 2013
Hi,
In a CC table, I want the datas displayed to the registred user only FROM this user. But if the user is an admin (or an author) i want ALL datas displayed.
I have looked for a solution on the forum for this question and have find this topic vith this tip :
<?php
$user =& JFactory::getUser();
if ( !in_array($user->gid, array('24', '25')) ) {
  // user is not an admin
  echo "WHERE `cf_user_id` = '{$user->id}'";
}
?>

But as Bob said, this is for Joomla 1.5 and I'm working on Joomla 2.5.9 with CC 4.0.RC3.2
So when i use this code, user actually read only HIS datas, but Admin has no access. Maybe is it coming from the diffrence of Joomla version ?
If anybody could suggest me something ? Thanks by advance...
Max_admin 02 Mar, 2013
Hi Stef,

First of all you need to make sure that you are using the correct groups ids for your admins, they are different in J2.5

2ndly, the $user->gid is an array in J2.5, so you have to account for this, try to convert your if statement to:

if(count(array_intersect($user->gid, array(24, 25))))


I think this should work after you insert the correct admin groups ids.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
BigStef 02 Mar, 2013
Hi,
and thanks for answering on a saturday evening ! :-)
That's was a good lead, so I found this on Convergence Forum. I rewrote the "else" for my own needs and it give that :

<?php
$user = & JFactory::getUser();
//8 is for Super User and 7 is for Administrator
if(isset($user->groups[8]) || isset($user->groups[7])){
}
else{
echo "`cf_user_id` = '{$user->id}'";
} 
?>

Seems to work very well ! Just as i'm writting php like a spanish cow : Is it correct to let the first bracket empty ?
Max_admin 07 Mar, 2013
Hi Stef,

Great, you mean this one:
if(isset($user->groups[8]) || isset($user->groups[7])){
}

if so then yes, it will simply do nothing, you may omit it if you can reverse the if clause check, but you may just leave it as its!🙂

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
BigStef 07 Mar, 2013
Hi Max,
You and Bob give a real good support here on the forum to help us working with yours components, but you also share all yours PHP and MySQL skills, and this is REALLY a plus ! Thanks a lot for all your work...
PS : Do you share the beers we can buy to Bob ? ;-)
Max_admin 10 Mar, 2013
Hi Stef,

You are welcome, this is how everybody learns🙂

Beers are for Bob because he does an extreme effort on the forums actually🙂

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
salvo72 23 Mar, 2013
Hi to all,
please...id like to know how use that code used by BigStef..
i mean...i too need to show the records from a db only to its owner by CC, and optionally to let him to edit the data....

so i need to controll if cf_user_id is equal to $user->id....and if they are equal the record are showed....but where have i put that code?
when i use the custom code in CUSTOM LIST SETTINGS i have no value for cf_user_id in the head.....just in the body...maybe am i wrong something?!!

thanks..best regards :-)
Salvo
BigStef 23 Mar, 2013
Hi Salvo,
I have put this code in the "WHERE SQL" of my connection (Tabs General > Sub-Tab General). And it works as simply as this.
If it don't in your connection, the first question will be : " Have you done you form with Chronoform ? " If yes, the cf_user_id is automatically created so you should not have problem... Is that the case ?
salvo72 29 Mar, 2013
Hi BigStef,
sorry for delay...
yes thanks....i put that in "WHERE SQL"...as you say...and it works good ;-)

Best regards...Salvo
This topic is locked and no more replies can be posted.