name; $description = $selectedUserData->description; CopyArray( $selectedUserData->groups, $groupsSelected ); $allGroups = GetGroups(); $groupsNotSelected = array_diff( $allGroups, $groupsSelected ); } // The save button was hit. else { // Get submitted data if ( array_key_exists( $userNameID, $_POST ) ) $userName = $_POST[ $userNameID ]; if ( array_key_exists( $userIDID, $_POST ) ) $userID = $_POST[ $userIDID ]; if ( array_key_exists( $passwordID, $_POST ) ) $password = $_POST[ $passwordID ]; if ( array_key_exists( $passwordConfirmationID, $_POST ) ) $passwordConfirmation = $_POST[ $passwordConfirmationID ]; if ( array_key_exists( $descriptionID, $_POST ) ) $description = $_POST[ $descriptionID ]; if ( array_key_exists( $groupsSelectedID, $_POST ) ) $groupsSelected = $_POST[ $groupsSelectedID ]; if ( array_key_exists( $groupsNotSelectedID, $_POST ) ) $groupsNotSelected = $_POST[ $groupsNotSelectedID ]; // Validate inputs. if ( empty( $userName ) ) throw new Exception( $errUserNameMissing ); if ( (!empty( $password ) || !empty( $passwordConfirmation )) && ( $password != $passwordConfirmation ) ) throw new Exception( $errPasswordConfirmationFailed ); // Update parameters of user. $site->UpdateUser( $userID, "", $userName, $password, $description ); // Create MgStringCollection with just one user to update group memberships. $userToUpdate = new MgStringCollection(); $userToUpdate->Add( $userID ); // Get old list of groups for user $oldGroupMemberships = GetGroupMemberships( $userID ); // Find group memberships to revoke. $revokeList = array_diff( $oldGroupMemberships, $groupsSelected ); if ( $revokeList != null && !empty( $revokeList ) ) { $groupMembershipsToRevoke = new MgStringCollection(); foreach ( $revokeList as $groupToRevoke ) $groupMembershipsToRevoke->Add( $groupToRevoke ); $site->RevokeGroupMembershipsFromUsers( $groupMembershipsToRevoke, $userToUpdate ); } // Find new group memberships to grant. $grantList = array_diff( $groupsSelected, $oldGroupMemberships ); if ( $grantList != null && !empty( $grantList ) ) { $groupMembershipsToGrant = new MgStringCollection(); foreach ( $grantList as $groupToGrant ) $groupMembershipsToGrant->Add( $groupToGrant ); $site->GrantGroupMembershipsToUsers( $groupMembershipsToGrant, $userToUpdate ); } // Everything is OK. $confirmationMsg = sprintf( $confSuccessfulUpdate, $userID ); SaveSessionVars(); header( 'Location: usermanagement.php?'.strip_tags(SID) ); exit(); } } catch ( MgException $e ) { CheckForFatalMgException( $e ); $errorMsg = $e->GetMessage(); } catch ( Exception $e ) { $errorMsg = $e->getMessage(); } ?>
User ID :
User name :
Description:
Password:
Confirm password:
leadInStr = 'Member of'; $control->col1Name = $groupsNotSelectedID.'[]'; $control->col3Name = $groupsSelectedID.'[]'; $control->col1Heading = 'Available groups'; $control->col3Heading = 'Member of these groups'; $control->col1List = $groupsNotSelected; $control->enabled = true; $control->size = 10; // SPECIAL HANDLING FOR EVERYONE GROUP: // If the Everyone group is in the $groupsSelected list (which it should be), it requires special handling. // Membership in this group cannot be revoked and, so, it should not be selected. The preferrable UI is to // disable this option in the select control; however, the disable parameter is not recognized by all browsers // for the OPTION tag and is not always recognized in JavaScript for this tag as well. Therefore, the OnChange // parameter of the select control is used. With this an alert box is popped up when Everyone is selected and // the selection is reversed. // In addition, to suggest that the Everyone group should not be selected at all, it's display name is changed // from "Everyone" to "Everyone (Built-in group)". if ( in_array( MgGroup::Everyone, $groupsSelected ) ) { $control->col3List = array(); $control->col3Vals = array(); foreach( $groupsSelected as $selectedGroup ) { if ( $selectedGroup == MgGroup::Everyone ) { $control->col3List[] = $everyoneGroupSelectorLabel; $control->col3Vals[] = MgGroup::Everyone; } else { $control->col3List[] = $selectedGroup; $control->col3Vals[] = $selectedGroup; } } $control->col3OnChange = "DisableOption( '".$groupsSelectedID."[]', '".MgGroup::Everyone."', 'The Everyone group is built-in. Membership in this group cannot be removed.');"; } else $control->col3List = $groupsSelected; DisplayAddRemoveControl( $control ); ?>