diff --git a/web/includes/actions.php b/web/includes/actions.php index 1f0e0ec47..58e721751 100644 --- a/web/includes/actions.php +++ b/web/includes/actions.php @@ -133,37 +133,50 @@ if ( !empty($action) ) { $filterName = $_REQUEST['newFilterName']; } 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 { $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 ) { $_REQUEST['filter']['sort_field'] = validStr($_REQUEST['sort_field']); $_REQUEST['filter']['sort_asc'] = validStr($_REQUEST['sort_asc']); $_REQUEST['filter']['limit'] = validInt($_REQUEST['limit']); - $sql .= " Query = ".dbEscape(jsonEncode($_REQUEST['filter'])); + $sql .= ' Query = '.dbEscape(jsonEncode($_REQUEST['filter'])); if ( !empty($_REQUEST['AutoArchive']) ) - $sql .= ", AutoArchive = ".dbEscape($_REQUEST['AutoArchive']); + $sql .= ', AutoArchive = '.dbEscape($_REQUEST['AutoArchive']); if ( !empty($_REQUEST['AutoVideo']) ) - $sql .= ", AutoVideo = ".dbEscape($_REQUEST['AutoVideo']); + $sql .= ', AutoVideo = '.dbEscape($_REQUEST['AutoVideo']); if ( !empty($_REQUEST['AutoUpload']) ) - $sql .= ", AutoUpload = ".dbEscape($_REQUEST['AutoUpload']); + $sql .= ', AutoUpload = '.dbEscape($_REQUEST['AutoUpload']); if ( !empty($_REQUEST['AutoEmail']) ) - $sql .= ", AutoEmail = ".dbEscape($_REQUEST['AutoEmail']); + $sql .= ', AutoEmail = '.dbEscape($_REQUEST['AutoEmail']); if ( !empty($_REQUEST['AutoMessage']) ) - $sql .= ", AutoMessage = ".dbEscape($_REQUEST['AutoMessage']); + $sql .= ', AutoMessage = '.dbEscape($_REQUEST['AutoMessage']); 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']) ) - $sql .= ", AutoDelete = ".dbEscape($_REQUEST['AutoDelete']); + $sql .= ', AutoDelete = '.dbEscape($_REQUEST['AutoDelete']); if ( !empty($_REQUEST['background']) ) - $sql .= ", Background = ".dbEscape($_REQUEST['background']); + $sql .= ', Background = '.dbEscape($_REQUEST['background']); if ( !empty($_REQUEST['concurrent']) ) - $sql .= ", Concurrent = ".dbEscape($_REQUEST['concurrent']); + $sql .= ', Concurrent = '.dbEscape($_REQUEST['concurrent']); $sql .= $endSql; 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 action == filter diff --git a/web/skins/classic/views/filter.php b/web/skins/classic/views/filter.php index 47820ab50..40b26f0ea 100644 --- a/web/skins/classic/views/filter.php +++ b/web/skins/classic/views/filter.php @@ -26,13 +26,13 @@ $selectName = 'Id'; $filterNames = array( ''=>translate('ChooseFilter') ); $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']; if ( $row['Background'] ) - $filterNames[$row['Id']] .= "*"; + $filterNames[$row['Id']] .= '*'; if ( $row['Concurrent'] ) - $filterNames[$row['Id']] .= "&"; - if ( !empty($_REQUEST['reload']) && isset($_REQUEST['Id']) && $_REQUEST['Id'] == $row['Id'] ) { + $filterNames[$row['Id']] .= '&'; + if ( isset($_REQUEST['Id']) && $_REQUEST['Id'] == $row['Id'] ) { $dbFilter = $row; } } @@ -41,10 +41,12 @@ $backgroundStr = ''; if ( $dbFilter ) { if ( $dbFilter['Background'] ) $backgroundStr = '['.strtolower(translate('Background')).']'; + if ( $dbFilter['Concurrent'] ) + $backgroundStr .= '['.strtolower(translate('Concurrent')).']'; $_REQUEST['filter'] = jsonDecode( $dbFilter['Query'] ); - $_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['limit'] = isset($_REQUEST['filter']['limit'])?$_REQUEST['filter']['limit']:""; + $_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['limit'] = isset($_REQUEST['filter']['limit'])?$_REQUEST['filter']['limit']:''; unset( $_REQUEST['filter']['sort_field'] ); unset( $_REQUEST['filter']['sort_asc'] ); unset( $_REQUEST['filter']['limit'] ); @@ -71,8 +73,8 @@ $obracketTypes = array(); $cbracketTypes = array(); if ( isset($_REQUEST['filter']['terms']) ) { for ( $i = 0; $i <= count($_REQUEST['filter']['terms'])-2; $i++ ) { - $obracketTypes[$i] = str_repeat( "(", $i ); - $cbracketTypes[$i] = str_repeat( ")", $i ); + $obracketTypes[$i] = str_repeat( '(', $i ); + $cbracketTypes[$i] = str_repeat( ')', $i ); } } diff --git a/web/skins/classic/views/filtersave.php b/web/skins/classic/views/filtersave.php index c9c045242..48d68c3f5 100644 --- a/web/skins/classic/views/filtersave.php +++ b/web/skins/classic/views/filtersave.php @@ -18,21 +18,18 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // -if ( !canEdit( 'Events' ) ) -{ - $view = "error"; +if ( !canEdit( 'Events' ) ) { + $view = 'error'; return; } -$selectName = "Id"; -$newSelectName = "newFilterName"; -foreach ( dbFetchAll( "select * from Filters order by Name" ) as $row ) -{ - $filterNames[$row['Id']] = $row['Name']; - if ( $_REQUEST['Id'] == $row['Id'] ) - { - $filterData = $row; - } +$selectName = 'Id'; +$newSelectName = 'newFilterName'; +foreach ( dbFetchAll( 'SELECT * FROM Filters ORDER BY Name' ) as $row ) { + $filterNames[$row['Id']] = $row['Name']; + if ( $_REQUEST['Id'] == $row['Id'] ) { + $filterData = $row; + } } $focusWindow = true; @@ -64,13 +61,14 @@ xhtmlHeaders(__FILE__, translate('SaveFilter') ); +

- +