updates in filters, try to get the new filter loaded when saving with a new name

This commit is contained in:
Isaac Connor 2017-03-27 13:12:37 -04:00
parent 146ac87b51
commit 8ef7a708bd
3 changed files with 48 additions and 35 deletions

View File

@ -133,37 +133,50 @@ if ( !empty($action) ) {
$filterName = $_REQUEST['newFilterName']; $filterName = $_REQUEST['newFilterName'];
} }
if ( $filterName ) { if ( $filterName ) {
$sql = "REPLACE INTO Filters SET Name = ".dbEscape($filterName).","; # Replace will teplace any filter with the same Id
# Since we aren't specifying the Id , this is effectively an insert
$sql = 'REPLACE INTO Filters SET Name = '.dbEscape($filterName).',';
} else { } else {
$sql = 'UPDATE Filters SET'; $sql = 'UPDATE Filters SET';
$endSql = "where Id = ".$_REQUEST['Id']; $endSql = 'WHERE Id = '.$_REQUEST['Id'];
} }
# endSql is only set if ! filterName... so... woulnd't this always be true
if ( !empty($filterName) || $endSql ) { if ( !empty($filterName) || $endSql ) {
$_REQUEST['filter']['sort_field'] = validStr($_REQUEST['sort_field']); $_REQUEST['filter']['sort_field'] = validStr($_REQUEST['sort_field']);
$_REQUEST['filter']['sort_asc'] = validStr($_REQUEST['sort_asc']); $_REQUEST['filter']['sort_asc'] = validStr($_REQUEST['sort_asc']);
$_REQUEST['filter']['limit'] = validInt($_REQUEST['limit']); $_REQUEST['filter']['limit'] = validInt($_REQUEST['limit']);
$sql .= " Query = ".dbEscape(jsonEncode($_REQUEST['filter'])); $sql .= ' Query = '.dbEscape(jsonEncode($_REQUEST['filter']));
if ( !empty($_REQUEST['AutoArchive']) ) if ( !empty($_REQUEST['AutoArchive']) )
$sql .= ", AutoArchive = ".dbEscape($_REQUEST['AutoArchive']); $sql .= ', AutoArchive = '.dbEscape($_REQUEST['AutoArchive']);
if ( !empty($_REQUEST['AutoVideo']) ) if ( !empty($_REQUEST['AutoVideo']) )
$sql .= ", AutoVideo = ".dbEscape($_REQUEST['AutoVideo']); $sql .= ', AutoVideo = '.dbEscape($_REQUEST['AutoVideo']);
if ( !empty($_REQUEST['AutoUpload']) ) if ( !empty($_REQUEST['AutoUpload']) )
$sql .= ", AutoUpload = ".dbEscape($_REQUEST['AutoUpload']); $sql .= ', AutoUpload = '.dbEscape($_REQUEST['AutoUpload']);
if ( !empty($_REQUEST['AutoEmail']) ) if ( !empty($_REQUEST['AutoEmail']) )
$sql .= ", AutoEmail = ".dbEscape($_REQUEST['AutoEmail']); $sql .= ', AutoEmail = '.dbEscape($_REQUEST['AutoEmail']);
if ( !empty($_REQUEST['AutoMessage']) ) if ( !empty($_REQUEST['AutoMessage']) )
$sql .= ", AutoMessage = ".dbEscape($_REQUEST['AutoMessage']); $sql .= ', AutoMessage = '.dbEscape($_REQUEST['AutoMessage']);
if ( !empty($_REQUEST['AutoExecute']) && !empty($_REQUEST['AutoExecuteCmd']) ) if ( !empty($_REQUEST['AutoExecute']) && !empty($_REQUEST['AutoExecuteCmd']) )
$sql .= ", AutoExecute = ".dbEscape($_REQUEST['AutoExecute']).", AutoExecuteCmd = ".dbEscape($_REQUEST['AutoExecuteCmd']); $sql .= ', AutoExecute = '.dbEscape($_REQUEST['AutoExecute']).", AutoExecuteCmd = ".dbEscape($_REQUEST['AutoExecuteCmd']);
if ( !empty($_REQUEST['AutoDelete']) ) if ( !empty($_REQUEST['AutoDelete']) )
$sql .= ", AutoDelete = ".dbEscape($_REQUEST['AutoDelete']); $sql .= ', AutoDelete = '.dbEscape($_REQUEST['AutoDelete']);
if ( !empty($_REQUEST['background']) ) if ( !empty($_REQUEST['background']) )
$sql .= ", Background = ".dbEscape($_REQUEST['background']); $sql .= ', Background = '.dbEscape($_REQUEST['background']);
if ( !empty($_REQUEST['concurrent']) ) if ( !empty($_REQUEST['concurrent']) )
$sql .= ", Concurrent = ".dbEscape($_REQUEST['concurrent']); $sql .= ', Concurrent = '.dbEscape($_REQUEST['concurrent']);
$sql .= $endSql; $sql .= $endSql;
dbQuery( $sql ); dbQuery( $sql );
$refreshParent = true; if ( $filterName ) {
$filter = dbFetchOne( 'SELECT * FROM Filters WHERE Name=?', NULL, array($filterName) );
if ( $filter ) {
# This won't work yet because refreshparent refreshes the old filter. Need to do a redirect instead of a refresh.
$_REQUEST['Id'] = $filter['Id'];
} else {
Error("No new Id despite new name");
}
}
$refreshParent = '/index.php?view=filter&Id='.$_REQUEST['Id'];
} }
} // end if canedit events } // end if canedit events
} // end if action == filter } // end if action == filter

View File

@ -26,13 +26,13 @@ $selectName = 'Id';
$filterNames = array( ''=>translate('ChooseFilter') ); $filterNames = array( ''=>translate('ChooseFilter') );
$dbFilter = NULL; $dbFilter = NULL;
foreach ( dbFetchAll( "select * from Filters order by Name" ) as $row ) { foreach ( dbFetchAll( 'SELECT * FROM Filters ORDER BY Name' ) as $row ) {
$filterNames[$row['Id']] = $row['Name']; $filterNames[$row['Id']] = $row['Name'];
if ( $row['Background'] ) if ( $row['Background'] )
$filterNames[$row['Id']] .= "*"; $filterNames[$row['Id']] .= '*';
if ( $row['Concurrent'] ) if ( $row['Concurrent'] )
$filterNames[$row['Id']] .= "&"; $filterNames[$row['Id']] .= '&';
if ( !empty($_REQUEST['reload']) && isset($_REQUEST['Id']) && $_REQUEST['Id'] == $row['Id'] ) { if ( isset($_REQUEST['Id']) && $_REQUEST['Id'] == $row['Id'] ) {
$dbFilter = $row; $dbFilter = $row;
} }
} }
@ -41,10 +41,12 @@ $backgroundStr = '';
if ( $dbFilter ) { if ( $dbFilter ) {
if ( $dbFilter['Background'] ) if ( $dbFilter['Background'] )
$backgroundStr = '['.strtolower(translate('Background')).']'; $backgroundStr = '['.strtolower(translate('Background')).']';
if ( $dbFilter['Concurrent'] )
$backgroundStr .= '['.strtolower(translate('Concurrent')).']';
$_REQUEST['filter'] = jsonDecode( $dbFilter['Query'] ); $_REQUEST['filter'] = jsonDecode( $dbFilter['Query'] );
$_REQUEST['sort_field'] = isset($_REQUEST['filter']['sort_field'])?$_REQUEST['filter']['sort_field']:"DateTime"; $_REQUEST['sort_field'] = isset($_REQUEST['filter']['sort_field'])?$_REQUEST['filter']['sort_field']:'DateTime';
$_REQUEST['sort_asc'] = isset($_REQUEST['filter']['sort_asc'])?$_REQUEST['filter']['sort_asc']:"1"; $_REQUEST['sort_asc'] = isset($_REQUEST['filter']['sort_asc'])?$_REQUEST['filter']['sort_asc']:'1';
$_REQUEST['limit'] = isset($_REQUEST['filter']['limit'])?$_REQUEST['filter']['limit']:""; $_REQUEST['limit'] = isset($_REQUEST['filter']['limit'])?$_REQUEST['filter']['limit']:'';
unset( $_REQUEST['filter']['sort_field'] ); unset( $_REQUEST['filter']['sort_field'] );
unset( $_REQUEST['filter']['sort_asc'] ); unset( $_REQUEST['filter']['sort_asc'] );
unset( $_REQUEST['filter']['limit'] ); unset( $_REQUEST['filter']['limit'] );
@ -71,8 +73,8 @@ $obracketTypes = array();
$cbracketTypes = array(); $cbracketTypes = array();
if ( isset($_REQUEST['filter']['terms']) ) { if ( isset($_REQUEST['filter']['terms']) ) {
for ( $i = 0; $i <= count($_REQUEST['filter']['terms'])-2; $i++ ) { for ( $i = 0; $i <= count($_REQUEST['filter']['terms'])-2; $i++ ) {
$obracketTypes[$i] = str_repeat( "(", $i ); $obracketTypes[$i] = str_repeat( '(', $i );
$cbracketTypes[$i] = str_repeat( ")", $i ); $cbracketTypes[$i] = str_repeat( ')', $i );
} }
} }

View File

@ -18,21 +18,18 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// //
if ( !canEdit( 'Events' ) ) if ( !canEdit( 'Events' ) ) {
{ $view = 'error';
$view = "error";
return; return;
} }
$selectName = "Id"; $selectName = 'Id';
$newSelectName = "newFilterName"; $newSelectName = 'newFilterName';
foreach ( dbFetchAll( "select * from Filters order by Name" ) as $row ) foreach ( dbFetchAll( 'SELECT * FROM Filters ORDER BY Name' ) as $row ) {
{ $filterNames[$row['Id']] = $row['Name'];
$filterNames[$row['Id']] = $row['Name']; if ( $_REQUEST['Id'] == $row['Id'] ) {
if ( $_REQUEST['Id'] == $row['Id'] ) $filterData = $row;
{ }
$filterData = $row;
}
} }
$focusWindow = true; $focusWindow = true;
@ -64,13 +61,14 @@ xhtmlHeaders(__FILE__, translate('SaveFilter') );
<input type="hidden" name="AutoExecute" value="<?php echo requestVar( 'AutoExecute' ) ?>"/> <input type="hidden" name="AutoExecute" value="<?php echo requestVar( 'AutoExecute' ) ?>"/>
<input type="hidden" name="AutoExecuteCmd" value="<?php echo requestVar( 'AutoExecuteCmd' ) ?>"/> <input type="hidden" name="AutoExecuteCmd" value="<?php echo requestVar( 'AutoExecuteCmd' ) ?>"/>
<input type="hidden" name="AutoDelete" value="<?php echo requestVar( 'AutoDelete' ) ?>"/> <input type="hidden" name="AutoDelete" value="<?php echo requestVar( 'AutoDelete' ) ?>"/>
<input type="hidden" name="Id" value="<?php echo $filterData['Id'] ?>"/>
<?php if ( count($filterNames) ) { ?> <?php if ( count($filterNames) ) { ?>
<p> <p>
<label for="<?php echo $selectName ?>"><?php echo translate('SaveAs') ?></label><?php echo buildSelect( $selectName, $filterNames ); ?><label for="<?php echo $newSelectName ?>"><?php echo translate('OrEnterNewName') ?></label><input type="text" size="32" id="<?php echo $newSelectName ?>" name="<?php echo $newSelectName ?>" value="<?php echo requestVar('filterName') ?>"/> <label for="<?php echo $selectName ?>"><?php echo translate('SaveAs') ?></label><?php echo buildSelect( $selectName, $filterNames ); ?><label for="<?php echo $newSelectName ?>"><?php echo translate('OrEnterNewName') ?></label><input type="text" size="32" id="<?php echo $newSelectName ?>" name="<?php echo $newSelectName ?>" value="<?php echo requestVar('filterName') ?>"/>
</p> </p>
<?php } else { ?> <?php } else { ?>
<p> <p>
<label for="<?php echo $newSelectName ?>"><?php echo translate('EnterNewFilterName') ?></label><input type="text" size="32" id="<?php echo $newSelectName ?>" name="<?php echo $newSelectName ?>" value=""> <label for="<?php echo $newSelectName ?>"><?php echo translate('EnterNewFilterName') ?></label><input type="text" id="<?php echo $newSelectName ?>" name="<?php echo $newSelectName ?>" />
</p> </p>
<?php } ?> <?php } ?>
<p> <p>