40
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($uid, true);
$usergroups = array();
$groups =& $member_handler->getGroupsByUser($uid, true);
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.