Skip to content

Commit 869c035

Browse files
fix: persist custom date filter across syslog page navigation (#251)
* fix: persist custom date filter across syslog page navigation When a user sets a custom date range and then navigates to the next page, the shift_span detection runs before validate_store_request_vars restores session values. shift_span was false (no date params in the page link), causing set_shift_span() to fall into the 'span' branch, which recalculated dates from predefined_timespan and killed the session date vars -- wiping the custom filter. Two-part fix: - In the 'custom' case, save date1/date2 to session (same pattern the existing 'shift' case already uses) so page navigation can find them. - Distinguish page navigation with saved custom dates (shift_span false + session dates present) from an explicit predefined-timespan selection. Only recalculate from predefined_timespan when no custom dates are in session. Fixes #250 Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * fix: guard session date keys with isset before access in set_shift_span Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * fix: guard both _date1 and _date2 session keys in set_shift_span If _date1 exists but _date2 is absent (partial session state), the old check passed the guard and entered the pagination-restore path. The inner isset() at line 800 already fell back safely, but the outer guard now explicitly requires both keys to avoid confusing partial-session scenarios. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * chore: add CHANGELOG entry for develop Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> --------- Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
1 parent 09e06ad commit 869c035

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
--- develop ---
44

5+
* issue#250: Fix date filter persistence by validating before shift_span detection
56
* issue: Making changes to support Cacti 1.3
67
* issue: Don't use MyISAM for non-analytical tables
78
* issue: The install advisor for Syslog was broken in current Cacti releases

syslog.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ function syslog_request_validation($current_tab, $force = false) {
779779
function set_shift_span($shift_span, $session_prefix) {
780780
global $graph_timeshifts;
781781

782-
if ($shift_span == 'span' || $shift_span === false) {
782+
if ($shift_span == 'span' || ($shift_span === false && (!isset($_SESSION[$session_prefix . '_date1']) || !isset($_SESSION[$session_prefix . '_date2'])))) {
783783
$span = array();
784784

785785
// Calculate the timespan
@@ -795,6 +795,21 @@ function set_shift_span($shift_span, $session_prefix) {
795795
kill_session_var($session_prefix . '_date2');
796796

797797
set_request_var('custom', false);
798+
} elseif ($shift_span === false) {
799+
// Page navigation: custom dates were set earlier; restore from session.
800+
if (isset($_SESSION[$session_prefix . '_date1']) && isset($_SESSION[$session_prefix . '_date2'])) {
801+
set_request_var('date1', $_SESSION[$session_prefix . '_date1']);
802+
set_request_var('date2', $_SESSION[$session_prefix . '_date2']);
803+
set_request_var('custom', true);
804+
} else {
805+
// Session keys missing; fall back to a fresh span calculation.
806+
$first_weekdayid = read_user_setting('first_weekdayid');
807+
$span = array();
808+
get_timespan($span, time(), get_request_var('predefined_timespan'), $first_weekdayid);
809+
set_request_var('date1', date('Y-m-d H:i:s', $span['begin_now']));
810+
set_request_var('date2', date('Y-m-d H:i:s', $span['end_now']));
811+
set_request_var('custom', false);
812+
}
798813
} elseif ($shift_span == 'shift') {
799814
$span = array();
800815

@@ -826,6 +841,9 @@ function set_shift_span($shift_span, $session_prefix) {
826841

827842
set_request_var('custom', true);
828843
} elseif ($shift_span == 'custom') {
844+
// Persist custom dates so page navigation preserves the filter.
845+
$_SESSION[$session_prefix . '_date1'] = get_request_var('date1');
846+
$_SESSION[$session_prefix . '_date2'] = get_request_var('date2');
829847
set_request_var('custom', true);
830848
}
831849
}

0 commit comments

Comments
 (0)