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, $groups, 5, true);
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