Fork me on GitHub
Get XOOPS XOOPSXOOPS FAQFAQ ForumsForums NewsNews ThemesThemes ModulesModules
New Posts New Topics All Posts All Forums Index General Modules Themes Development International XOOPS.org

Search

Nominate XOOPS!

Learn XOOPS Core

Donat-O-Meter

Make donations with PayPal!
Stats
Goal: $100.00
Due Date: Jul 31
Gross Amount: $15.00
Net Balance: $14.11
Left to go: $85.89

Donations
Anonymous ($15)Jul-20

Local Support

Advertisement

XOOPS Code hosted on SourceForge

Cumulus Tag Cloud

- 2 2.5 2.6 3.0 4 6 2013 Abuse Android AntiHarvesting AntiMalUser AntiSpam API Apple Battlefield Blocks Bootstrap Captcha cell chronolabs CHUNG content CĂN demo download Dresses facebook Fat floor Food for free Gateway Google Guide herre Home Honeypot HP html5 Human HỘ iPhone jQuery Language List Loss mobile module modules Monster new newbb news NHÀ online PARK Payment phone PHP Prevention profile project Protector publisher Rapid RESIDENCE responsive review Rights rmcommon Room security Sentry site Smartphone Smarty Solution Spam stem Studio support tag tags tdmcreate The Theme themes User userlog web weight Wishcraft xoops Xortify XPayment ZendFramework

New Users

Registering user

# 137617

nasro

Welcome to XOOPS!




Bottom   Previous Topic   Next Topic  Register To Post



#1 Posted on: 2004/10/12 8:23 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


Top

Mithrandir
XOOPS is my life!
XOOPS is my life!
Joined:
2003/6/21 11:37
From Copenhagen, Denmark
Group:
Registered Users
Posts: 6094
(Show More) (Show Less)


#2 Posted on: 2004/10/14 5:02 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);


Top

Mithrandir
XOOPS is my life!
XOOPS is my life!
Joined:
2003/6/21 11:37
From Copenhagen, Denmark
Group:
Registered Users
Posts: 6094
(Show More) (Show Less)


#3 Posted on: 2004/12/11 9:16 Re: Manage User's Group Membership from Edit User
It`s works

Thank you

GREAT WORK

Top

pepeli
Just popping in
Just popping in
Joined:
2004/1/16 17:06
Group:
Registered Users
Posts: 7
(Show More) (Show Less)


#4 Posted on: 2006/4/6 7:31 Re: Manage User's Group Membership from Edit User
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!

Top

Franki
Just popping in
Just popping in
Joined:
2004/10/18 3:42
Group:
Registered Users
Posts: 8
(Show More) (Show Less)


#5 Posted on: 2006/4/6 13:49 Re: Manage User's Group Membership from Edit User
going to use it. and then report back my feedback.

Top

Tailzehhhh
Just popping in
Just popping in
Joined:
2006/4/6 0:33
Group:
Registered Users
Posts: 20
(Show More) (Show Less)


#6 Posted on: 2006/4/7 22:59 Re: Manage User's Group Membership from Edit User
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...

Top

Franki
Just popping in
Just popping in
Joined:
2004/10/18 3:42
Group:
Registered Users
Posts: 8
(Show More) (Show Less)


#7 Posted on: 2006/6/7 10:54 Re: Manage User's Group Membership from Edit User
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.

Top

drummond
Just popping in
Just popping in
Joined:
2004/6/18 21:33
Group:
Registered Users
Posts: 36
(Show More) (Show Less)







You can view topic.
You cannot start a new topic.
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You can vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.

[Advanced Search]