Bug 19451: (QA follow-up) Replace weird subquery
[koha.git] / admin / preferences.pl
index a6b4776..1e12b1e 100755 (executable)
@@ -4,18 +4,18 @@
 #
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
 
@@ -28,7 +28,7 @@ use C4::ClassSource;
 use C4::Log;
 use C4::Output;
 use C4::Templates;
-use C4::Budgets qw(GetCurrency);
+use Koha::Acquisition::Currencies;
 use File::Spec;
 use IO::File;
 use YAML::Syck qw();
@@ -45,10 +45,10 @@ sub GetTab {
 
     my $tab_template = C4::Templates::gettemplate( 'admin/preferences/' . $tab . '.pref', 'intranet', $input );
 
-    my $active_currency = GetCurrency();
+    my $active_currency = Koha::Acquisition::Currencies->get_active;
     my $local_currency;
     if ($active_currency) {
-        $local_currency = $active_currency->{currency};
+        $local_currency = $active_currency->currency;
     }
     $tab_template->param(
         local_currency => $local_currency, # currency code is used, because we do not know how a given currency is formatted.
@@ -106,7 +106,8 @@ sub _get_chunk {
             keys %{ $options{'choices'} }
         ];
     } elsif ( $options{'multiple'} ) {
-        my @values = split /,/, $value;
+        my @values;
+        @values = split /,/, $value if defined($value);
         $chunk->{type}    = 'multiple';
         $chunk->{CHOICES} = [
             sort { $a->{'text'} cmp $b->{'text'} }
@@ -115,7 +116,7 @@ sub _get_chunk {
                 {
                     text     => $options{multiple}->{$option_value},
                     value    => $option_value,
-                    selected => grep /^$option_value$/, @values,
+                    selected => (grep /^$option_value$/, @values) ? 1 : 0,
                 }
               }
               keys %{ $options{multiple} }
@@ -185,6 +186,15 @@ sub TransformPrefsToHTML {
                         push @chunks, $piece;
                     }
                 } else {
+                    if ( $piece ) {
+                        my $version = Koha::version();
+                        my ( $major, $minor, $maintenance, $development ) = split( '\.', $version );
+                        if ( $minor % 2 ) {
+                            $piece =~ s|__VERSION__|${major}_${minor}|g;
+                        } else {
+                            $piece =~ s|__VERSION__|master|g;
+                        }
+                    }
                     push @chunks, { type_text => 1, contents => $piece };
                 }
             }
@@ -271,7 +281,15 @@ sub SearchPrefs {
 
 sub matches {
     my ( $text, $terms ) = @_;
-    if ( $text ) { return !grep( { $text !~ /$_/i } @$terms ); }
+    if ( $text ) {
+        return !grep(
+            {
+                my $re = eval{qr|$_|i};
+                $re = qr|\Q$_\E| if $@;
+                $text !~ m|$re|;
+            } @$terms
+        )
+    }
 }
 
 my $dbh = C4::Context->dbh;
@@ -296,17 +314,14 @@ $tab ||= 'acquisitions'; # Ideally this should be "local-use" but preferences.pl
 my $highlighted;
 
 if ( $op eq 'save' ) {
-    unless ( C4::Context->config( 'demo' ) ) {
-        foreach my $param ( $input->param() ) {
-            my ( $pref ) = ( $param =~ /pref_(.*)/ );
+    foreach my $param ( $input->param() ) {
+        my ( $pref ) = ( $param =~ /pref_(.*)/ );
 
-            next if ( !defined( $pref ) );
+        next if ( !defined( $pref ) );
 
-            my $value = join( ',', $input->param( $param ) );
+        my $value = join( ',', $input->param( $param ) );
 
-            C4::Context->set_preference( $pref, $value );
-            logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $pref . " | " . $value );
-        }
+        C4::Context->set_preference( $pref, $value );
     }
 
     print $input->redirect( '/cgi-bin/koha/admin/preferences.pl?tab=' . $tab );