Index: trunk/core/kernel/session/session.php =================================================================== diff -u -r6833 -r7391 --- trunk/core/kernel/session/session.php (.../session.php) (revision 6833) +++ trunk/core/kernel/session/session.php (.../session.php) (revision 7391) @@ -67,7 +67,7 @@ var $ChangedDirectVars = Array(); var $PersistentVars = Array (); - + var $OriginalData=Array(); var $TimestampField; @@ -93,13 +93,13 @@ function StoreSession(&$session, $additional_fields = Array()) { - $fields_hash = Array ( + $fields_hash = Array ( $this->IDField => $session->SID, $this->TimestampField => $session->Expiration ); - - $this->Conn->doInsert($fields_hash, $this->TableName); + $this->Conn->doInsert($fields_hash, $this->TableName); + foreach ($additional_fields as $field_name => $field_value) { $this->SetField($session, $field_name, $field_value); } @@ -250,10 +250,10 @@ } return $expired_sids; } - + function LoadPersistentVars(&$session) { - $user_id = $this->Application->GetVar('u_id'); + $user_id = $this->Application->RecallVar('user_id'); if ($user_id != -2) { // root & normal users $sql = 'SELECT VariableValue, VariableName @@ -265,31 +265,31 @@ $this->PersistentVars = Array (); } } - + function StorePersistentVar(&$session, $var_name, $var_value) { $this->PersistentVars[$var_name] = $var_value; - - $replace_hash = Array ( - 'PortalUserId' => $this->Application->GetVar('u_id'), + + $replace_hash = Array ( + 'PortalUserId' => $this->Application->RecallVar('user_id'), 'VariableName' => $var_name, 'VariableValue' => $var_value ); $this->Conn->doInsert($replace_hash, TABLE_PREFIX.'PersistantSessionData', 'REPLACE'); - + } - + function RecallPersistentVar(&$session, $var_name, $default = false) { return isset($this->PersistentVars[$var_name]) ? $this->PersistentVars[$var_name] : $default; } - + function RemovePersistentVar(&$session, $var_name) { unset($this->PersistentVars[$var_name]); - - $user_id = $this->Application->GetVar('u_id'); - + + $user_id = $this->Application->RecallVar('user_id'); + if ($user_id != -2) { $sql = 'DELETE FROM '.TABLE_PREFIX.'PersistantSessionData WHERE PortalUserId = '.$user_id.' AND VariableName = '.$this->Conn->qstr($var_name); @@ -488,21 +488,26 @@ else { //Otherwise we still suppose cookies are on, because may be it's the first time user visits the site //So we send cookies on to get it next time (when referal will tell us if they are realy off - setcookie( - 'cookies_on', - 1, - adodb_mktime()+31104000, //one year should be enough - $this->CookiePath, - $this->CookieDomain, - $this->CookieSecure - ); + $this->SetCookie('cookies_on', 1, adodb_mktime() + 31104000); //one year should be enough } } else $this->CookiesEnabled = true; return $this->CookiesEnabled; } + /** + * Sets cookie for current site using path and domain + * + * @param string $name + * @param mixed $value + * @param int $expires + */ + function SetCookie($name, $value, $expires = null) + { + setcookie($name, $value, $expires, $this->CookiePath, $this->CookieDomain, $this->CookieSecure); + } + function Check() { // we should check referer if cookies are disabled, and in combined mode @@ -656,22 +661,14 @@ { return isset($this->Application->HttpQuery->Cookie[$this->CookieName]) ? $this->Application->HttpQuery->Cookie[$this->CookieName] : false; } - + /** * Updates SID in cookie with new value * */ function SetSessionCookie() { - setcookie( - $this->CookieName, - $this->SID, - $this->Expiration, - $this->CookiePath, - $this->CookieDomain, - $this->CookieSecure - ); - + $this->SetCookie($this->CookieName, $this->SID, $this->Expiration); $_COOKIE[$this->CookieName] = $this->SID; // for compatibility with in-portal } @@ -724,7 +721,7 @@ function PrintSession($comment='') { if($this->Application->isDebugMode() && constOn('DBG_SHOW_SESSIONDATA')) { - // dump session data + // dump session data $this->Application->Debugger->appendHTML('SessionStorage ('.$comment.'):'); $session_data = $this->Data->GetParams(); ksort($session_data); @@ -747,7 +744,7 @@ } $this->Application->Debugger->dumpVars($session_data); } - + // to insert after HTTPQuery if it's visible // $new_row = constOn('DBG_SHOW_HTTPQUERY') ? 4 : 2; // $debugger->moveAfterRow($new_row,2); @@ -766,29 +763,43 @@ function SaveLastTemplate($t) { - $last_env = $this->Application->BuildEnv($t, Array('m_opener' => 'u', '__URLENCODE__' => 1), 'all'); + // save last_template + $wid = $this->Application->GetVar('m_wid'); + + $last_env = $this->getLastTemplateENV($t, Array('m_opener' => 'u')); $last_template = basename($_SERVER['PHP_SELF']).'|'.substr($last_env, strlen(ENV_VAR_NAME) + 1); - $this->StoreVar('last_template', $last_template); - $this->StoreVar('last_url', $_SERVER['REQUEST_URI']); - - $this->StoreVar('last_env', substr($this->Application->BuildEnv($t, Array('__URLENCODE__' => 1), 'all'), strlen(ENV_VAR_NAME)+1)); + $this->StoreVar(rtrim('last_template_'.$wid, '_'), $last_template); + + $last_env = $this->getLastTemplateENV($t, Array()); + $last_template = basename($_SERVER['PHP_SELF']).'|'.substr($last_env, strlen(ENV_VAR_NAME) + 1); + $this->StoreVar(rtrim('last_template_popup_'.$wid, '_'), $last_template); + + // 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)); } + function getLastTemplateENV($t, $params) + { + $params['__URLENCODE__'] = 1; + return $this->Application->BuildEnv($t, $params, 'all'); + } + function StoreVar($name, $value) { $this->Data->Set($name, $value); } - + function StorePersistentVar($name, $value) { $this->Storage->StorePersistentVar($this, $name, $value); } - + function LoadPersistentVars() { $this->Storage->LoadPersistentVars($this); } - + function StoreVarDefault($name, $value) { $tmp = $this->RecallVar($name); @@ -819,7 +830,7 @@ { return $this->Storage->RemovePersistentVar($this, $name); } - + /** * Ignores session varible value set before *