bug 5579 : Fixes several exports to embed items

- 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>
This commit is contained in:
Matthias Meusburger 2011-04-07 12:04:43 +02:00 committed by Chris Cormack
parent 6e217d1d21
commit a3ff0bb5cb
9 changed files with 48 additions and 49 deletions

View File

@ -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 {

View 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(),

View 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);

View File

@ -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();

View File

@ -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;
}
}
}

View File

@ -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') {

View File

@ -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') {

View File

@ -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;
}
}
}

View File

@ -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();