bug 5579 : Fixes several exports to embed items
authorMatthias Meusburger <matthias.meusburger@biblibre.com>
Thu, 7 Apr 2011 10:04:43 +0000 (12:04 +0200)
committerChris Cormack <chrisc@catalyst.net.nz>
Tue, 19 Apr 2011 10:35:15 +0000 (22:35 +1200)
  - The following export pages used to embed items when exporting,
    this was no longer the case, so they were fixed :
      Intranet :
        - basket/downloadcart.pl,
        - virtualshelves/downloadshelf.pl
        - catalogue/export.pl
      Opac :
        - opac/opac-downloadcart.pl
        - opac/opac-downloadshelf.pl
        - opac/opac-export.pl

  - Notes :
     - GetMarcBiblio used to embed items data, this was no longer the case,
       so an optional parameter was added to choose if items should be embedded or not.
       This way, previous work on this bug is not broken, and this is a pretty usefull
       feature, imho.
     - An optional parameter has been added to SetUTF8Flag, to be able to use NFD during
       normalization. This was required to make Unicode/UTF-8 export work again.

Signed-off-by: Claire Hernandez <claire.hernandez@biblibre.com>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
C4/Biblio.pm
C4/Charset.pm
C4/Record.pm
basket/downloadcart.pl
catalogue/export.pl
opac/opac-downloadcart.pl
opac/opac-downloadshelf.pl
opac/opac-export.pl
virtualshelves/downloadshelf.pl

index 856a74e..534c97d 100755 (executable)
@@ -1025,16 +1025,18 @@ sub GetMarcFromKohaField {
 
 =head2 GetMarcBiblio
 
-  my $record = GetMarcBiblio($biblionumber);
+  my $record = GetMarcBiblio($biblionumber, [$embeditems]);
 
 Returns MARC::Record representing bib identified by
 C<$biblionumber>.  If no bib exists, returns undef.
-The MARC record contains both biblio & item data.
+C<$embeditems>.  If set to true, items data are included.
+The MARC record contains biblio data, and items data if $embeditems is set to true.
 
 =cut
 
 sub GetMarcBiblio {
     my $biblionumber = shift;
+    my $embeditems   = shift || 0;
     my $dbh          = C4::Context->dbh;
     my $sth          = $dbh->prepare("SELECT marcxml FROM biblioitems WHERE biblionumber=? ");
     $sth->execute($biblionumber);
@@ -1048,6 +1050,8 @@ sub GetMarcBiblio {
         if ($@) { warn " problem with :$biblionumber : $@ \n$marcxml"; }
         return unless $record;
 
+       C4::Biblio::EmbedItemsInMarcBiblio($record, $biblionumber) if ($embeditems);
+
         #      $record = MARC::Record::new_from_usmarc( $marc) if $marc;
         return $record;
     } else {
index a4a06e7..a4e6b71 100644 (file)
@@ -112,7 +112,7 @@ sub IsStringUTF8ish {
 
 =head2 SetUTF8Flag
 
-  my $marc_record = SetUTF8Flag($marc_record);
+  my $marc_record = SetUTF8Flag($marc_record, $nfd);
 
 This function sets the PERL UTF8 flag for data.
 It is required when using new_from_usmarc 
@@ -120,6 +120,8 @@ since MARC::File::USMARC does not handle PERL UTF8 setting.
 When editing unicode marc records fields and subfields, you
 would end up in double encoding without using this function. 
 
+If $nfd is set, string normalization will use NFD instead of NFC
+
 FIXME
 In my opinion, this function belongs to MARC::Record and not
 to this package.
@@ -128,13 +130,13 @@ But since it handles charset, and MARC::Record, it finds its way in that package
 =cut
 
 sub SetUTF8Flag{
-       my ($record)=@_;
+       my ($record, $nfd)=@_;
        return unless ($record && $record->fields());
        foreach my $field ($record->fields()){
                if ($field->tag()>=10){
                        my @subfields;
                        foreach my $subfield ($field->subfields()){
-                               push @subfields,($$subfield[0],NormalizeString($$subfield[1]));
+                               push @subfields,($$subfield[0],NormalizeString($$subfield[1],$nfd));
                        }
                        my $newfield=MARC::Field->new(
                                                        $field->tag(),
index 990bb50..c5727f3 100644 (file)
@@ -359,7 +359,7 @@ sub marcrecord2csv {
     my $output;
 
     # Getting the record
-    my $record = GetMarcBiblio($biblio);
+    my $record = GetMarcBiblio($biblio, 1);
     next unless $record;
     # Getting the framework
     my $frameworkcode = GetFrameworkCode($biblio);
index 456f0a4..392a3e4 100755 (executable)
@@ -65,7 +65,7 @@ if ($bib_list && $format) {
 
         foreach my $biblio (@bibs) {
 
-            my $record = GetMarcBiblio($biblio);
+            my $record = GetMarcBiblio($biblio, 1);
 
             if ($format eq 'iso2709') {
                 $output .= $record->as_usmarc();
index f6f02d7..9bd49de 100755 (executable)
@@ -15,14 +15,9 @@ my $op=$query->param("op");
 my $format=$query->param("format");
 if ($op eq "export") {
        my $biblionumber = $query->param("bib");
-       my $dbh=C4::Context->dbh;
-       my $sth;
-       if ($biblionumber) {
-               $sth=$dbh->prepare("SELECT marc FROM biblioitems WHERE biblionumber =?");
-               $sth->execute($biblionumber);
-       }
-       while (my ($marc) = $sth->fetchrow) {
-               if ($marc){
+               if ($biblionumber){
+
+                       my $marc = GetMarcBiblio($biblionumber, 1);
 
                        if ($format =~ /endnote/) {
                                $marc = marc2endnote($marc);
@@ -44,12 +39,12 @@ if ($op eq "export") {
                                $marc = $marc->as_usmarc();
                        }
                        elsif ($format =~ /utf8/) {
-                               #default
+                               C4::Charset::SetUTF8Flag($marc, 1);
+                               $marc = $marc->as_usmarc();
                        }
                        print $query->header(
                                -type => 'application/octet-stream',
                 -attachment=>"bib-$biblionumber.$format");
                        print $marc;
                }
-       }
 }
index 7f2bb32..3a4cdc1 100755 (executable)
@@ -64,7 +64,7 @@ if ($bib_list && $format) {
     } else {
         foreach my $biblio (@bibs) {
 
-            my $record = GetMarcBiblio($biblio);
+            my $record = GetMarcBiblio($biblio, 1);
             next unless $record;
 
             if ($format eq 'iso2709') {
index ab1fe8d..ee9b0b1 100755 (executable)
@@ -68,7 +68,7 @@ if ($shelfid && $format) {
         foreach my $biblio (@$items) {
             my $biblionumber = $biblio->{biblionumber};
 
-            my $record = GetMarcBiblio($biblionumber);
+            my $record = GetMarcBiblio($biblionumber, 1);
             next unless $record;
 
             if ($format eq 'iso2709') {
index f9d3c25..e8f7ede 100755 (executable)
@@ -35,15 +35,11 @@ my $op=$query->param("op");
 my $format=$query->param("format");
 if ($op eq "export") {
        my $biblionumber = $query->param("bib");
-       my $dbh=C4::Context->dbh;
-       my $sth;
-       if ($biblionumber) {
-               $sth=$dbh->prepare("SELECT marc FROM biblioitems WHERE biblionumber =?");
-               $sth->execute($biblionumber);
-       }
-    my $error;
-       while (my ($marc) = $sth->fetchrow) {
-               if ($marc){
+       my $error;
+
+               if ($biblionumber){
+
+                       my $marc = GetMarcBiblio($biblionumber, 1);
 
                        if ($format =~ /endnote/) {
                                $marc = marc2endnote($marc);
@@ -60,32 +56,34 @@ if ($op eq "export") {
                        }
                        elsif ($format =~ /bibtex/) {
                                $marc = marc2bibtex(C4::Biblio::GetMarcBiblio($biblionumber),$biblionumber);
-                       }elsif ($format =~ /dc/) {
-                ($error,$marc) = marc2dcxml($marc,1);
+                       }
+                       elsif ($format =~ /dc/) {
+                               ($error,$marc) = marc2dcxml($marc,1);
                                $format = "dublin-core.xml";
                        }
                        elsif ($format =~ /marc8/) {
                                ($error,$marc) = changeEncoding($marc,"MARC","MARC21","MARC-8");
-                if (! $error){
-                    $marc = $marc->as_usmarc();
-                }
+                               if (! $error){
+                                   $marc = $marc->as_usmarc();
+                               }
                        }
                        elsif ($format =~ /utf8/) {
-                               #default
+                               C4::Charset::SetUTF8Flag($marc,1);
+                               $marc = $marc->as_usmarc();
                        }
-            if ($error){
-                print $query->header();
-                print $query->start_html();
-                print "<h1>An error occured </h1>";
-                print $error;
-                print $query->end_html();
-            }
-            else {
-                print $query->header(
-                               -type => 'application/octet-stream',
-                -attachment=>"bib-$biblionumber.$format");
-                print $marc;
-            }
+
+               if ($error){
+                   print $query->header();
+                   print $query->start_html();
+                   print "<h1>An error occured </h1>";
+                   print $error;
+                   print $query->end_html();
+               }
+               else {
+                   print $query->header(
+                                   -type => 'application/octet-stream',
+                   -attachment=>"bib-$biblionumber.$format");
+                   print $marc;
                }
-       }
+           }
 }
index 253eec1..1611f1a 100755 (executable)
@@ -68,7 +68,7 @@ if ($shelfid && $format) {
     foreach my $biblio (@$items) {
         my $biblionumber = $biblio->{biblionumber};
 
-        my $record = GetMarcBiblio($biblionumber);
+        my $record = GetMarcBiblio($biblionumber, 1);
 
         if ($format eq 'iso2709') {
             $output .= $record->as_usmarc();