Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ZoneMinder/zoneminder
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Connor committed Jul 16, 2024
2 parents 4b52232 + 75ecf1f commit 8c6396a
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 144 deletions.
2 changes: 1 addition & 1 deletion web/skins/classic/js/skin.js
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ function isJSON(str) {
};

function setCookie(name, value, seconds) {
var newValue = (typeof value === 'string') ? value : JSON.stringify(value);
var newValue = (typeof value === 'string' || typeof value === 'boolean') ? value : JSON.stringify(value);
let expires = "";
if (seconds) {
const date = new Date();
Expand Down
258 changes: 134 additions & 124 deletions web/skins/classic/views/_monitor_filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,163 +18,165 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//

require_once('includes/Monitor.php');

zm_session_start();
foreach (array('GroupId','Capturing','Analysing','Recording','ServerId','StorageId','Status','MonitorId','MonitorName','Source') as $var) {
if (isset($_REQUEST[$var])) {
if ($_REQUEST[$var] != '') {
$_SESSION[$var] = $_REQUEST[$var];
} else {
function addFilterSelect($name, $options) {
$html = '<span class="term '.$name.'Filter"><label>'.translate($name).'</label>';
$html .= '<span class="term-value-wrapper">';
$html .= htmlSelect($name.'[]', $options,
(isset($_SESSION[$name])?$_SESSION[$name]:''),
array(
'data-on-change'=>'submitThisForm',
'class'=>'chosen',
'multiple'=>'multiple',
'data-placeholder'=>'All',
)
);
$html .= '</span>';
$html .= '</span>'.PHP_EOL;
return $html;
}

function buildMonitorsFilters() {
global $user, $Servers;
require_once('includes/Monitor.php');

zm_session_start();
foreach (array('GroupId','Capturing','Analysing','Recording','ServerId','StorageId','Status','MonitorId','MonitorName','Source') as $var) {
if (isset($_REQUEST[$var])) {
if ($_REQUEST[$var] != '') {
$_SESSION[$var] = $_REQUEST[$var];
} else {
unset($_SESSION[$var]);
}
} else if (isset($_REQUEST['filtering'])) {
unset($_SESSION[$var]);
}
} else if (isset($_REQUEST['filtering'])) {
unset($_SESSION[$var]);
}
}
session_write_close();
session_write_close();

$storage_areas = ZM\Storage::find();
$StorageById = array();
foreach ($storage_areas as $S) {
$StorageById[$S->Id()] = $S;
}
$storage_areas = ZM\Storage::find();
$StorageById = array();
foreach ($storage_areas as $S) {
$StorageById[$S->Id()] = $S;
}

$ServersById = array();
foreach ($Servers as $s) {
$ServersById[$s->Id()] = $s;
}
$ServersById = array();
foreach ($Servers as $s) {
$ServersById[$s->Id()] = $s;
}

$html =
$html =
'
<div class="controlHeader">
<!-- Used to submit the form with the enter key -->
<input type="submit" class="d-none"/>
<input type="hidden" name="filtering" value=""/>
';
$groupSql = '';
if (canView('Groups')) {
$GroupsById = array();
foreach (ZM\Group::find() as $G) {
$GroupsById[$G->Id()] = $G;
$groupSql = '';
if (canView('Groups')) {
$GroupsById = array();
foreach (ZM\Group::find() as $G) {
$GroupsById[$G->Id()] = $G;
}

if (count($GroupsById)) {
$html .= '<span class="term" id="groupControl"><label>'. translate('Group') .'</label>';
$html .= '<span class="term-value-wrapper">';
# This will end up with the group_id of the deepest selection
$group_id = isset($_SESSION['GroupId']) ? $_SESSION['GroupId'] : null;
$html .= ZM\Group::get_group_dropdown();
$groupSql = ZM\Group::get_group_sql($group_id);
$html .= '</span>';
$html .= '</span>';
}
}

if (count($GroupsById)) {
$html .= '<span class="term" id="groupControl"><label>'. translate('Group') .'</label>';
$html .= '<span class="term-value-wrapper">';
# This will end up with the group_id of the deepest selection
$group_id = isset($_SESSION['GroupId']) ? $_SESSION['GroupId'] : null;
$html .= ZM\Group::get_group_dropdown();
$groupSql = ZM\Group::get_group_sql($group_id);
$html .= '</span>';
$html .= '</span>';
$selected_monitor_ids = isset($_SESSION['MonitorId']) ? $_SESSION['MonitorId'] : array();
if ( !is_array($selected_monitor_ids) ) {
$selected_monitor_ids = array($selected_monitor_ids);
}
}

$selected_monitor_ids = isset($_SESSION['MonitorId']) ? $_SESSION['MonitorId'] : array();
if ( !is_array($selected_monitor_ids) ) {
$selected_monitor_ids = array($selected_monitor_ids);
}
$conditions = array();
$values = array();

$conditions = array();
$values = array();

if ( $groupSql )
$conditions[] = $groupSql;
foreach ( array('ServerId','StorageId','Status','Capturing','Analysing','Recording') as $filter ) {
if ( isset($_SESSION[$filter]) ) {
if ( is_array($_SESSION[$filter]) ) {
$conditions[] = '`'.$filter . '` IN ('.implode(',', array_map(function(){return '?';}, $_SESSION[$filter])). ')';
$values = array_merge($values, $_SESSION[$filter]);
} else {
$conditions[] = '`'.$filter . '`=?';
$values[] = $_SESSION[$filter];
if ( $groupSql )
$conditions[] = $groupSql;
foreach ( array('ServerId','StorageId','Status','Capturing','Analysing','Recording') as $filter ) {
if ( isset($_SESSION[$filter]) ) {
if ( is_array($_SESSION[$filter]) ) {
$conditions[] = '`'.$filter . '` IN ('.implode(',', array_map(function(){return '?';}, $_SESSION[$filter])). ')';
$values = array_merge($values, $_SESSION[$filter]);
} else {
$conditions[] = '`'.$filter . '`=?';
$values[] = $_SESSION[$filter];
}
}
} # end foreach filter

if (count($user->unviewableMonitorIds()) ) {
$ids = $user->viewableMonitorIds();
$conditions[] = 'M.Id IN ('.implode(',',array_map(function(){return '?';}, $ids)).')';
$values = array_merge($values, $ids);
}
} # end foreach filter

if (count($user->unviewableMonitorIds()) ) {
$ids = $user->viewableMonitorIds();
$conditions[] = 'M.Id IN ('.implode(',',array_map(function(){return '?';}, $ids)).')';
$values = array_merge($values, $ids);
}
$html .= '<span class="term MonitorNameFilter"><label>'.translate('Name').'</label>';
$html .= '<span class="term-value-wrapper">';
$html .= '<input type="text" name="MonitorName" value="'.(isset($_SESSION['MonitorName'])?validHtmlStr($_SESSION['MonitorName']):'').'" placeholder="text or regular expression"/></span>';
$html .= '</span>'.PHP_EOL;

$html .= '<span class="term MonitorNameFilter"><label>'.translate('Name').'</label>';
$html .= '<span class="term-value-wrapper">';
$html .= '<input type="text" name="MonitorName" value="'.(isset($_SESSION['MonitorName'])?validHtmlStr($_SESSION['MonitorName']):'').'" placeholder="text or regular expression"/></span>';
$html .= '</span>'.PHP_EOL;
$html .= addFilterSelect('Capturing', array('None'=>translate('None'), 'Always'=>translate('Always'), 'OnDemand'=>translate('On Demand')));
$html .= addFilterSelect('Analysing', array('None'=>translate('None'), 'Always'=>translate('Always')));
$html .= addFilterSelect('Recording', array('None'=>translate('None'), 'OnMotion'=>translate('On Motion'),'Always'=>translate('Always')));

function addFilterSelect($name, $options) {
$html = '<span class="term '.$name.'Filter"><label>'.translate($name).'</label>';
$html .= '<span class="term-value-wrapper">';
$html .= htmlSelect($name.'[]', $options,
(isset($_SESSION[$name])?$_SESSION[$name]:''),
if ( count($ServersById) > 1 ) {
$html .= '<span class="term ServerFilter"><label>'. translate('Server').'</label>';
$html .= '<span class="term-value-wrapper">';
$html .= htmlSelect('ServerId[]', $ServersById,
(isset($_SESSION['ServerId'])?$_SESSION['ServerId']:''),
array(
'data-on-change'=>'submitThisForm',
'class'=>'chosen',
'multiple'=>'multiple',
'data-placeholder'=>'All',
)
);
$html .= '</span>';
$html .= '</span>'.PHP_EOL;
return $html;
}

$html .= addFilterSelect('Capturing', array('None'=>translate('None'), 'Always'=>translate('Always'), 'OnDemand'=>translate('On Demand')));
$html .= addFilterSelect('Analysing', array('None'=>translate('None'), 'Always'=>translate('Always')));
$html .= addFilterSelect('Recording', array('None'=>translate('None'), 'OnMotion'=>translate('On Motion'),'Always'=>translate('Always')));
$html .= '</span>';
$html .= '</span>';
} # end if have Servers

if ( count($ServersById) > 1 ) {
$html .= '<span class="term ServerFilter"><label>'. translate('Server').'</label>';
$html .= '<span class="term-value-wrapper">';
$html .= htmlSelect('ServerId[]', $ServersById,
(isset($_SESSION['ServerId'])?$_SESSION['ServerId']:''),
array(
'data-on-change'=>'submitThisForm',
'class'=>'chosen',
'multiple'=>'multiple',
'data-placeholder'=>'All',
)
);
$html .= '</span>';
$html .= '</span>';
} # end if have Servers
if ( count($StorageById) > 1 ) {
$html .= '<span class="term StorageFilter"><label>'.translate('Storage').'</label>';
$html .= '<span class="term-value-wrapper">';
$html .= htmlSelect('StorageId[]', $StorageById,
(isset($_SESSION['StorageId'])?$_SESSION['StorageId']:''),
array(
'data-on-change'=>'submitThisForm',
'class'=>'chosen',
'multiple'=>'multiple',
'data-placeholder'=>'All',
) );
$html .= '</span>';
$html .= '</span>';
} # end if have Storage Areas

if ( count($StorageById) > 1 ) {
$html .= '<span class="term StorageFilter"><label>'.translate('Storage').'</label>';
$html .= '<span class="term StatusFilter"><label>'.translate('Status').'</label>';
$status_options = array(
'Unknown' => translate('StatusUnknown'),
'NotRunning' => translate('StatusNotRunning'),
'Running' => translate('StatusRunning'),
'Connected' => translate('StatusConnected'),
);
$html .= '<span class="term-value-wrapper">';
$html .= htmlSelect('StorageId[]', $StorageById,
(isset($_SESSION['StorageId'])?$_SESSION['StorageId']:''),
$html .= htmlSelect( 'Status[]', $status_options,
( isset($_SESSION['Status']) ? $_SESSION['Status'] : '' ),
array(
'data-on-change'=>'submitThisForm',
'class'=>'chosen',
'multiple'=>'multiple',
'data-placeholder'=>'All',
'data-placeholder'=>'All'
) );
$html .= '</span>';
$html .= '</span>';
} # end if have Storage Areas

$html .= '<span class="term StatusFilter"><label>'.translate('Status').'</label>';
$status_options = array(
'Unknown' => translate('StatusUnknown'),
'NotRunning' => translate('StatusNotRunning'),
'Running' => translate('StatusRunning'),
'Connected' => translate('StatusConnected'),
);
$html .= '<span class="term-value-wrapper">';
$html .= htmlSelect( 'Status[]', $status_options,
( isset($_SESSION['Status']) ? $_SESSION['Status'] : '' ),
array(
'data-on-change'=>'submitThisForm',
'class'=>'chosen',
'multiple'=>'multiple',
'data-placeholder'=>'All'
) );
$html .= '</span>';
$html .= '</span>';

$html .= '<span class="term SourceFilter"><label>'.translate('Source').'</label>';
$html .= '<span class="term-value-wrapper">';
Expand All @@ -183,10 +185,10 @@ function addFilterSelect($name, $options) {
$html .= '</span>';

$sqlAll = 'SELECT M.*, S.*, E.*
FROM Monitors AS M
LEFT JOIN Monitor_Status AS S ON S.MonitorId=M.Id
LEFT JOIN Event_Summaries AS E ON E.MonitorId=M.Id
WHERE M.`Deleted`=false';
FROM Monitors AS M
LEFT JOIN Monitor_Status AS S ON S.MonitorId=M.Id
LEFT JOIN Event_Summaries AS E ON E.MonitorId=M.Id
WHERE M.`Deleted`=false';
$sqlSelected = $sqlAll . ( count($conditions) ? ' AND ' . implode(' AND ', $conditions) : '' ).' ORDER BY Sequence ASC';
$monitors = dbFetchAll($sqlSelected, null, $values);

Expand All @@ -195,7 +197,7 @@ function addFilterSelect($name, $options) {
if ( visibleMonitor($row['Id']) ) { #We count only available monitors.
++$colAllAvailableMonitors;
}
}
}

$displayMonitors = array();
$monitors_dropdown = array();
Expand Down Expand Up @@ -283,6 +285,14 @@ function addFilterSelect($name, $options) {
$display_monitor_ids = array_map(function($monitor_row){return $monitor_row['Id'];}, $displayMonitors);
$html .= '</span>';
$html .= '</span>';
echo $html;
$html .= '</div>';

return [
"filterBar" => $html,
"displayMonitors" => $displayMonitors,
"storage_areas" => $storage_areas,
"StorageById" => $StorageById,
"selected_monitor_ids" => $selected_monitor_ids
];
}
?>
</div>
8 changes: 5 additions & 3 deletions web/skins/classic/views/console.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@
require_once('includes/Group_Monitor.php');

$navbar = getNavBarHTML();
ob_start();
include('_monitor_filters.php');
$filterbar = ob_get_contents();
ob_end_clean();
$resultMonitorFilters = buildMonitorsFilters();
$filterbar = $resultMonitorFilters['filterBar'];
$displayMonitors = $resultMonitorFilters['displayMonitors'];
$storage_areas = $resultMonitorFilters['storage_areas'];
$StorageById = $resultMonitorFilters['StorageById'];

$displayMonitorIds = array_map(function($m){return $m['Id'];}, $displayMonitors);

Expand Down
6 changes: 3 additions & 3 deletions web/skins/classic/views/cycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
return;
}

ob_start();
include('_monitor_filters.php');
$filterbar = ob_get_contents();
ob_end_clean();
$resultMonitorFilters = buildMonitorsFilters();
$filterbar = $resultMonitorFilters['filterBar'];
$displayMonitors = $resultMonitorFilters['displayMonitors'];

$options = array();

Expand Down
6 changes: 3 additions & 3 deletions web/skins/classic/views/montage.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@

session_write_close();

ob_start();
include('_monitor_filters.php');
$filterbar = ob_get_contents();
ob_end_clean();
$resultMonitorFilters = buildMonitorsFilters();
$filterbar = $resultMonitorFilters['filterBar'];
$displayMonitors = $resultMonitorFilters['displayMonitors'];

$need_hls = false;
$need_janus = false;
Expand Down
7 changes: 4 additions & 3 deletions web/skins/classic/views/montagereview.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@
}

require_once('includes/Filter.php');
ob_start();
include('_monitor_filters.php');
$filter_bar = ob_get_contents();
ob_end_clean();
$resultMonitorFilters = buildMonitorsFilters();
$filterbar = $resultMonitorFilters['filterBar'];
$displayMonitors = $resultMonitorFilters['displayMonitors'];
$selected_monitor_ids = $resultMonitorFilters['selected_monitor_ids'];

$preference = ZM\User_Preference::find_one([
'UserId'=>$user->Id(),
Expand Down
Loading

0 comments on commit 8c6396a

Please sign in to comment.