Bug 8523 follow-up OPAC styles for ccsr theme
[koha.git] / C4 / Koha.pm
index f19a017..07c80c6 100644 (file)
@@ -24,7 +24,7 @@ use strict;
 #use warnings; FIXME - Bug 2505
 
 use C4::Context;
-
+use C4::Branch qw(GetBranchesCount);
 use Memoize;
 use DateTime;
 use DateTime::Format::MySQL;
@@ -112,7 +112,7 @@ sub slashifyDate {
 }
 
 # FIXME.. this should be moved to a MARC-specific module
-sub subfield_is_koha_internal_p ($) {
+sub subfield_is_koha_internal_p {
     my ($subfield) = @_;
 
     # We could match on 'lib' and 'tab' (and 'mandatory', & more to come!)
@@ -471,7 +471,7 @@ sub getitemtypeimagesrc {
        }
 }
 
-sub getitemtypeimagelocation($$) {
+sub getitemtypeimagelocation {
        my ( $src, $image ) = @_;
 
        return '' if ( !$image );
@@ -630,7 +630,7 @@ sub GetPrinters {
 
 =cut
 
-sub GetPrinter ($$) {
+sub GetPrinter {
     my ( $query, $printers ) = @_;    # get printer for this query from printers
     my $printer = $query->param('printer');
     my %cookie = $query->cookie('userenv');
@@ -674,6 +674,7 @@ sub getallthemes {
     opendir D, "$htdocs";
     my @dirlist = readdir D;
     foreach my $directory (@dirlist) {
+        next if $directory eq 'lib';
         -d "$htdocs/$directory/en" and push @themes, $directory;
     }
     return @themes;
@@ -713,14 +714,23 @@ sub getFacets {
                 tags  => [ qw/ 225a / ],
                 sep   => ', ',
             },
-        ];
-        my $library_facet = {
-            idx   => 'branch',
-            label => 'Libraries',
-            tags  => [ qw/ 995b / ],
-            expanded => '1',
-        };
-        push @$facets, $library_facet unless C4::Context->preference("singleBranchMode");
+            ];
+
+            my $library_facet;
+            unless ( C4::Context->preference("singleBranchMode") || GetBranchesCount() == 1 ) {
+                $library_facet = {
+                    idx  => 'branch',
+                    label => 'Libraries',
+                    tags        => [ qw/ 995b / ],
+                };
+            } else {
+                $library_facet = {
+                    idx  => 'location',
+                    label => 'Location',
+                    tags        => [ qw/ 995c / ],
+                };
+            }
+            push( @$facets, $library_facet );
     }
     else {
         $facets = [
@@ -760,16 +770,29 @@ sub getFacets {
                 tags  => [ qw/ 440a 490a / ],
                 sep   => ', ',
             },
+            {
+                idx   => 'itype',
+                label => 'ItemTypes',
+                tags  => [ qw/ 952y 942c / ],
+                sep   => ', ',
+            },
             ];
+
             my $library_facet;
-            $library_facet = {
-                idx   => 'branch',
-                label => 'Libraries',
-                tags  => [ qw/ 952b / ],
-                sep   => ', ',
-                expanded    => '1',
-            };
-            push @$facets, $library_facet unless C4::Context->preference("singleBranchMode");
+            unless ( C4::Context->preference("singleBranchMode") || GetBranchesCount() == 1 ) {
+                $library_facet = {
+                    idx  => 'branch',
+                    label => 'Libraries',
+                    tags        => [ qw / 952b / ],
+                };
+            } else {
+                $library_facet = {
+                    idx => 'location',
+                    label => 'Location',
+                    tags => [ qw / 952c / ],
+                };
+            }
+            push( @$facets, $library_facet );
     }
     return $facets;
 }
@@ -1067,13 +1090,14 @@ by the passed category and code
 =cut
 
 sub GetAuthorisedValueByCode {
-    my ( $category, $authvalcode ) = @_;
+    my ( $category, $authvalcode, $opac ) = @_;
 
+    my $field = $opac ? 'lib_opac' : 'lib';
     my $dbh = C4::Context->dbh;
-    my $sth = $dbh->prepare("SELECT lib FROM authorised_values WHERE category=? AND authorised_value =?");
+    my $sth = $dbh->prepare("SELECT $field FROM authorised_values WHERE category=? AND authorised_value =?");
     $sth->execute( $category, $authvalcode );
     while ( my $data = $sth->fetchrow_hashref ) {
-        return $data->{'lib'};
+        return $data->{ $field };
     }
 }
 
@@ -1103,7 +1127,7 @@ sub GetKohaAuthorisedValues {
        }
        return \%values;
   } else {
-       return undef;
+       return;
   }
 }
 
@@ -1134,7 +1158,7 @@ sub GetKohaAuthorisedValuesFromField {
        }
        return \%values;
   } else {
-       return undef;
+       return;
   }
 }
 
@@ -1226,7 +1250,7 @@ sub GetNormalizedUPC {
 }
 
 # Normalizes and returns the first valid ISBN found in the record
-# ISBN13 are converted into ISBN10. This is required to get Amazon cover book.
+# ISBN13 are converted into ISBN10. This is required to get some book cover images.
 sub GetNormalizedISBN {
     my ($isbn,$record,$marcflavour) = @_;
     my @fields;
@@ -1236,7 +1260,7 @@ sub GetNormalizedISBN {
         $isbn =~ s/(.*)( \| )(.*)/$1/;
         return _isbn_cleanup($isbn);
     }
-    return undef unless $record;
+    return unless $record;
 
     if ($marcflavour eq 'UNIMARC') {
         @fields = $record->field('010');
@@ -1245,7 +1269,7 @@ sub GetNormalizedISBN {
             if ($isbn) {
                 return _isbn_cleanup($isbn);
             } else {
-                return undef;
+                return;
             }
         }
     }
@@ -1256,7 +1280,7 @@ sub GetNormalizedISBN {
             if ($isbn) {
                 return _isbn_cleanup($isbn);
             } else {
-                return undef;
+                return;
             }
         }
     }
@@ -1301,7 +1325,7 @@ sub GetNormalizedOCLCNumber {
                 $oclc =~ s/\(OCoLC\)//;
                 return $oclc;
             } else {
-                return undef;
+                return;
             }
         }
     }