Bug 15354: Fix translated itemtype descriptions in circ rules
[srvgit] / admin / preferences.pl
index 2d0bac5..d9683f1 100755 (executable)
@@ -4,24 +4,22 @@
 #
 # 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 strict;
-use warnings;
+use Modern::Perl;
 
-use CGI;
-use Encode;
+use CGI qw ( -utf8 );
 use C4::Auth;
 use C4::Context;
 use C4::Koha;
@@ -36,6 +34,7 @@ use IO::File;
 use YAML::Syck qw();
 use List::MoreUtils qw(any);
 $YAML::Syck::ImplicitTyping = 1;
+$YAML::Syck::ImplicitUnicode = 1;
 our $lang;
 
 # use Smart::Comments;
@@ -55,7 +54,7 @@ sub GetTab {
         local_currency => $local_currency, # currency code is used, because we do not know how a given currency is formatted.
     );
 
-    return YAML::Syck::Load( Encode::decode('UTF-8',$tab_template->output()) );
+    return YAML::Syck::Load( $tab_template->output() );
 }
 
 sub _get_chunk {
@@ -106,6 +105,22 @@ sub _get_chunk {
             map { { text => $options{'choices'}->{$_}, value => $_, selected => ( $_ eq $value || ( $_ eq '' && ( $value eq '0' || !$value ) ) ) } }
             keys %{ $options{'choices'} }
         ];
+    } elsif ( $options{'multiple'} ) {
+        my @values;
+        @values = split /,/, $value if defined($value);
+        $chunk->{type}    = 'multiple';
+        $chunk->{CHOICES} = [
+            sort { $a->{'text'} cmp $b->{'text'} }
+              map {
+                my $option_value = $_;
+                {
+                    text     => $options{multiple}->{$option_value},
+                    value    => $option_value,
+                    selected => (grep /^$option_value$/, @values) ? 1 : 0,
+                }
+              }
+              keys %{ $options{multiple} }
+        ];
     }
 
     $chunk->{ 'type_' . $chunk->{'type'} } = 1;
@@ -248,7 +263,7 @@ sub SearchPrefs {
         if ( $matched_groups ) {
             my ( $title, $LINES ) = TransformPrefsToHTML( { $title => $matched_groups }, $searchfield );
 
-            push @tabs, { tab => $tab, tab_title => $title, LINES => $LINES, };
+            push @tabs, { tab => $tab, tab_title => $title, LINES => $LINES, tab_id => $tab_name };
         }
     }
 
@@ -257,7 +272,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;
@@ -332,7 +355,7 @@ if ( $op eq 'search' ) {
 if ( $tab ) {
     my ( $tab_title, $LINES ) = TransformPrefsToHTML( GetTab( $input, $tab ), $highlighted );
 
-    push @TABS, { tab_title => $tab_title, LINES => $LINES };
+    push @TABS, { tab_title => $tab_title, LINES => $LINES, tab_id => $tab };
     $template->param(
         $tab => 1,
         tab => $tab,