2008-07-14 21:54:50 +08:00
< ? php
//
// ZoneMinder web events view file, $Date$, $Revision$
2008-07-25 17:48:16 +08:00
// Copyright (C) 2001-2008 Philip Coombes
2008-07-14 21:54:50 +08:00
//
// 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
2016-12-26 23:23:16 +08:00
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2008-07-14 21:54:50 +08:00
//
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 ;
2008-07-14 21:54:50 +08:00
}
2018-04-03 21:57:22 +08:00
require_once ( 'includes/Event.php' );
2017-01-02 23:35:51 +08:00
2014-03-22 05:16:56 +08:00
$countSql = 'SELECT count(E.Id) AS EventCount FROM Monitors AS M INNER JOIN Events AS E ON (M.Id = E.MonitorId) WHERE' ;
2016-04-02 02:07:27 +08:00
$eventsSql = 'SELECT E.*,M.Name AS MonitorName,M.DefaultScale FROM Monitors AS M INNER JOIN Events AS E on (M.Id = E.MonitorId) WHERE' ;
2014-03-22 05:16:56 +08:00
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 ;
2014-03-22 05:16:56 +08:00
} else {
2017-06-01 09:34:38 +08:00
$countSql .= ' 1' ;
$eventsSql .= ' 1' ;
2008-07-14 21:54:50 +08:00
}
parseSort ();
2018-04-03 21:57:22 +08:00
parseFilter ( $_REQUEST [ 'filter' ]);
2008-07-14 21:54:50 +08:00
$filterQuery = $_REQUEST [ 'filter' ][ 'query' ];
2017-05-06 02:25:25 +08:00
if ( $_REQUEST [ 'filter' ][ 'sql' ] ) {
2017-06-01 09:34:38 +08:00
$countSql .= $_REQUEST [ 'filter' ][ 'sql' ];
$eventsSql .= $_REQUEST [ 'filter' ][ 'sql' ];
2008-07-14 21:54:50 +08:00
}
2018-09-27 02:10:49 +08:00
$eventsSql .= " ORDER BY $sortColumn $sortOrder ,Id $sortOrder " ;
2008-07-14 21:54:50 +08:00
2018-02-07 22:07:51 +08:00
$page = isset ( $_REQUEST [ 'page' ]) ? validInt ( $_REQUEST [ 'page' ]) : 0 ;
$limit = isset ( $_REQUEST [ 'limit' ]) ? validInt ( $_REQUEST [ 'limit' ]) : 0 ;
2008-09-26 17:47:20 +08:00
2018-04-03 21:57:22 +08:00
$nEvents = dbFetchOne ( $countSql , 'EventCount' );
2017-05-06 02:25:25 +08:00
if ( ! empty ( $limit ) && $nEvents > $limit ) {
2017-06-01 09:34:38 +08:00
$nEvents = $limit ;
2008-07-14 21:54:50 +08:00
}
$pages = ( int ) ceil ( $nEvents / ZM_WEB_EVENTS_PER_PAGE );
2018-02-07 22:07:51 +08:00
#Logger::Debug("Page $page Limit $limit #vents: $nEvents pages: $pages ");
2016-04-16 04:11:53 +08:00
if ( ! empty ( $page ) ) {
2017-05-06 02:25:25 +08:00
if ( $page < 0 )
$page = 1 ;
2018-02-07 22:07:51 +08:00
else if ( $pages and ( $page > $pages ) )
2017-05-06 02:25:25 +08:00
$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 ;
2008-07-14 21:54:50 +08:00
}
$maxShortcuts = 5 ;
2018-04-03 21:57:22 +08:00
$pagination = getPagination ( $pages , $page , $maxShortcuts , $filterQuery . $sortQuery . $limitQuery );
2008-07-14 21:54:50 +08:00
$focusWindow = true ;
2018-04-03 21:57:22 +08:00
if ( $_POST ) {
2019-01-24 00:30:51 +08:00
// I think this is basically so that a refresh doesn't repost
2019-02-22 22:19:07 +08:00
ZM\Logger :: Debug ( 'Redirecting to ' . $_SERVER [ 'REQUEST_URI' ]);
2019-01-24 00:30:51 +08:00
header ( 'Location: ?view=' . $view . htmlspecialchars_decode ( $filterQuery ) . htmlspecialchars_decode ( $sortQuery ) . $limitQuery . '&page=' . $page );
2018-04-03 21:57:22 +08:00
exit ();
}
2019-02-22 22:19:07 +08:00
$storage_areas = ZM\Storage :: find ();
2018-04-03 21:57:22 +08:00
$StorageById = array ();
foreach ( $storage_areas as $S ) {
$StorageById [ $S -> Id ()] = $S ;
2017-12-10 00:23:50 +08:00
}
2015-05-10 21:10:30 +08:00
xhtmlHeaders ( __FILE__ , translate ( 'Events' ) );
2008-07-14 21:54:50 +08:00
?>
< body >
< div id = " page " >
2018-09-08 04:31:11 +08:00
< ? php echo getNavBarHTML () ?>
2008-07-14 21:54:50 +08:00
< div id = " header " >
2019-02-10 09:34:59 +08:00
< a id = " refreshLink " href = " # " >< ? php echo translate ( 'Refresh' ) ?> </a>
2017-11-28 21:23:54 +08:00
< a id = " timelineLink " href = " ?view=timeline<?php echo $filterQuery ?> " >< ? php echo translate ( 'ShowTimeline' ) ?> </a>
2020-08-16 04:27:58 +08:00
< a href = " # " id = " backLink " >< ? php echo translate ( 'Back' ) ?> </a>
</ div >
< div id = " toolbar " >
< button id = " viewBtn " class = " btn btn-primary btn-sm " disabled >< i class = " fa fa-binoculars " ></ i > View </ button >
< button id = " archiveBtn " class = " btn btn-primary btn-sm " disabled >< i class = " fa fa-archive " ></ i > Archive </ button >
< button id = " unarchiveBtn " class = " btn btn-primary btn-sm " disabled >< i class = " fa fa-file-archive-o " ></ i > Unarchive </ button >
< button id = " editBtn " class = " btn btn-primary btn-sm " disabled >< i class = " fa fa-pencil " ></ i > Edit </ button >
< button id = " exportBtn " class = " btn btn-primary btn-sm " disabled >< i class = " fa fa-external-link " ></ i > Export </ button >
< button id = " downloadBtn " class = " btn btn-primary btn-sm " disabled >< i class = " fa fa-download " ></ i > Download Video </ button >
< button id = " deleteBtn " class = " btn btn-danger btn-sm " disabled >< i class = " fa fa-trash " ></ i > Delete </ button >
2008-07-14 21:54:50 +08:00
</ div >
2020-08-16 04:27:58 +08:00
< div class = " table-responsive-sm p-3 " >
< table
id = " eventTable "
data - toggle = " table "
data - pagination = " true "
data - search = " true "
data - cookie = " true "
data - cookie - id - table = " zmEventTable "
data - click - to - select = " true "
data - remember - order = " true "
data - show - columns = " true "
data - uncheckAll = " true "
data - toolbar = " #toolbar "
data - show - fullscreen = " true "
data - click - to - select = " true "
data - maintain - meta - data = " true "
data - mobile - responsive = " true "
class = " table-sm table-borderless " >
< thead >
2008-07-14 21:54:50 +08:00
< ? 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 ) ) {
2019-02-22 22:19:07 +08:00
$event = new ZM\Event ( $event_row );
2017-11-16 02:01:07 +08:00
if ( $event_row [ 'Archived' ] )
$archived = true ;
else
$unarchived = true ;
2017-06-01 09:34:38 +08:00
if ( ( $count ++% ZM_WEB_EVENTS_PER_PAGE ) == 0 ) {
2008-07-14 21:54:50 +08:00
?>
< tr >
2020-08-16 04:27:58 +08:00
< th data - sortable = " false " data - field = " toggleCheck " data - field = " state " data - checkbox = " true " name = " toggleCheck " value = " 1 " data - checkbox - name = " eids[] " data - on - click - this = " updateFormCheckboxesByName " ></ th >
< 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 = " 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>
2008-07-14 21:54:50 +08:00
< ? php
2017-05-31 01:47:30 +08:00
}
if ( ZM_WEB_LIST_THUMBS ) {
2008-07-14 21:54:50 +08:00
?>
2020-08-16 04:27:58 +08:00
< th data - sortable = " false " data - field = " Thumbnail " >< ? php echo translate ( 'Thumbnail' ) ?> </th>
2008-07-14 21:54:50 +08:00
< ? php
2017-05-31 01:47:30 +08:00
}
2008-07-14 21:54:50 +08:00
?>
</ tr >
2020-08-16 04:27:58 +08:00
</ thead >
< tbody >
2008-07-14 21:54:50 +08:00
< ? php
2017-05-31 01:47:30 +08:00
}
$scale = max ( reScale ( SCALE_BASE , $event -> DefaultScale (), ZM_WEB_DEFAULT_SCALE ), SCALE_BASE );
2008-07-14 21:54:50 +08:00
?>
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&eid=<?php echo $event->Id (). $filterQuery . $sortQuery .'&page=1 " > ' . $event -> Id () ?> </a></td>
< td >< a href = " ?view=event&eid=<?php echo $event->Id (). $filterQuery . $sortQuery .'&page=1 " > '.validHtmlStr($event->Name()).($event->Archived()?' * ':' ' ) ?> </a><br/>
2020-02-20 03:17:44 +08:00
< ? php
if ( $event -> Emailed () )
echo 'Emailed ' ;
?>
</ td >
2020-08-16 04:27:58 +08:00
< td >< ? php echo ( $event -> Archived () ) ? 'Yes' : 'No' ?> </td>
< td >< ? php echo makePopupLink ( '?view=monitor&mid=' . $event -> MonitorId (), 'zmMonitor' . $event -> MonitorId (), 'monitor' , $event -> MonitorName (), canEdit ( 'Monitors' ) ) ?> </td>
< td >< ? php echo makePopupLink ( '?view=eventdetail&eid=' . $event -> Id (), 'zmEventDetail' , 'eventdetail' , validHtmlStr ( $event -> Cause ()), canEdit ( 'Events' ), 'title="' . htmlspecialchars ( $event -> Notes ()) . '"' ) ?>
2019-08-28 21:19:09 +08:00
< ? php
# display notes as small text
2020-02-20 03:17:44 +08:00
if ( $event -> Notes () ) {
2019-08-28 21:19:09 +08:00
# if notes include detection objects, then link it to objdetect.jpg
2020-02-20 03:17:44 +08:00
if ( strpos ( $event -> Notes (), 'detected:' ) !== false ) {
2019-08-28 21:19:09 +08:00
# make a link
echo makePopupLink ( '?view=image&eid=' . $event -> Id () . '&fid=objdetect' , 'zmImage' ,
array ( 'image' , reScale ( $event -> Width (), $scale ), reScale ( $event -> Height (), $scale )),
2020-02-20 03:17:44 +08:00
'<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>' ;
2019-08-28 21:19:09 +08:00
}
}
?>
2019-02-11 23:58:34 +08:00
</ 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>
< td >< ? php echo makePopupLink ( '?view=frames&eid=' . $event -> Id (), 'zmFrames' ,
2019-07-04 05:19:10 +08:00
( ZM_WEB_LIST_THUMBS ? array ( 'frames' , ZM_WEB_LIST_THUMB_WIDTH , ZM_WEB_LIST_THUMB_HEIGHT ) : 'frames' ),
$event -> Frames () ) ?> </td>
2020-08-16 04:27:58 +08:00
< td >< ? php echo makePopupLink ( '?view=frames&eid=' . $event -> Id (), 'zmFrames' ,
2019-07-04 05:19:10 +08:00
( ZM_WEB_LIST_THUMBS ? array ( 'frames' , ZM_WEB_LIST_THUMB_WIDTH , ZM_WEB_LIST_THUMB_HEIGHT ) : 'frames' ),
$event -> AlarmFrames () ) ?> </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 (
2018-09-08 04:31:11 +08:00
'?view=frame&eid=' . $event -> Id () . '&fid=0' , 'zmImage' ,
array ( 'image' , reScale ( $event -> Width (), $scale ), reScale ( $event -> Height (), $scale )), $event -> MaxScore ()
); ?> </td>
2008-07-14 21:54:50 +08:00
< ? php
2018-04-03 21:57:22 +08:00
if ( count ( $storage_areas ) > 1 ) {
?>
2020-08-16 04:27:58 +08:00
< td >
2019-08-29 23:27:06 +08:00
< ? 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>
2008-07-14 21:54:50 +08:00
< ? 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 (), '&' );
2018-09-08 04:31:11 +08:00
$streamSrc = $event -> getStreamSrc ( array (
2020-03-30 22:09:53 +08:00
'mode' => 'jpeg' , 'scale' => $scale , 'maxfps' => ZM_WEB_VIDEO_MAXFPS , 'replay' => 'single' , 'rate' => '400' ), '&' );
2017-05-06 02:25:25 +08:00
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&eid=' . $event -> Id () . $filterQuery . $sortQuery . '&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
2008-07-14 21:54:50 +08:00
?>
</ tr >
< ? php
}
?>
</ tbody >
2017-10-19 00:43:51 +08:00
< ? php
if ( ZM_WEB_EVENT_DISK_SPACE ) {
?>
2018-09-08 04:31:11 +08:00
< 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 ) {
?>
2018-09-08 04:31:11 +08:00
< 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 ) {
2018-09-08 04:31:11 +08:00
?>
< td ></ td >
2017-10-19 00:43:51 +08:00
< ? php
}
2018-09-08 04:31:11 +08:00
?>
< td ></ td >
2017-10-19 00:43:51 +08:00
</ tr >
</ tfoot >
< ? php
}
?>
2008-07-14 21:54:50 +08:00
</ table >
2020-08-16 04:27:58 +08:00
</ div >
2008-07-14 21:54:50 +08:00
</ div >
2019-01-18 22:51:06 +08:00
< script nonce = " <?php echo $cspNonce ;?> " >
2017-11-16 02:01:07 +08:00
// These are defined in the .js.php but need to be updated down here.
2019-02-07 02:31:34 +08:00
// This might be better done by selecting through the dom for the archived class
2017-11-16 02:01:07 +08:00
archivedEvents = < ? php echo ! empty ( $archived ) ? 'true' : 'false' ?> ;
unarchivedEvents = < ? php echo ! empty ( $unarchived ) ? 'true' : 'false' ?> ;
</ script >
2008-07-14 21:54:50 +08:00
</ body >
</ html >