MyBB Ideas

The MyBB Ideas site allows users to suggest new features and changes in MyBB and the MyBB Group to easily review them to decide what direction MyBB should head in. Search existing ideas.

Function to check all usergroups of the user

5 votes

Submitted by Jan, 6th March 2008, 8:06:06 AM

According to this thread:
http://forum.mybboard.de/showthread.php?tid=8855

I thought it would be usefull, if the mybb has this function in its own. With this, every usergroup of the user is checked.

/**
* checks if the user is in one of the allowed usergroups
* @param $PARAM_allowed the allowed usergroups; seperated with ","(COMMA) f.e. 4,10,2
* @return boolean true if user is in one of the groups
*/
function check_user($PARAM_allowed = '')
//Standardparameter werden angegeben, um jeden Fehlaufruf abzufangen
{
//Definieren, das das Objekt $mybb global schon besteht
global $mybb;

// Setzte $access auf false
$access = false;

// Erstellen eines arrays aus allen übergebenen Usergruppen
$allowed_array = explode(',', $PARAM_allowed);

// Holen der sekundären Benutzergruppen des Users
$additional_str = $mybb->user['additionalgroups'];

// Erstellen eines arrays aus allen sekundären Benutzergruppen des Users
$additional_array = explode(',', $additional_str);

// Prüfen ob der User angemeldet ist
if ($mybb->user['uid'] != '0')
{
// Prüfen ob die sekündären Benutzergruppen in einem array sind
if (is_array($additional_array))
{
// Führe das folgende für jede sekündären Benutzergruppe aus
foreach ($additional_array as $addtionalgroup)
{
// Prüfen ob die erlaubten Benutzergruppen in einem array sind
if (is_array($allowed_array))
{
// Führe das folgende für jede erlaubten Benutzergruppe aus
foreach ($allowed_array as $allow)
{
// Ist die zusätzliche Benutzergruppe eine erlaubte Benutzergruppe
// ODER
// Ist die primäre Benutzergruppe eine erlaubte Benutzergruppe
if (($addtionalgroup == $allow) || ($mybb->user['usergroup'] == $allow))
{
// Setzte $access auf true
$access = true;
}
}
}
}
}
}
// Gibt die Erlaubnis zurück
return $access;
}

1 Comment

  1. For usergroup and forum permissions, all usergroups are already checked. For usergroup settings for the current user, they are all merged into $mybb->usergroup. I don't see what this function could be used for as we already have the same thing.

    DennisTT, 15th March 2008, 9:13:42 PM

Post a Comment

Before you can post a comment you must be a registered member of the MyBB Community Forums.

If you already have an account, log-in to it to post a comment or if you don't register a new account.