zoneminder/web/ajax/event.php

159 lines
5.4 KiB
PHP
Raw Normal View History

<?php
2013-12-18 00:07:19 +08:00
if ( empty($_REQUEST['id']) && empty($_REQUEST['eids']) ) {
2018-07-09 21:59:03 +08:00
ajaxError('No event id(s) supplied');
}
2018-07-09 21:59:03 +08:00
if ( canView('Events') ) {
2017-06-06 03:21:07 +08:00
switch ( $_REQUEST['action'] ) {
case 'video' :
{
if ( empty($_REQUEST['videoFormat']) ) {
2018-07-13 02:05:23 +08:00
ajaxError('Video Generation Failure, no format given');
2017-06-06 03:21:07 +08:00
} elseif ( empty($_REQUEST['rate']) ) {
2018-07-13 02:05:23 +08:00
ajaxError('Video Generation Failure, no rate given');
2017-06-06 03:21:07 +08:00
} elseif ( empty($_REQUEST['scale']) ) {
2018-07-13 02:05:23 +08:00
ajaxError('Video Generation Failure, no scale given');
2017-06-06 03:21:07 +08:00
} else {
$sql = 'SELECT E.*,M.Name AS MonitorName,M.DefaultRate,M.DefaultScale FROM Events AS E INNER JOIN Monitors AS M ON E.MonitorId = M.Id WHERE E.Id = ?'.monitorLimitSql();
2018-07-13 02:05:23 +08:00
if ( !($event = dbFetchOne($sql, NULL, array( $_REQUEST['id']))) ) {
ajaxError('Video Generation Failure, Unable to load event');
} else {
if ( $videoFile = createVideo($event, $_REQUEST['videoFormat'], $_REQUEST['rate'], $_REQUEST['scale'], !empty($_REQUEST['overwrite'])) )
ajaxResponse(array('response'=>$videoFile));
2017-06-06 03:21:07 +08:00
else
2018-07-13 02:05:23 +08:00
ajaxError('Video Generation Failed');
}
}
2017-06-06 03:21:07 +08:00
$ok = true;
break;
}
case 'deleteVideo' :
{
unlink( $videoFiles[$_REQUEST['id']] );
unset( $videoFiles[$_REQUEST['id']] );
ajaxResponse();
break;
}
case 'export' :
{
2018-07-09 21:59:03 +08:00
require_once(ZM_SKIN_PATH.'/includes/export_functions.php');
2017-06-06 03:21:07 +08:00
# We use session vars in here, so we need to restart the session because we stopped it in index.php to improve concurrency.
session_start();
2017-06-06 03:21:07 +08:00
if ( !empty($_REQUEST['exportDetail']) )
$exportDetail = $_SESSION['export']['detail'] = $_REQUEST['exportDetail'];
else
$exportDetail = false;
2018-07-09 21:59:03 +08:00
2017-06-06 03:21:07 +08:00
if ( !empty($_REQUEST['exportFrames']) )
$exportFrames = $_SESSION['export']['frames'] = $_REQUEST['exportFrames'];
else
$exportFrames = false;
2018-07-09 21:59:03 +08:00
2017-06-06 03:21:07 +08:00
if ( !empty($_REQUEST['exportImages']) )
$exportImages = $_SESSION['export']['images'] = $_REQUEST['exportImages'];
else
$exportImages = false;
2018-07-09 21:59:03 +08:00
2017-06-06 03:21:07 +08:00
if ( !empty($_REQUEST['exportVideo']) )
$exportVideo = $_SESSION['export']['video'] = $_REQUEST['exportVideo'];
else
$exportVideo = false;
2018-07-09 21:59:03 +08:00
2017-06-06 03:21:07 +08:00
if ( !empty($_REQUEST['exportMisc']) )
$exportMisc = $_SESSION['export']['misc'] = $_REQUEST['exportMisc'];
else
$exportMisc = false;
2018-07-09 21:59:03 +08:00
2017-06-06 03:21:07 +08:00
if ( !empty($_REQUEST['exportFormat']) )
$exportFormat = $_SESSION['export']['format'] = $_REQUEST['exportFormat'];
else
$exportFormat = '';
2017-06-06 03:21:07 +08:00
session_write_close();
2017-06-06 03:21:07 +08:00
$exportIds = !empty($_REQUEST['eids'])?$_REQUEST['eids']:$_REQUEST['id'];
2018-07-09 21:59:03 +08:00
if ( $exportFile = exportEvents(
$exportIds,
(isset($_REQUEST['connkey'])?$_REQUEST['connkey']:''),
$exportDetail,
$exportFrames,
$exportImages,
$exportVideo,
$exportMisc,
$exportFormat
) )
ajaxResponse(array('exportFile'=>$exportFile));
2017-06-06 03:21:07 +08:00
else
2018-07-09 21:59:03 +08:00
ajaxError('Export Failed');
2017-06-06 03:21:07 +08:00
break;
}
case 'download' :
{
2018-07-13 02:05:23 +08:00
require_once(ZM_SKIN_PATH.'/includes/export_functions.php');
$exportVideo = 1;
$exportFormat = $_REQUEST['exportFormat'];
$exportStructure = 'flat';
$exportIds = !empty($_REQUEST['eids'])?$_REQUEST['eids']:$_REQUEST['id'];
2018-07-13 02:05:23 +08:00
if ( $exportFile = exportEvents(
$exportIds,
(isset($_REQUEST['connkey'])?$_REQUEST['connkey']:''),
false,false, false, $exportVideo, false, $exportFormat, $exportStructure ) )
ajaxResponse(array('exportFile'=>$exportFile));
else
2018-07-13 02:05:23 +08:00
ajaxError('Export Failed');
break;
}
2017-06-06 03:21:07 +08:00
}
2018-07-13 02:05:23 +08:00
} // end if canView('Events')
2018-07-13 02:05:23 +08:00
if ( canEdit('Events') ) {
2017-06-06 03:21:07 +08:00
switch ( $_REQUEST['action'] ) {
case 'rename' :
{
if ( !empty($_REQUEST['eventName']) )
2018-07-13 02:05:23 +08:00
dbQuery('UPDATE Events SET Name = ? WHERE Id = ?', array($_REQUEST['eventName'], $_REQUEST['id']));
2017-06-06 03:21:07 +08:00
else
2018-07-13 02:05:23 +08:00
ajaxError('No new event name supplied');
ajaxResponse(array('refreshEvent'=>true, 'refreshParent'=>true));
2017-06-06 03:21:07 +08:00
break;
}
case 'eventdetail' :
{
2018-07-13 02:05:23 +08:00
dbQuery(
'UPDATE Events SET Cause = ?, Notes = ? WHERE Id = ?',
array($_REQUEST['newEvent']['Cause'], $_REQUEST['newEvent']['Notes'], $_REQUEST['id'])
);
ajaxResponse(array('refreshEvent'=>true, 'refreshParent'=>true));
2017-06-06 03:21:07 +08:00
break;
}
case 'archive' :
case 'unarchive' :
{
$archiveVal = ($_REQUEST['action'] == 'archive')?1:0;
2018-07-13 02:05:23 +08:00
dbQuery(
'UPDATE Events SET Archived = ? WHERE Id = ?',
array($archiveVal, $_REQUEST['id'])
);
ajaxResponse(array('refreshEvent'=>true, 'refreshParent'=>false));
2017-06-06 03:21:07 +08:00
break;
}
case 'delete' :
{
2018-07-13 02:05:23 +08:00
$Event = new Event($_REQUEST['id']);
2017-06-06 03:21:07 +08:00
if ( ! $Event->Id() ) {
2018-07-13 02:05:23 +08:00
ajaxResponse(array('refreshEvent'=>false, 'refreshParent'=>true, 'message'=> 'Event not found.'));
2017-06-06 03:21:07 +08:00
} else {
$Event->delete();
2018-07-13 02:05:23 +08:00
ajaxResponse(array('refreshEvent'=>false, 'refreshParent'=>true));
}
2017-06-06 03:21:07 +08:00
break;
}
}
2018-07-13 02:05:23 +08:00
} // end if canEdit('Events')
2018-07-13 02:05:23 +08:00
ajaxError('Unrecognised action or insufficient permissions');
?>