zoneminder/web/ajax/watch.php

102 lines
3.1 KiB
PHP
Raw Permalink Normal View History

<?php
//
// This is simplified version of the logic from ajax/events.php
2023-08-27 00:00:59 +00:00
// For efficiency, sorting and and pagination functionality have been excluded
//
$message = '';
$data = array();
//
// INITIALIZE AND CHECK SANITY
//
if ( !canView('Events') ) $message = 'Insufficient permissions for user '.$user->Username();
// Mid specifies the monitor id we are searching on
if ( empty($_REQUEST['mid']) ) {
$message = 'Must specify a monitor Id';
} else {
$mid = validCardinal($_REQUEST['mid']);
}
// Limit specifies the number of rows to return
if ( ( !is_int($_REQUEST['limit']) and !ctype_digit($_REQUEST['limit']) ) ) {
$message = 'Invalid value for limit: '.$_REQUEST['limit'];
} else {
$limit = $_REQUEST['limit'];
}
if ($message) {
ZM\Error($message);
ajaxError($message);
return;
}
// Sort specifies the name of the column to sort on
$sort = 'Id';
if (isset($_REQUEST['sort'])) {
$sort = $_REQUEST['sort'];
}
// Order specifies the sort direction, either asc or desc
$order = (isset($_REQUEST['order']) and (strtolower($_REQUEST['order']) == 'asc')) ? 'ASC' : 'DESC';
//
// MAIN LOOP
//
// The names of the dB columns in the events table we are interested in
$columns = array('Id', 'MonitorId', 'StorageId', 'Name', 'Cause', 'StartDateTime', 'EndDateTime', 'Length', 'Frames', 'AlarmFrames', 'TotScore', 'AvgScore', 'MaxScore', 'Archived', 'Emailed', 'Notes', 'DiskSpace');
if ( $sort != 'Id' ) {
if (!in_array($sort, $columns)) {
ZM\Error('Invalid sort field: ' . $sort);
$sort = 'Id';
} else if ($sort == 'EndDateTime') {
if ($order == 'ASC') {
$sort = 'E.EndDateTime IS NULL, E.EndDateTime';
} else {
$sort = 'E.EndDateTime IS NOT NULL, E.EndDateTime';
}
} else {
$sort = 'E.'.$sort;
}
}
$where = 'WHERE MonitorId = '.$mid;
(feat): Tags fix(tag): Create tags on mobile chore(tags): Change TagName to Name chore(tags): eslint chore(tags): dbFetchAll to dbQuery for removetag chore(events): eslint (attempt 2) feat(tags): Better handling of keyboard fix(tags): Enter key for creating new tag fix(tags): Don't allow space as a tag name feat(tags): Delete tag if last assignment removed fix(tags): Increase height of dropdown in progress fix(Tags): Use T.Id on the events page dropdown fix(Tags): Remove $availableTags from events.php chore(sql): Formatting sql statements feat(Tags): Working OR on filters and events pages fix(filter): Populate availableTags chore(Tags): code formatting fix(tag): Add tag on create tag Fix(tags): Remove tag from available if last feat(tags): Add zm_update.sql fix(chosen): Undo css width fix(chosen): tags dropdown width fix(tags): dropdown over timeline fix(tags): Full width input fix(events): Refresh table on page show chore(filter): Clean up availableTags chore(event): Clean up available & selected Tags fix(event): Update available tags on remove fix(event): Remove hack for selected tags feat(tags): Blur input after adding tag doc(tags): Initial tags documentation fix(tags): Dark theme dropdown fix(tags): Dark theme for tags on input fix(tags): Dark theme for highlight in dropdown fix(tags): Populate filter tags droplist chore(): Bump zm_update to 1.37.42 chore(tags): Move mobile check to skin.js chore(tags): Comment debug statements fix(tags): Enter key to create tag on mobile Chome chore(tags): Space in 'All Tags' for translation Temporary commit to handle cookie expiration times chore(tags): Remove unnecessary Tag(s) from en_gb chore(): Cleanup unnecessary Error and Debug chore(): Resolve merge conflicts chore(): Address merge conflicts with master
2023-06-03 23:27:43 +00:00
$col_str = ' E.*, GROUP_CONCAT(T.Name SEPARATOR ", ") AS Tags ';
$sql = 'SELECT ' .$col_str. ' FROM `Events` AS E
LEFT JOIN Events_Tags AS ET ON E.Id = ET.EventId
LEFT JOIN Tags AS T ON T.Id = ET.TagId
'.$where.' GROUP BY E.Id ORDER BY '.$sort.' '.$order.' LIMIT ?';
$rows = dbQuery($sql, array($limit));
$returned_rows = array();
if ($rows) {
foreach ( $rows as $row ) {
$event = new ZM\Event($row);
$event->remove_from_cache();
if (!$event->canView()) continue;
if ($event->Monitor()->Deleted()) continue;
$scale = intval(5*100*ZM_WEB_LIST_THUMB_WIDTH / $event->Width());
$imgSrc = $event->getThumbnailSrc(array(), '&amp;');
$streamSrc = $event->getStreamSrc(array(
'mode'=>'jpeg', 'scale'=>$scale, 'maxfps'=>ZM_WEB_VIDEO_MAXFPS, 'replay'=>'single', 'rate'=>'400'), '&amp;');
// Modify the row data as needed
$row['imgHtml'] = '<img id="thumbnail' .$event->Id(). '" src="' .$imgSrc. '" alt="Event '.$event->Id().'" width="' .validInt($event->ThumbnailWidth()). '" height="' .validInt($event->ThumbnailHeight()).'" stream_src="' .$streamSrc. '" still_src="' .$imgSrc. '" loading="lazy" />';
$row['Name'] = validHtmlStr($row['Name']);
$row['Length'] = gmdate('H:i:s', intval($row['Length']));
$returned_rows[] = $row;
} # end foreach row matching search
}
$data['rows'] = &$returned_rows;
ajaxResponse($data);
?>