From c69b5a5e4e6bcbccdb80de57f302fb01033a38f7 Mon Sep 17 00:00:00 2001 From: Harsh Singh <143034341+singhharsh1708@users.noreply.github.com> Date: Mon, 30 Nov 2026 04:08:33 +0530 Subject: [PATCH] fix: console footer event links match no events when no monitor is listed instead of every event (#8517) --- tests/php/test_console_footer_no_monitors.php | 109 ++++++++++++++++++ web/ajax/console.php | 25 ++-- 2 files changed, 123 insertions(+), 11 deletions(-) create mode 100644 tests/php/test_console_footer_no_monitors.php diff --git a/tests/php/test_console_footer_no_monitors.php b/tests/php/test_console_footer_no_monitors.php new file mode 100644 index 0000000000..58191e9c3a --- /dev/null +++ b/tests/php/test_console_footer_no_monitors.php @@ -0,0 +1,109 @@ +&1', $out, $rc); + echo implode("\n", $out)."\n"; + if ($rc !== 0) $failures++; + } + echo $failures ? "\n$failures case(s) FAILED\n" : "\nall cases passed\n"; + exit($failures ? 1 : 0); +} +$case = $argv[2]; + +namespace_stubs(); +function namespace_stubs() { + eval('namespace ZM { + function Error($m) {} function Warning($m) {} function Debug($m) {} + class Monitor { private $r; function __construct($r = null) { $this->r = $r; } function __call($n, $a) { return $n == "Id" ? $this->r["Id"] : 0; } } + class Storage { static function find() { return array(); } } + class Group_Monitor { static function find($a = null) { return array(); } } + }'); +} + +$stub = sys_get_temp_dir().'/zm_console_footer_'.getmypid(); +mkdir($stub, 0777, true); +file_put_contents($stub.'/_monitor_filters.php', ' $id, 'Name' => "M$id", 'Function' => 'Monitor', 'Enabled' => 1, 'Sequence' => $id, 'Deleted' => 0, + 'Status' => 'Running', 'Type' => 'Ffmpeg', 'ServerId' => 0, 'StorageId' => 0, 'Capturing' => 'Always', + 'Analysing' => 'None', 'Decoding' => 'None', 'Recording' => 'None', 'ZoneCount' => 0, 'Manufacturer' => null, 'Model' => null, + 'Width' => 1, 'Height' => 1, 'TotalEvents' => 2, 'HourEvents' => 0, 'DayEvents' => 0, 'WeekEvents' => 0, 'MonthEvents' => 0, 'ArchivedEvents' => 0); +} +if ($case == 'one') $rows = array(mon(5)); +if ($case == 'two') $rows = array(mon(5), mon(7)); +function dbFetchAll($sql, $col = null, $params = null) { return $GLOBALS['rows']; } + +$Servers = array(); +$user = new stdClass(); +$_REQUEST = array(); +$_COOKIE = array(); +function ajaxResponse($d = array()) { $GLOBALS['data'] = $d; } +function ajaxError($m) {} +$_REQUEST = array('task' => 'query'); + +require $root.'/web/ajax/console.php'; +$data = $GLOBALS['data']; + +$failures = 0; +function check($label, $got, $want) { + global $failures; + if ($got === $want) { echo "ok - $label\n"; return; } + $failures++; + echo "FAIL - $label\n got: ".var_export($got, true)."\n want: ".var_export($want, true)."\n"; +} +function monitorTerm($querystring) { + foreach (json_decode($querystring, true) as $t) { + if ($t['attr'] == 'Monitor') return $t; + } + return null; +} + +foreach (array('Total', 'Hour', 'Day', 'Week', 'Month', 'Archived') as $period) { + $t = monitorTerm($data['footer'][$period.'FilterQuery']); + if ($case == 'none') { + check("$period footer link is limited to a monitor no event has", $t ? $t['val'] : null, '0'); + } else if ($case == 'one') { + check("$period footer link is limited to the listed monitor", $t ? $t['val'] : null, '5'); + } else { + check("$period footer link is limited to the listed monitors", $t ? $t['val'] : null, '5,7'); + } +} +if ($case == 'none') check('the footer still counts no monitors', $data['footer']['monitor_count'], 0); +exit($failures ? 1 : 0); diff --git a/web/ajax/console.php b/web/ajax/console.php index 3a7308042c..db41e097b6 100644 --- a/web/ajax/console.php +++ b/web/ajax/console.php @@ -684,22 +684,25 @@ function queryRequest() { $data['footer'][$period.'Events'] = $footer_totals['event_totals'][$period]['events']; $data['footer'][$period.'EventDiskSpace'] = human_filesize($footer_totals['event_totals'][$period]['diskspace']); - // Generate filter querystring for footer (include monitor filter if monitors are filtered) - $filter = $eventCountsFooter[$period]['filter']; - if (count($all_filtered_monitors) > 0) { - $filter = addFilterTerm( - $filter, - count($filter['Query']['terms']), - array('cnj' => 'and', 'attr' => 'Monitor', 'op' => 'IN', 'val' => implode(',', array_column($all_filtered_monitors, 'Id'))) - ); - } - parseFilter($filter); - $data['footer'][$period.'FilterQuery'] = $filter['querystring']; + $data['footer'][$period.'FilterQuery'] = consoleFooterFilterQuery($eventCountsFooter[$period]['filter'], $all_filtered_monitors); } return $data; } +// The querystring a footer event total links to: the period's filter limited to the monitors +// the console is listing. With none listed the term would have no value and drop out, and the +// link would show every event, so it names monitor 0, which no event has. +function consoleFooterFilterQuery($filter, $monitors) { + $filter = addFilterTerm( + $filter, + count($filter['Query']['terms']), + array('cnj' => 'and', 'attr' => 'Monitor', 'op' => 'IN', 'val' => count($monitors) ? implode(',', array_column($monitors, 'Id')) : '0') + ); + parseFilter($filter); + return $filter['querystring']; +} + // Remove camera credentials from an exported monitor for users who cannot edit it. function exportStripCredentials(array $data) { unset($data['User'], $data['Pass'], $data['ONVIF_Username'], $data['ONVIF_Password']);