Bugzilla – Attachment 119078 Details for
Bug 13345
Choose the format for the attached file when sending a basket/list by email
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 13345: Allow patrons to choose format on sending basket/list by email
Bug-13345-Allow-patrons-to-choose-format-on-sendin.patch (text/plain), 40.37 KB, created by
Julian Maurice
on 2021-04-01 13:47:34 UTC
(
hide
)
Description:
Bug 13345: Allow patrons to choose format on sending basket/list by email
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2021-04-01 13:47:34 UTC
Size:
40.37 KB
patch
obsolete
>From 8f9739014d21dbceb56f45a7c5dcdc060f534f54 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Wed, 26 Nov 2014 13:50:50 +0100 >Subject: [PATCH] Bug 13345: Allow patrons to choose format on sending > basket/list by email > >It is already possible to download a basket(cart) or a list using >different format. >But by email, only iso2709 is possible. > >This patch adds the ability to select a format for the file attached to >the email when sending the basket/list content. > >Test plan: >1/ At the OPAC, add some records to your basket and send it by email >using different formats (RIS, BibTeX, MARC and the CSV profiles defined). >2/ At the OPAC, add some records to a list and send it by email using >the different formats. >3/ Redo step 1 at the intranet >4/ Redo step 2 at the intranet > >Note that subtitles are not displayed in all these cases. > >Note for QA: This patch refactors 2 main things: >1/ Template side: the dropdown list to select the format is now in an >include file (indeed, this list is used in 4 templates, this will make >easier further changes). >The include files are named 'download-export-available-formats.inc', >feel free to suggest something better. >The are used in: >[opac-]sendbasket.tt, [opac-]sendshelf.tt, [opac-]downloadbasket.tt and >[opac-]downloadshelf.tt. > >2/ Build records data and the records file >This job was done in 4 scripts: > - opac/opac-sendbasket.pl > - opac/opac-sendshelf.pl > - basket/sendbasket.pl > - virtualshelves/sendshelf.pl >Now it's done in C4::Biblio::BuildBiblioDataForExport and tests are >provided in t/db_dependent/Biblio/BuildBiblioDataForExport.t >Note that a similar job is done in [opac-]downloadcart.pl and >[opac-]downloadshelf.pl > >Sponsored-by: Mines Paristech >Signed-off-by: Nicole C. Engard <nengard@bywatersolutions.com> >Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> >Test pass and mail sent, no errors. >--- > C4/Biblio.pm | 83 ++++++++++++ > C4/Ris.pm | 4 +- > basket/sendbasket.pl | 56 +++----- > .../download-export-available-formats.inc | 9 ++ > .../prog/en/modules/basket/downloadcart.tt | 17 +-- > .../prog/en/modules/basket/sendbasket.tt | 6 +- > .../prog/en/modules/basket/sendbasketform.tt | 28 ++-- > .../modules/virtualshelves/downloadshelf.tt | 18 +-- > .../modules/virtualshelves/sendshelfform.tt | 4 + > .../download-export-available-formats.inc | 10 ++ > .../bootstrap/en/modules/opac-downloadcart.tt | 11 +- > .../en/modules/opac-downloadshelf.tt | 11 +- > .../en/modules/opac-sendbasketform.tt | 2 + > .../en/modules/opac-sendshelfform.tt | 3 + > opac/opac-downloadcart.pl | 8 +- > opac/opac-downloadshelf.pl | 6 +- > opac/opac-sendbasket.pl | 62 ++++----- > opac/opac-sendshelf.pl | 54 ++++---- > .../Biblio/BuildBiblioDataForExport.t | 120 ++++++++++++++++++ > virtualshelves/sendshelf.pl | 46 ++++--- > 20 files changed, 362 insertions(+), 196 deletions(-) > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/download-export-available-formats.inc > create mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/includes/download-export-available-formats.inc > create mode 100644 t/db_dependent/Biblio/BuildBiblioDataForExport.t > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index b482a99814..b697f784d6 100644 >--- a/C4/Biblio.pm >+++ b/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; > > >diff --git a/C4/Ris.pm b/C4/Ris.pm >index 867030c73c..a000679aa8 100644 >--- a/C4/Ris.pm >+++ b/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')); >diff --git a/basket/sendbasket.pl b/basket/sendbasket.pl >index 9e273b1f45..61758d51b3 100755 >--- a/basket/sendbasket.pl >+++ b/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; > } >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/download-export-available-formats.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/download-export-available-formats.inc >new file mode 100644 >index 0000000000..b8942ed736 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/download-export-available-formats.inc >@@ -0,0 +1,9 @@ >+<select name="format" id="dlformat"> >+ <option value="">-- Choose format --</option> >+ <option value="ris">RIS (Zotero, EndNote, others)</option> >+ <option value="bibtex">BibTeX</option> >+ <option value="iso2709">MARC</option> >+ [% FOREACH csv_profile IN csv_profiles %] >+ <option value="[% csv_profile.export_format_id | html %]">CSV - [% csv_profile.profile | html %]</option> >+ [% END %] >+</select> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/downloadcart.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/basket/downloadcart.tt >index b01aca4b1c..d0d8f235b6 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/downloadcart.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/basket/downloadcart.tt >@@ -9,18 +9,11 @@ > <form method="post" action="/cgi-bin/koha/basket/downloadcart.pl"> > <fieldset class="rows"> > <legend>Download cart</legend> >- <ol><li> >- <label for="format">Format:</label> >- <select name="format" id="format"> >- <option value="">-- Choose format --</option> >- <option value="iso2709">MARC</option> >- <option value="ris">RIS</option> >- <option value="bibtex">BibTex</option> >- [% FOREACH csv_profile IN csv_profiles %] >- <option value="[% csv_profile.export_format_id | html %]">CSV - [% csv_profile.profile | html %]</option> >- [% END %] >- >- </select></li> >+ <ol> >+ <li> >+ <label for="format">Format:</label> >+ [% INCLUDE 'download-export-available-formats.inc' %] >+ </li> > </ol> > </fieldset> > <fieldset class="action"> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/sendbasket.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/basket/sendbasket.tt >index 6af47706d0..b31d3c7278 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/sendbasket.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/basket/sendbasket.tt >@@ -32,7 +32,11 @@ Your cart > <li> > <span> > [% BIBLIO_RESULT.title | $raw %] >- [% IF ( BIBLIO_RESULT.subtitle ) %] [% BIBLIO_RESULT.subtitle | $raw %][% END %] >+ [% IF ( BIBLIO_RESULT.subtitle.size ) %] >+ [% FOREACH subtitle IN BIBLIO_RESULT.subtitle %] >+ [% subtitle.subfield | $raw %] >+ [% END %] >+ [% END %] > [% BIBLIO_RESULT.part_number | $raw %] [% BIBLIO_RESULT.part_name | $raw %] > </span> > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/sendbasketform.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/basket/sendbasketform.tt >index 087d5afb65..72bc0cb1b3 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/sendbasketform.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/basket/sendbasketform.tt >@@ -18,18 +18,22 @@ > > [% INCLUDE 'blocking_errors.inc' %] > <form action="/cgi-bin/koha/basket/sendbasket.pl" method="post"> >- >-<fieldset class="rows"> >-<legend>Sending your cart</legend> >-<ol> <li> >- <label for="email_add">Email address:</label> >- <input type="text" id="email_add" name="email_add" size="43" class="focus" /> >- </li> >- <li> >- <label for="comment">Comment:</label> >- <textarea id="comment" name="comment" rows="4" cols="40"></textarea> >- </li> >- </ol> >+ <fieldset class="rows"> >+ <legend>Sending your cart</legend> >+ <ol> >+ <li> >+ <label for="email_add">Email address:</label> >+ <input type="text" id="email_add" name="email_add" size="43" class="focus" /> >+ </li> >+ <li> >+ <label for="comment">Comment:</label> >+ <textarea id="comment" name="comment" rows="4" cols="40"></textarea> >+ </li> >+ <li> >+ <label for="format">Format:</label> >+ [% INCLUDE 'download-export-available-formats.inc' %] >+ </li> >+ </ol> > </fieldset> > <fieldset class="action"> <input type="submit" value="Send" /> <a class="cancel close" href="#">Cancel</a> </fieldset> > <input type="hidden" name="bib_list" value="[% bib_list | html %]" /> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/downloadshelf.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/downloadshelf.tt >index 577eafeef7..a91af3800c 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/downloadshelf.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/downloadshelf.tt >@@ -26,18 +26,12 @@ > <form method="post" action="/cgi-bin/koha/virtualshelves/downloadshelf.pl"> > <fieldset class="rows"> > <legend>Download list</legend> >- <ol><li> >- <label for="format">Format: </label> >- <select name="format" id="format"> >- <option value="">-- Choose format --</option> >- <option value="iso2709">MARC</option> >- <option value="ris">RIS</option> >- <option value="bibtex">BibTex</option> >- [% FOREACH csv_profile IN csv_profiles %] >- <option value="[% csv_profile.export_format_id | html %]">CSV - [% csv_profile.profile | html %]</option> >- [% END %] >- </select> >- </li></ol> >+ <ol> >+ <li> >+ <label for="format">Format: </label> >+ [% INCLUDE 'download-export-available-formats.inc' %] >+ </li> >+ </ol> > </fieldset> > <fieldset class="action"><input type="hidden" name="shelfid" value="[% shelfid | html %]" /> > <input type="submit" name="save" value="Save" /> <a class="cancel close" href="#">Cancel</a> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/sendshelfform.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/sendshelfform.tt >index ec399270bf..b7818a2eb0 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/sendshelfform.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/sendshelfform.tt >@@ -27,6 +27,10 @@ > <label for="comment">Comment:</label> > <textarea id="comment" name="comment" rows="4" cols="40"></textarea> > </li> >+ <li> >+ <label for="comment">Format:</label> >+ [% INCLUDE 'download-export-available-formats.inc' %] >+ </li> > <li> > <input type="hidden" name="shelfid" value="[% shelfid | html %]" /> > </li></ol></fieldset> >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/download-export-available-formats.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/download-export-available-formats.inc >new file mode 100644 >index 0000000000..cbef78a7fd >--- /dev/null >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/download-export-available-formats.inc >@@ -0,0 +1,10 @@ >+<select name="format" id="dlformat"> >+ <option value="">-- Choose format --</option> >+ <option value="ris">RIS (Zotero, EndNote, others)</option> >+ <option value="bibtex">BibTeX</option> >+ <option value="isbd">ISBD</option> >+ <option value="iso2709">MARC</option> >+ [% FOREACH csv_profile IN csv_profiles %] >+ <option value="[% csv_profile.export_format_id | html %]">CSV - [% csv_profile.profile | html %]</option> >+ [% END %] >+</select> >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadcart.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadcart.tt >index 9e9ad9d031..79047a6ce8 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadcart.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadcart.tt >@@ -11,16 +11,7 @@ > <div id="userdownloadcart" class="maincontent"> > <h1>Download cart</h1> > <form method="post" action="/cgi-bin/koha/opac-downloadcart.pl"> >- <select name="format" id="format"> >- <option value="">-- Choose format --</option> >- <option value="ris">RIS (Zotero, EndNote, others)</option> >- <option value="bibtex">BibTeX</option> >- <option value="isbd">ISBD</option> >- <option value="iso2709">MARC</option> >- [% FOREACH csv_profile IN csv_profiles %] >- <option value="[% csv_profile.export_format_id | html %]">CSV - [% csv_profile.profile | html %]</option> >- [% END %] >- </select> >+ [% INCLUDE 'download-export-available-formats.inc' %] > <fieldset class="action"> > <input type="hidden" name="bib_list" value="[% bib_list | html %]" /> > <input type="submit" name="save" value="Go" /> >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadshelf.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadshelf.tt >index 78b0e4dc6a..bb8c4e814e 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadshelf.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadshelf.tt >@@ -56,16 +56,7 @@ > <h1>Download list <em>[% shelf.shelfname | html %]</em></h1> > <form method="post" action="/cgi-bin/koha/opac-downloadshelf.pl"> > <fieldset> >- <select name="format" id="dlformat" required="required"> >- <option value="">-- Choose format --</option> >- <option value="ris">RIS (Zotero, EndNote, others)</option> >- <option value="bibtex">BibTeX</option> >- <option value="isbd">ISBD</option> >- <option value="iso2709">MARC</option> >- [% FOREACH csv_profile IN csv_profiles %] >- <option value="[% csv_profile.export_format_id | html %]">CSV - [% csv_profile.profile | html %]</option> >- [% END %] >- </select> >+ [% INCLUDE 'download-export-available-formats.inc' %] > <span class="required">Required</span> > </fieldset> > >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasketform.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasketform.tt >index 5449518d34..455009e968 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasketform.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasketform.tt >@@ -36,6 +36,8 @@ > <textarea id="comment" name="comment" rows="4" cols="40"></textarea> > <input type="hidden" name="bib_list" value="[% bib_list | html %]" /> > <input type="hidden" name="csrf_token" value="[% csrf_token | html %]" /> >+ <label for="format">Format:</label> >+ [% INCLUDE 'download-export-available-formats.inc' %] > </fieldset> > [% IF Koha.Preference('RequestOnOpac') || Koha.Preference('OpacRenewalAllowed') %]<p id="donotrequestbymail">Please do not use this mail to request or renew books.</p>[% END %] > <fieldset class="action"> >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendshelfform.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendshelfform.tt >index ece40092f1..cb7af5eb40 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendshelfform.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendshelfform.tt >@@ -39,6 +39,9 @@ > <label for="comment">Comment:</label> > <textarea id="comment" name="comment" rows="4" cols="40"></textarea> > >+ <label for="format">Format:</label> >+ [% INCLUDE 'download-export-available-formats.inc' %] >+ > <input type="hidden" name="shelfid" value="[% shelfid | html %]" /> > </fieldset> > [% IF Koha.Preference('RequestOnOpac') || Koha.Preference('OpacRenewalAllowed') %]<p id="donotrequestbymail">Please do not use this mail to request or renew books.</p>[% END %] >diff --git a/opac/opac-downloadcart.pl b/opac/opac-downloadcart.pl >index 0fb7a02f3c..ab91daf68f 100755 >--- a/opac/opac-downloadcart.pl >+++ b/opac/opac-downloadcart.pl >@@ -63,7 +63,7 @@ if ($bib_list && $format) { > my $extension; > my $type; > >- # CSV >+ # CSV > if ($format =~ /^\d+$/) { > > my $csv_profile = Koha::CsvProfiles->find($format); >@@ -73,8 +73,9 @@ if ($bib_list && $format) { > } > > $output = marc2csv(\@bibs, $format); >+ $format = 'csv'; > >- # Other formats >+ # Other formats > } else { > my $record_processor = Koha::RecordProcessor->new({ > filters => 'ViewPolicy' >@@ -119,9 +120,6 @@ if ($bib_list && $format) { > } > } > >- # If it was a CSV export we change the format after the export so the file extension is fine >- $format = "csv" if ($format =~ m/^\d+$/); >- > print $query->header( > -type => ($type) ? $type : 'application/octet-stream', > -'Content-Transfer-Encoding' => 'binary', >diff --git a/opac/opac-downloadshelf.pl b/opac/opac-downloadshelf.pl >index 99d14a73da..48c5b9268f 100755 >--- a/opac/opac-downloadshelf.pl >+++ b/opac/opac-downloadshelf.pl >@@ -87,6 +87,9 @@ if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { > push @biblios, $content->biblionumber; > } > $output = marc2csv(\@biblios, $format); >+ >+ $format = 'csv'; >+ > # Other formats > } else { > my $record_processor = Koha::RecordProcessor->new({ >@@ -129,9 +132,6 @@ if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { > } > } > >- # If it was a CSV export we change the format after the export so the file extension is fine >- $format = "csv" if ($format =~ m/^\d+$/); >- > print $query->header( > -type => ($type) ? $type : 'application/octet-stream', > -'Content-Transfer-Encoding' => 'binary', >diff --git a/opac/opac-sendbasket.pl b/opac/opac-sendbasket.pl >index eee5e2c29b..44415c1c00 100755 >--- a/opac/opac-sendbasket.pl >+++ b/opac/opac-sendbasket.pl >@@ -33,6 +33,7 @@ use C4::Templates (); > use Koha::Email; > use Koha::Patrons; > use Koha::Token; >+use Koha::CsvProfiles; > > my $query = CGI->new; > >@@ -46,6 +47,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; > >@@ -68,46 +70,25 @@ if ( $email_add ) { > 'opac-sendbasket.tt', 'opac', $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, >- opac => 1, >- borcat => $borcat }); >- 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, >+ template => 'opac', >+ } >+ ); >+ 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, > firstname => $patron->firstname, > surname => $patron->surname, >@@ -143,7 +124,7 @@ $email_header > $body > END_OF_BODY > >- if ( !defined $iso2709 ) { >+ if ( !defined $records_file ) { > carp "Error sending mail: empty basket"; > $template->param( error => 1 ); > } >@@ -158,9 +139,9 @@ END_OF_BODY > $email->header( 'X-Abuse-Report' => C4::Context->preference('KohaAdminEmailAddress') ); > $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', > ); > my $library = $patron->library; >@@ -186,6 +167,7 @@ else { > virtualshelves => C4::Context->preference("virtualshelves"), > csrf_token => Koha::Token->new->generate_csrf( > { session_id => $new_session_id, } ), >+ csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc' }) ], > ); > output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; > } >diff --git a/opac/opac-sendshelf.pl b/opac/opac-sendshelf.pl >index c97aa450dc..26ddd48921 100755 >--- a/opac/opac-sendshelf.pl >+++ b/opac/opac-sendshelf.pl >@@ -32,6 +32,7 @@ use C4::Members; > use Koha::Email; > use Koha::Patrons; > use Koha::Virtualshelves; >+use Koha::CsvProfiles; > > my $query = CGI->new; > >@@ -51,6 +52,7 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( > > my $shelfid = $query->param('shelfid'); > my $email = $query->param('email'); >+my $format = $query->param('format') || 'iso2709'; > > my $dbh = C4::Context->dbh; > >@@ -74,40 +76,31 @@ if ( $email ) { > > my $shelf = Koha::Virtualshelves->find( $shelfid ); > my $contents = $shelf->get_contents; >- my $marcflavour = C4::Context->preference('marcflavour'); >- my $iso2709; >- my @results; > >+ my @biblionumbers; > while ( my $content = $contents->next ) { > my $biblionumber = $content->biblionumber; >- my $record = GetMarcBiblio({ >- biblionumber => $biblionumber, >- embed_items => 1, >- opac => 1, >- borcat => $borcat }); >- next unless $record; >- my $fw = GetFrameworkCode($biblionumber); >- my $dat = GetBiblioData($biblionumber); >- >- my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); >- my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); >- >- my @items = GetItemsInfo( $biblionumber ); >- >- $dat->{ISBN} = GetMarcISBN($record, $marcflavour); >- $dat->{MARCSUBJCTS} = $marcsubjctsarray; >- $dat->{MARCAUTHORS} = $marcauthorsarray; >- $dat->{'biblionumber'} = $biblionumber; >- $dat->{ITEM_RESULTS} = \@items; >- $dat->{HASAUTHORS} = $dat->{'author'} || @$marcauthorsarray; >- >- $iso2709 .= $record->as_usmarc(); >- >- push( @results, $dat ); >+ push @biblionumbers, $biblionumber; > } > >+ my $csv_profile_id; >+ if ( $format =~ m|^\d+$| ) { >+ $csv_profile_id = $format; >+ $format = 'csv'; >+ } >+ my $data = C4::Biblio::BuildBiblioDataForExport( >+ { >+ biblionumbers => \@biblionumbers, >+ format => $format, >+ csv_profile_id => $csv_profile_id, >+ template => 'opac', >+ } >+ ); >+ my $records_file = $data->{records_file}; >+ my $records_data = $data->{records_data}; >+ > $template2->param( >- BIBLIO_RESULTS => \@results, >+ BIBLIO_RESULTS => $records_data, > comment => $comment, > shelfname => $shelf->shelfname, > firstname => $patron->firstname, >@@ -153,9 +146,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 => 'list.iso2709', >+ name => "list.$format", > disposition => 'attachment', > ); > my $library = Koha::Patrons->find( $borrowernumber )->library; >@@ -178,6 +171,7 @@ END_OF_BODY > }else{ > $template->param( shelfid => $shelfid, > url => "/cgi-bin/koha/opac-sendshelf.pl", >+ csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc' }) ], > ); > output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; > } >diff --git a/t/db_dependent/Biblio/BuildBiblioDataForExport.t b/t/db_dependent/Biblio/BuildBiblioDataForExport.t >new file mode 100644 >index 0000000000..e779274b6a >--- /dev/null >+++ b/t/db_dependent/Biblio/BuildBiblioDataForExport.t >@@ -0,0 +1,120 @@ >+use Modern::Perl; >+use Test::More tests => 4; >+ >+use Test::MockModule; >+use MARC::Record; >+use MARC::Field; >+ >+use C4::Biblio; >+use C4::Context; >+use C4::Items; >+use C4::Record; >+use Koha::DateUtils; >+use Koha::Item; >+ >+use t::lib::TestBuilder; >+ >+my $schema = Koha::Database->new()->schema(); >+$schema->storage->txn_begin(); >+ >+my $builder = t::lib::TestBuilder->new(); >+ >+my $title = q|The art of computer programming|; >+my $author = 'Knuth, Donald Ervin'; >+my $biblio = $builder->build_sample_biblio({ title => $title, author => $author }); >+my $record = $biblio->metadata->record; >+if (C4::Context->preference('marcflavour') eq 'UNIMARC') { >+ $record->append_fields( >+ MARC::Field->new(200, ' ', ' ', a => 'The art of another title', f => 'Donald E. Knuth. II'), >+ MARC::Field->new(700, '0', '0', a => 'Knuth,Donald Ervin'), >+ ); >+} else { >+ $record->field(245)->update(c => $author); >+ $record->append_fields( >+ MARC::Field->new(245, ' ', ' ', a => 'The art of another title', f => 'Donald E. Knuth. II'), >+ ); >+} >+$record->append_fields( >+ MARC::Field->new( >+ 600, ' ', '1', >+ a => 'Computer programming.', >+ 9 => '462', >+ ), >+ MARC::Field->new( >+ 600, ' ', '0', >+ a => 'Computer algorithms.', >+ 9 => '499', >+ ), >+); >+$biblio->metadata->update({ metadata => $record->as_xml() }); >+my $biblionumber = $biblio->biblionumber; >+my $item = $builder->build_sample_item({ biblionumber => $biblionumber, library => 'CPL', itype => 'CANNOT', barcode => 'my new barcode' }); >+ >+subtest 'csv' => sub { >+ plan tests => 1; >+ my $csv_content = C4::Context->preference('marcflavour') eq 'UNIMARC' >+ ? 'Title=200$a|Subject=600$a' >+ : 'Title=245$a|Subject=600$a'; >+ my $csv_profile_id = insert_csv_profile({ csv_content => $csv_content }); >+ >+ my $csv_data = C4::Biblio::BuildBiblioDataForExport({ >+ biblionumbers => [ $biblionumber ], >+ format => 'csv', >+ csv_profile_id => $csv_profile_id, >+ }); >+ >+ is_deeply( $csv_data, { records_data => [], records_file => qq{Title|Subject >+"$title,The art of another title"|"Computer programming.,Computer algorithms." >+}}, 'BuildBiblioDataForExport should return correct values in csv' ); >+}; >+ >+subtest 'iso2709' => sub { >+ plan tests => 7; >+ my $iso2709_data = C4::Biblio::BuildBiblioDataForExport({ >+ biblionumbers => [ $biblionumber ], >+ format => 'iso2709', >+ }); >+ >+ my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1}); >+ >+ like( $iso2709_data->{records_file}, qr{00467nam a2200121 a \d+140211b xxu||||| |||| 00| 0 eng d1 aKnuth, Donald Ervind193814a$titlecDonald E. Knuth.9014aThe art of another titlecDonald E. Knuth. II91 1aComputer programming.9462 0aComputer algorithms.9499 c57d57 00104070910aCPLbCPLd$todaypmy new barcoder$todayw$todayyCANNOT}, 'BuildBiblioDataForExport should return a correct records file in iso2709' ); >+ >+ my $first_biblio_data = @{ $iso2709_data->{records_data} }[0]; >+ is( $first_biblio_data->{HASAUTHORS}, 1 ); >+ is( scalar( @{ $first_biblio_data->{MARCSUBJCTS} } ), 2, '499 and 462' ); >+ is( $first_biblio_data->{title}, $title ); >+ is( scalar( @{ $first_biblio_data->{ITEM_RESULTS} } ), 1, '1 item' ); >+ is( scalar( @{ $first_biblio_data->{MARCAUTHORS} } ), 1, '1 author' ); >+ is( $first_biblio_data->{biblionumber}, $biblionumber, 'bibionumber is correct' ); >+}; >+ >+subtest 'ris' => sub { >+ plan tests => 1; >+ my $ris_data = C4::Biblio::BuildBiblioDataForExport({ >+ biblionumbers => [ $biblionumber ], >+ format => 'ris', >+ }); >+ is( $ris_data->{records_file}, qq|TY - GEN\r\nAU - Knuth,Donald Ervin\r\nTI - $title\r\nKW - Computer programming.\r\nKW - Computer algorithms.\r\nER - \r\n|,); >+}; >+ >+subtest 'bibtex' => sub { >+ plan tests => 1; >+ my $bibtex_data = C4::Biblio::BuildBiblioDataForExport({ >+ biblionumbers => [ $biblionumber ], >+ format => 'bibtex', >+ }); >+ my $expected = qq|\@book{$biblionumber,\n\tauthor = {Knuth,Donald Ervin},\n\ttitle = {The art of computer programming}\n}\n|; >+ is( $bibtex_data->{records_file}, $expected); >+}; >+ >+sub insert_csv_profile { >+ my ( $params ) = @_; >+ my $dbh = C4::Context->dbh; >+ $dbh->do(q| >+ INSERT INTO export_format(profile, description, content, csv_separator, field_separator, subfield_separator, encoding, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?) >+ |, {}, ("TEST_PROFILE4", "my desc", $params->{csv_content}, '|', ';', ',', 'utf8', 'marc') >+ ); >+ return $dbh->last_insert_id( undef, undef, 'export_format', undef ); >+} >+ >+$schema->storage->txn_rollback(); >diff --git a/virtualshelves/sendshelf.pl b/virtualshelves/sendshelf.pl >index f15e2c9f64..d280fb3796 100755 >--- a/virtualshelves/sendshelf.pl >+++ b/virtualshelves/sendshelf.pl >@@ -30,6 +30,7 @@ use C4::Items; > use C4::Output; > use Koha::Email; > use Koha::Virtualshelves; >+use Koha::CsvProfiles; > > my $query = CGI->new; > >@@ -44,6 +45,7 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( > > my $shelfid = $query->param('shelfid'); > my $to_address = $query->param('email'); >+my $format = $query->param('format') || 'iso2709'; > > my $dbh = C4::Context->dbh; > >@@ -61,35 +63,30 @@ if ($to_address) { > > my $shelf = Koha::Virtualshelves->find( $shelfid ); > my $contents = $shelf->get_contents; >- my $marcflavour = C4::Context->preference('marcflavour'); >- my $iso2709; >- my @results; > >+ my @biblionumbers; > while ( my $content = $contents->next ) { > my $biblionumber = $content->biblionumber; >- my $dat = GetBiblioData($biblionumber); >- my $record = GetMarcBiblio({ >- biblionumber => $biblionumber, >- embed_items => 1 }); >- my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); >- my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); >- >- my @items = GetItemsInfo($biblionumber); >- >- $dat->{ISBN} = GetMarcISBN($record, $marcflavour); >- $dat->{MARCSUBJCTS} = $marcsubjctsarray; >- $dat->{MARCAUTHORS} = $marcauthorsarray; >- $dat->{'biblionumber'} = $biblionumber; >- $dat->{ITEM_RESULTS} = \@items; >- $dat->{HASAUTHORS} = $dat->{'author'} || @$marcauthorsarray; >- >- $iso2709 .= $record->as_usmarc(); >+ push @biblionumbers, $biblionumber; >+ } > >- push( @results, $dat ); >+ my $csv_profile_id; >+ if ( $format =~ m|^\d+$| ) { >+ $csv_profile_id = $format; >+ $format = 'csv'; > } >+ 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}; > > $template2->param( >- BIBLIO_RESULTS => \@results, >+ BIBLIO_RESULTS => $records_data, > comment => $comment, > shelfname => $shelf->shelfname, > ); >@@ -133,9 +130,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 => 'shelf.iso2709', >+ name => "shelf.$format", > disposition => 'attachment', > ); > >@@ -156,6 +153,7 @@ else { > $template->param( > shelfid => $shelfid, > url => "/cgi-bin/koha/virtualshelves/sendshelf.pl", >+ csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc' }) ], > ); > output_html_with_http_headers $query, $cookie, $template->output; > } >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 13345
:
34013
|
34392
|
35509
|
36270
|
38032
|
47297
|
56499
|
61210
|
100886
|
101998
|
101999
|
103433
|
103434
|
103435
| 119078