Files
zoneminder/web/includes/actions/event.php
Jash Ambaliya a6d9c0acc0 fix: event actions report a failed write instead of auditing and refreshing (#7950)
* fix: event actions report a failed write instead of auditing and refreshing refs #7949

* test: event delete actions rely on deleteEvent returning the delete result refs #7949
2026-11-24 22:32:39 -05:00

72 lines
2.8 KiB
PHP

<?php
//
// ZoneMinder web action
// Copyright (C) 2019 ZoneMinder LLC
//
// 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.
//
// If there is an action on an event, then we must have an id.
if ( empty($_REQUEST['eid']) ) {
ZM\Warning('No eid in action on event view');
return;
}
// Event scope actions. Require edit on this event, which includes access to its monitor.
global $error_message;
$event = new ZM\Event(validCardinal($_REQUEST['eid']));
if ( $event->Id() and $event->canEdit() ) {
$_REQUEST['eid'] = $event->Id();
$failMessage = '';
if ( ($action == 'rename') && isset($_REQUEST['eventName']) ) {
if ( dbQuery('UPDATE Events SET Name=? WHERE Id=?', array($_REQUEST['eventName'], $_REQUEST['eid'])) === null ) {
$failMessage = 'Error renaming event '.$_REQUEST['eid'].': '.htmlspecialchars(dbLastError()).'<br/>';
} else {
ZM\AuditAction('rename', 'event', $_REQUEST['eid'], 'Name: '.$_REQUEST['eventName']);
}
} else if ( $action == 'eventdetail' ) {
if ( dbQuery('UPDATE Events SET Cause=?, Notes=? WHERE Id=?',
array(
$_REQUEST['newEvent']['Cause'],
$_REQUEST['newEvent']['Notes'],
$_REQUEST['eid']
)
) === null ) {
$failMessage = 'Error updating event '.$_REQUEST['eid'].': '.htmlspecialchars(dbLastError()).'<br/>';
} else {
ZM\AuditAction('update', 'event', $_REQUEST['eid'], 'Detail update');
$refreshParent = true;
$closePopup = true;
}
} else if ( $action == 'archive' or $action == 'unarchive' ) {
if ( dbQuery('UPDATE Events SET Archived=? WHERE Id=?', array(($action == 'archive') ? 1 : 0, $_REQUEST['eid'])) === null ) {
$failMessage = 'Error updating event '.$_REQUEST['eid'].': '.htmlspecialchars(dbLastError()).'<br/>';
}
} else if ( $action == 'delete' ) {
if ( deleteEvent($_REQUEST['eid']) ) {
ZM\AuditAction('delete', 'event', $_REQUEST['eid'], '');
$refreshParent = true;
} else {
$failMessage = 'Error deleting event '.$_REQUEST['eid'].'<br/>';
}
}
if ( $failMessage !== '' ) {
ZM\Warning(strip_tags($failMessage));
$error_message .= $failMessage;
}
} // end if event canEdit
?>