Index: branches/RC/core/units/users/users_event_handler.php =================================================================== diff -u -N -r10005 -r10024 --- branches/RC/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 10005) +++ branches/RC/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 10024) @@ -12,8 +12,8 @@ $permissions = Array ( // admin 'OnSetPersistantVariable' => Array('self' => 'view'), // because setting to logged in user only - 'OnUpdateRootPassword' => Array('self' => true), - 'OnUpdatePassword' => Array('self' => true), + 'OnUpdateRootPassword' => Array('self' => true), + 'OnUpdatePassword' => Array('self' => true), // front 'OnRefreshForm' => Array('self' => true), @@ -56,7 +56,7 @@ if (!$this->Application->IsAdmin()) { $object->addFilter('status_filter', '%1$s.Status = '.STATUS_ACTIVE); } - + if ($event->Special == 'group') { $group_id = $this->Application->GetVar('g_id'); if ($group_id !== false) { @@ -71,7 +71,7 @@ $object->addFilter('already_member_filter', '%1$s.PortalUserId NOT IN ('.implode(',', $user_ids).')'); } } - } + } } @@ -246,9 +246,11 @@ $this->Application->SetVar('u.current_id', $user_id); $this->Application->StoreVar('user_id', $user_id); - $this_login = (int)$object->getPersistantVar('ThisLogin'); - $object->setPersistantVar('LastLogin', $this_login); - $object->setPersistantVar('ThisLogin', adodb_mktime()); + $this->Application->LoadPersistentVars(); + + $this_login = (int)$this->Application->RecallPersistentVar('ThisLogin'); + $this->Application->StorePersistentVar('LastLogin', $this_login); + $this->Application->StorePersistentVar('ThisLogin', adodb_mktime()); } else { $object->Load(-2); @@ -397,6 +399,7 @@ } $this->Application->resetCounters('UserSession'); + $event->SetRedirectParam('pass', 'all'); } @@ -1103,11 +1106,9 @@ */ function OnSetPersistantVariable(&$event) { - $object =& $event->getObject(); - $field = $this->Application->GetVar('field'); $value = $this->Application->GetVar('value'); - $object->setPersistantVar($field, $value); + $this->Application->StorePersistentVar($field, $value); $force_tab = $this->Application->GetVar('SetTab'); if ($force_tab) { @@ -1155,7 +1156,7 @@ { return $this->OnUpdatePassword($event); } - + /** * Allows to change root password * @@ -1170,7 +1171,7 @@ if ($id == $user_id && ($user_id > 0 || $user_id == -1)) { $user_dummy =& $this->Application->recallObject($event->Prefix.'.-item', null, Array('skip_autoload' => true)); /* @var $user_dummy kDBItem */ - + $user_dummy->Load($id); $status_field = array_shift($this->Application->getUnitOption($event->Prefix, 'StatusField')); @@ -1191,12 +1192,12 @@ $verify_options = $object->GetFieldOptions('VerifyRootPassword'); $verify_options['salt'] = 'b38'; $object->SetFieldOptions('VerifyRootPassword', $verify_options); - + // this is internal hack to allow root/root passwords for dev if ($this->Application->isDebugMode() && $field_values['RootPassword'] == 'root') { $this->Application->ConfigHash['Min_Password'] = 4; } - + $this->RemoveRequiredFields($object); $object->SetDBField('RootPassword', $this->Application->ConfigValue('RootPass')); $object->SetFieldsFromHash($field_values); @@ -1430,7 +1431,7 @@ $this->Application->setUnitOption($event->Prefix, 'Fields', $fields); } } - + /** * OnMassCloneUsers * @@ -1451,7 +1452,7 @@ $cloned_users = $temp_handler->CloneItems($event->Prefix, '', $ids); $this->clearSelectedIDs($event); } - + /** * When cloning users, reset password (set random) * @@ -1466,13 +1467,13 @@ $object->SetDBField('Password', rand(100000000, 999999999)); $object->SetDBField('CreatedOn', adodb_mktime()); $object->SetDBField('ResourceId', false); // this will reset it - + // change email cause it should be unique $object->NameCopy(array(), $object->GetID(), 'Email', 'copy%1$s.%2$s'); - + $object->UpdateFormattersSubFields(); } - + /** * Copy user groups after copying user * @@ -1482,11 +1483,79 @@ { $id = $event->getEventParam('id'); $original_id = $event->getEventParam('original_id'); - + $sql = 'INSERT '.TABLE_PREFIX."UserGroup SELECT $id, GroupId, MembershipExpires, PrimaryGroup, 0 FROM ".TABLE_PREFIX."UserGroup WHERE PortalUserId = $original_id"; $this->Conn->Query($sql); } - + + /** + * Saves selected ids to session + * + * @param kEvent $event + */ + function OnSaveSelected(&$event) + { + $this->StoreSelectedIDs($event); + + // remove current ID, otherwise group selector will use it in filters + $this->Application->DeleteVar($event->getPrefixSpecial(true).'_id'); + } + + /** + * Adds selected link to listing + * + * @param kEvent $event + */ + function OnProcessSelected(&$event) + { + $event->SetRedirectParam('opener', 'u'); + $user_ids = $this->getSelectedIDs($event, true); + $this->clearSelectedIDs($event); + + $dst_field = $this->Application->RecallVar('dst_field'); + if ($dst_field != 'PrimaryGroupId') { + return ; + } + + $group_ids = $this->Application->GetVar('g'); + $primary_group_id = $group_ids ? array_shift( array_keys($group_ids) ) : false; + + if (!$user_ids || !$primary_group_id) { + return ; + } + + $table_name = $this->Application->getUnitOption('ug', 'TableName'); + + $sql = 'SELECT PortalUserId + FROM '.$table_name.' + WHERE (GroupId = '.$primary_group_id.') AND (PortalUserId IN ('.implode(',', $user_ids).'))'; + $existing_members = $this->Conn->GetCol($sql); + + // 1. reset primary group mark + $sql = 'UPDATE '.$table_name.' + SET PrimaryGroup = 0 + WHERE PortalUserId IN ('.implode(',', $user_ids).')'; + $this->Conn->Query($sql); + + foreach ($user_ids as $user_id) { + if (in_array($user_id, $existing_members)) { + // 2. already member of that group -> just make primary + $sql = 'UPDATE '.$table_name.' + SET PrimaryGroup = 1 + WHERE (PortalUserId = '.$user_id.') AND (GroupId = '.$primary_group_id.')'; + $this->Conn->Query($sql); + } + else { + // 3. not member of that group -> make member & make primary + $fields_hash = Array ( + 'GroupId' => $primary_group_id, + 'PortalUserId' => $user_id, + 'PrimaryGroup' => 1, + ); + $this->Conn->doInsert($fields_hash, $table_name); + } + } + } } ?> \ No newline at end of file