zoneminder/web/skins/classic/views/report_event_audit.php

213 lines
9.5 KiB
PHP
Raw Normal View History

2018-04-11 04:06:01 +08:00
<?php
//
// ZoneMinder web console file, $Date$, $Revision$
// Copyright (C) 2001-2008 Philip Coombes
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
$navbar = getNavBarHTML();
ob_start();
include('_monitor_filters.php');
$filterbar = ob_get_contents();
ob_end_clean();
noCacheHeaders();
2020-04-10 23:10:13 +08:00
xhtmlHeaders( __FILE__, translate('Console'));
2018-04-11 04:06:01 +08:00
if ( isset($_REQUEST['minTime']) ) {
$minTime = validHtmlStr($_REQUEST['minTime']);
} else {
2020-04-10 23:10:13 +08:00
$minTime = strftime('%FT%T', time() - (2*3600));
}
if ( isset($_REQUEST['maxTime']) ) {
$maxTime = validHtmlStr($_REQUEST['maxTime']);
} else {
$maxTime = strftime('%FT%T',time() - 3600);
}
2018-04-11 04:06:01 +08:00
2020-12-05 04:17:04 +08:00
$filter = new ZM\Filter();
$filter->addTerm(array('attr'=>'StartDateTime', 'op'=>'>=', 'val'=>$minTime, 'obr'=>'1'));
$filter->addTerm(array('attr'=>'StartDateTime', 'op'=>'<=', 'val'=>$maxTime, 'cnj'=>'and', 'cbr'=>'1'));
if ( count($selected_monitor_ids) ) {
2020-12-05 04:17:04 +08:00
$filter->addTerm(array('attr'=>'MonitorId', 'op'=>'IN', 'val'=>implode(',', $selected_monitor_ids), 'cnj'=>'and'));
} else if ( ( $group_id != 0 || isset($_SESSION['ServerId']) || isset($_SESSION['StorageId']) || isset($_SESSION['Status']) ) ) {
2018-04-11 04:06:01 +08:00
# this should be redundant
2020-04-10 23:10:13 +08:00
for ( $i=0; $i < count($displayMonitors); $i++ ) {
if ( $i == 0 ) {
2020-12-05 04:17:04 +08:00
$filter->addTerm(array('attr'=>'MonitorId', 'op'=>'=', 'val'=>$displayMonitors[$i]['Id'], 'cnj'=>'and', 'obr'=>'1'));
2020-04-10 23:10:13 +08:00
} else if ( $i == count($displayMonitors)-1 ) {
2020-12-05 04:17:04 +08:00
$filter->addTerm(array('attr'=>'MonitorId', 'op'=>'=', 'val'=>$displayMonitors[$i]['Id'], 'cnj'=>'or', 'cbr'=>'1'));
} else {
2020-12-05 04:17:04 +08:00
$filter->addTerm(array('attr'=>'MonitorId', 'op'=>'=', 'val'=>$displayMonitors[$i]['Id'], 'cnj'=>'or'));
2018-04-11 04:06:01 +08:00
}
}
}
2020-12-05 04:17:04 +08:00
$filterQuery = $filter->querystring();
ZM\Debug($filterQuery);
2018-04-11 04:06:01 +08:00
$eventsSql = 'SELECT *,
UNIX_TIMESTAMP(E.StartDateTime) AS StartTimeSecs,
UNIX_TIMESTAMP(EndDateTime) AS EndTimeSecs
2018-04-11 04:06:01 +08:00
FROM Events AS E
WHERE 1 > 0
';
2020-04-10 23:10:13 +08:00
if ( !empty($user['MonitorIds']) ) {
2018-04-11 04:06:01 +08:00
$eventsSql .= ' AND MonitorId IN ('.$user['MonitorIds'].')';
}
if ( count($selected_monitor_ids) ) {
2020-04-10 23:10:13 +08:00
$eventsSql .= ' AND MonitorId IN ('.implode(',', $selected_monitor_ids).')';
2018-04-11 04:06:01 +08:00
}
if ( isset($minTime) && isset($maxTime) ) {
$eventsSql .= " AND EndDateTime > '" . $minTime . "' AND StartDateTime < '" . $maxTime . "'";
2018-04-11 04:06:01 +08:00
}
$eventsSql .= ' ORDER BY Id ASC';
$result = dbQuery($eventsSql);
if ( !$result ) {
ZM\Fatal('SQL-ERR');
2018-04-11 04:06:01 +08:00
return;
}
$EventsByMonitor = array();
2020-04-10 23:10:13 +08:00
while ( $event = $result->fetch(PDO::FETCH_ASSOC) ) {
$Event = new ZM\Event($event);
2018-04-11 04:06:01 +08:00
if ( ! isset($EventsByMonitor[$event['MonitorId']]) )
2020-04-10 23:10:13 +08:00
$EventsByMonitor[$event['MonitorId']] = array('Events'=>array(), 'MinGap'=>0, 'MaxGap'=>0, 'FileMissing'=>array(), 'ZeroSize'=>array());
2018-04-11 04:06:01 +08:00
if ( count($EventsByMonitor[$event['MonitorId']]['Events']) ) {
$last_event = end($EventsByMonitor[$event['MonitorId']]['Events']);
#Debug(print_r($last_event,true));
2018-04-11 04:06:01 +08:00
$gap = $last_event->EndTimeSecs() - $event['StartTimeSecs'];
if ( $gap < $EventsByMonitor[$event['MonitorId']]['MinGap'] )
$EventsByMonitor[$event['MonitorId']]['MinGap'] = $gap;
if ( $gap > $EventsByMonitor[$event['MonitorId']]['MaxGap'] )
$EventsByMonitor[$event['MonitorId']]['MaxGap'] = $gap;
} # end if has previous events
2020-04-10 23:10:13 +08:00
if ( !$Event->file_exists() ) {
$EventsByMonitor[$event['MonitorId']]['FileMissing'][] = $Event;
} else if ( ! $Event->file_size() ) {
$EventsByMonitor[$event['MonitorId']]['ZeroSize'][] = $Event;
2018-04-11 04:06:01 +08:00
}
$EventsByMonitor[$event['MonitorId']]['Events'][] = $Event;
} # end foreach event
?>
<body>
<form name="monitorForm" method="get" action="?">
2018-04-11 04:06:01 +08:00
<input type="hidden" name="view" value="<?php echo $view ?>"/>
<input type="hidden" name="action" value=""/>
<?php echo $navbar ?>
<div class="filterBar">
<?php echo $filterbar ?>
<div id="DateTimeDiv">
<label>Event Start Time</label>
2020-04-10 23:10:13 +08:00
<input type="text" name="minTime" id="minTime" value="<?php echo preg_replace('/T/', ' ', $minTime) ?>" oninput="this.form.submit();"/> to
<input type="text" name="maxTime" id="maxTime" value="<?php echo preg_replace('/T/', ' ', $maxTime) ?>" oninput="this.form.submit();"/>
2018-04-11 04:06:01 +08:00
</div>
</div><!--FilterBar-->
<div class="container-fluid">
<table class="table table-striped table-hover table-condensed" id="consoleTable">
<thead class="thead-highlight">
<tr>
<th class="colId"><?php echo translate('Id') ?></th>
<th class="colName"><i class="material-icons md-18">videocam</i>&nbsp;<?php echo translate('Name') ?></th>
<th class="colServer"><?php echo translate('Server') ?></th>
2018-04-11 04:06:01 +08:00
<th class="colEvents"><?php echo translate('Events') ?></th>
<th class="colFirstEvent"><?php echo translate('FirstEvent') ?></th>
<th class="colLastEvent"><?php echo translate('LastEvent') ?></th>
2018-04-11 04:06:01 +08:00
<th class="colMinGap"><?php echo translate('MinGap') ?></th>
<th class="colMaxGap"><?php echo translate('MaxGap') ?></th>
<th class="colMissingFiles"><?php echo translate('MissingFiles') ?></th>
<th class="colZeroSize"><?php echo translate('ZeroSize') ?></th>
2018-04-11 04:06:01 +08:00
</tr>
</thead>
<tbody>
<?php
2020-04-10 23:10:13 +08:00
for ( $monitor_i = 0; $monitor_i < count($displayMonitors); $monitor_i += 1 ) {
2018-04-11 04:06:01 +08:00
$monitor = $displayMonitors[$monitor_i];
$Monitor = new ZM\Monitor($monitor);
2020-04-10 23:10:13 +08:00
$montagereview_link = '?view=montagereview&live=0&MonitorId='.$monitor['Id'].'&minTime='.$minTime.'&maxTime='.$maxTime;
2020-12-05 04:17:04 +08:00
$monitor_filter = $filter->addTerm(array('cnj'=>'and', 'attr'=>'MonitorId', 'op'=>'=', 'val'=>$monitor['Id']));
if ( isset($EventsByMonitor[$Monitor->Id()]) ) {
$EventCounts = $EventsByMonitor[$Monitor->Id()];
$MinGap = $EventCounts['MinGap'];
$MaxGap = $EventCounts['MaxGap'];
$FileMissing = $EventCounts['FileMissing'];
$ZeroSize = $EventCounts['ZeroSize'];
$FirstEvent = $EventCounts['Events'][0];
$LastEvent = end($EventCounts['Events']);
} else {
$MinGap = 0;
$MaxGap = 0;
$FileMissing = array();
$ZeroSize = array();
$FirstEvent = 0;
$LastEvent = 0;
}
if ( count($FileMissing) ) {
2020-12-05 04:17:04 +08:00
$FileMissing_filter = new ZM\Filter();
$FileMissing_filter->addTerm(array('attr'=>'Id', 'op'=>'IN', 'val'=>implode(',', array_map(function($Event){return $Event->Id();}, $FileMissing))));
}
if ( count($ZeroSize) ) {
2020-12-05 04:17:04 +08:00
$ZeroSize_filter = new ZM\Filter();
$ZeroSize_filter->addTerm(array('attr'=>'Id', 'op'=>'IN', 'val'=>implode(',', array_map(function($Event){return $Event->Id();}, $ZeroSize))));
}
2018-04-11 04:06:01 +08:00
?>
<tr id="<?php echo 'monitor_id-'.$monitor['Id'] ?>" title="<?php echo $monitor['Id'] ?>">
<td class="colId"><a href="<?php echo $montagereview_link ?>"><?php echo $monitor['Id'] ?></a></td>
2018-04-11 04:06:01 +08:00
<td class="colName">
2020-04-10 23:10:13 +08:00
<a href="<?php echo $montagereview_link ?>"><?php echo validHtmlStr($monitor['Name']) ?></a><br/>
<div class="small text-nowrap text-muted">
2018-04-11 04:06:01 +08:00
<?php echo implode('<br/>',
array_map(function($group_id){
2020-12-05 04:17:04 +08:00
$Group = ZM\Group::find_one(array('Id'=>$group_id));
if ( $Group ) {
$Groups = $Group->Parents();
array_push( $Groups, $Group );
}
return implode(' &gt; ', array_map(function($Group){ return '<a href="?view=montagereview&amp;GroupId='.$Group->Id().'">'.validHtmlStr($Group->Name()).'</a>'; }, $Groups ));
2020-04-10 23:10:13 +08:00
}, $Monitor->GroupIds()));
2020-12-05 04:17:04 +08:00
2018-04-11 04:06:01 +08:00
?>
</div></td>
2020-04-10 23:10:13 +08:00
<td class="colServer"><?php echo validHtmlStr($Monitor->Server()->Name())?></td>
2020-12-05 04:17:04 +08:00
<td class="colEvents"><a href="?view=<?php echo ZM_WEB_EVENTS_VIEW ?>&amp;page=1<?php echo $monitor_filter->querystring() ?>"><?php echo isset($EventsByMonitor[$Monitor->Id()])?count($EventsByMonitor[$Monitor->Id()]['Events']):0 ?></a></td>
<td class="colFirstEvent"><?php echo $FirstEvent ? $FirstEvent->link_to($FirstEvent->Id().' at '.$FirstEvent->StartDateTime()) : 'none'?></td>
<td class="colLastEvent"><?php echo $LastEvent ? $LastEvent->link_to($LastEvent->Id().' at '.$LastEvent->StartDateTime()) : 'none'?></td>
<td class="colMinGap"><?php echo $MinGap ?></td>
<td class="colMaxGap"><?php echo $MaxGap ?></td>
<td class="colFileMissing<?php echo count($FileMissing) ? ' errorText' : ''?>">
2020-12-05 04:17:04 +08:00
<?php echo count($FileMissing) ? '<a href="?view='.ZM_WEB_EVENTS_VIEW.'&amp;page=1'.$FileMissing_filter->querystring().'">'.count($FileMissing).'</a>' : '0' ?>
</td>
<td class="colZeroSize<?php echo count($ZeroSize) ? ' errorText' : ''?>">
2020-12-05 04:17:04 +08:00
<?php echo count($ZeroSize) ? '<a href="?view='.ZM_WEB_EVENTS_VIEW.'&amp;page=1'.$ZeroSize_filter->querystring().'">'.count($ZeroSize).'</a>' : '0' ?>
</td>
2018-04-11 04:06:01 +08:00
</tr>
<?php
} # end for each monitor
?>
</tbody>
</table>
</div>
</form>
<?php xhtmlFooter() ?>