11
deka87
Re: Paid access to some parts of the website
  • 2009/1/15 9:58

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


so what about <{if !$xoops_isuser}><{/if}> tags restricting content for a definite group only?

maybe add this in the adsitem.php (the script a part of which I want to restrict):

$usergroup =& $member_handler->getGroupsByUser($thisUser->getVar('uid'), true);


and then the edit the template for adsitem.php like:

<{if !$usergroup == X}>The content I want to show to the X group only<{/if}>

Im not sure about my coding ability, so please correct it if you can..
Mind anchors

12
deka87
Re: Paid access to some parts of the website
  • 2009/1/15 16:19

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


guys please check the code cos it's not working ...
Mind anchors

13
ghia
Re: Paid access to some parts of the website
  • 2009/1/15 17:44

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Did you assign it to the template?
$xoopsTpl->assign('usergroup'$usergroup);

14
trabis
Re: Paid access to some parts of the website
  • 2009/1/15 18:45

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


$usergroups = array();
$groups =& $member_handler->getGroupsByUser($thisUser->getVar('uid'), true);
foreach (
$groups as $group) {
    
$usergroups[] = $group->getVar('name');
}

if (
in_array('mygroup'$usergroups)) {
    
$xoopsTpl->assign('hasPrivileges'true);
}


Then use:

<{if $hasPrivileges}>something here<{/if}>

in the template.
Replace 'mygroup' by the name of the group that has privileges.

15
Mazarin
Re: Paid access to some parts of the website
  • 2009/1/15 23:02

  • Mazarin

  • Just can't stay away

  • Posts: 533

  • Since: 2008/12/10


I'm also looking for something like this to show additional content for certain user groups on pages (albeit not for money). However, I can't seem to get the line
$groups =& $member_handler->getGroupsByUser($thisUser->getVar('uid'), true);
to work, since all execution of code stops after that (i.e. everything before that line is written on the screen, but nothing after).

Any suggestions?

16
trabis
Re: Paid access to some parts of the website
  • 2009/1/15 23:45

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


$thisUser->getVar('uid') must be the cause of your problem
You must replace it by the id of the user that is seeing the page
Something like
$uid = is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0;
$groups =& $member_handler->getGroupsByUser($uid, true);

17
Mazarin
Re: Paid access to some parts of the website
  • 2009/1/16 6:51

  • Mazarin

  • Just can't stay away

  • Posts: 533

  • Since: 2008/12/10


That makes sense. I'll try that tonight. Thanks!

18
deka87
Re: Paid access to some parts of the website
  • 2009/1/16 8:02

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


Thanks guys I'll give it a shot.
Mind anchors

19
Mazarin
Re: Paid access to some parts of the website
  • 2009/1/16 22:24

  • Mazarin

  • Just can't stay away

  • Posts: 533

  • Since: 2008/12/10


Hmm, I still can't get it to work. Though, looking at userinfo.php and seeing this line:
$groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
makes me think this should be something like it. Are we perhaps getting confused by different implementations in different versions of XOOPS here? I run 2.3.2b myself.

In addition, I get some really weird results when experimenting with this. When I use the code above and print the results onscreen, it seems the system classifies me as an anonymous user, even though I'm an admin. Also, if I look at the Who's online block, the system has registered two users online (1 user, 1 anonymous), even though I only have one connection to the server (and this is fresh after reboot of both server and client, so no other connections have been made). Weird...or perhaps (more likely) I'm just a n00b...

20
trabis
Re: Paid access to some parts of the website
  • 2009/1/16 23:33

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


That is because you did not set $member_handler

The correct code for you will be:
$member_handler =& xoops_gethandler('member');
$uid is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0;
$groups =& $member_handler->getGroupsByUser($uidtrue);
$usergroups = array();
$groups =& $member_handler->getGroupsByUser($uidtrue);
foreach (
$groups as $group) {
    
$usergroups[] = $group->getVar('name');
}

if (
in_array('mygroup'$usergroups)) {
    
$xoopsTpl->assign('hasPrivileges'true);
}


And you must use this code after the inclusion of header.php (to make $xoopsTpl work)

Login

Who's Online

375 user(s) are online (255 user(s) are browsing Support Forums)


Members: 0


Guests: 375


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits