2008-07-14 13:54:50 +00:00
|
|
|
<?php
|
2020-05-23 14:15:48 +00:00
|
|
|
ini_set('display_errors', '0');
|
2008-07-14 13:54:50 +00:00
|
|
|
|
2013-12-17 16:07:19 +00:00
|
|
|
if ( empty($_REQUEST['id']) && empty($_REQUEST['eids']) ) {
|
2018-07-09 13:59:03 +00:00
|
|
|
ajaxError('No event id(s) supplied');
|
2008-07-14 13:54:50 +00:00
|
|
|
}
|
|
|
|
|
2021-08-18 14:11:18 +00:00
|
|
|
if ( canView('Events') or canView('Snapshots') ) {
|
2017-06-05 19:21:07 +00:00
|
|
|
switch ( $_REQUEST['action'] ) {
|
2019-03-20 18:25:34 +00:00
|
|
|
case 'video' :
|
|
|
|
if ( empty($_REQUEST['videoFormat']) ) {
|
|
|
|
ajaxError('Video Generation Failure, no format given');
|
|
|
|
} elseif ( empty($_REQUEST['rate']) ) {
|
|
|
|
ajaxError('Video Generation Failure, no rate given');
|
|
|
|
} elseif ( empty($_REQUEST['scale']) ) {
|
|
|
|
ajaxError('Video Generation Failure, no scale given');
|
|
|
|
} else {
|
2023-06-03 23:27:43 +00:00
|
|
|
$sql = '
|
|
|
|
SELECT
|
|
|
|
E.*,
|
|
|
|
M.Name
|
|
|
|
AS MonitorName,M.DefaultRate,M.DefaultScale,
|
|
|
|
GROUP_CONCAT(T.Name SEPARATOR ", ")
|
|
|
|
AS Tags
|
|
|
|
FROM Events
|
|
|
|
AS E
|
|
|
|
INNER JOIN Monitors
|
|
|
|
AS M
|
|
|
|
ON E.MonitorId = M.Id
|
|
|
|
LEFT JOIN Events_Tags
|
|
|
|
AS ET
|
|
|
|
ON E.Id = ET.EventId
|
|
|
|
LEFT JOIN Tags
|
|
|
|
AS T
|
|
|
|
ON T.Id = ET.TagId
|
|
|
|
WHERE
|
|
|
|
E.Id = ?'.monitorLimitSql();
|
2019-03-20 18:25:34 +00:00
|
|
|
if ( !($event = dbFetchOne($sql, NULL, array( $_REQUEST['id']))) ) {
|
|
|
|
ajaxError('Video Generation Failure, Unable to load event');
|
|
|
|
} else {
|
2022-09-06 17:46:54 +00:00
|
|
|
require_once('includes/Event.php');
|
|
|
|
$Event = new ZM\Event($event);
|
|
|
|
|
|
|
|
if ( $videoFile = $Event->createVideo($_REQUEST['videoFormat'], $_REQUEST['rate'], $_REQUEST['scale'], $_REQUEST['transform'], !empty($_REQUEST['overwrite'])) )
|
2019-03-20 18:25:34 +00:00
|
|
|
ajaxResponse(array('response'=>$videoFile));
|
|
|
|
else
|
|
|
|
ajaxError('Video Generation Failed');
|
2017-06-05 19:21:07 +00:00
|
|
|
}
|
2019-03-20 18:25:34 +00:00
|
|
|
}
|
|
|
|
$ok = true;
|
|
|
|
break;
|
|
|
|
case 'deleteVideo' :
|
2020-05-23 14:15:48 +00:00
|
|
|
unlink($videoFiles[$_REQUEST['id']]);
|
|
|
|
unset($videoFiles[$_REQUEST['id']]);
|
2019-03-20 18:25:34 +00:00
|
|
|
ajaxResponse();
|
|
|
|
break;
|
|
|
|
case 'export' :
|
|
|
|
require_once(ZM_SKIN_PATH.'/includes/export_functions.php');
|
2008-07-14 13:54:50 +00:00
|
|
|
|
2019-03-20 18:25:34 +00:00
|
|
|
# We use session vars in here, so we need to restart the session
|
|
|
|
# because we stopped it in index.php to improve concurrency.
|
|
|
|
zm_session_start();
|
2016-06-07 14:38:37 +00:00
|
|
|
|
2019-03-20 18:25:34 +00:00
|
|
|
if ( !empty($_REQUEST['exportDetail']) )
|
|
|
|
$exportDetail = $_SESSION['export']['detail'] = $_REQUEST['exportDetail'];
|
|
|
|
else
|
|
|
|
$exportDetail = false;
|
2018-07-09 13:59:03 +00:00
|
|
|
|
2019-03-20 18:25:34 +00:00
|
|
|
if ( !empty($_REQUEST['exportFrames']) )
|
|
|
|
$exportFrames = $_SESSION['export']['frames'] = $_REQUEST['exportFrames'];
|
|
|
|
else
|
|
|
|
$exportFrames = false;
|
2018-07-09 13:59:03 +00:00
|
|
|
|
2019-03-20 18:25:34 +00:00
|
|
|
if ( !empty($_REQUEST['exportImages']) )
|
|
|
|
$exportImages = $_SESSION['export']['images'] = $_REQUEST['exportImages'];
|
|
|
|
else
|
|
|
|
$exportImages = false;
|
2018-07-09 13:59:03 +00:00
|
|
|
|
2019-03-20 18:25:34 +00:00
|
|
|
if ( !empty($_REQUEST['exportVideo']) )
|
|
|
|
$exportVideo = $_SESSION['export']['video'] = $_REQUEST['exportVideo'];
|
|
|
|
else
|
|
|
|
$exportVideo = false;
|
2018-07-09 13:59:03 +00:00
|
|
|
|
2019-03-20 18:25:34 +00:00
|
|
|
if ( !empty($_REQUEST['exportMisc']) )
|
|
|
|
$exportMisc = $_SESSION['export']['misc'] = $_REQUEST['exportMisc'];
|
|
|
|
else
|
|
|
|
$exportMisc = false;
|
2018-07-09 13:59:03 +00:00
|
|
|
|
2019-03-20 18:25:34 +00:00
|
|
|
if ( !empty($_REQUEST['exportFormat']) )
|
|
|
|
$exportFormat = $_SESSION['export']['format'] = $_REQUEST['exportFormat'];
|
|
|
|
else
|
|
|
|
$exportFormat = '';
|
2008-07-14 13:54:50 +00:00
|
|
|
|
2019-03-20 18:25:34 +00:00
|
|
|
if ( !empty($_REQUEST['exportCompress']) )
|
|
|
|
$exportCompress = $_SESSION['export']['compress'] = $_REQUEST['exportCompress'];
|
|
|
|
else
|
|
|
|
$exportCompress = false;
|
2018-09-07 13:08:33 +00:00
|
|
|
|
2021-08-06 17:10:44 +00:00
|
|
|
if ( !empty($_REQUEST['exportStructure']) )
|
|
|
|
$exportStructure = $_SESSION['export']['structure'] = $_REQUEST['exportStructure'];
|
|
|
|
else
|
|
|
|
$exportStructure = false;
|
|
|
|
|
2019-03-20 18:25:34 +00:00
|
|
|
session_write_close();
|
2016-06-07 14:38:37 +00:00
|
|
|
|
2019-03-20 18:25:34 +00:00
|
|
|
$exportIds = !empty($_REQUEST['eids']) ? $_REQUEST['eids'] : $_REQUEST['id'];
|
2021-08-06 17:10:44 +00:00
|
|
|
if ($exportFile = exportEvents(
|
2019-03-20 18:25:34 +00:00
|
|
|
$exportIds,
|
|
|
|
(isset($_REQUEST['connkey'])?$_REQUEST['connkey']:''),
|
|
|
|
$exportDetail,
|
|
|
|
$exportFrames,
|
|
|
|
$exportImages,
|
|
|
|
$exportVideo,
|
|
|
|
$exportMisc,
|
|
|
|
$exportFormat,
|
2021-08-05 17:28:13 +00:00
|
|
|
$exportCompress,
|
2021-08-06 17:10:44 +00:00
|
|
|
$exportStructure,
|
2021-11-10 19:23:36 +00:00
|
|
|
(!empty($_REQUEST['exportFile'])?$_REQUEST['exportFile']:'zmExport')
|
2021-08-06 17:10:44 +00:00
|
|
|
)) {
|
|
|
|
ajaxResponse(array('exportFile'=>$exportFile));
|
|
|
|
} else {
|
2019-03-20 18:25:34 +00:00
|
|
|
ajaxError('Export Failed');
|
2021-08-06 17:10:44 +00:00
|
|
|
}
|
2019-03-20 18:25:34 +00:00
|
|
|
break;
|
|
|
|
case 'download' :
|
|
|
|
require_once(ZM_SKIN_PATH.'/includes/export_functions.php');
|
|
|
|
$exportVideo = 1;
|
|
|
|
$exportFormat = $_REQUEST['exportFormat'];
|
|
|
|
$exportStructure = 'flat';
|
|
|
|
$exportIds = !empty($_REQUEST['eids'])?$_REQUEST['eids']:$_REQUEST['id'];
|
|
|
|
if ( $exportFile = exportEvents(
|
|
|
|
$exportIds,
|
|
|
|
(isset($_REQUEST['connkey'])?$_REQUEST['connkey']:''),
|
2019-07-24 16:31:43 +00:00
|
|
|
false,#detail
|
|
|
|
false,#frames
|
|
|
|
false,#images
|
2021-08-18 14:11:18 +00:00
|
|
|
true, #$exportVideo,
|
2019-07-24 16:31:43 +00:00
|
|
|
false,#Misc
|
|
|
|
$exportFormat,
|
|
|
|
false#,#Compress
|
2022-05-24 16:11:18 +00:00
|
|
|
, $exportStructure
|
2019-07-24 16:31:43 +00:00
|
|
|
) ) {
|
2020-05-23 14:15:48 +00:00
|
|
|
ajaxResponse(array(
|
|
|
|
'exportFile'=>$exportFile,
|
|
|
|
'exportFormat'=>$exportFormat,
|
|
|
|
'connkey'=>(isset($_REQUEST['connkey'])?$_REQUEST['connkey']:'')
|
|
|
|
));
|
2019-07-24 16:31:43 +00:00
|
|
|
} else {
|
2019-03-20 18:25:34 +00:00
|
|
|
ajaxError('Export Failed');
|
2019-07-24 16:31:43 +00:00
|
|
|
}
|
2019-03-20 18:25:34 +00:00
|
|
|
break;
|
2017-06-05 19:21:07 +00:00
|
|
|
}
|
2018-07-12 18:05:23 +00:00
|
|
|
} // end if canView('Events')
|
2009-03-27 09:14:54 +00:00
|
|
|
|
2018-07-12 18:05:23 +00:00
|
|
|
if ( canEdit('Events') ) {
|
2017-06-05 19:21:07 +00:00
|
|
|
switch ( $_REQUEST['action'] ) {
|
2019-03-20 18:25:34 +00:00
|
|
|
case 'rename' :
|
|
|
|
if ( !empty($_REQUEST['eventName']) )
|
|
|
|
dbQuery('UPDATE Events SET Name = ? WHERE Id = ?', array($_REQUEST['eventName'], $_REQUEST['id']));
|
|
|
|
else
|
|
|
|
ajaxError('No new event name supplied');
|
|
|
|
ajaxResponse(array('refreshEvent'=>true, 'refreshParent'=>true));
|
|
|
|
break;
|
|
|
|
case 'eventdetail' :
|
|
|
|
dbQuery(
|
|
|
|
'UPDATE Events SET Cause = ?, Notes = ? WHERE Id = ?',
|
|
|
|
array($_REQUEST['newEvent']['Cause'], $_REQUEST['newEvent']['Notes'], $_REQUEST['id'])
|
|
|
|
);
|
|
|
|
ajaxResponse(array('refreshEvent'=>true, 'refreshParent'=>true));
|
|
|
|
break;
|
|
|
|
case 'archive' :
|
|
|
|
case 'unarchive' :
|
|
|
|
$archiveVal = ($_REQUEST['action'] == 'archive')?1:0;
|
|
|
|
dbQuery(
|
|
|
|
'UPDATE Events SET Archived = ? WHERE Id = ?',
|
|
|
|
array($archiveVal, $_REQUEST['id'])
|
|
|
|
);
|
|
|
|
ajaxResponse(array('refreshEvent'=>true, 'refreshParent'=>false));
|
|
|
|
break;
|
|
|
|
case 'delete' :
|
2019-04-10 15:46:12 +00:00
|
|
|
$Event = new ZM\Event($_REQUEST['id']);
|
2020-05-23 14:15:48 +00:00
|
|
|
if ( !$Event->Id() ) {
|
2019-03-20 18:25:34 +00:00
|
|
|
ajaxResponse(array('refreshEvent'=>false, 'refreshParent'=>true, 'message'=> 'Event not found.'));
|
|
|
|
} else {
|
|
|
|
$Event->delete();
|
|
|
|
ajaxResponse(array('refreshEvent'=>false, 'refreshParent'=>true));
|
|
|
|
}
|
|
|
|
break;
|
2023-06-03 23:27:43 +00:00
|
|
|
case 'getselectedtags' :
|
|
|
|
$sql = '
|
|
|
|
SELECT
|
|
|
|
T.*
|
|
|
|
FROM Tags
|
|
|
|
AS T
|
|
|
|
INNER JOIN Events_Tags
|
|
|
|
AS ET
|
|
|
|
ON ET.TagId = T.Id
|
|
|
|
WHERE ET.EventId = ?
|
|
|
|
';
|
|
|
|
$values = array($_REQUEST['id']);
|
|
|
|
$response = dbFetchAll($sql, NULL, $values);
|
|
|
|
ajaxResponse(array('response'=>$response));
|
|
|
|
break;
|
|
|
|
case 'addtag' :
|
|
|
|
$sql = 'INSERT INTO Events_Tags (TagId, EventId, AssignedBy) VALUES (?, ?, ?)';
|
|
|
|
$values = array($_REQUEST['tid'], $_REQUEST['id'], $user->Id());
|
|
|
|
$response = dbFetchAll($sql, NULL, $values);
|
|
|
|
|
|
|
|
$sql = 'UPDATE Tags SET LastAssignedDate = NOW() WHERE Id = ?';
|
|
|
|
$values = array($_REQUEST['tid']);
|
|
|
|
dbFetchAll($sql, NULL, $values);
|
|
|
|
|
|
|
|
ajaxResponse(array('response'=>$response));
|
|
|
|
break;
|
|
|
|
case 'removetag' :
|
|
|
|
$tagId = $_REQUEST['tid'];
|
|
|
|
dbQuery('DELETE FROM Events_Tags WHERE TagId = ? AND EventId = ?', array($tagId, $_REQUEST['id']));
|
|
|
|
$sql = "SELECT * FROM Events_Tags WHERE TagId = $tagId";
|
|
|
|
$rowCount = dbNumRows($sql);
|
|
|
|
if ($rowCount < 1) {
|
|
|
|
$sql = 'DELETE FROM Tags WHERE Id = ?';
|
|
|
|
$values = array($_REQUEST['tid']);
|
|
|
|
$response = dbNumRows($sql, $values);
|
|
|
|
ajaxResponse(array('response'=>$response));
|
|
|
|
}
|
|
|
|
ajaxResponse();
|
|
|
|
break;
|
2019-03-20 18:25:34 +00:00
|
|
|
} // end switch action
|
2018-07-12 18:05:23 +00:00
|
|
|
} // end if canEdit('Events')
|
2008-07-14 13:54:50 +00:00
|
|
|
|
2023-04-23 16:57:29 +00:00
|
|
|
ajaxError('Unrecognised action '.$_REQUEST['action'].' or insufficient permissions for user '.$user->Username());
|
2008-07-14 13:54:50 +00:00
|
|
|
?>
|