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

328 lines
14 KiB
PHP
Raw Normal View History

<?php
//
// ZoneMinder web events view 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.
//
2018-04-03 21:57:22 +08:00
if ( !canView('Events') || (!empty($_REQUEST['execute']) && !canEdit('Events')) ) {
2017-06-01 09:34:38 +08:00
$view = 'error';
return;
}
2018-04-03 21:57:22 +08:00
require_once('includes/Event.php');
$countSql = 'SELECT count(E.Id) AS EventCount FROM Monitors AS M INNER JOIN Events AS E ON (M.Id = E.MonitorId) WHERE';
$eventsSql = 'SELECT E.*,M.Name AS MonitorName,M.DefaultScale FROM Monitors AS M INNER JOIN Events AS E on (M.Id = E.MonitorId) WHERE';
if ( $user['MonitorIds'] ) {
2019-08-28 21:19:09 +08:00
$user_monitor_ids = ' M.Id in ('.$user['MonitorIds'].')';
$countSql .= $user_monitor_ids;
$eventsSql .= $user_monitor_ids;
} else {
2017-06-01 09:34:38 +08:00
$countSql .= ' 1';
$eventsSql .= ' 1';
}
parseSort();
2018-04-03 21:57:22 +08:00
parseFilter($_REQUEST['filter']);
$filterQuery = $_REQUEST['filter']['query'];
if ( $_REQUEST['filter']['sql'] ) {
2017-06-01 09:34:38 +08:00
$countSql .= $_REQUEST['filter']['sql'];
$eventsSql .= $_REQUEST['filter']['sql'];
}
$eventsSql .= " ORDER BY $sortColumn $sortOrder,Id $sortOrder";
$page = isset($_REQUEST['page']) ? validInt($_REQUEST['page']) : 0;
$limit = isset($_REQUEST['limit']) ? validInt($_REQUEST['limit']) : 0;
2018-04-03 21:57:22 +08:00
$nEvents = dbFetchOne($countSql, 'EventCount');
if ( !empty($limit) && $nEvents > $limit ) {
2017-06-01 09:34:38 +08:00
$nEvents = $limit;
}
$pages = (int)ceil($nEvents/ZM_WEB_EVENTS_PER_PAGE);
#Logger::Debug("Page $page Limit $limit #vents: $nEvents pages: $pages ");
if ( !empty($page) ) {
if ( $page < 0 )
$page = 1;
else if ( $pages and ( $page > $pages ) )
$page = $pages;
$limitStart = (($page-1)*ZM_WEB_EVENTS_PER_PAGE);
if ( empty( $limit ) ) {
$limitAmount = ZM_WEB_EVENTS_PER_PAGE;
} else {
$limitLeft = $limit - $limitStart;
$limitAmount = ($limitLeft>ZM_WEB_EVENTS_PER_PAGE)?ZM_WEB_EVENTS_PER_PAGE:$limitLeft;
}
2020-08-06 23:57:35 +08:00
$eventsSql .= " LIMIT $limitStart, $limitAmount";
2018-04-03 21:57:22 +08:00
} elseif ( !empty($limit) ) {
2020-08-06 23:57:35 +08:00
$eventsSql .= ' LIMIT 0, '.$limit;
}
$maxShortcuts = 5;
2018-04-03 21:57:22 +08:00
$pagination = getPagination($pages, $page, $maxShortcuts, $filterQuery.$sortQuery.$limitQuery);
$focusWindow = true;
2018-04-03 21:57:22 +08:00
if ( $_POST ) {
// I think this is basically so that a refresh doesn't repost
ZM\Logger::Debug('Redirecting to ' . $_SERVER['REQUEST_URI']);
header('Location: ?view=' . $view.htmlspecialchars_decode($filterQuery).htmlspecialchars_decode($sortQuery).$limitQuery.'&page='.$page);
2018-04-03 21:57:22 +08:00
exit();
}
$storage_areas = ZM\Storage::find();
2018-04-03 21:57:22 +08:00
$StorageById = array();
foreach ( $storage_areas as $S ) {
$StorageById[$S->Id()] = $S;
}
2015-05-10 21:10:30 +08:00
xhtmlHeaders(__FILE__, translate('Events') );
?>
<body>
<div id="page">
<?php echo getNavBarHTML() ?>
<!-- Toolbar button placement and styling handled by bootstrap-tables -->
2020-08-16 04:27:58 +08:00
<div id="toolbar">
2020-08-19 05:57:03 +08:00
<button id="backBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Back') ?>" disabled><i class="fa fa-arrow-left"></i></button>
<button id="refreshBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Refresh') ?>" ><i class="fa fa-refresh"></i></button>
<button id="tlineBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('ShowTimeline') ?>" ><i class="fa fa-history"></i></button>
<button id="viewBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('View') ?>" disabled><i class="fa fa-binoculars"></i></button>
<button id="archiveBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Archive') ?>" disabled><i class="fa fa-archive"></i></button>
<button id="unarchiveBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Unarchive') ?>" disabled><i class="fa fa-file-archive-o"></i></button>
<button id="editBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Edit') ?>" disabled><i class="fa fa-pencil"></i></button>
<button id="exportBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Export') ?>" disabled><i class="fa fa-external-link"></i></button>
<button id="downloadBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('DownloadVideo') ?>" disabled><i class="fa fa-download"></i></button>
<button id="deleteBtn" class="btn btn-danger" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Delete') ?>" disabled><i class="fa fa-trash"></i></button>
</div>
2020-08-16 04:27:58 +08:00
<!-- Table styling handled by bootstrap-tables -->
2020-08-16 04:27:58 +08:00
<div class="table-responsive-sm p-3">
<table
id="eventTable"
data-toggle="table"
data-pagination="true"
2020-08-18 00:02:25 +08:00
data-show-pagination-switch="true"
2020-08-19 04:12:07 +08:00
data-page-list="[10, 25, 50, 100, 200, All]"
2020-08-16 04:27:58 +08:00
data-search="true"
data-cookie="true"
data-cookie-id-table="zmEventsTable"
data-cookie-expire="2y"
2020-08-16 04:27:58 +08:00
data-click-to-select="true"
data-remember-order="true"
data-show-columns="true"
2020-08-21 20:11:57 +08:00
data-show-export="true"
2020-08-16 04:27:58 +08:00
data-uncheckAll="true"
data-toolbar="#toolbar"
data-show-fullscreen="true"
data-click-to-select="true"
data-maintain-meta-data="true"
data-mobile-responsive="true"
data-buttons-class="btn btn-normal"
2020-08-16 04:27:58 +08:00
class="table-sm table-borderless">
<thead>
<?php
$count = 0;
2017-10-19 00:43:51 +08:00
$disk_space_total = 0;
2018-04-03 21:57:22 +08:00
$results = dbQuery($eventsSql);
while ( $event_row = dbFetchNext($results) ) {
$event = new ZM\Event($event_row);
2017-06-01 09:34:38 +08:00
if ( ($count++%ZM_WEB_EVENTS_PER_PAGE) == 0 ) {
?>
<!-- Row styling is handled by bootstrap-tables -->
<tr>
2020-08-17 07:00:11 +08:00
<th data-sortable="false" data-field="toggleCheck" data-checkbox="true"></th>
2020-08-16 04:27:58 +08:00
<th data-sortable="true" data-field="Id"><?php echo translate('Id') ?></th>
<th data-sortable="true" data-field="Name"><?php echo translate('Name') ?></th>
<th data-sortable="true" data-field="Archived"><?php echo translate('Archived') ?></th>
<th data-sortable="true" data-field="Emailed"><?php echo translate('Emailed') ?></th>
2020-08-16 04:27:58 +08:00
<th data-sortable="true" data-field="Monitor"><?php echo translate('Monitor') ?></th>
<th data-sortable="true" data-field="Cause"><?php echo translate('Cause') ?></th>
<th data-sortable="true" data-field="AttrStartTime"><?php echo translate('AttrStartTime') ?></th>
<th data-sortable="true" data-field="AttrEndTime"><?php echo translate('AttrEndTime') ?></th>
<th data-sortable="true" data-field="Duration"><?php echo translate('Duration') ?></th>
<th data-sortable="true" data-field="Frames"><?php echo translate('Frames') ?></th>
<th data-sortable="true" data-field="AlarmBrFrames"><?php echo translate('AlarmBrFrames') ?></th>
<th data-sortable="true" data-field="TotalBrScore"><?php echo translate('TotalBrScore') ?></th>
<th data-sortable="true" data-field="AvgBrScore"><?php echo translate('AvgBrScore') ?></th>
<th data-sortable="true" data-field="MaxBrScore"><?php echo translate('MaxBrScore') ?></th>
2017-05-31 01:47:30 +08:00
<?php
2018-04-03 21:57:22 +08:00
if ( count($storage_areas) > 1 ) {
?>
2020-08-16 04:27:58 +08:00
<th data-sortable="true" data-field="Storage"><?php echo translate('Storage') ?></th>
2018-04-03 21:57:22 +08:00
<?php
}
2017-10-19 00:43:51 +08:00
if ( ZM_WEB_EVENT_DISK_SPACE ) {
?>
2020-08-16 04:27:58 +08:00
<th data-sortable="true" data-field="DiskSpace"><?php echo translate('DiskSpace') ?></th>
<?php
2017-05-31 01:47:30 +08:00
}
if ( ZM_WEB_LIST_THUMBS ) {
?>
2020-08-16 04:27:58 +08:00
<th data-sortable="false" data-field="Thumbnail"><?php echo translate('Thumbnail') ?></th>
<?php
2017-05-31 01:47:30 +08:00
}
?>
</tr>
2020-08-16 04:27:58 +08:00
</thead>
<tbody>
<?php
2017-05-31 01:47:30 +08:00
}
$scale = max( reScale( SCALE_BASE, $event->DefaultScale(), ZM_WEB_DEFAULT_SCALE ), SCALE_BASE );
?>
2020-08-16 04:27:58 +08:00
<tr<?php echo ( $event->Archived() ) ? ' class="archived"' : '' ?>>
<td data-checkbox="true"></td>
<td><a href="?view=event&amp;eid=<?php echo $event->Id().$filterQuery.$sortQuery.'&amp;page=1">'.$event->Id() ?></a></td>
<td><a href="?view=event&amp;eid=<?php echo $event->Id().$filterQuery.$sortQuery.'&amp;page=1">'.validHtmlStr($event->Name())?></a>
<?php
$archived = ( $event->Archived() ) ? translate('Archived') : '';
$emailed = ( $event->Emailed() ) ? ' '.translate('Emailed') : '';
echo '<br/><div class="small text-nowrap text-muted">'.$archived.$emailed.'</div>';
?>
</td>
<td class="text-center"><?php echo ( $event->Archived() ) ? 'Yes' : 'No' ?></td>
<td class="text-center"><?php echo ( $event->Emailed() ) ? 'Yes' : 'No' ?></td>
2020-08-16 04:27:58 +08:00
<td><?php echo makePopupLink( '?view=monitor&amp;mid='.$event->MonitorId(), 'zmMonitor'.$event->MonitorId(), 'monitor', $event->MonitorName(), canEdit( 'Monitors' ) ) ?></td>
<td><?php echo makePopupLink( '?view=eventdetail&amp;eid='.$event->Id(), 'zmEventDetail', 'eventdetail', validHtmlStr($event->Cause()), canEdit( 'Events' ), 'title="'.htmlspecialchars($event->Notes()).'"' ) ?>
<?php
# display notes as small text
if ( $event->Notes() ) {
# if notes include detection objects, then link it to objdetect.jpg
if ( strpos($event->Notes(), 'detected:') !== false ) {
# make a link
echo makePopupLink( '?view=image&amp;eid='.$event->Id().'&amp;fid=objdetect', 'zmImage',
array('image', reScale($event->Width(), $scale), reScale($event->Height(), $scale)),
'<div class="small text-nowrap text-muted"><u>'.$event->Notes().'</u></div>');
} else if ( $event->Notes() != 'Forced Web: ' ) {
echo '<br/><div class="small text-nowrap text-muted">'.$event->Notes().'</div>';
}
}
?>
</td>
2020-08-16 04:27:58 +08:00
<td><?php echo strftime(STRF_FMT_DATETIME_SHORTER, strtotime($event->StartTime())) ?></td>
<td><?php echo strftime(STRF_FMT_DATETIME_SHORTER, strtotime($event->EndTime()) ) ?></td>
<td><?php echo gmdate("H:i:s", $event->Length() ) ?></td>
2020-08-20 01:04:08 +08:00
<td><a href="?view=frames&amp;eid=<?php echo $event->Id() ?>"><?php echo $event->Frames() ?></a></td>
<td><a href="?view=frames&amp;eid=<?php echo $event->Id() ?>"><?php echo $event->AlarmFrames() ?></a></td>
2020-08-16 04:27:58 +08:00
<td><?php echo $event->TotScore() ?></td>
<td><?php echo $event->AvgScore() ?></td>
<td><?php echo makePopupLink(
'?view=frame&amp;eid='.$event->Id().'&amp;fid=0', 'zmImage',
array('image', reScale($event->Width(), $scale), reScale($event->Height(), $scale)), $event->MaxScore()
); ?></td>
<?php
2018-04-03 21:57:22 +08:00
if ( count($storage_areas) > 1 ) {
?>
2020-08-16 04:27:58 +08:00
<td>
<?php
if ( $event->StorageId() ) {
echo isset($StorageById[$event->StorageId()]) ? $StorageById[$event->StorageId()]->Name() : 'Unknown Storage Id: '.$event->StorageId();
} else {
echo 'Default';
}
if ( $event->SecondaryStorageId() ) {
echo '<br/>'.(isset($StorageById[$event->SecondaryStorageId()]) ? $StorageById[$event->SecondaryStorageId()]->Name() : 'Unknown Storage Id '.$event->SecondaryStorageId());
}
?>
</td>
2018-04-03 21:57:22 +08:00
<?php
}
2017-05-31 01:47:30 +08:00
if ( ZM_WEB_EVENT_DISK_SPACE ) {
2017-10-19 00:43:51 +08:00
$disk_space_total += $event->DiskSpace();
2017-05-31 01:47:30 +08:00
?>
2020-08-16 04:27:58 +08:00
<td class="colDiskSpace"><?php echo human_filesize($event->DiskSpace()) ?></td>
<?php
2017-05-31 01:47:30 +08:00
}
if ( ZM_WEB_LIST_THUMBS ) {
2020-08-16 04:27:58 +08:00
echo '<td class="colThumbnail zoom">';
2019-12-03 04:34:23 +08:00
$imgSrc = $event->getThumbnailSrc(array(),'&amp;');
$streamSrc = $event->getStreamSrc(array(
'mode'=>'jpeg', 'scale'=>$scale, 'maxfps'=>ZM_WEB_VIDEO_MAXFPS, 'replay'=>'single', 'rate'=>'400'), '&amp;');
2019-09-04 22:11:16 +08:00
$imgHtml = '<img id="thumbnail'.$event->Id().'" src="'.$imgSrc.'" alt="'. validHtmlStr('Event '.$event->Id()) .'" style="width:'. validInt($event->ThumbnailWidth()) .'px;height:'. validInt($event->ThumbnailHeight()).'px;" stream_src="'.$streamSrc.'" still_src="'.$imgSrc.'"/>';
2018-01-22 10:27:01 +08:00
echo '<a href="?view=event&amp;eid='. $event->Id().$filterQuery.$sortQuery.'&amp;page=1">'.$imgHtml.'</a>';
2018-04-15 22:27:08 +08:00
echo '</td>';
2017-05-31 01:47:30 +08:00
} // end if ZM_WEB_LIST_THUMBS
?>
</tr>
<?php
}
?>
</tbody>
2017-10-19 00:43:51 +08:00
<?php
if ( ZM_WEB_EVENT_DISK_SPACE ) {
?>
<tfoot>
<tr>
2017-10-19 00:43:51 +08:00
<td colspan="11">Totals:</td>
2018-04-03 21:57:22 +08:00
<?php
if ( count($storage_areas)>1 ) {
?>
<td class="colStorage"></td>
2018-04-03 21:57:22 +08:00
<?php
}
?>
2018-04-15 22:27:08 +08:00
<td class="colDiskSpace"><?php echo human_filesize($disk_space_total) ?></td>
2017-10-19 00:43:51 +08:00
<?php
if ( ZM_WEB_LIST_THUMBS ) {
?>
<td></td>
2017-10-19 00:43:51 +08:00
<?php
}
?>
<td></td>
2017-10-19 00:43:51 +08:00
</tr>
</tfoot>
<?php
}
?>
</table>
2020-08-16 04:27:58 +08:00
</div>
</div>
2020-08-18 21:06:58 +08:00
<!-- Delete Confirmation Modal -->
<div id="deleteConfirm" class="modal fade" class="modal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Delete Confirmation</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p><?php echo translate('ConfirmDeleteEvents') ?></p>
2020-08-18 21:06:58 +08:00
</div>
<div class="modal-footer">
<button id="delCancelBtn" type="button" class="btn btn-secondary" data-dismiss="modal"><?php echo translate('Cancel') ?></button>
<button id ="delConfirmBtn" type="button" class="btn btn-danger"><?php echo translate('Delete') ?></button>
</div>
</div>
</div>
</div>
</body>
</html>