X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=admin%2Fpreferences.pl;h=d9683f125c1062201d5417b747f090b00fb596ef;hb=cc87d60b4afd274b6282dfd2e79ce8ffa845ef1f;hp=db91e76e7da0c0f8db333818a828ba929da1b3bc;hpb=dc1680f8a97e3632dbc388bf15edfcb36d8911ff;p=koha.git diff --git a/admin/preferences.pl b/admin/preferences.pl index db91e76e7d..d9683f125c 100755 --- a/admin/preferences.pl +++ b/admin/preferences.pl @@ -4,23 +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 . -use strict; -use warnings; +use Modern::Perl; -use CGI; +use CGI qw ( -utf8 ); use C4::Auth; use C4::Context; use C4::Koha; @@ -33,7 +32,9 @@ use C4::Budgets qw(GetCurrency); use File::Spec; 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; @@ -104,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; @@ -120,6 +137,13 @@ sub TransformPrefsToHTML { my $tab = $data->{ $title }; $tab = { '' => $tab } if ( ref( $tab ) eq 'ARRAY' ); + my @override_syspref_names; + if ( exists($ENV{OVERRIDE_SYSPREF_NAMES}) && + defined($ENV{OVERRIDE_SYSPREF_NAMES}) + ) { + @override_syspref_names = split /,/, $ENV{OVERRIDE_SYSPREF_NAMES}; + } + foreach my $group ( sort keys %$tab ) { if ( $group ) { push @lines, { is_group_title => 1, title => $group }; @@ -156,6 +180,7 @@ sub TransformPrefsToHTML { $name_entry->{'highlighted'} = 1; } } + $name_entry->{'overridden'} = 1 if ( any { $name eq $_ } @override_syspref_names ); push @names, $name_entry; } else { push @chunks, $piece; @@ -164,7 +189,6 @@ sub TransformPrefsToHTML { push @chunks, { type_text => 1, contents => $piece }; } } - push @lines, { CHUNKS => \@chunks, NAMES => \@names, is_group_title => 0 }; } } @@ -216,12 +240,10 @@ sub SearchPrefs { foreach my $piece ( @$line ) { if ( ref( $piece ) eq 'HASH' ) { - if ( !$piece->{'pref'} ){ next; } - if ( $piece->{'pref'} =~ /^$searchfield$/i ) { - my ( undef, $LINES ) = TransformPrefsToHTML( $data, $searchfield ); - - return { search_jumped => 1, tab => $tab_name, tab_title => $title, LINES => $LINES }; - } elsif ( matches( $piece->{'pref'}, \@terms) ) { + if ( !$piece->{'pref'} ){ + next; + } + if ( matches( $piece->{'pref'}, \@terms) ) { $matched = 1; } elsif ( ref( $piece->{'choices'} ) eq 'HASH' && grep( { $_ && matches( $_, \@terms ) } values( %{ $piece->{'choices'} } ) ) ) { $matched = 1; @@ -241,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 }; } } @@ -250,14 +272,22 @@ 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; our $input = new CGI; my ( $template, $borrowernumber, $cookie ) = get_template_and_user( - { template_name => "admin/preferences.tmpl", + { template_name => "admin/preferences.tt", query => $input, type => "intranet", authnotrequired => 0, @@ -325,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,