Index: kernel/application.php =================================================================== --- kernel/application.php (revision 13756) +++ kernel/application.php (working copy) @@ -1383,9 +1383,9 @@ $this->Session->StoreVar($var, $val, $optional); } - function StorePersistentVar($var, $val) + function StorePersistentVar($var, $val, $optional = false) { - $this->Session->StorePersistentVar($var, $val); + $this->Session->StorePersistentVar($var, $val, $optional); } function StoreVarDefault($var, $val, $optional=false) Index: kernel/db/db_event_handler.php =================================================================== --- kernel/db/db_event_handler.php (revision 13756) +++ kernel/db/db_event_handler.php (working copy) @@ -926,18 +926,11 @@ if ($per_page) { // per-page found in request -> store in session and persistent session - $this->Application->StoreVar($event->getPrefixSpecial() . '_PerPage', $per_page, true); //true for optional - $this->Application->StorePersistentVar($event->getPrefixSpecial() . '_PerPage.' . $view_name, $per_page); + $this->setListSetting($event, 'PerPage', $per_page); } else { // per-page not found in request -> get from pesistent session (or session) - $storage_prefix = $event->getEventParam('same_special') ? $event->Prefix : $event->getPrefixSpecial(); - $per_page = $this->Application->RecallPersistentVar($storage_prefix . '_PerPage.' . $view_name, ALLOW_DEFAULT_SETTINGS); - - if (!$per_page) { - // per-page is stored to current session - $per_page = $this->Application->RecallVar($storage_prefix . '_PerPage'); - } + $per_page = $this->getListSetting($event, 'PerPage'); } } @@ -983,11 +976,10 @@ } } else { - $storage_prefix = $event->getEventParam('same_special') ? $event->Prefix : $event->Prefix_Special; - $cur_sort1 = $this->Application->RecallVar($storage_prefix . '_Sort1'); - $cur_sort1_dir = $this->Application->RecallVar($storage_prefix . '_Sort1_Dir'); - $cur_sort2 = $this->Application->RecallVar($storage_prefix . '_Sort2'); - $cur_sort2_dir = $this->Application->RecallVar($storage_prefix . '_Sort2_Dir'); + $cur_sort1 = $this->getListSetting($event, 'Sort1'); + $cur_sort1_dir = $this->getListSetting($event, 'Sort1_Dir'); + $cur_sort2 = $this->getListSetting($event, 'Sort2'); + $cur_sort2_dir = $this->getListSetting($event, 'Sort2_Dir'); } $tag_sort_by = $event->getEventParam('sort_by'); @@ -1055,6 +1047,43 @@ } /** + * Gets list setting by name (persistent or real session) + * + * @param kEvent $event + * @param string $variable_name + * @return string + */ + function getListSetting(&$event, $variable_name) + { + $view_name = $this->Application->RecallVar($event->getPrefixSpecial() . '_current_view'); + $storage_prefix = $event->getEventParam('same_special') ? $event->Prefix : $event->getPrefixSpecial(); + + // get sorting from pesistent session + $variable_value = $this->Application->RecallPersistentVar($storage_prefix . '_' . $variable_name . '.' . $view_name, ALLOW_DEFAULT_SETTINGS); + + /*if (!$variable_value) { + // get sorting from session + $variable_value = $this->Application->RecallVar($storage_prefix . '_' . $variable_name); + }*/ + + return $variable_value; + } + + /** + * Sets list setting by name (persistent and real session) + * + * @param kEvent $event + * @param string $variable_name + * @param string $variable_value + */ + function setListSetting(&$event, $variable_name, $variable_value) + { + $view_name = $this->Application->RecallVar($event->getPrefixSpecial() . '_current_view'); +// $this->Application->StoreVar($event->getPrefixSpecial() . '_' . $variable_name, $variable_value, true); //true for optional + $this->Application->StorePersistentVar($event->getPrefixSpecial() . '_' . $variable_name . '.' . $view_name, $variable_value, true); //true for optional + } + + /** * Add filters found in session * * @param kEvent $event @@ -1130,17 +1159,17 @@ */ function OnSetSorting(&$event) { - $cur_sort1 = $this->Application->RecallVar($event->Prefix_Special.'_Sort1'); - $cur_sort1_dir = $this->Application->RecallVar($event->Prefix_Special.'_Sort1_Dir'); + $cur_sort1 = $this->getListSetting($event, 'Sort1'); + $cur_sort1_dir = $this->getListSetting($event, 'Sort1_Dir'); $use_double_sorting = $this->Application->ConfigValue('UseDoubleSorting'); if ($use_double_sorting) { - $cur_sort2 = $this->Application->RecallVar($event->Prefix_Special.'_Sort2'); - $cur_sort2_dir = $this->Application->RecallVar($event->Prefix_Special.'_Sort2_Dir'); + $cur_sort2 = $this->getListSetting($event, 'Sort2'); + $cur_sort2_dir = $this->getListSetting($event, 'Sort2_Dir'); } - $passed_sort1 = $this->Application->GetVar($event->getPrefixSpecial(true).'_Sort1'); + $passed_sort1 = $this->Application->GetVar($event->getPrefixSpecial(true) . '_Sort1'); if ($cur_sort1 == $passed_sort1) { $cur_sort1_dir = $cur_sort1_dir == 'asc' ? 'desc' : 'asc'; } @@ -1153,12 +1182,12 @@ $cur_sort1_dir = 'asc'; } - $this->Application->StoreVar($event->Prefix_Special.'_Sort1', $cur_sort1); - $this->Application->StoreVar($event->Prefix_Special.'_Sort1_Dir', $cur_sort1_dir); + $this->setListSetting($event, 'Sort1', $cur_sort1); + $this->setListSetting($event, 'Sort1_Dir', $cur_sort1_dir); if ($use_double_sorting) { - $this->Application->StoreVar($event->Prefix_Special.'_Sort2', $cur_sort2); - $this->Application->StoreVar($event->Prefix_Special.'_Sort2_Dir', $cur_sort2_dir); + $this->setListSetting($event, 'Sort2', $cur_sort2); + $this->setListSetting($event, 'Sort2_Dir', $cur_sort2_dir); } } @@ -1177,8 +1206,8 @@ list ($field, $dir) = explode('|', $combined); if ($this->Application->isAdmin || !$this->Application->GetVar('main_list')) { - $this->Application->StoreVar($prefix_special . '_Sort1', $field); - $this->Application->StoreVar($prefix_special . '_Sort1_Dir', $dir); + $this->setListSetting($event, 'Sort1', $field); + $this->setListSetting($event, 'Sort1_Dir', $dir); } else { $event->setPseudoClass('_List'); Index: kernel/session/session.php =================================================================== --- kernel/session/session.php (revision 13756) +++ kernel/session/session.php (working copy) @@ -371,13 +371,14 @@ * @param Session $session * @param string $var_name * @param mixed $var_value + * @param bool $optional */ - function StorePersistentVar(&$session, $var_name, $var_value) + function StorePersistentVar(&$session, $var_name, $var_value, $optional = false) { $user_id = $session->RecallVar('user_id'); if ($user_id == USER_GUEST || $user_id === false) { // -2 (when not logged in), false (when after u:OnLogout event) - $session->StoreVar($var_name, $var_value); + $session->StoreVar($var_name, $var_value, $optional); return ; } @@ -1297,9 +1298,9 @@ } } - function StorePersistentVar($name, $value) + function StorePersistentVar($name, $value, $optional = false) { - $this->Storage->StorePersistentVar($this, $name, $value); + $this->Storage->StorePersistentVar($this, $name, $value, $optional); } function LoadPersistentVars()