From f37d08e042f7ea05a3c78238ba4fde1040610712 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Tue, 22 Sep 2020 09:30:32 +1200 Subject: [PATCH] Bug 3150: Move emails for sending cart and list contents to notices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch creates notices using Template Toolkit syntax for sending emails containing cart and list contents. To test: 1. Apply Bug 27266 2. Run update database and restart services 3. In the staff client, add multiple items to your cart and to a list 4. Go to your cart and click Send to email the contents 5. Add an email and a comment and click Send 6. Confirm the information shown in the success message is correct 7. In your terminal, log into the database. View the message queue ( i.e. select * from message_queue; ). Confirm that your email has been queued and the content is all correct. Confirm the cart contents has been included as an attachment. 8. Go to your list and click Send list to email the contents 9. Repeat steps 5-7 10. Log into the OPAC 11. Add multiple items to your cart and to a list 12. Repeat steps 4-9 13. By the end, you should have four emails in your message queue. All of the data about the items should be correct, they should all have attachments, and be addressed to the correct email address. Sponsored-by: Bibliotheksservice-Zentrum Baden-Württemberg (BSZ) Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: David Nind --- basket/sendbasket.pl | 134 ++++-------- .../bug_3150_-_add_LIST_and_CART_notices.perl | 224 +++++++++++++++++++ .../data/mysql/en/mandatory/sample_notices.yml | 238 +++++++++++++++++++++ .../mysql/fr-FR/1-Obligatoire/sample_notices.sql | 219 +++++++++++++++++++ opac/opac-sendbasket.pl | 150 ++++--------- opac/opac-sendshelf.pl | 133 ++++-------- virtualshelves/sendshelf.pl | 121 ++++------- 7 files changed, 852 insertions(+), 367 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_3150_-_add_LIST_and_CART_notices.perl diff --git a/basket/sendbasket.pl b/basket/sendbasket.pl index c52c2cf69c..1943911f2c 100755 --- a/basket/sendbasket.pl +++ b/basket/sendbasket.pl @@ -56,111 +56,61 @@ if ( $email_add ) { session_id => scalar $query->cookie('CGISESSID'), token => scalar $query->param('csrf_token'), }); - my $comment = $query->param('comment'); - # Since we are already logged in, no need to check credentials again - # when loading a second template. - my $template2 = C4::Templates::gettemplate( - 'basket/sendbasket.tt', 'intranet', $query, - ); + my $patron = Koha:::Patrons->find( $borrowernumber ); + + my $comment = $query->param('comment'); 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 $biblio = Koha::Biblios->find( $biblionumber ); - my $record = GetMarcBiblio({ - biblionumber => $biblionumber, - embed_items => 1 }); - my $marcauthorsarray = $biblio->get_marc_authors; - 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 $resultsarray = \@results; - $template2->param( - BIBLIO_RESULTS => $resultsarray, - comment => $comment - ); - - # Getting template result - my $template_res = $template2->output(); - my $body; - - my $subject; - # Analysing information and getting mail properties - if ( $template_res =~ /(?.*)/s ) { - $subject = $+{subject}; - $subject =~ s|\n?(.*)\n?|$1|; - } - else { - $subject = "no subject"; - } - - my $email_header = ""; - if ( $template_res =~ /
(.*)/s ) { - $email_header = $1; - $email_header =~ s|\n?(.*)\n?|$1|; - } - if ( $template_res =~ /(.*)/s ) { - $body = $1; - $body =~ s|\n?(.*)\n?|$1|; + foreach my $bib ( @bibs ) { + my $biblio = Koha::Biblios->find($bib); + $iso2709 .= $biblio->metadata->record->as_usmarc(); } - my $THE_body = <param( error => 1 ); + } else { + my %loops = ( + biblio => \@bibs, + ); - my $email = Koha::Email->create( - { - to => $email_add, - subject => $subject, - } + my %substitute = ( + comment => $comment, ); - $email->text_body( $THE_body ); - $email->attach( - Encode::encode( "UTF-8", $iso2709 ), - content_type => 'application/octet-stream', - name => 'basket.iso2709', - disposition => 'attachment', + my $letter = C4::Letters::GetPreparedLetter( + module => 'catalog', + letter_code => 'CART', + lang => $patron->lang, + tables => { + borrowers => $borrowernumber, + }, + message_transport_type => 'email', + loops => \%loops, + substitute => \%substitute, ); - my $library = Koha::Patrons->find( $borrowernumber )->library; - $email->send_or_die({ transport => $library->smtp_server->transport }); - $template->param( SENT => "1" ); - } - catch { - carp "Error sending mail: $_"; - $template->param( error => 1 ); - }; + my $attachment = { + filename => 'basket.iso2709', + type => 'application/octet-stream', + content => Encode::encode("UTF-8", $iso2709), + }; + + my $user_email = $patron->first_valid_email_address || C4::Context->preference('KohaAdminEmailAddress'); + C4::Letters::EnqueueLetter({ + letter => $letter, + message_transport_type => 'email', + borrowernumber => $patron->borrowernumber, + to_address => $email_add, + reply_address => $user_email, + attachments => [$attachment], + }); + $template->param( SENT => 1 ); + } $template->param( email_add => $email_add ); output_html_with_http_headers $query, $cookie, $template->output; } diff --git a/installer/data/mysql/atomicupdate/bug_3150_-_add_LIST_and_CART_notices.perl b/installer/data/mysql/atomicupdate/bug_3150_-_add_LIST_and_CART_notices.perl new file mode 100644 index 0000000000..610a58ac12 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_3150_-_add_LIST_and_CART_notices.perl @@ -0,0 +1,224 @@ +$DBversion = 'XXX'; +if( CheckVersion( $DBversion ) ) { + $dbh->do(q{ INSERT IGNORE INTO letter (module, code, branchcode, name, is_html, title, content, message_transport_type, lang) VALUES + ('catalog','LIST','','Send list',1,'Your list: [% listname | html %]',"[%- USE raw -%] +

Hi,

+

[% borrower.firstname | $raw %] [% borrower.surname | $raw %] sent you a list from our online catalog called: [% listname | $raw %].

+

Please note that the attached file is a MARC bibliographic records file which can be imported into personal bibliographic software like EndNote, Reference Manager or ProCite.

+
+

[% comment | $raw %]

+
+
    +[% FOREACH biblio IN biblios %] +
  1. + + [% biblio.title | $raw %] + [% IF ( biblio.subtitle ) %] + [% FOREACH subtitle IN biblio.subtitle.split(' | ') %] + [% subtitle | $raw %] + [% END %] + [% END %] + [% biblio.part_number | $raw %] [% biblio.part_name | $raw %] + +

    + [% IF ( biblio.author || biblio.get_authors_from_MARC ) %] + Author(s): [% IF ( biblio.author ) %][% biblio.author | $raw %][% END %] + [% IF ( biblio.get_authors_from_MARC ) %] + [% IF ( biblio.author ) %]; [% END %] + [% FOREACH author IN biblio.get_authors_from_MARC %] + [% FOREACH subfield IN author.MARCAUTHOR_SUBFIELDS_LOOP %] + [% subfield.separator | $raw %][% subfield.value | $raw %] + [% END %] + [% UNLESS ( loop.last ) %];[% END %] + [% END %] + [% END %] +
    + [% END %] + [% SET biblioitem = biblio.biblioitem %] + [% IF ( biblioitem.isbn ) %] + + ISBN: [% FOREACH isbn IN biblioitem.isbn %] + [% isbn | $raw %] + [% UNLESS ( loop.last ) %]; [% END %] + [% END %] +
    + [% END %] + [% IF ( biblioitem.publishercode ) %] + + Published by: [% biblioitem.publishercode | $raw %] + [% IF ( biblioitem.publicationyear ) %] + in [% biblioitem.publicationyear | $raw %] + [% END %] + [% IF ( biblioitem.pages ) %] + , [% biblioitem.pages | $raw %] + [% END %] +
    + [% END %] + [% IF ( biblio.seriestitle ) %] + + Collection: [% biblio.seriestitle | $raw %] +
    + [% END %] + [% IF ( biblio.copyrightdate ) %] + + Copyright year: [% biblio.copyrightdate | $raw %] +
    + [% END %] + [% IF ( biblio.notes ) %] + + Notes: [% biblio.notes | $raw %] +
    + [% END %] + [% IF ( biblio.unititle ) %] + + Unified title: [% biblio.unititle | $raw %] +
    + [% END %] + [% IF ( biblio.serial ) %] + + Serial: [% biblio.serial | $raw %] +
    + [% END %] + [% IF ( biblioitem.lccn ) %] + + LCCN: [% biblioitem.lccn | $raw %] +
    + [% END %] + [% IF ( biblioitem.url ) %] + + URL: [% biblioitem.url | html %] + + [% END %] +

    + [% SET OPACBaseURL = Koha.Preference('OPACBaseURL') %] + [% IF ( OPACBaseURL ) %] +

    In online catalog: [% OPACBaseURL | $raw %]/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblio.biblionumber | html %]

    + [% END %] + [% IF ( biblio.items.count > 0 ) %] +

    Items: +

      + [% FOREACH item IN biblio.items %]
    • + [% item.holding_branch.branchname | $raw %] + [% item.location | $raw %] + [% IF item.itemcallnumber %]([% item.itemcallnumber | $raw %])[% END %] + [% item.barcode | $raw %] +
    • [% END %] +
    +

    + [% END %] +
    +
  2. +[% END %] +
", 'email','default' ), + ('catalog','CART','','Send cart',1,'Your cart',"[%- USE raw -%] +

Hi,

+

[% borrower.firstname | $raw %] [% borrower.surname | $raw %] sent you a cart from our online catalog.

+

Please note that the attached file is a MARC bibliographic records file which can be imported into personal bibliographic software like EndNote, Reference Manager or ProCite.

+
+

[% comment | $raw %]

+
+
    +[% FOREACH biblio IN biblios %] +
  1. + + [% biblio.title | $raw %] + [% IF ( biblio.subtitle ) %] + [% FOREACH subtitle IN biblio.subtitle.split(' | ') %] + [% subtitle | $raw %] + [% END %] + [% END %] + [% biblio.part_number | $raw %] [% biblio.part_name | $raw %] + +

    + [% IF ( biblio.author || biblio.get_authors_from_MARC ) %] + Author(s): [% IF ( biblio.author ) %][% biblio.author | $raw %][% END %] + [% IF ( biblio.get_authors_from_MARC ) %] + [% IF ( biblio.author ) %]; [% END %] + [% FOREACH author IN biblio.get_authors_from_MARC %] + [% FOREACH subfield IN author.MARCAUTHOR_SUBFIELDS_LOOP %] + [% subfield.separator | $raw %][% subfield.value | $raw %] + [% END %] + [% UNLESS ( loop.last ) %];[% END %] + [% END %] + [% END %] +
    + [% END %] + [% SET biblioitem = biblio.biblioitem %] + [% IF ( biblioitem.isbn ) %] + + ISBN: [% FOREACH isbn IN biblioitem.isbn %] + [% isbn | $raw %] + [% UNLESS ( loop.last ) %]; [% END %] + [% END %] +
    + [% END %] + [% IF ( biblioitem.publishercode ) %] + + Published by: [% biblioitem.publishercode | $raw %] + [% IF ( biblioitem.publicationyear ) %] + in [% biblioitem.publicationyear | $raw %] + [% END %] + [% IF ( biblioitem.pages ) %] + , [% biblioitem.pages | $raw %] + [% END %] +
    + [% END %] + [% IF ( biblio.seriestitle ) %] + + Collection: [% biblio.seriestitle | $raw %] +
    + [% END %] + [% IF ( biblio.copyrightdate ) %] + + Copyright year: [% biblio.copyrightdate | $raw %] +
    + [% END %] + [% IF ( biblio.notes ) %] + + Notes: [% biblio.notes | $raw %] +
    + [% END %] + [% IF ( biblio.unititle ) %] + + Unified title: [% biblio.unititle | $raw %] +
    + [% END %] + [% IF ( biblio.serial ) %] + + Serial: [% biblio.serial | $raw %] +
    + [% END %] + [% IF ( biblioitem.lccn ) %] + + LCCN: [% biblioitem.lccn | $raw %] +
    + [% END %] + [% IF ( biblioitem.url ) %] + + URL: [% biblioitem.url | html %] + + [% END %] +

    + [% SET OPACBaseURL = Koha.Preference('OPACBaseURL') %] + [% IF ( OPACBaseURL ) %] +

    In online catalog: [% OPACBaseURL | $raw %]/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblio.biblionumber | html %]

    + [% END %] + [% IF ( biblio.items.count > 0 ) %] +

    Items: +

      + [% FOREACH item IN biblio.items %]
    • + [% item.holding_branch.branchname | $raw %] + [% item.location | $raw %] + [% IF item.itemcallnumber %]([% item.itemcallnumber | $raw %])[% END %] + [% item.barcode | $raw %] +
    • [% END %] +
    +

    + [% END %] +
    +
  2. +[% END %] +
",'email','default') }); + + NewVersion( $DBversion, 3150, 'Add LIST and CART notices' ); +} diff --git a/installer/data/mysql/en/mandatory/sample_notices.yml b/installer/data/mysql/en/mandatory/sample_notices.yml index 517f380425..ff16cfcb6e 100644 --- a/installer/data/mysql/en/mandatory/sample_notices.yml +++ b/installer/data/mysql/en/mandatory/sample_notices.yml @@ -1571,3 +1571,241 @@ tables: - "This item must be renewed at the library." - "[% END %]" - "[% END %]" + + - module: catalog + code: LIST + branchcode: "" + name: "Send list" + is_html: 1 + title: "Your list: [% listname | html %]" + message_transport_type: email + lang: default + content: + - "[%- USE raw -%]" + - "

Hi,

" + - "

[% borrower.firstname | $raw %] [% borrower.surname | $raw %] sent you a list from our online catalog called: [% listname | $raw %].

" + - "

Please note that the attached file is a MARC bibliographic records file which can be imported into personal bibliographic software like EndNote, Reference Manager or ProCite.

" + - "
" + - "

[% comment | $raw %]

" + - "
" + - "
    " + - "[% FOREACH biblio IN biblios %]" + - "
  1. " + - "" + - "[% biblio.title | $raw %]" + - "[% IF ( biblio.subtitle ) %]" + - "[% FOREACH subtitle IN biblio.subtitle.split(' | ') %]" + - "[% subtitle | $raw %]" + - "[% END %]" + - "[% END %]" + - "[% biblio.part_number | $raw %] [% biblio.part_name | $raw %]" + - "" + - "

    " + - "[% IF ( biblio.author || biblio.get_authors_from_MARC ) %]" + - "Author(s): [% IF ( biblio.author ) %][% biblio.author | $raw %][% END %]" + - "[% IF ( biblio.get_authors_from_MARC ) %]" + - "[% IF ( biblio.author ) %]; [% END %]" + - "[% FOREACH author IN biblio.get_authors_from_MARC %]" + - "[% FOREACH subfield IN author.MARCAUTHOR_SUBFIELDS_LOOP %]" + - "[% subfield.separator | $raw %][% subfield.value | $raw %]" + - "[% END %]" + - "[% UNLESS ( loop.last ) %];[% END %]" + - "[% END %]" + - "[% END %]" + - "
    " + - "[% END %]" + - "[% SET biblioitem = biblio.biblioitem %]" + - "[% IF ( biblioitem.isbn ) %]" + - "" + - "ISBN: [% FOREACH isbn IN biblioitem.isbn %]" + - "[% isbn | $raw %]" + - "[% UNLESS ( loop.last ) %]; [% END %]" + - "[% END %]" + - "
    " + - "[% END %]" + - "[% IF ( biblioitem.publishercode ) %]" + - "" + - "Published by: [% biblioitem.publishercode | $raw %]" + - "[% IF ( biblioitem.publicationyear ) %]" + - "in [% biblioitem.publicationyear | $raw %]" + - "[% END %]" + - "[% IF ( biblioitem.pages ) %]" + - ", [% biblioitem.pages | $raw %]" + - "[% END %]" + - "
    " + - "[% END %]" + - "[% IF ( biblio.seriestitle ) %]" + - "" + - "Collection: [% biblio.seriestitle | $raw %]" + - "
    " + - "[% END %]" + - "[% IF ( biblio.copyrightdate ) %]" + - "" + - "Copyright year: [% biblio.copyrightdate | $raw %]" + - "
    " + - "[% END %]" + - "[% IF ( biblio.notes ) %]" + - "" + - "Notes: [% biblio.notes | $raw %]" + - "
    " + - "[% END %]" + - "[% IF ( biblio.unititle ) %]" + - "" + - "Unified title: [% biblio.unititle | $raw %]" + - "
    " + - "[% END %]" + - "[% IF ( biblio.serial ) %]" + - "" + - "Serial: [% biblio.serial | $raw %]" + - "
    " + - "[% END %]" + - "[% IF ( biblioitem.lccn ) %]" + - "" + - "LCCN: [% biblioitem.lccn | $raw %]" + - "
    " + - "[% END %]" + - "[% IF ( biblioitem.url ) %]" + - "" + - "URL: [% biblioitem.url | html %]" + - "" + - "[% END %]" + - "

    " + - "[% SET OPACBaseURL = Koha.Preference('OPACBaseURL') %]" + - "[% IF ( OPACBaseURL ) %]" + - "

    In online catalog: [% OPACBaseURL | $raw %]/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblio.biblionumber | html %]

    " + - "[% END %]" + - "[% IF ( biblio.items.count > 0 ) %]" + - "

    Items:" + - "

      " + - "[% FOREACH item IN biblio.items %]
    • " + - "[% item.holding_branch.branchname | $raw %]" + - "[% item.location | $raw %]" + - "[% IF item.itemcallnumber %]([% item.itemcallnumber | $raw %])[% END %]" + - "[% item.barcode | $raw %]" + - "
    • [% END %]" + - "
    " + - "

    " + - "[% END %]" + - "
    " + - "
  2. " + - "[% END %]" + - "
" + + - module: catalog + code: CART + branchcode: "" + name: "Send cart" + is_html: 1 + title: "Your cart" + message_transport_type: email + lang: default + content: + - "[%- USE raw -%]" + - "

Hi,

" + - "

[% borrower.firstname | $raw %] [% borrower.surname | $raw %] sent you a cart from our online catalog.

" + - "

Please note that the attached file is a MARC bibliographic records file which can be imported into personal bibliographic software like EndNote, Reference Manager or ProCite.

" + - "
" + - "

[% comment | $raw %]

" + - "
" + - "
    " + - "[% FOREACH biblio IN biblios %]" + - "
  1. " + - "" + - "[% biblio.title | $raw %]" + - "[% IF ( biblio.subtitle ) %]" + - "[% FOREACH subtitle IN biblio.subtitle.split(' | ') %]" + - "[% subtitle | $raw %]" + - "[% END %]" + - "[% END %]" + - "[% biblio.part_number | $raw %] [% biblio.part_name | $raw %]" + - "" + - "

    " + - "[% IF ( biblio.author || biblio.get_authors_from_MARC ) %]" + - "Author(s): [% IF ( biblio.author ) %][% biblio.author | $raw %][% END %]" + - "[% IF ( biblio.get_authors_from_MARC ) %]" + - "[% IF ( biblio.author ) %]; [% END %]" + - "[% FOREACH author IN biblio.get_authors_from_MARC %]" + - "[% FOREACH subfield IN author.MARCAUTHOR_SUBFIELDS_LOOP %]" + - "[% subfield.separator | $raw %][% subfield.value | $raw %]" + - "[% END %]" + - "[% UNLESS ( loop.last ) %];[% END %]" + - "[% END %]" + - "[% END %]" + - "
    " + - "[% END %]" + - "[% SET biblioitem = biblio.biblioitem %]" + - "[% IF ( biblioitem.isbn ) %]" + - "" + - "ISBN: [% FOREACH isbn IN biblioitem.isbn %]" + - "[% isbn | $raw %]" + - "[% UNLESS ( loop.last ) %]; [% END %]" + - "[% END %]" + - "
    " + - "[% END %]" + - "[% IF ( biblioitem.publishercode ) %]" + - "" + - "Published by: [% biblioitem.publishercode | $raw %]" + - "[% IF ( biblioitem.publicationyear ) %]" + - "in [% biblioitem.publicationyear | $raw %]" + - "[% END %]" + - "[% IF ( biblioitem.pages ) %]" + - ", [% biblioitem.pages | $raw %]" + - "[% END %]" + - "
    " + - "[% END %]" + - "[% IF ( biblio.seriestitle ) %]" + - "" + - "Collection: [% biblio.seriestitle | $raw %]" + - "
    " + - "[% END %]" + - "[% IF ( biblio.copyrightdate ) %]" + - "" + - "Copyright year: [% biblio.copyrightdate | $raw %]" + - "
    " + - "[% END %]" + - "[% IF ( biblio.notes ) %]" + - "" + - "Notes: [% biblio.notes | $raw %]" + - "
    " + - "[% END %]" + - "[% IF ( biblio.unititle ) %]" + - "" + - "Unified title: [% biblio.unititle | $raw %]" + - "
    " + - "[% END %]" + - "[% IF ( biblio.serial ) %]" + - "" + - "Serial: [% biblio.serial | $raw %]" + - "
    " + - "[% END %]" + - "[% IF ( biblioitem.lccn ) %]" + - "" + - "LCCN: [% biblioitem.lccn | $raw %]" + - "
    " + - "[% END %]" + - "[% IF ( biblioitem.url ) %]" + - "" + - "URL: [% biblioitem.url | html %]" + - "" + - "[% END %]" + - "

    " + - "[% SET OPACBaseURL = Koha.Preference('OPACBaseURL') %]" + - "[% IF ( OPACBaseURL ) %]" + - "

    In online catalog: [% OPACBaseURL | $raw %]/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblio.biblionumber | html %]

    " + - "[% END %]" + - "[% IF ( biblio.items.count > 0 ) %]" + - "

    Items:" + - "

      " + - "[% FOREACH item IN biblio.items %]
    • " + - "[% item.holding_branch.branchname | $raw %]" + - "[% item.location | $raw %]" + - "[% IF item.itemcallnumber %]([% item.itemcallnumber | $raw %])[% END %]" + - "[% item.barcode | $raw %]" + - "
    • [% END %]" + - "
    " + - "

    " + - "[% END %]" + - "
    " + - "
  2. " + - "[% END %]" + - "
" diff --git a/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql b/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql index 28e7734241..cdf326f0bf 100644 --- a/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql +++ b/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql @@ -475,3 +475,222 @@ INSERT IGNORE INTO letter (module, code, name, title, content, message_transport [% END %] [% END %] ", 'email'); + +INSERT IGNORE INTO letter (module, code, branchcode, name, is_html, title, content, message_transport_type, lang) VALUES ('catalog','LIST','','Send list',1,'Your list: [% listname | html %]',"[%- USE raw -%] +

Hi,

+

[% borrower.firstname | $raw %] [% borrower.surname | $raw %] sent you a list from our online catalog called: [% listname | $raw %].

+

Please note that the attached file is a MARC bibliographic records file which can be imported into personal bibliographic software like EndNote, Reference Manager or ProCite.

+
+

[% comment | $raw %]

+
+
    +[% FOREACH biblio IN biblios %] +
  1. + + [% biblio.title | $raw %] + [% IF ( biblio.subtitle ) %] + [% FOREACH subtitle IN biblio.subtitle.split(' | ') %] + [% subtitle | $raw %] + [% END %] + [% END %] + [% biblio.part_number | $raw %] [% biblio.part_name | $raw %] + +

    + [% IF ( biblio.author || biblio.get_authors_from_MARC ) %] + Author(s): [% IF ( biblio.author ) %][% biblio.author | $raw %][% END %] + [% IF ( biblio.get_authors_from_MARC ) %] + [% IF ( biblio.author ) %]; [% END %] + [% FOREACH author IN biblio.get_authors_from_MARC %] + [% FOREACH subfield IN author.MARCAUTHOR_SUBFIELDS_LOOP %] + [% subfield.separator | $raw %][% subfield.value | $raw %] + [% END %] + [% UNLESS ( loop.last ) %];[% END %] + [% END %] + [% END %] +
    + [% END %] + [% SET biblioitem = biblio.biblioitem %] + [% IF ( biblioitem.isbn ) %] + + ISBN: [% FOREACH isbn IN biblioitem.isbn %] + [% isbn | $raw %] + [% UNLESS ( loop.last ) %]; [% END %] + [% END %] +
    + [% END %] + [% IF ( biblioitem.publishercode ) %] + + Published by: [% biblioitem.publishercode | $raw %] + [% IF ( biblioitem.publicationyear ) %] + in [% biblioitem.publicationyear | $raw %] + [% END %] + [% IF ( biblioitem.pages ) %] + , [% biblioitem.pages | $raw %] + [% END %] +
    + [% END %] + [% IF ( biblio.seriestitle ) %] + + Collection: [% biblio.seriestitle | $raw %] +
    + [% END %] + [% IF ( biblio.copyrightdate ) %] + + Copyright year: [% biblio.copyrightdate | $raw %] +
    + [% END %] + [% IF ( biblio.notes ) %] + + Notes: [% biblio.notes | $raw %] +
    + [% END %] + [% IF ( biblio.unititle ) %] + + Unified title: [% biblio.unititle | $raw %] +
    + [% END %] + [% IF ( biblio.serial ) %] + + Serial: [% biblio.serial | $raw %] +
    + [% END %] + [% IF ( biblioitem.lccn ) %] + + LCCN: [% biblioitem.lccn | $raw %] +
    + [% END %] + [% IF ( biblioitem.url ) %] + + URL: [% biblioitem.url | html %] + + [% END %] +

    + [% SET OPACBaseURL = Koha.Preference('OPACBaseURL') %] + [% IF ( OPACBaseURL ) %] +

    In online catalog: [% OPACBaseURL | $raw %]/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblio.biblionumber | html %]

    + [% END %] + [% IF ( biblio.items.count > 0 ) %] +

    Items: +

      + [% FOREACH item IN biblio.items %]
    • + [% item.holding_branch.branchname | $raw %] + [% item.location | $raw %] + [% IF item.itemcallnumber %]([% item.itemcallnumber | $raw %])[% END %] + [% item.barcode | $raw %] +
    • [% END %] +
    +

    + [% END %] +
    +
  2. +[% END %] +
", 'email','default' ), +('catalog','CART','','Send cart',1,'Your cart',"[%- USE raw -%] +

Hi,

+

[% borrower.firstname | $raw %] [% borrower.surname | $raw %] sent you a cart from our online catalog.

+

Please note that the attached file is a MARC bibliographic records file which can be imported into personal bibliographic software like EndNote, Reference Manager or ProCite.

+
+

[% comment | $raw %]

+
+
    +[% FOREACH biblio IN biblios %] +
  1. + + [% biblio.title | $raw %] + [% IF ( biblio.subtitle ) %] + [% FOREACH subtitle IN biblio.subtitle.split(' | ') %] + [% subtitle | $raw %] + [% END %] + [% END %] + [% biblio.part_number | $raw %] [% biblio.part_name | $raw %] + +

    + [% IF ( biblio.author || biblio.get_authors_from_MARC ) %] + Author(s): [% IF ( biblio.author ) %][% biblio.author | $raw %][% END %] + [% IF ( biblio.get_authors_from_MARC ) %] + [% IF ( biblio.author ) %]; [% END %] + [% FOREACH author IN biblio.get_authors_from_MARC %] + [% FOREACH subfield IN author.MARCAUTHOR_SUBFIELDS_LOOP %] + [% subfield.separator | $raw %][% subfield.value | $raw %] + [% END %] + [% UNLESS ( loop.last ) %];[% END %] + [% END %] + [% END %] +
    + [% END %] + [% SET biblioitem = biblio.biblioitem %] + [% IF ( biblioitem.isbn ) %] + + ISBN: [% FOREACH isbn IN biblioitem.isbn %] + [% isbn | $raw %] + [% UNLESS ( loop.last ) %]; [% END %] + [% END %] +
    + [% END %] + [% IF ( biblioitem.publishercode ) %] + + Published by: [% biblioitem.publishercode | $raw %] + [% IF ( biblioitem.publicationyear ) %] + in [% biblioitem.publicationyear | $raw %] + [% END %] + [% IF ( biblioitem.pages ) %] + , [% biblioitem.pages | $raw %] + [% END %] +
    + [% END %] + [% IF ( biblio.seriestitle ) %] + + Collection: [% biblio.seriestitle | $raw %] +
    + [% END %] + [% IF ( biblio.copyrightdate ) %] + + Copyright year: [% biblio.copyrightdate | $raw %] +
    + [% END %] + [% IF ( biblio.notes ) %] + + Notes: [% biblio.notes | $raw %] +
    + [% END %] + [% IF ( biblio.unititle ) %] + + Unified title: [% biblio.unititle | $raw %] +
    + [% END %] + [% IF ( biblio.serial ) %] + + Serial: [% biblio.serial | $raw %] +
    + [% END %] + [% IF ( biblioitem.lccn ) %] + + LCCN: [% biblioitem.lccn | $raw %] +
    + [% END %] + [% IF ( biblioitem.url ) %] + + URL: [% biblioitem.url | html %] + + [% END %] +

    + [% SET OPACBaseURL = Koha.Preference('OPACBaseURL') %] + [% IF ( OPACBaseURL ) %] +

    In online catalog: [% OPACBaseURL | $raw %]/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblio.biblionumber | html %]

    + [% END %] + [% IF ( biblio.items.count > 0 ) %] +

    Items: +

      + [% FOREACH item IN biblio.items %]
    • + [% item.holding_branch.branchname | $raw %] + [% item.location | $raw %] + [% IF item.itemcallnumber %]([% item.itemcallnumber | $raw %])[% END %] + [% item.barcode | $raw %] +
    • [% END %] +
    +

    + [% END %] +
    +
  2. +[% END %] +
",'email','default'); diff --git a/opac/opac-sendbasket.pl b/opac/opac-sendbasket.pl index 14dd409667..82c262e190 100755 --- a/opac/opac-sendbasket.pl +++ b/opac/opac-sendbasket.pl @@ -57,126 +57,60 @@ if ( $email_add ) { session_id => scalar $query->cookie('CGISESSID'), token => scalar $query->param('csrf_token'), }); + my $patron = Koha::Patrons->find( $borrowernumber ); - my $borcat = $patron ? $patron->categorycode : q{}; - my $user_email = $patron->first_valid_email_address - || C4::Context->preference('KohaAdminEmailAddress'); - my $email_replyto = $patron->firstname . " " . $patron->surname . " <$user_email>"; my $comment = $query->param('comment'); - # Since we are already logged in, no need to check credentials again - # when loading a second template. - my $template2 = C4::Templates::gettemplate( - '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 $biblio = Koha::Biblios->find( $biblionumber ); - my $record = GetMarcBiblio({ - biblionumber => $biblionumber, - embed_items => 1, - opac => 1, - borcat => $borcat }); - my $marcauthorsarray = $biblio->get_marc_authors; - 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 $resultsarray = \@results; - - $template2->param( - BIBLIO_RESULTS => $resultsarray, - comment => $comment, - firstname => $patron->firstname, - surname => $patron->surname, - ); - - # Getting template result - my $template_res = $template2->output(); - my $body; - - # Analysing information and getting mail properties - my $subject; - if ( $template_res =~ /\(?.*)\/s ) { - $subject = $+{subject}; - $subject =~ s|\n?(.*)\n?|$1|; - } - else { - $subject = "no subject"; - } - - my $email_header = ""; - if ( $template_res =~ /
(.*)/s ) { - $email_header = $1; - $email_header =~ s|\n?(.*)\n?|$1|; - } - - if ( $template_res =~ /(.*)/s ) { - $body = $1; - $body =~ s|\n?(.*)\n?|$1|; - } - - my $THE_body = <find($bib); + $iso2709 .= $biblio->metadata->record->as_usmarc(); + }; if ( !defined $iso2709 ) { carp "Error sending mail: empty basket"; $template->param( error => 1 ); - } - else { - try { - # if you want to use the KohaAdmin address as from, that is the default no need to set it - my $email = Koha::Email->create({ - to => $email_add, - reply_to => $email_replyto, - subject => $subject, - }); - $email->header( 'X-Abuse-Report' => C4::Context->preference('KohaAdminEmailAddress') ); - $email->text_body( $THE_body ); - $email->attach( - Encode::encode( "UTF-8", $iso2709 ), - content_type => 'application/octet-stream', - name => 'basket.iso2709', - disposition => 'attachment', - ); - my $library = $patron->library; - $email->transport( $library->smtp_server->transport ); - $email->send_or_die; - $template->param( SENT => "1" ); - } - catch { - carp "Error sending mail: $_"; - $template->param( error => 1 ); + } else { + my %loops = ( + biblio => \@bibs, + ); + + my %substitute = ( + comment => $comment, + ); + + my $letter = C4::Letters::GetPreparedLetter( + module => 'catalog', + letter_code => 'CART', + lang => $patron->lang, + tables => { + borrowers => $borrowernumber, + }, + message_transport_type => 'email', + loops => \%loops, + substitute => \%substitute, + ); + + my $attachment = { + filename => 'basket.iso2709', + type => 'application/octet-stream', + content => Encode::encode("UTF-8", $iso2709), }; - } + + my $user_email = $patron->first_valid_email_address || C4::Context->preference('KohaAdminEmailAddress'); + C4::Letters::EnqueueLetter({ + letter => $letter, + message_transport_type => 'email', + borrowernumber => $patron->borrowernumber, + to_address => $email_add, + reply_address => $user_email, + attachments => [$attachment], + }); + + $template->param( SENT => 1 ); $template->param( email_add => $email_add ); 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 621bca9c02..ae30a35c43 100755 --- a/opac/opac-sendshelf.pl +++ b/opac/opac-sendshelf.pl @@ -75,104 +75,59 @@ if ( $email ) { ); my $patron = Koha::Patrons->find( $borrowernumber ); - my $borcat = $patron ? $patron->categorycode : q{}; my $shelf = Koha::Virtualshelves->find( $shelfid ); my $contents = $shelf->get_contents; - my $marcflavour = C4::Context->preference('marcflavour'); my $iso2709; - my @results; 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 $biblio = Koha::Biblios->find( $biblionumber ); - my $fw = GetFrameworkCode($biblionumber); - my $dat = GetBiblioData($biblionumber); - - my $marcauthorsarray = $biblio->get_marc_authors; - 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 ); - } - - $template2->param( - BIBLIO_RESULTS => \@results, - comment => $comment, - shelfname => $shelf->shelfname, - firstname => $patron->firstname, - surname => $patron->surname, - ); - - # Getting template result - my $template_res = $template2->output(); - my $body; - - my $subject; - # Analysing information and getting mail properties - if ( $template_res =~ /(?.*)/s ) { - $subject = $+{subject}; - $subject =~ s|\n?(.*)\n?|$1|; - } - else { - $subject = "no subject"; - } - - my $email_header = ""; - if ( $template_res =~ /
(.*)/s ) { - $email_header = $1; - $email_header =~ s|\n?(.*)\n?|$1|; - } - - if ( $template_res =~ /(.*)/s ) { - $body = $1; - $body =~ s|\n?(.*)\n?|$1|; - } + push @biblionumbers, $content->biblionumber; + my $biblio = Koha::Biblios->find($content->biblionumber); + $iso2709 .= $biblio->metadata->record->as_usmarc(); + }; - my $THE_body = <create( - { - to => $email, - subject => $subject, - } - ); - $email->text_body( $THE_body ); - $email->attach( - Encode::encode( "UTF-8", $iso2709 ), - content_type => 'application/octet-stream', - name => 'list.iso2709', - disposition => 'attachment', + if ( !defined $iso2709 ) { + carp "Error sending mail: empty list"; + $template->param( error => 1 ); + } else { + my %loops = ( + biblio => \@biblionumbers, + ); + + my %substitute = ( + comment => $comment, + listname => $shelf->shelfname, + ); + + my $letter = C4::Letters::GetPreparedLetter( + module => 'catalog', + letter_code => 'LIST', + lang => $patron->lang, + tables => { + borrowers => $borrowernumber, + }, + message_transport_type => 'email', + loops => \%loops, + substitute => \%substitute, ); - my $library = Koha::Patrons->find( $borrowernumber )->library; - $email->transport( $library->smtp_server->transport ); - $email->send_or_die; - $template->param( SENT => "1" ); + + my $attachment = { + filename => 'list.iso2709', + type => 'application/octet-stream', + content => Encode::encode("UTF-8", $iso2709), + }; + + C4::Letters::EnqueueLetter({ + letter => $letter, + message_transport_type => 'email', + borrowernumber => $patron->borrowernumber, + to_address => $email, + reply_address => $patron->first_valid_email_address, + attachments => [$attachment], + }); + + $template->param( SENT => 1 ); } - catch { - carp "Error sending mail: $_"; - $template->param( error => 1 ); - }; $template->param( shelfid => $shelfid, diff --git a/virtualshelves/sendshelf.pl b/virtualshelves/sendshelf.pl index acb1a52d1d..e1c92989ec 100755 --- a/virtualshelves/sendshelf.pl +++ b/virtualshelves/sendshelf.pl @@ -64,95 +64,60 @@ if ($to_address) { } ); + my $patron = Koha:::Patrons->find( $borrowernumber ); my $shelf = Koha::Virtualshelves->find( $shelfid ); my $contents = $shelf->get_contents; - my $marcflavour = C4::Context->preference('marcflavour'); + my @biblionumbers; my $iso2709; - my @results; while ( my $content = $contents->next ) { - my $biblionumber = $content->biblionumber; - my $biblio = Koha::Biblios->find( $biblionumber ); - my $dat = GetBiblioData($biblionumber); - my $record = GetMarcBiblio({ - biblionumber => $biblionumber, - embed_items => 1 }); - my $marcauthorsarray = $biblio->get_marc_authors; - 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 ); - } - - $template2->param( - BIBLIO_RESULTS => \@results, - comment => $comment, - shelfname => $shelf->shelfname, - ); - - # Getting template result - my $template_res = $template2->output(); - my $body; - - my $subject; - # Analysing information and getting mail properties - if ( $template_res =~ /(?.*)/s ) { - $subject = $+{subject}; - $subject =~ s|\n?(.*)\n?|$1|; - } - else { - $subject = "no subject"; - } - - my $email_header = ""; - if ( $template_res =~ /
(.*)/s ) { - $email_header = $1; - $email_header =~ s|\n?(.*)\n?|$1|; - } + push @biblionumbers, $content->biblionumber; + my $biblio = Koha::Biblios->find($content->biblionumber); + $iso2709 .= $biblio->metadata->record->as_usmarc(); + }; - if ( $template_res =~ /(.*)/s ) { - $body = $1; - $body =~ s|\n?(.*)\n?|$1|; - } + if ( !defined $iso2709 ) { + carp "Error sending mail: empty basket"; + $template->param( error => 1 ); + } else { + my %loops = ( + biblio => \@biblionumbers, + ); - my $THE_body = <create( - { - to => $to_address, - subject => $subject, - } + my %substitute = ( + comment => $comment, + listname => $shelf->shelfname, ); - $email->text_body( $THE_body ); - $email->attach( - Encode::encode("UTF-8", $iso2709), - content_type => 'application/octet-stream', - name => 'shelf.iso2709', - disposition => 'attachment', + + my $letter = C4::Letters::GetPreparedLetter( + module => 'catalog', + letter_code => 'LIST', + lang => $patron->lang, + tables => { + borrowers => $borrowernumber, + }, + message_transport_type => 'email', + loops => \%loops, + substitute => \%substitute, ); - my $library = Koha::Patrons->find( $borrowernumber )->library; - $email->send_or_die({ transport => $library->smtp_server->transport }); - $template->param( SENT => "1" ); + my $attachment = { + filename => 'shelf.iso2709', + type => 'application/octet-stream', + content => Encode::encode("UTF-8", $iso2709), + }; + + C4::Letters::EnqueueLetter({ + letter => $letter, + message_transport_type => 'email', + borrowernumber => $patron->borrowernumber, + to_address => $to_address, + reply_address => $patron->first_valid_email_address, + attachments => [$attachment], + }); + + $template->param( SENT => 1 ); } - catch { - carp "Error sending mail: $_"; - $template->param( error => 1 ); - }; $template->param( email => $to_address ); output_html_with_http_headers $query, $cookie, $template->output; -- 2.11.0