1
123456
get user's group/level
  • 2005/11/6 3:12

  • 123456

  • Just popping in

  • Posts: 21

  • Since: 2005/9/23


hello mates,
how do i get the user's group/level? ie, as far as i know, to check if an user is admin, i'd use "$xoops_isadmin" right? how can i do the same with a custom group? :) help

2
Dave_L
Re: get the user's group/level
  • 2005/11/6 3:31

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


Examples:

// needed if inside a function
global $xoopsUser$xoopsModule;

// true if current user has admin-right for current module
$is_admin is_object($xoopsUser) and is_object($xoopsModule) and $xoopsUser->isAdmin($xoopsModule->getVar('mid'));

// array of IDs of groups to which current user belongs
$member_handler =& xoops_gethandler('member');
$group_ids =& is_object($xoopsUser) ? $member_handler->getGroupsByUser($xoopsUser->getVar('uid')) : array();

// true if current user is in group ID #17
$in_group in_array(17$group_ids);

3
123456
Re: get the user's group/level
  • 2005/11/6 4:18

  • 123456

  • Just popping in

  • Posts: 21

  • Since: 2005/9/23


thanks for all examples but i'm still confused, can you give me some examples using "If - else"? and.. how do i know the group's id?

4
Dave_L
Re: get the user's group/level
  • 2005/11/6 10:27

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


if ($in_group) {
   echo 
"User is in the groupn";
} else {
   echo 
"User is not in the groupn";
}


Please explain more precisely what you want to do.

5
123456
Re: get the user's group/level
  • 2005/11/6 18:02

  • 123456

  • Just popping in

  • Posts: 21

  • Since: 2005/9/23


i want to get the user's group, so if the user group is () do something else nothing. for example if the user's group is "TEST" i'll do "echo test" else if the group is "Registered Users" i'll do "echo registered user"
this code below is my "test.php":
include "mainfile.php";
$member_handler =& xoops_gethandler('member');
$group_ids =& is_object($xoopsUser) ? $member_handler->getGroupsByUser($xoopsUser->getVar('uid')) : array();
echo 
"$group_ids" ";
$in_group in_array(1$group_ids);
if (
$in_group) {
   echo 
"User is in the groupn";
} else {
   echo 
"User is not in the groupn";
}
?>

Return is:
"1 User is not in the group."

it always return 1, User is not in the group. i'm quite sure i'm doing something wrong, but what exactly?

6
123456
Re: get the user's group/level
  • 2005/11/9 17:06

  • 123456

  • Just popping in

  • Posts: 21

  • Since: 2005/9/23


dead?

Login

Who's Online

435 user(s) are online (351 user(s) are browsing Support Forums)


Members: 0


Guests: 435


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