From 8f4b991a7683f18e40b2b5e434204aa8293acd57 Mon Sep 17 00:00:00 2001 From: Thomas Vincent Date: Fri, 6 Mar 2026 12:12:36 -0800 Subject: [PATCH 1/4] 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 --- syslog.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/syslog.php b/syslog.php index 185e0cd..5be1d14 100644 --- a/syslog.php +++ b/syslog.php @@ -779,7 +779,7 @@ function syslog_request_validation($current_tab, $force = false) { function set_shift_span($shift_span, $session_prefix) { global $graph_timeshifts; - if ($shift_span == 'span' || $shift_span === false) { + if ($shift_span == 'span' || ($shift_span === false && !isset($_SESSION[$session_prefix . '_date1']))) { $span = array(); // Calculate the timespan @@ -795,6 +795,11 @@ function set_shift_span($shift_span, $session_prefix) { kill_session_var($session_prefix . '_date2'); set_request_var('custom', false); + } elseif ($shift_span === false) { + // Page navigation: custom dates were set earlier; restore from session. + set_request_var('date1', $_SESSION[$session_prefix . '_date1']); + set_request_var('date2', $_SESSION[$session_prefix . '_date2']); + set_request_var('custom', true); } elseif ($shift_span == 'shift') { $span = array(); @@ -826,6 +831,9 @@ function set_shift_span($shift_span, $session_prefix) { set_request_var('custom', true); } elseif ($shift_span == 'custom') { + // Persist custom dates so page navigation preserves the filter. + $_SESSION[$session_prefix . '_date1'] = get_request_var('date1'); + $_SESSION[$session_prefix . '_date2'] = get_request_var('date2'); set_request_var('custom', true); } } From 7570ab613d33ab3f3a91bc897a9cc0f5bcbca76a Mon Sep 17 00:00:00 2001 From: Thomas Vincent Date: Fri, 6 Mar 2026 21:59:37 -0800 Subject: [PATCH 2/4] fix: guard session date keys with isset before access in set_shift_span Signed-off-by: Thomas Vincent --- syslog.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/syslog.php b/syslog.php index 5be1d14..f669b85 100644 --- a/syslog.php +++ b/syslog.php @@ -797,9 +797,19 @@ function set_shift_span($shift_span, $session_prefix) { set_request_var('custom', false); } elseif ($shift_span === false) { // Page navigation: custom dates were set earlier; restore from session. - set_request_var('date1', $_SESSION[$session_prefix . '_date1']); - set_request_var('date2', $_SESSION[$session_prefix . '_date2']); - set_request_var('custom', true); + if (isset($_SESSION[$session_prefix . '_date1']) && isset($_SESSION[$session_prefix . '_date2'])) { + set_request_var('date1', $_SESSION[$session_prefix . '_date1']); + set_request_var('date2', $_SESSION[$session_prefix . '_date2']); + set_request_var('custom', true); + } else { + // Session keys missing; fall back to a fresh span calculation. + $first_weekdayid = read_user_setting('first_weekdayid'); + $span = array(); + get_timespan($span, time(), get_request_var('predefined_timespan'), $first_weekdayid); + set_request_var('date1', date('Y-m-d H:i:s', $span['begin_now'])); + set_request_var('date2', date('Y-m-d H:i:s', $span['end_now'])); + set_request_var('custom', false); + } } elseif ($shift_span == 'shift') { $span = array(); From f59b1efd37087bf97957dd722a42b62fc3dc1a15 Mon Sep 17 00:00:00 2001 From: Thomas Vincent Date: Fri, 6 Mar 2026 22:18:14 -0800 Subject: [PATCH 3/4] 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 --- syslog.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syslog.php b/syslog.php index f669b85..50bd2e1 100644 --- a/syslog.php +++ b/syslog.php @@ -779,7 +779,7 @@ function syslog_request_validation($current_tab, $force = false) { function set_shift_span($shift_span, $session_prefix) { global $graph_timeshifts; - if ($shift_span == 'span' || ($shift_span === false && !isset($_SESSION[$session_prefix . '_date1']))) { + if ($shift_span == 'span' || ($shift_span === false && (!isset($_SESSION[$session_prefix . '_date1']) || !isset($_SESSION[$session_prefix . '_date2'])))) { $span = array(); // Calculate the timespan From 8badb3d8032800c288d0cbaf59926d408ba9b093 Mon Sep 17 00:00:00 2001 From: Thomas Vincent Date: Sun, 8 Mar 2026 03:55:27 -0700 Subject: [PATCH 4/4] chore: add CHANGELOG entry for develop Signed-off-by: Thomas Vincent --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f1e7f2..3e5c5a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ --- develop --- +* issue#250: Fix date filter persistence by validating before shift_span detection * issue: Making changes to support Cacti 1.3 * issue: Don't use MyISAM for non-analytical tables * issue: The install advisor for Syslog was broken in current Cacti releases