@@ -, +, @@ basket/list by email --- a/C4/Biblio.pm +++ a/C4/Biblio.pm @@ -93,6 +93,7 @@ use C4::Charset; use C4::Linker; use C4::OAI::Sets; use C4::Debug; +use C4::Ris; use Koha::Caches; use Koha::Authority::Types; @@ -3216,6 +3217,88 @@ sub RemoveAllNsb { return $record; } +=head2 BuildBiblioDataForExport + + my $data = BuildBiblioDataForExport({ + biblionumbers => \@biblionumbers, + format => $format, + template => $template, # Only used for ISBD format + csv_profile_id => $csv_profile_id, # Only used for CSV format + +Returns a hashref with the following keys: + +=over + +=item * records_file A string containing the export file contents + +=item * records_data An array of hashrefs for all biblio records + +=back + +=cut + +sub BuildBiblioDataForExport { + my ( $params ) = @_; + my $biblionumbers = $params->{biblionumbers}; + my $format = $params->{format}; + my $template = $params->{template}; # Only used for ISBD + my ( @records_data, $records_file ); + + # CSV + if ($format eq 'csv' ) { + + # FIXME should be used at the beginning of this module + # But compilation explodes... + require C4::Record; + $records_file = C4::Record::marc2csv($biblionumbers, $params->{csv_profile_id}); + + # Other formats + } else { + # retrieve biblios from shelf + my $marcflavour = C4::Context->preference('marcflavour'); + foreach my $biblionumber (@$biblionumbers) { + my $dat = GetBiblioData($biblionumber); + next unless $dat; + my $record = GetMarcBiblio({ biblionumber => $biblionumber, embed_items => 1 }); + my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); + my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); + my $fw = GetFrameworkCode($biblionumber); + + my @items = C4::Items::GetItemsInfo( $biblionumber ); + + my $hasauthors = 0; + if($dat->{'author'} || @$marcauthorsarray) { + $hasauthors = 1; + } + + $dat->{MARCSUBJCTS} = $marcsubjctsarray; + $dat->{MARCAUTHORS} = $marcauthorsarray; + $dat->{HASAUTHORS} = $hasauthors; + $dat->{biblionumber} = $biblionumber; + $dat->{ITEM_RESULTS} = \@items; + + if ($format eq 'iso2709') { + $records_file .= $record->as_usmarc(); + } + elsif ($format eq 'ris') { + $records_file .= C4::Ris::marc2ris($record); + } + elsif ($format eq 'bibtex') { + require C4::Record; + $records_file .= C4::Record::marc2bibtex($record, $biblionumber); + } + elsif ( $format eq 'isbd' ) { + # Only called from the OPAC at the moment + $records_file .= C4::Biblio::GetISBDView($biblionumber, $template); + } + + push( @records_data, $dat ); + } + } + + return { records_file => $records_file, records_data => \@records_data }; +} + 1; --- a/C4/Ris.pm +++ a/C4/Ris.pm @@ -439,6 +439,8 @@ sub print_typetag { sub normalize_author { my($rawauthora, $rawauthorb, $rawauthorc, $nametype) = @_; + $nametype //= 0; + if ($nametype == 0) { # ToDo: convert every input to Last[,(F.|First)[ (M.|Middle)[,Suffix]]] warn("name >>$rawauthora<< in direct order - leave as is") if $marcprint; @@ -831,7 +833,7 @@ sub get_keywords { ## loop over all 6XX fields foreach my $kwfield (@keywords) { - if ($kwfield != undef) { + if (defined $kwfield) { ## authornames get special treatment if ($fieldname eq "600") { my $val = normalize_author($kwfield->subfield('a'), $kwfield->subfield('b'), $kwfield->subfield('c'), $kwfield->indicator('1')); --- a/basket/sendbasket.pl +++ a/basket/sendbasket.pl @@ -29,6 +29,7 @@ use C4::Output; use C4::Templates (); use Koha::Email; use Koha::Token; +use Koha::CsvProfiles; my $query = CGI->new; @@ -43,6 +44,7 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( my $bib_list = $query->param('bib_list') || ''; my $email_add = $query->param('email_add'); +my $format = $query->param('format') || 'iso2709'; my $dbh = C4::Context->dbh; @@ -60,43 +62,24 @@ if ( $email_add ) { 'basket/sendbasket.tt', 'intranet', $query, ); - my @bibs = split( /\//, $bib_list ); - my @results; - my $iso2709; - my $marcflavour = C4::Context->preference('marcflavour'); - foreach my $biblionumber (@bibs) { - $template2->param( biblionumber => $biblionumber ); - - my $dat = GetBiblioData($biblionumber); - next unless $dat; - my $record = GetMarcBiblio({ - biblionumber => $biblionumber, - embed_items => 1 }); - my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); - my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); - - my @items = GetItemsInfo( $biblionumber ); - - my $hasauthors = 0; - if($dat->{'author'} || @$marcauthorsarray) { - $hasauthors = 1; - } - - - $dat->{MARCSUBJCTS} = $marcsubjctsarray; - $dat->{MARCAUTHORS} = $marcauthorsarray; - $dat->{HASAUTHORS} = $hasauthors; - $dat->{'biblionumber'} = $biblionumber; - $dat->{ITEM_RESULTS} = \@items; - - $iso2709 .= $record->as_usmarc(); - - push( @results, $dat ); + my $csv_profile_id; + if ( $format =~ m|^\d+$| ) { + $csv_profile_id = $format; + $format = 'csv'; } + my @biblionumbers = split( /\//, $bib_list ); + my $data = C4::Biblio::BuildBiblioDataForExport( + { + biblionumbers => \@biblionumbers, + format => $format, + csv_profile_id => $csv_profile_id + } + ); + my $records_file = $data->{records_file}; + my $records_data = $data->{records_data}; - my $resultsarray = \@results; $template2->param( - BIBLIO_RESULTS => $resultsarray, + BIBLIO_RESULTS => $records_data, comment => $comment ); @@ -141,9 +124,9 @@ END_OF_BODY $email->text_body( $THE_body ); $email->attach( - Encode::encode( "UTF-8", $iso2709 ), + Encode::encode( "UTF-8", $records_file ), content_type => 'application/octet-stream', - name => 'basket.iso2709', + name => "basket.$format", disposition => 'attachment', ); @@ -166,6 +149,7 @@ else { suggestion => C4::Context->preference("suggestion"), virtualshelves => C4::Context->preference("virtualshelves"), csrf_token => Koha::Token->new->generate_csrf({ session_id => scalar $query->cookie('CGISESSID'), }), + csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc' }) ], ); output_html_with_http_headers $query, $cookie, $template->output; } --- a/koha-tmpl/intranet-tmpl/prog/en/includes/download-export-available-formats.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/download-export-available-formats.inc @@ -0,0 +1,9 @@ + --- a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/downloadcart.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/downloadcart.tt @@ -9,18 +9,11 @@