spacing. Add defaults for AutoMoveTo and AutoCopyTo so that we don't get false changes. redirect is a global, so make it so. Re-null the Id of the filter object after temp execute so that we don't reference a no longer existing filter.

This commit is contained in:
Isaac Connor 2021-08-12 12:53:46 -04:00
parent ccb4bb27dd
commit cd3359c3eb
1 changed files with 23 additions and 23 deletions

View File

@ -20,40 +20,39 @@
global $error_message; global $error_message;
// Event scope actions, view permissions only required // Event scope actions, view permissions only required
if ( !canView('Events') ) { if (!canView('Events')) {
$error_message = 'You do not have permission to view Events.'; $error_message = 'You do not have permission to view Events.';
ZM\Warning($error_message); ZM\Warning($error_message);
return; return;
} }
if ( isset($_REQUEST['object']) and ( $_REQUEST['object'] == 'filter' ) ) { if (isset($_REQUEST['object']) and ($_REQUEST['object'] == 'filter')) {
if ( $action == 'addterm' ) { if ($action == 'addterm') {
$_REQUEST['filter'] = addFilterTerm($_REQUEST['filter'], $_REQUEST['line']); $_REQUEST['filter'] = addFilterTerm($_REQUEST['filter'], $_REQUEST['line']);
} elseif ( $action == 'delterm' ) { } else if ($action == 'delterm') {
$_REQUEST['filter'] = delFilterTerm($_REQUEST['filter'], $_REQUEST['line']); $_REQUEST['filter'] = delFilterTerm($_REQUEST['filter'], $_REQUEST['line']);
} else if ( canEdit('Events') ) { } else if (canEdit('Events')) {
require_once('includes/Filter.php'); require_once('includes/Filter.php');
$filter = new ZM\Filter($_REQUEST['Id']); $filter = new ZM\Filter($_REQUEST['Id']);
if ( $action == 'delete' ) { if ($action == 'delete') {
if ( !empty($_REQUEST['Id']) ) { if (!empty($_REQUEST['Id'])) {
if ( $filter->Background() ) { if ($filter->Background()) {
$filter->control('stop'); $filter->control('stop');
} }
$filter->delete(); $filter->delete();
} else { } else {
ZM\Error('No filter id passed when deleting'); ZM\Error('No filter id passed when deleting');
} }
} else if ( ( $action == 'Save' ) or ( $action == 'SaveAs' ) or ( $action == 'execute' ) ) { } else if (( $action == 'Save' ) or ( $action == 'SaveAs' ) or ( $action == 'execute' )) {
$_REQUEST['filter']['Query']['sort_field'] = validStr($_REQUEST['filter']['Query']['sort_field']); $_REQUEST['filter']['Query']['sort_field'] = validStr($_REQUEST['filter']['Query']['sort_field']);
$_REQUEST['filter']['Query']['sort_asc'] = validStr($_REQUEST['filter']['Query']['sort_asc']); $_REQUEST['filter']['Query']['sort_asc'] = validStr($_REQUEST['filter']['Query']['sort_asc']);
$_REQUEST['filter']['Query']['limit'] = validInt($_REQUEST['filter']['Query']['limit']); $_REQUEST['filter']['Query']['limit'] = validInt($_REQUEST['filter']['Query']['limit']);
$_REQUEST['filter']['AutoCopy'] = empty($_REQUEST['filter']['AutoCopy']) ? 0 : 1; $_REQUEST['filter']['AutoCopy'] = empty($_REQUEST['filter']['AutoCopy']) ? 0 : 1;
$_REQUEST['filter']['AutoCopyTo'] = empty($_REQUEST['filter']['AutoCopyTo']) ? 0 : $_REQUEST['filter']['AutoCopyTo'];
$_REQUEST['filter']['AutoMove'] = empty($_REQUEST['filter']['AutoMove']) ? 0 : 1; $_REQUEST['filter']['AutoMove'] = empty($_REQUEST['filter']['AutoMove']) ? 0 : 1;
$_REQUEST['filter']['AutoMoveTo'] = empty($_REQUEST['filter']['AutoMoveTo']) ? 0 : $_REQUEST['filter']['AutoMoveTo'];
$_REQUEST['filter']['AutoArchive'] = empty($_REQUEST['filter']['AutoArchive']) ? 0 : 1; $_REQUEST['filter']['AutoArchive'] = empty($_REQUEST['filter']['AutoArchive']) ? 0 : 1;
$_REQUEST['filter']['AutoVideo'] = empty($_REQUEST['filter']['AutoVideo']) ? 0 : 1; $_REQUEST['filter']['AutoVideo'] = empty($_REQUEST['filter']['AutoVideo']) ? 0 : 1;
$_REQUEST['filter']['AutoUpload'] = empty($_REQUEST['filter']['AutoUpload']) ? 0 : 1; $_REQUEST['filter']['AutoUpload'] = empty($_REQUEST['filter']['AutoUpload']) ? 0 : 1;
@ -65,7 +64,7 @@ if ( isset($_REQUEST['object']) and ( $_REQUEST['object'] == 'filter' ) ) {
$_REQUEST['filter']['Background'] = empty($_REQUEST['filter']['Background']) ? 0 : 1; $_REQUEST['filter']['Background'] = empty($_REQUEST['filter']['Background']) ? 0 : 1;
$_REQUEST['filter']['Concurrent'] = empty($_REQUEST['filter']['Concurrent']) ? 0 : 1; $_REQUEST['filter']['Concurrent'] = empty($_REQUEST['filter']['Concurrent']) ? 0 : 1;
$changes = $filter->changes($_REQUEST['filter']); $changes = $filter->changes($_REQUEST['filter']);
ZM\Debug('Changes: ' . print_r($changes,true)); ZM\Debug('Changes: ' . print_r($changes, true));
if ($filter->Id() and ($action == 'Save')) { if ($filter->Id() and ($action == 'Save')) {
if ($filter->Background()) $filter->control('stop'); if ($filter->Background()) $filter->control('stop');
@ -74,12 +73,13 @@ if ( isset($_REQUEST['object']) and ( $_REQUEST['object'] == 'filter' ) ) {
return; return;
} }
} else { } else {
if ( $action == 'execute' ) { if ($action == 'execute') {
if ( count($changes) ) { # If there are changes use a temp filter to do the execute
if (count($changes)) {
$filter->Name('_TempFilter'.time()); $filter->Name('_TempFilter'.time());
$filter->Id(null); $filter->Id(null);
} }
} else if ( $action == 'SaveAs' ) { } else if ($action == 'SaveAs') {
$filter->Id(null); $filter->Id(null);
} }
if (!$filter->save($changes)) { if (!$filter->save($changes)) {
@ -91,18 +91,19 @@ if ( isset($_REQUEST['object']) and ( $_REQUEST['object'] == 'filter' ) ) {
$_REQUEST['Id'] = $filter->Id(); $_REQUEST['Id'] = $filter->Id();
} }
if ( $action == 'execute' ) { if ($action == 'execute') {
$filter->execute(); $filter->execute();
if ( count($changes) ) if (count($changes)) {
$filter->delete(); $filter->delete();
$filter->Id(null);
$view = 'events'; }
} else if ( $filter->Background() ) { } else if ($filter->Background()) {
$filter->control('start'); $filter->control('start');
} }
global $redirect;
$redirect = '?view=filter'.$filter->querystring('filter', '&'); $redirect = '?view=filter'.$filter->querystring('filter', '&');
} else if ( $action == 'control' ) { } else if ($action == 'control') {
if ( $_REQUEST['command'] == 'start' if ( $_REQUEST['command'] == 'start'
or $_REQUEST['command'] == 'stop' or $_REQUEST['command'] == 'stop'
or $_REQUEST['command'] == 'restart' or $_REQUEST['command'] == 'restart'
@ -114,5 +115,4 @@ if ( isset($_REQUEST['object']) and ( $_REQUEST['object'] == 'filter' ) ) {
} // end if save or execute } // end if save or execute
} // end if canEdit(Events) } // end if canEdit(Events)
} // end if object == filter } // end if object == filter
?> ?>