31
Mazarin
Re: Paid access to some parts of the website
  • 2009/1/18 10:08

  • Mazarin

  • Just can't stay away

  • Posts: 533

  • Since: 2008/12/10


Please excuse the layman's terms in trying to describe where I'm trying to do this, but I still haven't been able to fully grasp how everything is connected here.

I'm trying to write the code in a template (globalnav.html, or rather I'm including a php page where I write the code) that's controlling a horizontal navigation bar just under the "header" of the page. This template is in turn included in the theme.html file. (here is the demo for the theme, as my site isn't online yet http://xoops4noobs.ovh.org/index.php?xoops_theme_select=blueday_dynamique). I assume that attaching the file here won't help as the problem doesn't actually lay in the code itself, but rather how it is connected to a number preceding files.

What I'm trying to achieve is to have additional options in the dropdown menus from this menubar depending on which user group the user belong to.

32
deka87
Re: Paid access to some parts of the website
  • 2009/1/18 10:56

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


A question regarding this code:

$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);
}


what if i want to show something to everybody except 'mygroup' members. and I wan to make the restriction not in my template (which would be like
<{if not $hasPrivileges}>something here<{/if}>
but I want to do it in a php file like:

if (in_array('mygroup'$usergroups)) {
echo 
"text not for 'mygroup' users";
}

so I want "text not for 'mygroup' users" to show for everybody but the 'mygroup' users. how would I have to correct the aforesaid code?
Mind anchors

33
Mazarin
Re: Paid access to some parts of the website
  • 2009/1/18 11:34

  • Mazarin

  • Just can't stay away

  • Posts: 533

  • Since: 2008/12/10


I'm sure there's a prettier way, but you could always just add an "else" with the text and leave the true if clause blank

34
deka87
Re: Paid access to some parts of the website
  • 2009/1/18 11:38

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


im sorry i didnt get hwo I should edit this code
if (in_array('mygroup'$usergroups)) {
echo 
"text not for 'mygroup' users";
}
Mind anchors

35
Mazarin
Re: Paid access to some parts of the website
  • 2009/1/18 13:12

  • Mazarin

  • Just can't stay away

  • Posts: 533

  • Since: 2008/12/10


if (in_array('mygroup'$usergroups)) {

} else {
   echo 
"text not for 'mygroup' users";
}


But maybe that's not what you were after?

36
deka87
Re: Paid access to some parts of the website
  • 2009/1/18 13:30

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


isnt't this going to show "text not for 'mygroup' users" for the 'mygroup' users? I want the opposite - to show it to eevrybody BUT 'mygroup' users..
Mind anchors

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

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


if (!in_array('mygroup'$usergroups)) {
echo 
"text not for 'mygroup' users";
}

38
Mazarin
Re: Paid access to some parts of the website
  • 2009/1/18 15:48

  • Mazarin

  • Just can't stay away

  • Posts: 533

  • Since: 2008/12/10


Yeah, that's the neat way of doing it. It's just a matter of negating the statement.

Anyway, trabis, do you have any idea what's causing my problems with the "navigation version" of this? Can I provide some other information that will aid in solving this?

39
trabis
Re: Paid access to some parts of the website
  • 2009/1/18 17:51

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Quote:

niei0637 wrote:
Yeah, that's the neat way of doing it. It's just a matter of negating the statement.

Anyway, trabis, do you have any idea what's causing my problems with the "navigation version" of this? Can I provide some other information that will aid in solving this?


Please paste the code of the file and changes you made in the theme.

40
Mazarin
Re: Paid access to some parts of the website
  • 2009/1/18 20:45

  • Mazarin

  • Just can't stay away

  • Posts: 533

  • Since: 2008/12/10


require(XOOPS_ROOT_PATH.'/mainfile.php');
require(
XOOPS_ROOT_PATH.'/header.php');
$member_handler =& xoops_gethandler('member'); 
$uid is_object($xoopsUser) ? 
echo 
$uid;
$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);
echo "Access"
} else {
echo 
"No access";
}



Actually, I haven't made any changes to your code, except adding a couple of lines printing the uid and verifying which clause of the if I'm in. In the theme, the only modification I've made to globalnav.html is an include statement to include the php file where I've written the code.
<{include_php file="$xoops_rootpath/themes/blueday_dynamique/xotpl/checkusergroup.php" }>


No other changes to the theme whatsoever.

Now, when I print out the uid, I only get 0, and of course I only get the No Access text from the false if clause. If I use the same code on a "separate" php page in a module, the code works perfectly. It's just when trying to use it with the theme navigation bar that it doesn't work and I would really like to know why.

Login

Who's Online

406 user(s) are online (281 user(s) are browsing Support Forums)


Members: 0


Guests: 406


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