Bug 6939 DefaultClassificationSource should be default in 942
[koha.git] / admin / preferences.pl
index 5bc4c09..0dcec19 100755 (executable)
@@ -13,9 +13,9 @@
 # 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., 59 Temple Place,
-# Suite 330, Boston, MA  02111-1307 USA
+# 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.
 
 use strict;
 use warnings;
@@ -28,7 +28,8 @@ use C4::Languages qw(getTranslatedLanguages);
 use C4::ClassSource;
 use C4::Log;
 use C4::Output;
-use C4::Budget qw(GetCurrency);
+use C4::Templates;
+use C4::Budgets qw(GetCurrency);
 use File::Spec;
 use IO::File;
 use YAML::Syck qw();
@@ -41,10 +42,15 @@ 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;
+    if ($active_currency) {
+        $local_currency = $active_currency->{currency};
+    }
     $tab_template->param(
-        local_currency => GetCurrency()->{'currency'}, # currency code is used, because we do not know how a given currency is formatted.
+        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() );
@@ -58,6 +64,8 @@ sub _get_chunk {
 
     if ( $options{'class'} && $options{'class'} eq 'password' ) {
         $chunk->{'input_type'} = 'password';
+    } elsif ( $options{'class'} && $options{'class'} eq 'date' ) {
+        $chunk->{'dateinput'} = 1;
     } elsif ( $options{'type'} && ( $options{'type'} eq 'opac-languages' || $options{'type'} eq 'staff-languages' ) ) {
         my $current_languages = { map { +$_, 1 } split( /\s*,\s*/, $value ) };
 
@@ -157,7 +165,7 @@ sub TransformPrefsToHTML {
                 }
             }
 
-            push @lines, { CHUNKS => \@chunks, NAMES => \@names };
+            push @lines, { CHUNKS => \@chunks, NAMES => \@names, is_group_title => 0 };
         }
     }
 
@@ -167,7 +175,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;
 
@@ -187,12 +195,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];
@@ -202,7 +204,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;
             }
@@ -214,16 +216,17 @@ 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'} ) ) {
+                        } elsif ( 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 );
@@ -245,6 +248,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;
 
@@ -261,7 +269,8 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
 $lang = $template->param( 'lang' );
 my $op = $input->param( 'op' ) || '';
 my $tab = $input->param( 'tab' );
-$tab ||= 'local-use';
+$tab ||= 'acquisitions'; # Ideally this should be "local-use" but preferences.pl
+                         # does not presently support local use preferences
 
 my $highlighted;