1
Mithrandir
Manage User's Group Membership from Edit User

How to add a multi-select of groups on the administration-side "edit user" page:

modules/system/admin/users/users.php line 148:
$groups array_values($user->getGroups()); 
//This is a new line that must come before the existing        include XOOPS_ROOT_PATH."/modules/system/admin/users/userform.php";


modules/system/admin/users/userform.php line 114:
$group_select = new XoopsFormSelectGroup(_US_GROUPS'groups'false$groups5true);


same file a little lower:
$form->addElement($mailok_radio); //existing line
$form->addElement($group_select); //new line
$form->addElement($fct_hidden); //existing line


Now it will show the select element, but we need it to actually do something as well, so add another parameter to the updateUser() function in modules/system/admin/users/users.php so it looks like this:
function updateUser($uid$uname$name$url$email$user_icq$user_aim$user_yim$user_msnm$user_from$user_occ$user_intrest$user_viewemail$user_avatar$user_sig$attachsig$theme$pass$pass2$rank$bio$uorder$umode$notify_method$notify_mode$timezone_offset$user_mailok$groups = array())

(Only added $groups = array() as the last parameter)

Right, but it will have to use this extra parameter, too, so change this in modules/system/admin/users/users.php - updateUser() function:
if (!$member_handler->insertUser($edituser)) {
     
xoops_cp_header();
     echo 
$edituser->getHtmlErrors();
     
xoops_cp_footer();
} else {
     
redirect_header("admin.php?fct=users",1,_AM_DBUPDATED);
}

to
if (!$member_handler->insertUser($edituser)) {
    
xoops_cp_header();
    echo 
$edituser->getHtmlErrors();
    
xoops_cp_footer();
} else {
    if (
$groups != array()) {
        
//Get user's old groups
        
$oldgroups $edituser->getGroups();
        
$member_handler =& xoops_gethandler('member');
        foreach (
$oldgroups as $groupid) {
            
//remove user's membership of these groups
            
$member_handler->removeUsersFromGroup($groupid, array($edituser->getVar('uid')));
        }
        foreach (
$groups as $groupid) {
            
//Add the user to the new groups
            
$member_handler->addUserToGroup($groupid$edituser->getVar('uid'));
        }
    }
    
redirect_header("admin.php?fct=users",1,_AM_DBUPDATED);
}


And finally, we need to call the updateUser() function with the proper parameters

modules/system/admin/users/main.php line 55:
updateUser($uid$username$name$url$email$user_icq$user_aim$user_yim$user_msnm$user_from$user_occ$user_intrest$user_viewemail$user_avatar$user_sig$attachsig$theme$password$pass2$rank$bio$uorder$umode$notify_method$notify_mode$timezone_offset$user_mailok$groups);

(just added $groups as a last parameter)

Now there's only one thing left - and that is to add the language constant, we use in the userform to the proper language file:
xoops-root/language/[language]/user.php:
define('_US_GROUPS''User's Groups'); //or whatever translation, you want

2
Mithrandir
Re: Manage User's Group Membership from Edit User

Alright, Take 2 on this one:

modules/system/admin/users/userform.php:
// Groups administration addition XOOPS 2.0.9: Mith
global $xoopsUser;
$gperm_handler =& xoops_gethandler('groupperm');
//If user has admin rights on groups
if ($gperm_handler->checkRight("system_admin"XOOPS_SYSTEM_GROUP$xoopsUser->getGroups(), 1)) {
    
//add group selection
    
$group_select = new XoopsFormSelectGroup(_US_GROUPS'groups'false$groups5true);
}
else {
    
//add empty variable
    
$group_select = new XoopsFormHidden('groups', array());
}


instead of the previous addition there - we want only users, who have system admin rights over groups to be able to use this.

Also, we do not want accidents, where users are accidently removing themselves from the webmaster's group, so:

modules/system/admin/users/users.php - updateUsers() function:
if ($groups != array()) {
   global 
$xoopsUser;
   
$oldgroups $edituser->getGroups();
   
//If the edited user is the current user and the current
   //user WAS in the webmaster's group and is NOT in the new groups array
   
if ($edituser->getVar('uid') == $xoopsUser->getVar('uid') && (in_array(XOOPS_GROUP_ADMIN$oldgroups)) && !(in_array(XOOPS_GROUP_ADMIN$groups))) {
       
//Add the webmaster's group to the groups array to prevent accidentally 
       //removing oneself from the webmaster's group
       
array_push($groupsXOOPS_GROUP_ADMIN);
    }                
    
$member_handler =& xoops_gethandler('member');
    foreach (
$oldgroups as $groupid) {
       
$member_handler->removeUsersFromGroup($groupid, array($edituser->getVar('uid')));
    }
    foreach (
$groups as $groupid) {
       
$member_handler->addUserToGroup($groupid$edituser->getVar('uid'));
    }
}
redirect_header("admin.php?fct=users",1,_AM_DBUPDATED);

3
pepeli
Re: Manage User's Group Membership from Edit User
  • 2004/12/11 15:16

  • pepeli

  • Just popping in

  • Posts: 7

  • Since: 2004/1/16


It`s works

Thank you

GREAT WORK

4
Franki
Re: Manage User's Group Membership from Edit User
  • 2006/4/6 12:31

  • Franki

  • Just popping in

  • Posts: 8

  • Since: 2004/10/18


I know I'm digging this up from the grave, but I think I found a bug but i cannot figure out to fix it (and this seems to be the only related thread I've found after many hours of searching). I hope a guru here can help:

[version 2.0.13.2]

When the Admin logs in and uses "Add User" (under Edit/Delete Users), even if a different group(s) is selected by the admin through this process, this new user is NEVER ADDED to the group(s) selected - the only group the new user is added to is "Registered" (groupid = 2). Even if the Registered group is not selected, new user is added to this group anyway.

I've tried looking through the codes, but am only a newbie. Please help!

5
Tailzehhhh
Re: Manage User's Group Membership from Edit User
  • 2006/4/6 18:49

  • Tailzehhhh

  • Just popping in

  • Posts: 20

  • Since: 2006/4/6 5


going to use it. and then report back my feedback.

6
Franki
Re: Manage User's Group Membership from Edit User
  • 2006/4/8 3:59

  • Franki

  • Just popping in

  • Posts: 8

  • Since: 2004/10/18


thanks Tailzehhhh.

Anyone else having this problem?

I can't even find the function that create/add the new user (to the database) through the admin area...

7
drummond
Re: Manage User's Group Membership from Edit User
  • 2006/6/7 15:54

  • drummond

  • Just popping in

  • Posts: 36

  • Since: 2004/6/19


Yep, I've always had this problem with XOOPS with every version I have ever used. Still doesn't work in 2.0.13.2. And I've tried it on a couple different servers and browsers.

Anyone know how to fix this? Sounds like a system bug to me.

Login

Who's Online

183 user(s) are online (118 user(s) are browsing Support Forums)


Members: 0


Guests: 183


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits