Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: H - maaliskuu 29, 2006, 03:17:51 IP

Otsikko: SSI check user is in secondary usergroup
Kirjoitti: H - maaliskuu 29, 2006, 03:17:51 IP
There are many posts on the forum about checking if the user is logged in or is an admin/moderator.

However is there a way to see if a user is in a secondary usergroup?
Otsikko: Re: SSI check user is in secondary usergroup
Kirjoitti: Thantos - maaliskuu 29, 2006, 04:56:12 IP
Well it depends on a couple things:
Can that group ever be a primary group?
Do you want to exclude those who have that group as a primary group (if it can be primary)?


If the first is false (ie it can never be a primary group) or the first is true and the second is false then you can just use:
in_array(##, $user_info['groups']);

If the first is true and the second is true then you'll have to do a query

$res = db_query("
  SELECT ID_MEMBER
  FROM {$db_prefix}members
  WHERE ID_GROUP != ##
    AND ## IN (additionalGroups)
    AND ID_MEMBER=$ID_MEMBER
  LIMIT 1", __FILE__, __LINE__);
if ( mysql_num_rows($res) == 0 )
  die("Go away you");
mysql_free_result($res);
Otsikko: Re: SSI check user is in secondary usergroup
Kirjoitti: H - maaliskuu 30, 2006, 11:01:38 AP
Thanks