BUG: fix patron search
[koha.git] / C4 / Ris.pm
index ec3159f..f244bf6 100644 (file)
--- a/C4/Ris.pm
+++ b/C4/Ris.pm
@@ -41,6 +41,7 @@ package C4::Ris;
 # Modified 2008 by BibLibre for Koha
 # Modified 2011 by Catalyst
 # Modified 2011 by Equinox Software, Inc.
+# Modified 2016 by Universidad de El Salvador
 #
 # This file is part of Koha.
 #
@@ -64,7 +65,6 @@ use Modern::Perl;
 use List::MoreUtils qw/uniq/;
 use vars qw(@ISA @EXPORT);
 
-use C4::Biblio qw(GetMarcSubfieldStructureFromKohaField);
 use Koha::SimpleMARC qw(read_field);
 
 
@@ -76,11 +76,7 @@ use Koha::SimpleMARC qw(read_field);
   &marc2ris
 );
 
-our $utf;
-our $intype;
-our $marcprint;
-our $protoyear;
-
+our $marcprint = 0; # Debug flag;
 
 =head1 marc2bibtex - Convert from UNIMARC to RIS
 
@@ -97,8 +93,7 @@ sub marc2ris {
     my $output;
 
     my $marcflavour = C4::Context->preference("marcflavour");
-    $intype = lc($marcflavour);
-    my $marcprint = 0; # Debug flag;
+    my $intype = lc($marcflavour);
 
     # Let's redirect stdout
     open my $oldout, ">&STDOUT";
@@ -113,7 +108,6 @@ sub marc2ris {
     if ( $intype eq "marc21" ) {
         if ( $leader =~ /^.{9}a/ ) {
             print "<marc>---\r\n<marc>UTF-8 data\r\n" if $marcprint;
-            $utf = 1;
         }
         else {
             print "<marc>---\r\n<marc>MARC-8 data\r\n" if $marcprint;
@@ -165,7 +159,7 @@ sub marc2ris {
        foreach my $field (@author_fields) {
            if (length($field)) {
                my $author = &get_author($field);
-               print "AU  - ",&charconv($author),"\r\n";
+               print "AU  - ",$author,"\r\n";
            }
        }
 
@@ -191,7 +185,7 @@ sub marc2ris {
        foreach my $field (@editor_fields) {
            if (length($field)) {
                my $editor = &get_editor($field);
-               print "ED  - ",&charconv($editor),"\r\n";
+               print "ED  - ",$editor,"\r\n";
            }
        }
 
@@ -266,7 +260,7 @@ sub marc2ris {
     @kwpool = uniq @kwpool;
 
     for my $kw ( @kwpool ) {
-        print "KW  - ", &charconv($kw), "\r\n";
+        print "KW  - ", $kw, "\r\n";
     }
 
        ## 5XX have various candidates for notes and abstracts. We pool
@@ -293,7 +287,7 @@ sub marc2ris {
        my $allnotes = join "; ", @notepool;
 
        if (length($allnotes) > 0) {
-           print "N1  - ", &charconv($allnotes), "\r\n";
+           print "N1  - ", $allnotes, "\r\n";
        }
 
        ## 320/520 have the abstract
@@ -355,69 +349,75 @@ sub print_typetag {
     ## of the leader of a MARC record, the values are the RIS types
     ## that might appropriately represent these types.
     my %ustypehash = (
-                   "a" => "BOOK",
-                   "c" => "MUSIC",
-                   "d" => "MUSIC",
-                   "e" => "MAP",
-                   "f" => "MAP",
-                   "g" => "ADVS",
-                   "i" => "SOUND",
-                   "j" => "SOUND",
-                   "k" => "ART",
-                   "m" => "DATA",
-                   "o" => "GEN",
-                   "p" => "GEN",
-                   "r" => "ART",
-                   "t" => "GEN",
-               );
-    
+            "a" => "BOOK",
+            "c" => "MUSIC",
+            "d" => "MUSIC",
+            "e" => "MAP",
+            "f" => "MAP",
+            "g" => "ADVS",
+            "i" => "SOUND",
+            "j" => "SOUND",
+            "k" => "ART",
+            "m" => "DATA",
+            "o" => "GEN",
+            "p" => "GEN",
+            "r" => "ART",
+            "t" => "MANSCPT",
+            );
+
     my %unitypehash = (
-                   "a" => "BOOK",
-                   "b" => "BOOK",
-                   "c" => "MUSIC",
-                   "d" => "MUSIC",
-                   "e" => "MAP",
-                   "f" => "MAP",
-                   "g" => "ADVS",
-                   "i" => "SOUND",
-                   "j" => "SOUND",
-                   "k" => "ART",
-                   "l" => "ELEC",
-                   "m" => "ADVS",
-                   "r" => "ART",
-               );
-    
+            "a" => "BOOK",
+            "b" => "MANSCPT",
+            "c" => "MUSIC",
+            "d" => "MUSIC",
+            "e" => "MAP",
+            "f" => "MAP",
+            "g" => "ADVS",
+            "i" => "SOUND",
+            "j" => "SOUND",
+            "k" => "ART",
+            "l" => "ELEC",
+            "m" => "GEN",
+            "r" => "ART",
+            );
+
     ## The type of a MARC record is found at position 06 of the leader
     my $typeofrecord = defined($leader) && length $leader >=6 ?
                        substr($leader, 6, 1): undef;
+    ## Pos 07 == Bibliographic level
+    my $biblevel = defined($leader) && length $leader >=7 ?
+                       substr($leader, 7, 1): '';
 
-    ## ToDo: for books, field 008 positions 24-27 might have a few more
+    ## TODO: for books, field 008 positions 24-27 might have a few more
     ## hints
 
     my %typehash;
-    
-    ## the ukmarc here is just a guess
-    if (! defined $intype) {
-        ## assume MARC21 as default
-        %typehash = %ustypehash;
-    }
-    elsif ($intype eq "marc21" || $intype eq "ukmarc") {
-       %typehash = %ustypehash;
-    }
-    elsif ($intype eq "unimarc") {
-       %typehash = %unitypehash;
+    my $marcflavour = C4::Context->preference("marcflavour");
+    my $intype = lc($marcflavour);
+    if ($intype eq "unimarc") {
+        %typehash = %unitypehash;
     }
     else {
-       ## assume MARC21 as default
-       %typehash = %ustypehash;
+        %typehash = %ustypehash;
     }
 
     if (!defined $typeofrecord || !exists $typehash{$typeofrecord}) {
-       print "TY  - BOOK\r\n"; ## most reasonable default
-       warn ("no type found - assume BOOK") if $marcprint;
-    }
-    else {
-       print "TY  - $typehash{$typeofrecord}\r\n";
+        print "TY  - GEN\r\n"; ## most reasonable default
+        warn ("no type found - assume GEN") if $marcprint;
+    } elsif ( $typeofrecord =~ "a" ) {
+        if ( $biblevel eq 'a' ) {
+            print "TY  - GEN\r\n"; ## monographic component part
+        } elsif ( $biblevel eq 'b' || $biblevel eq 's' ) {
+            print "TY  - SER\r\n"; ## serial or serial component part
+        } elsif ( $biblevel eq 'm' ) {
+            print "TY  - $typehash{$typeofrecord}\r\n"; ## book
+        } elsif ( $biblevel eq 'c' || $biblevel eq 'd' ) {
+            print "TY  - GEN\r\n"; ## collections, part of collections or made-up collections
+        } elsif ( $biblevel eq 'i' ) {
+            print "TY  - DATA\r\n"; ## updating loose-leafe as Dataset
+        }
+    } else {
+        print "TY  - $typehash{$typeofrecord}\r\n";
     }
 
     ## use $typeofrecord as the return value, just in case
@@ -482,6 +482,8 @@ sub get_author {
 
     ## the sequence of the name parts is encoded either in indicator
     ## 1 (marc21) or 2 (unimarc)
+    my $marcflavour = C4::Context->preference("marcflavour");
+    my $intype = lc($marcflavour);
     if ($intype eq "unimarc") {
        $indicator = 2;
     }
@@ -552,13 +554,15 @@ $clean_subtitle ||= q{};
        $clean_title =~ s% *[/:;.]$%%;
        $clean_subtitle =~ s%^ *(.*) *[/:;.]$%$1%;
 
+    my $marcflavour = C4::Context->preference("marcflavour");
+    my $intype = lc($marcflavour);
        if (length($clean_title) > 0
            || (length($clean_subtitle) > 0 && $intype ne "unimarc")) {
-           print "TI  - ", &charconv($clean_title);
+           print "TI  - ", $clean_title;
 
            ## subfield $b is relevant only for marc21/ukmarc
            if (length($clean_subtitle) > 0 && $intype ne "unimarc") {
-               print ": ",&charconv($clean_subtitle);
+               print ": ",$clean_subtitle;
            }
            print "\r\n";
        }
@@ -568,6 +572,7 @@ $clean_subtitle ||= q{};
        ## be written and designated. The field is free-form and resistant
        ## to all parsing efforts, so this information is lost on me
     }
+    return;
 }
 
 ##********************************************************************
@@ -588,16 +593,19 @@ sub print_stitle {
        $clean_title =~ s% *[/:;.]$%%;
 
        if (length($clean_title) > 0) {
-           print "T2  - ", &charconv($clean_title),"\r\n";
+           print "T2  - ", $clean_title,"\r\n";
        }
 
+    my $marcflavour = C4::Context->preference("marcflavour");
+    my $intype = lc($marcflavour);
        if ($intype eq "unimarc") {
            print "<marc>Series vol(\$v): ",$titlefield->subfield('v'),"\r\n" if $marcprint;
            if (length($titlefield->subfield('v')) > 0) {
-               print "VL  - ", &charconv($titlefield->subfield('v')),"\r\n";
+               print "VL  - ", $titlefield->subfield('v'),"\r\n";
            }
        }
     }
+    return;
 }
 
 ##********************************************************************
@@ -618,7 +626,7 @@ sub print_isbn {
        }
 
     my $isbn = $isbnfield->subfield('a');
-       print "SN  - ", &charconv($isbn), "\r\n";
+       print "SN  - ", $isbn, "\r\n";
     }
 }
 
@@ -640,7 +648,7 @@ sub print_issn {
        }
 
        my $issn = substr($issnfield->subfield('a'), 0, 9);
-       print "SN  - ", &charconv($issn), "\r\n";
+       print "SN  - ", $issn, "\r\n";
     }
 }
 
@@ -652,7 +660,7 @@ sub print_uri {
 
     foreach my $f856 (@f856s) {
         if (my $uri = $f856->subfield('u')) {
-               print "UR  - ", charconv($uri), "\r\n";
+               print "UR  - ", $uri, "\r\n";
         }
     }
 }
@@ -669,7 +677,7 @@ sub print_loc_callno {
        warn("no LOC call number found") if $marcprint;
     }
     else {
-       print "AV  - ", &charconv($callnofield->subfield('a')), " ", &charconv($callnofield->subfield('b')), "\r\n";
+       print "AV  - ", $callnofield->subfield('a'), " ", $callnofield->subfield('b'), "\r\n";
     }
 }
 
@@ -685,7 +693,7 @@ sub print_dewey {
        warn("no Dewey number found") if $marcprint;
     }
     else {
-       print "U1  - ", &charconv($deweyfield->subfield('a')), " ", &charconv($deweyfield->subfield('2')), "\r\n";
+       print "U1  - ", $deweyfield->subfield('a'), " ", $deweyfield->subfield('2'), "\r\n";
     }
 }
 
@@ -726,6 +734,8 @@ sub print_pubinfo {
        my $pubsub_publisher;
        my $pubsub_date;
 
+    my $marcflavour = C4::Context->preference("marcflavour");
+    my $intype = lc($marcflavour);
        if ($intype eq "unimarc") {
            $pubsub_place = "a";
            $pubsub_publisher = "c";
@@ -758,7 +768,7 @@ sub print_pubinfo {
                ## the dates are free-form, so we want to extract
                ## a four-digit year and leave the rest as
                ## "other info"
-               $protoyear = @$tuple[1];
+        my $protoyear = @$tuple[1];
                print "<marc>Year (260\$c): $protoyear\r\n" if $marcprint;
 
                ## strip any separator chars at the end
@@ -799,10 +809,10 @@ sub print_pubinfo {
 
        ## now dump the collected CY and PB lists
        if (@cities > 0) {
-           print "CY  - ", &charconv(join(", ", @cities)), "\r\n";
+           print "CY  - ", join(", ", @cities), "\r\n";
        }
        if (@publishers > 0) {
-           print "PB  - ", &charconv(join(", ", @publishers)), "\r\n";
+           print "PB  - ", join(", ", @publishers), "\r\n";
        }
     }
 }
@@ -1002,30 +1012,9 @@ sub print_abstract {
     my $allabs = join "; ", @abstrings;
 
     if (length($allabs) > 0) {
-       print "N2  - ", &charconv($allabs), "\r\n";
+       print "N2  - ", $allabs, "\r\n";
     }
 
 }
 
-    
-    
-##********************************************************************
-## charconv(): converts to a different charset based on a global var
-## Arguments: string
-## Returns: string
-##********************************************************************
-sub charconv {
-    if ($utf) {
-       ## return unaltered if already utf-8
-       return @_;
-    }
-    elsif (my $uniout eq "t") {
-       ## convert to utf-8
-       return marc8_to_utf8("@_");
-    }
-    else {
-       ## return unaltered if no utf-8 requested
-       return @_;
-    }
-}
 1;