Index: branches/RC/core/install/install_schema.sql =================================================================== diff -u -N -r9419 -r10024 --- branches/RC/core/install/install_schema.sql (.../install_schema.sql) (revision 9419) +++ branches/RC/core/install/install_schema.sql (.../install_schema.sql) (revision 10024) @@ -138,9 +138,11 @@ ); CREATE TABLE PersistantSessionData ( + VariableId bigint(20) NOT NULL auto_increment, PortalUserId int(11) NOT NULL default '0', VariableName varchar(255) NOT NULL default '', VariableValue text NOT NULL, + PRIMARY KEY (VariableId), KEY UserId (PortalUserId), KEY VariableName (VariableName) ); Index: branches/RC/kernel/admin_templates/img/toolbar/tool_primary_user_group_f2.gif =================================================================== diff -u -N Binary files differ Index: branches/RC/core/install/upgrades.sql =================================================================== diff -u -N -r10005 -r10024 --- branches/RC/core/install/upgrades.sql (.../upgrades.sql) (revision 10005) +++ branches/RC/core/install/upgrades.sql (.../upgrades.sql) (revision 10024) @@ -167,3 +167,4 @@ INSERT INTO ConfigurationAdmin VALUES ('KeepSessionOnBrowserClose', 'la_title_General', 'la_prompt_KeepSessionOnBrowserClose', 'checkbox', NULL, NULL, '13', '0', '0'); INSERT INTO ConfigurationValues VALUES (DEFAULT, 'KeepSessionOnBrowserClose', 0, 'Proj-Base', 'in-portal:configure_general'); +ALTER TABLE PersistantSessionData ADD VariableId BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST; \ No newline at end of file Index: branches/RC/kernel/admin_templates/img/toolbar/tool_primary_user_group_f3.gif =================================================================== diff -u -N Binary files differ Index: branches/RC/core/units/users/users_item.php =================================================================== diff -u -N -r8929 -r10024 --- branches/RC/core/units/users/users_item.php (.../users_item.php) (revision 8929) +++ branches/RC/core/units/users/users_item.php (.../users_item.php) (revision 10024) @@ -1,48 +1,6 @@ GetID(); - if (!$id) return ; - $sql = 'SELECT VariableValue, VariableName - FROM '.TABLE_PREFIX.'PersistantSessionData - WHERE PortalUserId = '.$id; - $this->persistantVars = $this->Conn->GetCol($sql, 'VariableName'); - } - - function setPersistantVar($var_name, $var_value) - { - $this->persistantVars[$var_name] = $var_value; - - if ($this->GetID() > 0 || $this->GetID() == -1) { - $replace_hash = Array( 'PortalUserId' => $this->GetID(), - 'VariableName' => $var_name, - 'VariableValue' => $var_value - ); - $this->Conn->doInsert($replace_hash, TABLE_PREFIX.'PersistantSessionData', 'REPLACE'); - } - else { - $this->Application->StoreVar($var_name, $var_value); - } - } - - function getPersistantVar($var_name) - { - return getArrayValue($this->persistantVars, $var_name); - } - - function Load($id, $id_field_name = null) - { - $ret = parent::Load($id, $id_field_name); - if ($ret || $id == -1) { - $this->LoadPersistantVars($id); - } - return $ret; - } - /** * Returns IDs of groups to which user belongs and membership is not expired * Index: branches/RC/core/units/user_profile/user_profile_config.php =================================================================== diff -u -N -r8929 -r10024 --- branches/RC/core/units/user_profile/user_profile_config.php (.../user_profile_config.php) (revision 8929) +++ branches/RC/core/units/user_profile/user_profile_config.php (.../user_profile_config.php) (revision 10024) @@ -14,7 +14,7 @@ 4 => 'mode', ), - 'IDField' => 'VariableName', + 'IDField' => 'VariableId', 'TableName' => TABLE_PREFIX.'PersistantSessionData', 'ForeignKey' => 'PortalUserId', Index: branches/RC/core/kernel/db/db_event_handler.php =================================================================== diff -u -N -r10005 -r10024 --- branches/RC/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 10005) +++ branches/RC/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 10024) @@ -153,7 +153,7 @@ 'OnViewFile' => Array('self'=>true, 'subitem'=>true), 'OnSaveWidths' => Array('self'=>true, 'subitem'=>true), - + 'OnValidateMInputFields' => Array('self'=>'view'), ); $this->permMapping = array_merge($this->permMapping, $permissions); @@ -2021,8 +2021,7 @@ list($id,$field_values) = each($items_info); $preset_key = $field_values['ExportPresets']; - $user =& $this->Application->recallObject('u.current'); - $export_settings = $user->getPersistantVar('export_settings'); + $export_settings = $this->Application->RecallPersistentVar('export_settings'); if (!$export_settings) return ; $export_settings = unserialize($export_settings); if (!isset($export_settings[$event->Prefix])) return ; @@ -2037,7 +2036,7 @@ } if ($to_delete) { unset($export_settings[$event->Prefix][$to_delete]); - $user->setPersistantVar('export_settings', serialize($export_settings)); + $this->Application->StorePersistentVar('export_settings', serialize($export_settings)); } } } @@ -2142,7 +2141,7 @@ readfile($path); exit(); } - + /** * Validates MInput control fields * @@ -2152,7 +2151,7 @@ { $minput_helper =& $this->Application->recallObject('MInputHelper'); /* @var $minput_helper MInputHelper */ - + $minput_helper->OnValidateMInputFields($event); } Index: branches/RC/core/units/general/cat_dbitem_export.php =================================================================== diff -u -N -r9842 -r10024 --- branches/RC/core/units/general/cat_dbitem_export.php (.../cat_dbitem_export.php) (revision 9842) +++ branches/RC/core/units/general/cat_dbitem_export.php (.../cat_dbitem_export.php) (revision 10024) @@ -1196,8 +1196,7 @@ $object =& $event->getObject( Array('skip_autoload' => true) ); $options = $object->GetFieldOptions('ExportPresets'); - $user =& $this->Application->recallObject('u.current'); - $export_settings = $user->getPersistantVar('export_settings'); + $export_settings = $this->Application->RecallPersistentVar('export_settings'); if (!$export_settings) return ; $export_settings = unserialize($export_settings); @@ -1316,11 +1315,11 @@ { if ($object->GetDBField('ExportSavePreset')) { $name = $object->GetDBField('ExportPresetName'); - $user =& $this->Application->recallObject('u.current'); - $export_settings = $user->getPersistantVar('export_settings'); + + $export_settings = $this->Application->RecallPersistentVar('export_settings'); $export_settings = $export_settings ? unserialize($export_settings) : array(); $export_settings[$event->Prefix][$name] = $field_values; - $user->setPersistantVar('export_settings', serialize($export_settings)); + $this->Application->StorePersistentVar('export_settings', serialize($export_settings)); } $progress_t = $this->Application->RecallVar('export_progress_t'); Index: branches/RC/kernel/units/user_profile/user_profile_config.php =================================================================== diff -u -N -r8929 -r10024 --- branches/RC/kernel/units/user_profile/user_profile_config.php (.../user_profile_config.php) (revision 8929) +++ branches/RC/kernel/units/user_profile/user_profile_config.php (.../user_profile_config.php) (revision 10024) @@ -14,7 +14,7 @@ 4 => 'mode', ), - 'IDField' => 'VariableName', + 'IDField' => 'VariableId', 'TableName' => TABLE_PREFIX.'PersistantSessionData', 'ForeignKey' => 'PortalUserId', Index: branches/RC/kernel/admin_templates/img/toolbar/tool_primary_user_group.gif =================================================================== diff -u -N Binary files differ 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 Index: branches/RC/core/kernel/session/session.php =================================================================== diff -u -N -r10005 -r10024 --- branches/RC/core/kernel/session/session.php (.../session.php) (revision 10005) +++ branches/RC/core/kernel/session/session.php (.../session.php) (revision 10024) @@ -269,19 +269,27 @@ } } + /** + * Stores variable to persistent session + * + * @param Session $session + * @param string $var_name + * @param mixed $var_value + */ function StorePersistentVar(&$session, $var_name, $var_value) { $user_id = $session->RecallVar('user_id'); if ($user_id == -2 || $user_id === false) { // -2 (when not logged in), false (when after u:OnLogout event) + $session->StoreVar($var_name, $var_value); return ; } $this->PersistentVars[$var_name] = $var_value; $key_clause = 'PortalUserId = '.$user_id.' AND VariableName = '.$this->Conn->qstr($var_name); - $sql = 'SELECT VariableValue + $sql = 'SELECT VariableName FROM '.TABLE_PREFIX.'PersistantSessionData WHERE '.$key_clause; $record_found = $this->Conn->GetOne($sql); @@ -300,14 +308,28 @@ } } + /** + * Gets persistent variable + * + * @param Session $session + * @param string $var_name + * @param mixed $default + * @return mixed + */ function RecallPersistentVar(&$session, $var_name, $default = false) { - if (isset($this->PersistentVars[$var_name])) { + if ($session->RecallVar('user_id') == -2) { + return $session->RecallVar($var_name, $default); + } + + if (array_key_exists($var_name, $this->PersistentVars)) { return $this->PersistentVars[$var_name]; } elseif ($default == '_USE_DEFAULT_USER_DATA_') { $default_user_id = $this->Application->ConfigValue('DefaultSettingsUserId'); - if (!$default_user_id) $default_user_id = -1; + if (!$default_user_id) { + $default_user_id = -1; + } $sql = 'SELECT VariableValue, VariableName FROM '.TABLE_PREFIX.'PersistantSessionData WHERE VariableName = '.$this->Conn->qstr($var_name).' AND PortalUserId = '.$default_user_id; @@ -318,7 +340,9 @@ } return $value; } - else return $default; + else { + return $default; + } } function RemovePersistentVar(&$session, $var_name) Index: branches/RC/admin/install/upgrades/inportal_upgrade_v4.2.2.sql =================================================================== diff -u -N -r9866 -r10024 --- branches/RC/admin/install/upgrades/inportal_upgrade_v4.2.2.sql (.../inportal_upgrade_v4.2.2.sql) (revision 9866) +++ branches/RC/admin/install/upgrades/inportal_upgrade_v4.2.2.sql (.../inportal_upgrade_v4.2.2.sql) (revision 10024) @@ -3,6 +3,7 @@ INSERT INTO ConfigurationAdmin VALUES ('RecycleBinFolder', 'la_Text_General', 'la_config_RecycleBinFolder', 'text', NULL , NULL , 10.11, 0, 0); INSERT INTO ConfigurationValues VALUES (DEFAULT, 'RecycleBinFolder', '', 'In-Portal', 'in-portal:configure_categories'); +ALTER TABLE PersistantSessionData ADD VariableId BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST; UPDATE Modules SET Version = '4.2.2' WHERE Name = 'Core'; UPDATE Modules SET Version = '4.2.2' WHERE Name = 'In-Portal'; \ No newline at end of file Index: branches/RC/core/admin_templates/incs/header.tpl =================================================================== diff -u -N -r10005 -r10024 --- branches/RC/core/admin_templates/incs/header.tpl (.../header.tpl) (revision 10005) +++ branches/RC/core/admin_templates/incs/header.tpl (.../header.tpl) (revision 10024) @@ -37,6 +37,10 @@ var $base_path = ''; var img_path = '/img/'; +var phrases = { + 'la_Delete_Confirm' : '' +} + NumberFormatter.ThousandsSep = ''; NumberFormatter.DecimalSep = ''; Index: branches/RC/kernel/admin_templates/users/users_list.tpl =================================================================== diff -u -N -r9047 -r10024 --- branches/RC/kernel/admin_templates/users/users_list.tpl (.../users_list.tpl) (revision 9047) +++ branches/RC/kernel/admin_templates/users/users_list.tpl (.../users_list.tpl) (revision 10024) @@ -31,6 +31,15 @@ std_delete_items('u') } ) ); + a_toolbar.AddButton ( + new ToolBarButton( + 'in-portal:primary_user_group', + '::', + function() { + openSelector('u', '', 'PrimaryGroupId', '800x600', 'OnSaveSelected'); + } + ) + ); a_toolbar.AddButton( new ToolBarSeparator('sep1') ); @@ -67,6 +76,6 @@ \ No newline at end of file