X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=admin%2Fpreferences.pl;h=1513adc5c6713c81b5faeee06249614646fd1983;hb=5d6c092921919526ade501facb1220f8a108a08f;hp=d523c755b502eee526340ae5dc942d6e854d58a2;hpb=8e00f55216feb6b160d281b7020639cc27928dd2;p=koha_fer diff --git a/admin/preferences.pl b/admin/preferences.pl index d523c755b5..1513adc5c6 100755 --- a/admin/preferences.pl +++ b/admin/preferences.pl @@ -21,6 +21,7 @@ use strict; use warnings; use CGI; +use Encode; use C4::Auth; use C4::Context; use C4::Koha; @@ -28,10 +29,12 @@ use C4::Languages qw(getTranslatedLanguages); use C4::ClassSource; use C4::Log; use C4::Output; +use C4::Templates; use C4::Budgets qw(GetCurrency); use File::Spec; use IO::File; use YAML::Syck qw(); +use List::MoreUtils qw(any); $YAML::Syck::ImplicitTyping = 1; our $lang; @@ -41,7 +44,7 @@ our $lang; sub GetTab { my ( $input, $tab ) = @_; - my $tab_template = C4::Output::gettemplate( 'admin/preferences/' . $tab . '.pref', 'intranet', $input ); + my $tab_template = C4::Templates::gettemplate( 'admin/preferences/' . $tab . '.pref', 'intranet', $input ); my $active_currency = GetCurrency(); my $local_currency; @@ -52,7 +55,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( $tab_template->output() ); + return YAML::Syck::Load( Encode::decode('UTF-8',$tab_template->output()) ); } sub _get_chunk { @@ -119,6 +122,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 }; @@ -155,6 +165,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; @@ -163,7 +174,6 @@ sub TransformPrefsToHTML { push @chunks, { type_text => 1, contents => $piece }; } } - push @lines, { CHUNKS => \@chunks, NAMES => \@names, is_group_title => 0 }; } } @@ -174,7 +184,7 @@ sub TransformPrefsToHTML { sub _get_pref_files { my ( $input, $open_files ) = @_; - my ( $htdocs, $theme, $lang, undef ) = C4::Output::_get_template_file( 'admin/preferences/admin.pref', 'intranet', $input ); + my ( $htdocs, $theme, $lang, undef ) = C4::Templates::_get_template_file( 'admin/preferences/admin.pref', 'intranet', $input ); my %results; @@ -194,12 +204,6 @@ sub SearchPrefs { my %tab_files = _get_pref_files( $input ); our @terms = split( /\s+/, $searchfield ); - sub matches { - my ( $text ) = @_; - - return !grep( { $text !~ /$_/i } @terms ); - } - foreach my $tab_name ( keys %tab_files ) { my $data = GetTab( $input, $tab_name ); my $title = ( keys( %$data ) )[0]; @@ -209,7 +213,7 @@ sub SearchPrefs { my $matched_groups; while ( my ( $group_title, $contents ) = each %$tab ) { - if ( matches( $group_title ) ) { + if ( matches( $group_title, \@terms ) ) { $matched_groups->{$group_title} = $contents; next; } @@ -221,16 +225,15 @@ sub SearchPrefs { foreach my $piece ( @$line ) { if ( ref( $piece ) eq 'HASH' ) { - 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'} ) ) { + if ( !$piece->{'pref'} ){ + next; + } + if ( matches( $piece->{'pref'}, \@terms) ) { $matched = 1; - } elsif ( ref( $piece->{'choices'} ) eq 'HASH' && grep( { $_ && matches( $_ ) } values( %{ $piece->{'choices'} } ) ) ) { + } elsif ( ref( $piece->{'choices'} ) eq 'HASH' && grep( { $_ && matches( $_, \@terms ) } values( %{ $piece->{'choices'} } ) ) ) { $matched = 1; } - } elsif ( matches( $piece ) ) { + } elsif ( matches( $piece, \@terms ) ) { $matched = 1; } last if ( $matched ); @@ -252,6 +255,11 @@ sub SearchPrefs { return @tabs; } +sub matches { + my ( $text, $terms ) = @_; + if ( $text ) { return !grep( { $text !~ /$_/i } @$terms ); } +} + my $dbh = C4::Context->dbh; our $input = new CGI; @@ -260,7 +268,7 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( query => $input, type => "intranet", authnotrequired => 0, - flagsrequired => { parameters => 1 }, + flagsrequired => { parameters => 'parameters_remaining_permissions' }, debug => 1, } ); @@ -296,7 +304,10 @@ my @TABS; if ( $op eq 'search' ) { my $searchfield = $input->param( 'searchfield' ); - $searchfield =~ s/[^a-zA-Z0-9_ -]//g; + $searchfield =~ s/\p{IsC}//g; + $searchfield =~ s/\s+/ /; + $searchfield =~ s/^\s+//; + $searchfield =~ s/\s+$//; $template->param( searchfield => $searchfield );