Index: trunk/core/kernel/session/session.php =================================================================== diff -u -N -r8104 -r8402 --- trunk/core/kernel/session/session.php (.../session.php) (revision 8104) +++ trunk/core/kernel/session/session.php (.../session.php) (revision 8402) @@ -256,7 +256,7 @@ function LoadPersistentVars(&$session) { - $user_id = $this->Application->RecallVar('user_id'); + $user_id = $session->RecallVar('user_id'); if ($user_id != -2) { // root & normal users $sql = 'SELECT VariableValue, VariableName @@ -271,15 +271,33 @@ 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) + return ; + } + $this->PersistentVars[$var_name] = $var_value; - - $replace_hash = Array ( - 'PortalUserId' => $this->Application->RecallVar('user_id'), - 'VariableName' => $var_name, - 'VariableValue' => $var_value - ); - $this->Conn->doInsert($replace_hash, TABLE_PREFIX.'PersistantSessionData', 'REPLACE'); - + + $key_clause = 'PortalUserId = '.$user_id.' AND VariableName = '.$this->Conn->qstr($var_name); + + $sql = 'SELECT VariableValue + FROM '.TABLE_PREFIX.'PersistantSessionData + WHERE '.$key_clause; + $record_found = $this->Conn->GetOne($sql); + + $fields_hash = Array ( + 'PortalUserId' => $user_id, + 'VariableName' => $var_name, + 'VariableValue' => $var_value, + ); + + if ($record_found) { + $this->Conn->doUpdate($fields_hash, TABLE_PREFIX.'PersistantSessionData', $key_clause); + } + else { + $this->Conn->doInsert($fields_hash, TABLE_PREFIX.'PersistantSessionData'); + } } function RecallPersistentVar(&$session, $var_name, $default = false) @@ -291,7 +309,7 @@ { unset($this->PersistentVars[$var_name]); - $user_id = $this->Application->RecallVar('user_id'); + $user_id = $session->RecallVar('user_id'); if ($user_id != -2) { $sql = 'DELETE FROM '.TABLE_PREFIX.'PersistantSessionData @@ -662,6 +680,8 @@ // front-session called from admin or otherwise, then save it's data $this->SaveData(); } + + $this->Application->resetCounters('UserSession'); } /** @@ -786,6 +806,31 @@ // save other last... variables for mistical purposes (customizations may be) $this->StoreVar('last_url', $_SERVER['REQUEST_URI']); // needed by ord:StoreContinueShoppingLink $this->StoreVar('last_env', substr($last_env, strlen(ENV_VAR_NAME)+1)); + + // save last_template in persistant session + if (!$wid) { + if ($this->Application->IsAdmin()) { + // only for main window, not popups, not login template, not temp mode (used in adm:MainFrameLink tag) + $temp_mode = false; + $passed = explode(',', $this->Application->GetVar('passed')); + foreach ($passed as $passed_prefix) { + if ($this->Application->GetVar($passed_prefix.'_mode')) { + $temp_mode = true; + break; + } + } + + if (!$temp_mode) { + $this->StorePersistentVar('last_template_popup', $last_template); + } + } + elseif ($this->Application->GetVar('admin') == 1) { + $admin_session =& $this->Application->recallObject('Session.admin'); + /* @var $admin_ses Session */ + + $admin_session->StorePersistentVar('last_template_popup', '../'.$last_template); + } + } } function getLastTemplateENV($t, $params) @@ -871,6 +916,7 @@ { return $this->Storage->DeleteExpired(); } + /** * Allows to check if user in this session is logged in or not * @@ -879,6 +925,7 @@ function LoggedIn() { $user_id = $this->RecallVar('user_id'); + $ret = $user_id > 0; if ($this->RecallVar('admin') == 1 && ($user_id == -1)) { $ret = true;