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 2e09334b9c
commit 3ca920f1a9
1 changed files with 23 additions and 23 deletions

View File

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