Index: branches/RC/core/units/user_groups/user_groups_eh.php =================================================================== diff -u -N -r8929 -r10005 --- branches/RC/core/units/user_groups/user_groups_eh.php (.../user_groups_eh.php) (revision 8929) +++ branches/RC/core/units/user_groups/user_groups_eh.php (.../user_groups_eh.php) (revision 10005) @@ -9,6 +9,7 @@ */ function OnProcessSelected(&$event) { + if ($event->Prefix == 'u-ug') { $new_groups = $this->Application->GetVar('g'); if (!$new_groups) { return ; @@ -35,7 +36,37 @@ $this->Conn->doInsert($fields_hash, $table_name); } } + } + if ($event->Prefix == 'g-ug') { + $new_users = $this->Application->GetVar('u'); + if (!$new_users) { + return ; + } + + $new_users = array_keys($new_users); + + // don't insert duplicate group membership record + $group_id = $this->Application->GetVar('g_id'); + $table_name = $this->Application->GetTempName(TABLE_PREFIX.'UserGroup', 'prefix:g'); + $sql = 'SELECT PortalUserId + FROM '.$table_name.' + WHERE GroupId = '.$group_id; + $old_users = $this->Conn->GetCol($sql); + + $new_users = array_diff($new_users, $old_users); + if ($new_users) { + foreach ($new_users as $new_user) { + $fields_hash = Array ( + 'GroupId' => $group_id, + 'PortalUserId' => $new_user, + 'PrimaryGroup' => 0, + ); + $this->Conn->doInsert($fields_hash, $table_name); + } + } + } + $this->Application->StoreVar($this->Application->GetTopmostPrefix($event->Prefix).'_modified', '1'); $event->SetRedirectParam('opener', 'u'); } @@ -77,11 +108,21 @@ $ids = $event->getEventParam('ids'); if ($ids) { $object =& $event->getObject( Array('skip_autoload' => true) ); + + if ($event->Prefix == 'u-ug') { $user_id = $this->Application->GetVar('u_id'); $sql = 'SELECT '.$object->IDField.' FROM '.$object->TableName.' WHERE '.$object->IDField.' IN ('.implode(',', $ids).') AND PortalUserId = '.$user_id.' AND PrimaryGroup = 0'; $ids = $this->Conn->GetCol($sql); + } + elseif ($event->Prefix == 'g-ug') { + $group_id = $this->Application->GetVar('g_id'); + $sql = 'SELECT '.$object->IDField.' + FROM '.$object->TableName.' + WHERE '.$object->IDField.' IN ('.implode(',', $ids).') AND GroupId = '.$group_id.' AND PrimaryGroup = 0'; + $ids = $this->Conn->GetCol($sql); + } $event->setEventParam('ids', $ids); } }