Fix deleting snapshots

This commit is contained in:
Isaac Connor 2021-08-06 13:11:04 -04:00
parent ad9ce720fd
commit 2f7c44dce2
1 changed files with 18 additions and 15 deletions

View File

@ -8,21 +8,23 @@ $data = array();
// INITIALIZE AND CHECK SANITY // INITIALIZE AND CHECK SANITY
// //
if ( !canView('Snapshots') ) $message = 'Insufficient permissions for user '.$user['Username']; if (!canView('Snapshots'))
$message = 'Insufficient permissions for user '.$user['Username'];
if ( empty($_REQUEST['task']) ) { $task = '';
if (empty($_REQUEST['task'])) {
$message = 'Must specify a task'; $message = 'Must specify a task';
} else { } else {
$task = $_REQUEST['task']; $task = $_REQUEST['task'];
} }
if ( empty($_REQUEST['ids']) ) { if (empty($_REQUEST['ids'])) {
if ( isset($_REQUEST['task']) && $_REQUEST['task'] != 'query' ) $message = 'No snapshot id(s) supplied'; if ($task != 'query') $message = 'No snapshot id(s) supplied';
} else { } else {
$eids = $_REQUEST['ids']; $ids = $_REQUEST['ids'];
} }
if ( $message ) { if ($message) {
ajaxError($message); ajaxError($message);
return; return;
} }
@ -36,15 +38,15 @@ $advsearch = isset($_REQUEST['advsearch']) ? json_decode($_REQUEST['advsearch'],
// Sort specifies the name of the column to sort on // Sort specifies the name of the column to sort on
$sort = 'Id'; $sort = 'Id';
if ( isset($_REQUEST['sort']) ) { if (isset($_REQUEST['sort'])) {
$sort = $_REQUEST['sort']; $sort = $_REQUEST['sort'];
} }
// Offset specifies the starting row to return, used for pagination // Offset specifies the starting row to return, used for pagination
$offset = 0; $offset = 0;
if ( isset($_REQUEST['offset']) ) { if (isset($_REQUEST['offset'])) {
if ( ( !is_int($_REQUEST['offset']) and !ctype_digit($_REQUEST['offset']) ) ) { if ((!is_int($_REQUEST['offset']) and !ctype_digit($_REQUEST['offset']))) {
ZM\Error('Invalid value for offset: ' . $_REQUEST['offset']); ZM\Error('Invalid value for offset: '.$_REQUEST['offset']);
} else { } else {
$offset = $_REQUEST['offset']; $offset = $_REQUEST['offset'];
} }
@ -56,8 +58,8 @@ $order = (isset($_REQUEST['order']) and (strtolower($_REQUEST['order']) == 'asc'
// Limit specifies the number of rows to return // Limit specifies the number of rows to return
// Set the default to 0 for events view, to prevent an issue with ALL pagination // Set the default to 0 for events view, to prevent an issue with ALL pagination
$limit = 0; $limit = 0;
if ( isset($_REQUEST['limit']) ) { if (isset($_REQUEST['limit'])) {
if ( ( !is_int($_REQUEST['limit']) and !ctype_digit($_REQUEST['limit']) ) ) { if ((!is_int($_REQUEST['limit']) and !ctype_digit($_REQUEST['limit']))) {
ZM\Error('Invalid value for limit: ' . $_REQUEST['limit']); ZM\Error('Invalid value for limit: ' . $_REQUEST['limit']);
} else { } else {
$limit = $_REQUEST['limit']; $limit = $_REQUEST['limit'];
@ -68,14 +70,14 @@ if ( isset($_REQUEST['limit']) ) {
// MAIN LOOP // MAIN LOOP
// //
switch ( $task ) { switch ($task) {
case 'delete' : case 'delete' :
if ( !canEdit('Snapshots') ) { if (!canEdit('Snapshots')) {
ajaxError('Insufficient permissions for user '.$user['Username']); ajaxError('Insufficient permissions for user '.$user['Username']);
return; return;
} }
foreach ( $ids as $id ) $data[] = deleteRequest($id); foreach ($ids as $id) $data[] = deleteRequest($id);
break; break;
case 'query' : case 'query' :
$data = queryRequest($search, $advsearch, $sort, $offset, $order, $limit); $data = queryRequest($search, $advsearch, $sort, $offset, $order, $limit);
@ -99,6 +101,7 @@ function deleteRequest($id) {
//$message[] = array($id=>'Event is archived, cannot delete it.'); //$message[] = array($id=>'Event is archived, cannot delete it.');
} else { } else {
$snapshot->delete(); $snapshot->delete();
$message[] = array($id=>'Snapshot deleted.');
} }
return $message; return $message;