Bugzilla – Attachment 34013 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), 55.74 KB, created by
Jonathan Druart
on 2014-11-28 11:30:47 UTC
(
hide
)
Description:
Bug 13345: Allow patrons to choose format on sending basket/list by email
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2014-11-28 11:30:47 UTC
Size:
55.74 KB
patch
obsolete
>From d82794f91ab7908ecb98d6732b05d4df1ffe5260 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 > >Not that subtitles are not displayed in all these cases. > >Note for QA: This patch refactors 3 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 >Not that a similar job is done in [opac-]downloadcart.pl and >[opac-]downloadshelf.pl > >3/ Build the subject and body of the email sent >Same as before, the job was done at the same places. >Now it's done in Koha::Email->fill_body_for_sending (feel free to >suggestion a better name) and tests are provided in t/Koha_Email.t > >Some tests for BuildBiblioDataForExport can fail if bug 13360 is not >pushed yet. >--- > C4/Biblio.pm | 60 +++++++++ > Koha/Email.pm | 75 +++++++++++ > basket/basket.pl | 6 +- > basket/downloadcart.pl | 1 - > basket/sendbasket.pl | 113 ++++------------- > .../includes/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 | 34 ++--- > .../en/modules/virtualshelves/downloadshelf.tt | 18 +-- > .../en/modules/virtualshelves/sendshelfform.tt | 34 ++--- > .../includes/download-export-available-formats.inc | 9 ++ > .../bootstrap/en/modules/opac-downloadcart.tt | 10 +- > .../bootstrap/en/modules/opac-downloadshelf.tt | 10 +- > .../bootstrap/en/modules/opac-sendbasket.tt | 6 +- > .../bootstrap/en/modules/opac-sendbasketform.tt | 2 + > .../bootstrap/en/modules/opac-sendshelfform.tt | 5 +- > opac/opac-downloadcart.pl | 9 +- > opac/opac-downloadshelf.pl | 8 +- > opac/opac-sendbasket.pl | 121 +++++------------- > opac/opac-sendshelf.pl | 113 ++++------------- > t/Koha_Email.t | 77 +++++++++++- > t/data/templates/send_by_email.tt | 11 ++ > t/db_dependent/Biblio/BuildBiblioDataForExport.t | 139 +++++++++++++++++++++ > virtualshelves/downloadshelf.pl | 1 - > virtualshelves/sendshelf.pl | 110 ++++------------ > 26 files changed, 562 insertions(+), 442 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/data/templates/send_by_email.tt > create mode 100644 t/db_dependent/Biblio/BuildBiblioDataForExport.t > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index 8d62a61..176ae43 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -38,6 +38,7 @@ use C4::ClassSource; > use C4::Charset; > use C4::Linker; > use C4::OAI::Sets; >+use C4::Ris; > > use Koha::Cache; > >@@ -3760,6 +3761,65 @@ sub RemoveAllNsb { > return $record; > } > >+sub BuildBiblioDataForExport { >+ my ( $params ) = @_; >+ my $biblionumbers = $params->{biblionumbers}; >+ my $format = $params->{format}; >+ 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); >+ my $record = GetMarcBiblio($biblionumber, 1); >+ my $marcnotesarray = GetMarcNotes( $record, $marcflavour ); >+ my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); >+ my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); >+ my $fw = GetFrameworkCode($biblionumber); >+ my $subtitle = GetRecordValue( 'subtitle', $record, $fw ); >+ >+ my @items = C4::Items::GetItemsInfo( $biblionumber ); >+ >+ my $hasauthors = 0; >+ if($dat->{'author'} || @$marcauthorsarray) { >+ $hasauthors = 1; >+ } >+ >+ $dat->{MARCNOTES} = $marcnotesarray; >+ $dat->{MARCSUBJCTS} = $marcsubjctsarray; >+ $dat->{MARCAUTHORS} = $marcauthorsarray; >+ $dat->{HASAUTHORS} = $hasauthors; >+ $dat->{biblionumber} = $biblionumber; >+ $dat->{ITEM_RESULTS} = \@items; >+ $dat->{subtitle} = $subtitle; >+ >+ if ($format eq 'iso2709') { >+ $records_file .= $record->as_usmarc(); >+ } >+ elsif ($format eq 'ris') { >+ $records_file .= C4::Ris::marc2ris($record); >+ } >+ elsif ($format eq 'bibtex') { >+ $records_file .= C4::Record::marc2bibtex($record, $biblionumber); >+ } >+ >+ push( @records_data, $dat ); >+ } >+ } >+ >+ return { records_file => $records_file, records_data => \@records_data }; >+} >+ > 1; > > >diff --git a/Koha/Email.pm b/Koha/Email.pm >index fc392a3..c11e670 100644 >--- a/Koha/Email.pm >+++ b/Koha/Email.pm >@@ -18,6 +18,9 @@ > package Koha::Email; > > use Modern::Perl; >+use Encode qw( encode ); >+use MIME::QuotedPrint; >+use MIME::Base64; > > use base qw(Class::Accessor); > use C4::Context; >@@ -60,6 +63,78 @@ sub create_message_headers { > $mail{'Message'} = $params->{message} if $params->{message}; > $mail{'Subject'} = $params->{subject} if $params->{subject}; > $mail{'Content-Type'} = $params->{contenttype} if $params->{contenttype}; >+ $self->{mail} = \%mail; > return %mail; > } >+ >+sub fill_body_for_sending { >+ my ( $self, $params ) = @_; >+ my $template = $params->{template}; >+ my $default_filename = $params->{default_filename}; >+ my $attachment = $params->{attachment}; >+ >+ my %mail = %{ $self->{mail} }; >+ >+ # Analysing information and getting mail properties >+ if ( $template =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) { >+ $mail{Subject} = $1; >+ $mail{Subject} =~ s|\n?(.*)\n?|$1|; >+ $mail{Subject} = Encode::encode("UTF-8", $mail{Subject}); >+ } >+ else { $mail{Subject} = "no subject"; } >+ >+ my $email_header = ""; >+ if ( $template =~ /<HEADER>(.*)<END_HEADER>/s ) { >+ $email_header = $1; >+ $email_header =~ s|\n?(.*)\n?|$1|; >+ $email_header = encode_qp(Encode::encode("UTF-8", $email_header)); >+ } >+ >+ if ( $template =~ /<FILENAME>(.*)<END_FILENAME>/s ) { >+ $default_filename = $1; >+ $default_filename =~ s|\n?(.*)\n?|$1|; >+ } >+ >+ my $body; >+ if ( $template =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) { >+ $body = $1; >+ $body =~ s|\n?(.*)\n?|$1|; >+ $body = encode_qp(Encode::encode("UTF-8", $body)); >+ } >+ >+ my $boundary = "====" . time() . "===="; >+ >+ # We set and put the multipart content >+ $mail{'Content-Type'} = qq|multipart/mixed; boundary="$boundary"|; >+ >+ # If the attachement is a csv file, it's already encoded >+ # See C4::Record::marc2csv which calls C4::Record::marcrecord2csv >+ unless ( $default_filename =~ m|.csv$| ) { >+ $attachment = Encode::encode( "UTF-8", $attachment ) >+ } >+ my $file = encode_base64( $attachment ); >+ $boundary = '--' . $boundary; >+ >+ $mail{body} = <<END_OF_BODY; >+$boundary >+MIME-Version: 1.0 >+Content-Type: text/plain; charset="utf-8" >+Content-Transfer-Encoding: quoted-printable >+ >+$email_header >+$body >+$boundary >+Content-Type: application/octet-stream; name="$default_filename" >+Content-Transfer-Encoding: base64 >+Content-Disposition: attachment; filename="$default_filename" >+ >+$file >+$boundary-- >+END_OF_BODY >+ >+ $self->{mail} = \%mail; >+ >+ return %mail; >+} >+ > 1; >diff --git a/basket/basket.pl b/basket/basket.pl >index ea8e863..d726221 100755 >--- a/basket/basket.pl >+++ b/basket/basket.pl >@@ -15,16 +15,14 @@ > # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, > # Suite 330, Boston, MA 02111-1307 USA > >- >-use strict; >-use warnings; >+use Modern::Perl; > use CGI qw ( -utf8 ); > use C4::Koha; > use C4::Biblio; > use C4::Items; > use C4::Auth; > use C4::Output; >-use C4::Csv; >+use C4::Csv qw( GetCsvProfilesLoop ); > > my $query = new CGI; > >diff --git a/basket/downloadcart.pl b/basket/downloadcart.pl >index 199271e..1669e39 100755 >--- a/basket/downloadcart.pl >+++ b/basket/downloadcart.pl >@@ -21,7 +21,6 @@ use strict; > use warnings; > > use CGI qw ( -utf8 ); >-use Encode qw(encode); > > use C4::Auth; > use C4::Biblio; >diff --git a/basket/sendbasket.pl b/basket/sendbasket.pl >index 9c3e6a5..02b110b 100755 >--- a/basket/sendbasket.pl >+++ b/basket/sendbasket.pl >@@ -15,21 +15,18 @@ > # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, > # Suite 330, Boston, MA 02111-1307 USA > >-use strict; >-use warnings; >+use Modern::Perl; > > use CGI qw ( -utf8 ); >-use Encode qw(encode); > use Carp; > > use Mail::Sendmail; >-use MIME::QuotedPrint; >-use MIME::Base64; > use C4::Biblio; > use C4::Items; > use C4::Auth; > use C4::Output; > use C4::Biblio; >+use C4::Csv qw( GetCsvProfilesLoop ); > use Koha::Email; > > my $query = new CGI; >@@ -47,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 $email_sender = $query->param('email_sender'); >+my $format = $query->param('format') || 'iso2709'; > > my $dbh = C4::Context->dbh; > >@@ -64,98 +62,38 @@ if ( $email_add ) { > } > ); > >- 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); >- my $record = GetMarcBiblio($biblionumber, 1); >- my $marcnotesarray = GetMarcNotes( $record, $marcflavour ); >- my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); >- my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); >- >- my @items = GetItemsInfo( $biblionumber ); >- >- my $hasauthors = 0; >- if($dat->{'author'} || @$marcauthorsarray) { >- $hasauthors = 1; >- } >- >- >- $dat->{MARCNOTES} = $marcnotesarray; >- $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, > email_sender => $email_sender, > comment => $comment > ); > > # Getting template result > my $template_res = $template2->output(); >- my $body; >- >- # Analysing information and getting mail properties >- if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) { >- $mail{subject} = $1; >- $mail{subject} =~ s|\n?(.*)\n?|$1|; >- $mail{subject} = Encode::encode("UTF-8", $mail{subject}); >- } >- else { $mail{'subject'} = "no subject"; } > >- my $email_header = ""; >- if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) { >- $email_header = $1; >- $email_header =~ s|\n?(.*)\n?|$1|; >- $email_header = encode_qp(Encode::encode("UTF-8", $email_header)); >- } >- >- my $email_file = "basket.txt"; >- if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) { >- $email_file = $1; >- $email_file =~ s|\n?(.*)\n?|$1|; >- } >- >- if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) { >- $body = $1; >- $body =~ s|\n?(.*)\n?|$1|; >- $body = encode_qp(Encode::encode("UTF-8", $body)); >- } >- >- my $boundary = "====" . time() . "===="; >- >- # Writing mail >- $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\""; >- my $isofile = encode_base64(encode("UTF-8", $iso2709)); >- $boundary = '--' . $boundary; >- $mail{body} = <<END_OF_BODY; >-$boundary >-Content-Type: text/plain; charset="utf-8" >-Content-Transfer-Encoding: quoted-printable >- >-$email_header >-$body >-$boundary >-Content-Type: application/octet-stream; name="basket.iso2709" >-Content-Transfer-Encoding: base64 >-Content-Disposition: attachment; filename="basket.iso2709" >- >-$isofile >-$boundary-- >-END_OF_BODY >+ %mail = $email->fill_body_for_sending( >+ { >+ template => $template_res, >+ default_filename => "basket.$format", >+ attachment => $records_file, >+ } >+ ); > > # Sending mail > if ( sendmail %mail ) { >@@ -176,6 +114,7 @@ else { > url => "/cgi-bin/koha/basket/sendbasket.pl", > suggestion => C4::Context->preference("suggestion"), > virtualshelves => C4::Context->preference("virtualshelves"), >+ csv_profiles => GetCsvProfilesLoop('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 0000000..4aec38a >--- /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 %]">CSV - [% csv_profile.profile %]</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 a343bd8..f81839a 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">iso2709</option> >- <option value="ris">RIS</option> >- <option value="bibtex">BibTex</option> >- [% FOREACH csv_profile IN csv_profiles %] >- <option value="[% csv_profile.export_format_id %]">CSV - [% csv_profile.profile %]</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 0514bc1..8646756 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 %] >- [% IF ( BIBLIO_RESULT.subtitle ) %] [% BIBLIO_RESULT.subtitle %][% END %] >+ [% IF ( BIBLIO_RESULT.subtitle.size ) %] >+ [% FOREACH subtitle IN BIBLIO_RESULT.subtitle %] >+ [% subtitle.subfield %] >+ [% END %] >+ [% END %] > </span> > > <p> >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 d0f7957..4fb6d37 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/sendbasketform.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/basket/sendbasketform.tt >@@ -17,21 +17,27 @@ > [% ELSE %] > > <form action="[% url %]" 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> >- <li> >+ <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="hidden" name="bib_list" value="[% bib_list %]" /> >- </li></ol></fieldset> >- <fieldset class="action"> <input type="submit" value="Send" /> <a class="cancel close" href="#">Cancel</a> </fieldset> >+ <input type="submit" value="Send" /> <a class="cancel close" href="#">Cancel</a> >+ </fieldset> > </form> > > [% END %]</div> >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 00cb335..41827da 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/downloadshelf.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/downloadshelf.tt >@@ -10,18 +10,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">iso2709</option> >- <option value="ris">RIS</option> >- <option value="bibtex">BibTex</option> >- [% FOREACH csv_profile IN csv_profiles %] >- <option value="[% csv_profile.export_format_id %]">CSV - [% csv_profile.profile %]</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 %]" /> > <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 e38a071..0728aec 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/sendshelfform.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/sendshelfform.tt >@@ -16,21 +16,27 @@ > [% ELSE %] > > <form action="[% url %]" method="post"> >- >-<fieldset class="rows"> >-<legend>Sending your list</legend> >-<ol> <li> >- <label for="email">Email address:</label> >- <input type="text" id="email" name="email" size="43" class="focus" /> >- </li> >- <li> >- <label for="comment">Comment:</label> >- <textarea id="comment" name="comment" rows="4" cols="40"></textarea> >- </li> >- <li> >+ <fieldset class="rows"> >+ <legend>Sending your list</legend> >+ <ol> >+ <li> >+ <label for="email">Email address:</label> >+ <input type="text" id="email" name="email" 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="hidden" name="shelfid" value="[% shelfid %]" /> >- </li></ol></fieldset> >- <fieldset class="action"> <input type="submit" value="Send" /> <a class="cancel close" href="#">Cancel</a> </fieldset> >+ <input type="submit" value="Send" /> <a class="cancel close" href="#">Cancel</a> >+ </fieldset> > </form> > > [% END %]</div> >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 0000000..4aec38a >--- /dev/null >+++ b/koha-tmpl/opac-tmpl/bootstrap/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 %]">CSV - [% csv_profile.profile %]</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 8536c46..932fd8e 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadcart.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadcart.tt >@@ -10,15 +10,7 @@ > <div id="userdownloadcart"> > <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="iso2709">MARC</option> >- [% FOREACH csv_profile IN csv_profiles %] >- <option value="[% csv_profile.export_format_id %]">CSV - [% csv_profile.profile %]</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 87df1da..cea1a83 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadshelf.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadshelf.tt >@@ -49,15 +49,7 @@ > <h1>Download list <i>[% shelfname %]</i></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="iso2709">MARC</option> >- [% FOREACH csv_profile IN csv_profiles %] >- <option value="[% csv_profile.export_format_id %]">CSV - [% csv_profile.profile %]</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-sendbasket.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasket.tt >index 29c4cbb..ed8e23b 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasket.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasket.tt >@@ -32,7 +32,11 @@ Your cart > <li> > <span> > [% BIBLIO_RESULT.title %] >- [% IF ( BIBLIO_RESULT.subtitle ) %] [% BIBLIO_RESULT.subtitle %][% END %] >+ [% IF ( BIBLIO_RESULT.subtitle.size ) %] >+ [% FOREACH subtitle IN BIBLIO_RESULT.subtitle %] >+ [% subtitle.subfield %] >+ [% END %] >+ [% END %] > </span> > > <p> >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 a2f4bcc..647a5fb 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasketform.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasketform.tt >@@ -33,6 +33,8 @@ > <label for="comment">Comment:</label> > <textarea id="comment" name="comment" rows="4" cols="40"></textarea> > <input type="hidden" name="bib_list" value="[% bib_list %]" /> >+ <label for="format">Format:</label> >+ [% INCLUDE 'download-export-available-formats.inc' %] > </fieldset> > <fieldset class="action"> > <input type="submit" class="btn" value="Send" /> >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 30ad182..c59fb8d 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendshelfform.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendshelfform.tt >@@ -37,7 +37,10 @@ > <label for="comment">Comment:</label> > <textarea id="comment" name="comment" rows="4" cols="40"></textarea> > >- <input type="hidden" name="shelfid" value="[% shelfid %]" /> >+ <label for="format">Format:</label> >+ [% INCLUDE 'download-export-available-formats.inc' %] >+ >+ <input type="hidden" name="shelfid" value="[% shelfid %]" /> > </fieldset> > <fieldset class="action"> > <input type="submit" value="Send" class="btn" /> >diff --git a/opac/opac-downloadcart.pl b/opac/opac-downloadcart.pl >index 98a7f3c..1cfe96e 100755 >--- a/opac/opac-downloadcart.pl >+++ b/opac/opac-downloadcart.pl >@@ -21,7 +21,6 @@ use strict; > use warnings; > > use CGI qw ( -utf8 ); >-use Encode qw(encode); > > use C4::Auth; > use C4::Biblio; >@@ -55,12 +54,13 @@ if ($bib_list && $format) { > my $marcflavour = C4::Context->preference('marcflavour'); > my $output; > >- # CSV >+ # CSV > if ($format =~ /^\d+$/) { > > $output = marc2csv(\@bibs, $format); >+ $format = 'csv'; > >- # Other formats >+ # Other formats > } else { > foreach my $biblio (@bibs) { > >@@ -79,9 +79,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 => 'application/octet-stream', > -'Content-Transfer-Encoding' => 'binary', >diff --git a/opac/opac-downloadshelf.pl b/opac/opac-downloadshelf.pl >index 7a6b1dd..5fce5a9 100755 >--- a/opac/opac-downloadshelf.pl >+++ b/opac/opac-downloadshelf.pl >@@ -21,7 +21,6 @@ use strict; > use warnings; > > use CGI qw ( -utf8 ); >-use Encode qw(encode); > > use C4::Auth; > use C4::Biblio; >@@ -65,7 +64,9 @@ if ( ShelfPossibleAction( (defined($borrowernumber) ? $borrowernumber : -1), $sh > push @biblios, $_->{biblionumber}; > } > $output = marc2csv(\@biblios, $format); >- >+ >+ $format = 'csv'; >+ > # Other formats > } else { > foreach my $biblio (@$items) { >@@ -86,9 +87,6 @@ if ( ShelfPossibleAction( (defined($borrowernumber) ? $borrowernumber : -1), $sh > } > } > >- # 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 => 'application/octet-stream', > -'Content-Transfer-Encoding' => 'binary', >diff --git a/opac/opac-sendbasket.pl b/opac/opac-sendbasket.pl >index d0aa34a..863e773 100755 >--- a/opac/opac-sendbasket.pl >+++ b/opac/opac-sendbasket.pl >@@ -17,22 +17,19 @@ > # with Koha; if not, write to the Free Software Foundation, Inc., > # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. > >-use strict; >-use warnings; >+use Modern::Perl; > > use CGI qw ( -utf8 ); >-use Encode qw(encode); > use Carp; > > use Mail::Sendmail; >-use MIME::QuotedPrint; >-use MIME::Base64; > use C4::Biblio; > use C4::Items; > use C4::Auth; > use C4::Output; > use C4::Biblio; > use C4::Members; >+use C4::Csv qw( GetCsvProfilesLoop ); > use Koha::Email; > > my $query = new CGI; >@@ -50,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 $email_sender = $query->param('email_sender'); >+my $format = $query->param('format') || 'iso2709'; > > my $dbh = C4::Context->dbh; > >@@ -79,43 +77,24 @@ if ( $email_add ) { > } > ); > >- 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); >- my $record = GetMarcBiblio($biblionumber, 1); >- my $marcnotesarray = GetMarcNotes( $record, $marcflavour ); >- my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); >- my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); >- >- my @items = GetItemsInfo( $biblionumber ); >- >- my $hasauthors = 0; >- if($dat->{'author'} || @$marcauthorsarray) { >- $hasauthors = 1; >- } >- >- >- $dat->{MARCNOTES} = $marcnotesarray; >- $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, > email_sender => $email_sender, > comment => $comment, > firstname => $user->{firstname}, >@@ -124,68 +103,23 @@ if ( $email_add ) { > > # Getting template result > my $template_res = $template2->output(); >- my $body; >- >- # Analysing information and getting mail properties >- >- if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) { >- $mail{subject} = $1; >- $mail{subject} =~ s|\n?(.*)\n?|$1|; >- $mail{subject} = Encode::encode("UTF-8", $mail{subject}); >- } >- else { $mail{'subject'} = "no subject"; } > >- my $email_header = ""; >- if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) { >- $email_header = $1; >- $email_header =~ s|\n?(.*)\n?|$1|; >- $email_header = encode_qp(Encode::encode("UTF-8", $email_header)); >- } >- >- my $email_file = "basket.txt"; >- if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) { >- $email_file = $1; >- $email_file =~ s|\n?(.*)\n?|$1|; >- } >- >- if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) { >- $body = $1; >- $body =~ s|\n?(.*)\n?|$1|; >- $body = encode_qp(Encode::encode("UTF-8", $body)); >- } >- >- $mail{body} = $body; >- >- my $boundary = "====" . time() . "===="; >- >- $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\""; >- my $isofile = encode_base64(encode("UTF-8", $iso2709)); >- $boundary = '--' . $boundary; >- $mail{body} = <<END_OF_BODY; >-$boundary >-MIME-Version: 1.0 >-Content-Type: text/plain; charset="UTF-8" >-Content-Transfer-Encoding: quoted-printable >- >-$email_header >-$body >-$boundary >-Content-Type: application/octet-stream; name="basket.iso2709" >-Content-Transfer-Encoding: base64 >-Content-Disposition: attachment; filename="basket.iso2709" >- >-$isofile >-$boundary-- >-END_OF_BODY >+ %mail = $email->fill_body_for_sending( >+ { >+ template => $template_res, >+ default_filename => "basket.$format", >+ attachment => $records_file, >+ } >+ ); > > # Sending mail (if not empty basket) >- if ( defined($iso2709) && sendmail %mail ) { >+ if ( defined($records_file) && sendmail %mail ) { > # do something if it works.... > $template->param( SENT => "1" ); > } > else { > # do something if it doesnt work.... >- carp "Error sending mail: empty basket" if !defined($iso2709); >+ carp "Error sending mail: empty basket" unless defined($records_file); > carp "Error sending mail: $Mail::Sendmail::error" if $Mail::Sendmail::error; > $template->param( error => 1 ); > } >@@ -198,6 +132,7 @@ else { > url => "/cgi-bin/koha/opac-sendbasket.pl", > suggestion => C4::Context->preference("suggestion"), > virtualshelves => C4::Context->preference("virtualshelves"), >+ csv_profiles => GetCsvProfilesLoop('marc'), > ); > output_html_with_http_headers $query, $cookie, $template->output; > } >diff --git a/opac/opac-sendshelf.pl b/opac/opac-sendshelf.pl >index 3086ccc..ff3e391 100755 >--- a/opac/opac-sendshelf.pl >+++ b/opac/opac-sendshelf.pl >@@ -17,22 +17,19 @@ > # with Koha; if not, write to the Free Software Foundation, Inc., > # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. > >-use strict; >-use warnings; >+use Modern::Perl; > > use CGI qw ( -utf8 ); >-use Encode qw( encode ); > use Carp; > > use Mail::Sendmail; >-use MIME::QuotedPrint; >-use MIME::Base64; > use C4::Auth; > use C4::Biblio; > use C4::Items; > use C4::Output; > use C4::VirtualShelves; > use C4::Members; >+use C4::Csv qw( GetCsvProfilesLoop ); > use Koha::Email; > > my $query = new CGI; >@@ -49,6 +46,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; > >@@ -76,41 +74,27 @@ if ( $email ) { > > my @shelf = GetShelf($shelfid); > my ($items, $totitems) = GetShelfContents($shelfid); >- my $marcflavour = C4::Context->preference('marcflavour'); >- my $iso2709; >- my @results; >- >- # retrieve biblios from shelf >- foreach my $biblio (@$items) { >- my $biblionumber = $biblio->{biblionumber}; >- my $fw = GetFrameworkCode($biblionumber); >- my $dat = GetBiblioData($biblionumber); >- my $record = GetMarcBiblio($biblionumber, 1); >- my $marcnotesarray = GetMarcNotes( $record, $marcflavour ); >- my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); >- my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); >- my $subtitle = GetRecordValue('subtitle', $record, $fw); >- >- my @items = GetItemsInfo( $biblionumber ); >- >- $dat->{ISBN} = GetMarcISBN($record, $marcflavour); >- $dat->{MARCNOTES} = $marcnotesarray; >- $dat->{MARCSUBJCTS} = $marcsubjctsarray; >- $dat->{MARCAUTHORS} = $marcauthorsarray; >- $dat->{'biblionumber'} = $biblionumber; >- $dat->{ITEM_RESULTS} = \@items; >- $dat->{subtitle} = $subtitle; >- $dat->{HASAUTHORS} = $dat->{'author'} || @$marcauthorsarray; >- >- $iso2709 .= $record->as_usmarc(); >- >- push( @results, $dat ); >+ >+ my $csv_profile_id; >+ if ( $format =~ m|^\d+$| ) { >+ $csv_profile_id = $format; >+ $format = 'csv'; > } >+ my @biblionumbers = map { $_->{biblionumber} } @$items; >+ 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 $user = GetMember(borrowernumber => $borrowernumber); > > $template2->param( >- BIBLIO_RESULTS => \@results, >+ BIBLIO_RESULTS => $records_data, > email_sender => $mail{'from'}, > comment => $comment, > shelfname => $shelf[1], >@@ -122,57 +106,13 @@ if ( $email ) { > my $template_res = $template2->output(); > my $body; > >- # Analysing information and getting mail properties >- if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) { >- $mail{subject} = $1; >- $mail{subject} =~ s|\n?(.*)\n?|$1|; >- } >- else { $mail{'subject'} = "no subject"; } >- $mail{subject} = Encode::encode("UTF-8", $mail{subject}); >- >- my $email_header = ""; >- if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) { >- $email_header = $1; >- $email_header =~ s|\n?(.*)\n?|$1|; >- $email_header = encode_qp(Encode::encode("UTF-8", $email_header)); >- } >- >- my $email_file = "list.txt"; >- if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) { >- $email_file = $1; >- $email_file =~ s|\n?(.*)\n?|$1|; >- } >- >- if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) { >- $body = $1; >- $body =~ s|\n?(.*)\n?|$1|; >- $body = encode_qp(Encode::encode("UTF-8", $body)); >- } >- >- my $boundary = "====" . time() . "===="; >- >- # We set and put the multipart content >- $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\""; >- >- my $isofile = encode_base64(encode("UTF-8", $iso2709)); >- $boundary = '--' . $boundary; >- >- $mail{body} = <<END_OF_BODY; >-$boundary >-MIME-Version: 1.0 >-Content-Type: text/plain; charset="utf-8" >-Content-Transfer-Encoding: quoted-printable >- >-$email_header >-$body >-$boundary >-Content-Type: application/octet-stream; name="list.iso2709" >-Content-Transfer-Encoding: base64 >-Content-Disposition: attachment; filename="list.iso2709" >- >-$isofile >-$boundary-- >-END_OF_BODY >+ %mail = $message->fill_body_for_sending( >+ { >+ template => $template_res, >+ default_filename => "list.$format", >+ attachment => $records_file, >+ } >+ ); > > # Sending mail > if ( sendmail %mail ) { >@@ -192,6 +132,7 @@ END_OF_BODY > }else{ > $template->param( shelfid => $shelfid, > url => "/cgi-bin/koha/opac-sendshelf.pl", >+ csv_profiles => GetCsvProfilesLoop('marc'), > ); > output_html_with_http_headers $query, $cookie, $template->output; > } >diff --git a/t/Koha_Email.t b/t/Koha_Email.t >index 93dd55b..0c30b12 100755 >--- a/t/Koha_Email.t >+++ b/t/Koha_Email.t >@@ -1,7 +1,13 @@ > use Modern::Perl; > >+use MIME::QuotedPrint; >+use MIME::Base64; >+use Template; >+ > use t::lib::Mocks; >-use Test::More tests => 4; # last test to print >+use Test::More tests => 6; >+ >+use FindBin qw( $Bin ); > > use_ok('Koha::Email'); > >@@ -9,8 +15,73 @@ my $from = 'chrisc@catalyst.net.nz'; > t::lib::Mocks::mock_preference('ReplytoDefault', $from); > t::lib::Mocks::mock_preference('ReturnpathDefault', $from); > >- >- > ok( my $email = Koha::Email->new(), 'Create a Koha::Email Object'); > ok( my %mail = $email->create_message_headers({from => $from}),'Set headers'); > is ($mail{'From'}, $from, 'Set correctly'); >+ >+ >+my $subject = q|My subject μΣä¼Ã©|; >+my $header = q|My header μΣä¼Ã©|; >+my $message = q|My Message μΣä¼Ã©|; >+ >+my $template_filepath = $Bin . '/data/templates/send_by_email.tt'; >+my $tt = Template->new( ENCODING => 'UTF-8', ABSOLUTE => 1 ); >+ >+subtest 'csv' => sub { >+ plan tests => 5; >+ my $csv_attachment = q|title >+ "La Recherche" >+ "Problèmes politiques et sociaux" >+ "Sud Provence Côte d'Azur" >+ "The art of computer programming μΣä¼Ã©" >+ |; >+ # the csv is generated by C4::Record::marc2csv and is already encoded >+ $csv_attachment = Encode::encode('UTF-8', $csv_attachment); >+ >+ my $output; >+ $tt->process( $template_filepath, { test => 'pouet' }, \$output ); >+ >+ %mail = $email->fill_body_for_sending( >+ { >+ template => $output, >+ default_filename => 'myfile.csv', >+ attachment => $csv_attachment, >+ } >+ ); >+ >+ is ($mail{From}, $from, 'From is still set correctly'); >+ like( $mail{Subject}, qr{$subject}, ); >+ >+ my $encoded_header = encode_qp($header); >+ my $encoded_message = encode_qp($header); >+ my $encoded_csv_attachment = encode_base64($csv_attachment); >+ like( $mail{body}, qr{$encoded_header}, ); >+ like( $mail{body}, qr{$encoded_message}, ); >+ like( $mail{body}, qr{$encoded_csv_attachment}, ); >+}; >+ >+subtest 'iso2709' => sub { >+ plan tests => 5; >+ my $ris_attachment = qq|TY - BOOK\r\nAU - Knuth, Donald Ervin\r\nTI - The art of computer programming μΣä¼Ã©\r\nKW - Computer programming\r\nKW - Computer algorithms\r\nER - \r\n|; >+ >+ my $output; >+ $tt->process( $template_filepath, { test => 'pouet' }, \$output ); >+ >+ %mail = $email->fill_body_for_sending( >+ { >+ template => $output, >+ default_filename => 'myfile.ris', >+ attachment => $ris_attachment, >+ } >+ ); >+ >+ is ($mail{From}, $from, 'From is still set correctly'); >+ like( $mail{Subject}, qr{$subject}, ); >+ >+ my $encoded_header = encode_qp($header); >+ my $encoded_message = encode_qp($header); >+ my $encoded_ris_attachment = encode_base64(Encode::encode('UTF-8', $ris_attachment)); >+ like( $mail{body}, qr{$encoded_header}, ); >+ like( $mail{body}, qr{$encoded_message}, ); >+ like( $mail{body}, qr{$encoded_ris_attachment}, ); >+}; >diff --git a/t/data/templates/send_by_email.tt b/t/data/templates/send_by_email.tt >new file mode 100644 >index 0000000..9cbd611 >--- /dev/null >+++ b/t/data/templates/send_by_email.tt >@@ -0,0 +1,11 @@ >+<SUBJECT> >+My subject μΣä¼Ã© >+<END_SUBJECT> >+ >+<HEADER> >+My header μΣä¼Ã© >+<END_HEADER> >+ >+<MESSAGE> >+My Message μΣä¼Ã© >+<END_MESSAGE> >diff --git a/t/db_dependent/Biblio/BuildBiblioDataForExport.t b/t/db_dependent/Biblio/BuildBiblioDataForExport.t >new file mode 100644 >index 0000000..238c4f8 >--- /dev/null >+++ b/t/db_dependent/Biblio/BuildBiblioDataForExport.t >@@ -0,0 +1,139 @@ >+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; >+ >+my $dbh = C4::Context->dbh; >+$dbh->{AutoCommit} = 0; >+$dbh->{RaiseError} = 1; >+ >+my $module_biblio = Test::MockModule->new('C4::Biblio'); >+ >+#my $title = q|The art of computer programming μΣä¼Ã©|; >+my $title = q|The art of computer programming|; >+my $record = new_record(); >+my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, q|| ); >+AddItem({ homebranch => 'CPL', holdingbranch => 'CPL', itype => 'CANNOT', barcode => 'my new barcode' }, $biblionumber); >+ >+subtest 'csv' => sub { >+ plan tests => 1; >+ my $csv_content = q(Title=245$a|Author=245$c|Subject=650$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|Author|Subject >+"$title,The art of another title"|"Donald E. Knuth.,Donald E. Knuth. II"|"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}, qq{$title | The art of another title}, ); >+ is( scalar( @{ $first_biblio_data->{ITEM_RESULTS} } ), 1, '1 item' ); >+ is( scalar( @{ $first_biblio_data->{MARCAUTHORS} } ), 0, '0 author' ); # Could be fixed if needed >+ 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 - BOOK\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', >+ }); >+ is( $bibtex_data->{records_file}, qq|\@book{$biblionumber, >+ author = {Knuth, Donald Ervin}, >+ title = {The art of computer programming} >+} >+|); >+}; >+ >+sub insert_csv_profile { >+ my ( $params ) = @_; >+ $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 ); >+} >+ >+sub new_record { >+ my $record = MARC::Record->new; >+ $record->leader('03174nam a2200445 a 4500'); >+ my @fields = ( >+ MARC::Field->new( >+ '008', "140211b xxu||||| |||| 00| 0 eng d" >+ ), >+ MARC::Field->new( >+ 100, '1', ' ', >+ a => 'Knuth, Donald Ervin', >+ d => '1938', >+ ), >+ MARC::Field->new( >+ 245, '1', '4', >+ a => $title, >+ c => 'Donald E. Knuth.', >+ 9 => '0', >+ ), >+ MARC::Field->new( >+ 245, '1', '4', >+ a => 'The art of another title', >+ c => 'Donald E. Knuth. II', >+ 9 => '1', >+ ), >+ MARC::Field->new( >+ 650, ' ', '1', >+ a => 'Computer programming.', >+ 9 => '462', >+ ), >+ MARC::Field->new( >+ 650, ' ', '0', >+ a => 'Computer algorithms.', >+ 9 => '499', >+ ), >+ MARC::Field->new( >+ 952, ' ', ' ', >+ p => '3010023917', >+ y => 'BK', >+ c => 'GEN', >+ d => '2001-06-25', >+ ), >+ ); >+ $record->append_fields(@fields); >+ return $record; >+} >+ >+done_testing; >diff --git a/virtualshelves/downloadshelf.pl b/virtualshelves/downloadshelf.pl >index 27fc7f9..0b29936 100755 >--- a/virtualshelves/downloadshelf.pl >+++ b/virtualshelves/downloadshelf.pl >@@ -21,7 +21,6 @@ use strict; > use warnings; > > use CGI qw ( -utf8 ); >-use Encode qw(encode); > > use C4::Auth; > use C4::Biblio; >diff --git a/virtualshelves/sendshelf.pl b/virtualshelves/sendshelf.pl >index 031c38a..8ad0bb8 100755 >--- a/virtualshelves/sendshelf.pl >+++ b/virtualshelves/sendshelf.pl >@@ -17,21 +17,18 @@ > # with Koha; if not, write to the Free Software Foundation, Inc., > # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. > >-use strict; >-use warnings; >+use Modern::Perl; > > use CGI qw ( -utf8 ); >-use Encode qw( encode ); > use Carp; > > use Mail::Sendmail; >-use MIME::QuotedPrint; >-use MIME::Base64; > use C4::Auth; > use C4::Biblio; > use C4::Items; > use C4::Output; > use C4::VirtualShelves; >+use C4::Csv qw( GetCsvProfilesLoop ); > use Koha::Email; > > my $query = new CGI; >@@ -48,6 +45,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; > >@@ -72,34 +70,22 @@ if ($email) { > > my @shelf = GetShelf($shelfid); > my ( $items, $totitems ) = GetShelfContents($shelfid); >- my $marcflavour = C4::Context->preference('marcflavour'); >- my $iso2709; >- my @results; >- >- # retrieve biblios from shelf >- foreach my $biblio (@$items) { >- my $biblionumber = $biblio->{biblionumber}; >- my $fw = GetFrameworkCode($biblionumber); >- my $dat = GetBiblioData($biblionumber); >- my $record = GetMarcBiblio($biblionumber, 1); >- my $marcnotesarray = GetMarcNotes( $record, $marcflavour ); >- my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); >- my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); >- my $subtitle = GetRecordValue( 'subtitle', $record, $fw ); >- >- my @items = GetItemsInfo($biblionumber); >- >- $dat->{MARCNOTES} = $marcnotesarray; >- $dat->{MARCSUBJCTS} = $marcsubjctsarray; >- $dat->{MARCAUTHORS} = $marcauthorsarray; >- $dat->{'biblionumber'} = $biblionumber; >- $dat->{ITEM_RESULTS} = \@items; >- $dat->{subtitle} = $subtitle; >- >- $iso2709 .= $record->as_usmarc(); >- >- push( @results, $dat ); >+ >+ my $csv_profile_id; >+ if ( $format =~ m|^\d+$| ) { >+ $csv_profile_id = $format; >+ $format = 'csv'; > } >+ my @biblionumbers = map { $_->{biblionumber} } @$items; >+ 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}; > > if ( C4::Context->preference('OPACBaseURL') ) { > $template2->param( >@@ -107,7 +93,7 @@ if ($email) { > } > > $template2->param( >- BIBLIO_RESULTS => \@results, >+ BIBLIO_RESULTS => $records_data, > email_sender => $mail{'from'}, > comment => $comment, > shelfname => $shelf[1], >@@ -115,57 +101,14 @@ if ($email) { > > # Getting template result > my $template_res = $template2->output(); >- my $body; >- >- # Analysing information and getting mail properties >- if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) { >- $mail{'subject'} = Encode::encode("UTF-8", $1); >- $mail{subject} =~ s|\n?(.*)\n?|$1|; >- } >- else { $mail{'subject'} = "no subject"; } >- >- my $email_header = ""; >- if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) { >- $email_header = $1; >- $email_header =~ s|\n?(.*)\n?|$1|; >- $email_header = encode_qp(Encode::encode("UTF-8", $email_header)); >- } >- >- my $email_file = "list.txt"; >- if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) { >- $email_file = $1; >- $email_file =~ s|\n?(.*)\n?|$1|; >- } > >- if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) { >- $body = $1; >- $body =~ s|\n?(.*)\n?|$1|; >- $body = encode_qp(Encode::encode("UTF-8", $body)); >- } >- >- my $boundary = "====" . time() . "===="; >- >- # We set and put the multipart content >- $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\""; >- >- my $isofile = encode_base64( encode( "UTF-8", $iso2709 ) ); >- $boundary = '--' . $boundary; >- >- $mail{body} = <<END_OF_BODY; >-$boundary >-Content-Type: text/plain; charset="utf-8" >-Content-Transfer-Encoding: quoted-printable >- >-$email_header >-$body >-$boundary >-Content-Type: application/octet-stream; name="shelf.iso2709" >-Content-Transfer-Encoding: base64 >-Content-Disposition: attachment; filename="shelf.iso2709" >- >-$isofile >-$boundary-- >-END_OF_BODY >+ %mail = $message->fill_body_for_sending( >+ { >+ template => $template_res, >+ default_filename => "list.$format", >+ attachment => $records_file, >+ } >+ ); > > # Sending mail > if ( sendmail %mail ) { >@@ -187,6 +130,7 @@ else { > $template->param( > shelfid => $shelfid, > url => "/cgi-bin/koha/virtualshelves/sendshelf.pl", >+ csv_profiles => GetCsvProfilesLoop('marc'), > ); > output_html_with_http_headers $query, $cookie, $template->output; > } >-- >2.1.0
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