@@ -, +, @@ notices --- basket/sendbasket.pl | 133 ++++-------- .../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 | 149 ++++--------- opac/opac-sendshelf.pl | 133 ++++-------- virtualshelves/sendshelf.pl | 121 ++++------- 7 files changed, 852 insertions(+), 365 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_3150_-_add_LIST_and_CART_notices.perl --- a/basket/sendbasket.pl +++ a/basket/sendbasket.pl @@ -55,110 +55,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 $biblio = Koha::Biblios->find( $biblionumber ) or next; - my $dat = $biblio->unblessed; - 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( $biblionumber ) or next; + $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; } --- a/installer/data/mysql/atomicupdate/bug_3150_-_add_LIST_and_CART_notices.perl +++ a/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' ); +} --- a/installer/data/mysql/en/mandatory/sample_notices.yml +++ a/installer/data/mysql/en/mandatory/sample_notices.yml @@ -1576,3 +1576,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 %]" + - "
" --- a/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql +++ a/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'); --- a/opac/opac-sendbasket.pl +++ a/opac/opac-sendbasket.pl @@ -56,125 +56,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 $biblio = Koha::Biblios->find( $biblionumber ) or next; - my $dat = $biblio->unblessed; - 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( $biblionumber ) or next; + $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 }; --- a/opac/opac-sendshelf.pl +++ a/opac/opac-sendshelf.pl @@ -73,104 +73,59 @@ if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { ); 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 $biblio = Koha::Biblios->find( $biblionumber ) or next; - my $dat = $biblio->unblessed; - my $record = GetMarcBiblio({ - biblionumber => $biblionumber, - embed_items => 1, - opac => 1, - borcat => $borcat }); - next unless $record; - my $fw = GetFrameworkCode($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, --- a/virtualshelves/sendshelf.pl +++ a/virtualshelves/sendshelf.pl @@ -69,94 +69,59 @@ if ($to_address) { } ); + my $patron = Koha:::Patrons->find( $borrowernumber ); 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 ) or next; - my $dat = $biblio->unblessed; - 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; --