From 741d24a954b168f816f5438f5fd545241e95bf8f Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Tue, 22 Sep 2020 09:30:32 +1200 Subject: [PATCH] Bug 3150: WIP --- .../bug_3150_-_add_LIST_and_CART_notices.perl | 297 +++++++++++++++++++++ .../data/mysql/en/mandatory/sample_notices.yml | 7 + opac/opac-sendshelf.pl | 86 +++--- 3 files changed, 339 insertions(+), 51 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_3150_-_add_LIST_and_CART_notices.perl 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..0676f6adc0 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_3150_-_add_LIST_and_CART_notices.perl @@ -0,0 +1,297 @@ +$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 + ('catalogue','LIST','','Send list',1,'Your list: [% listname %]'," +

Hi,

+ +

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

+ +

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.

+
+ +

<>

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

    + [% IF ( BIBLIO_RESULT.HASAUTHORS ) %] + Author(s): [% IF ( BIBLIO_RESULT.author ) %][% BIBLIO_RESULT.author | $raw %][% END %] + + [% IF ( BIBLIO_RESULT.MARCAUTHORS ) %] + [% IF ( BIBLIO_RESULT.author ) %]; [% END %] + [% FOREACH MARCAUTHOR IN BIBLIO_RESULT.MARCAUTHORS %] + [% FOREACH MARCAUTHOR_SUBFIELDS_LOO IN MARCAUTHOR.MARCAUTHOR_SUBFIELDS_LOOP %] + [% MARCAUTHOR_SUBFIELDS_LOO.separator | $raw %][% MARCAUTHOR_SUBFIELDS_LOO.value | $raw %] + [% END %] + [% UNLESS ( loop.last ) %];[% END %] + [% END %] + [% END %] +
    + [% END %] + + [% IF ( BIBLIO_RESULT.ISBN ) %] + + ISBN: [% FOREACH isbn IN BIBLIO_RESULT.ISBN %] + [% isbn | $raw %] + [% UNLESS ( loop.last ) %]; [% END %] + [% END %] +
    + [% END %] + + [% IF BIBLIO_RESULT.publishercode %] + + Published by: [% BIBLIO_RESULT.publishercode | $raw %] + [% IF ( BIBLIO_RESULT.publicationyear ) %] + in [% BIBLIO_RESULT.publicationyear | $raw %] + [% END %] + [% IF ( BIBLIO_RESULT.pages ) %] + , [% BIBLIO_RESULT.pages | $raw %] + [% END %] + [% IF BIBLIO_RESULT.item('size') %] + , [% BIBLIO_RESULT.item('size') | html %] + [% END %] +
    + [% END %] + + [% IF BIBLIO_RESULT.collection %] + + Collection: [% BIBLIO_RESULT.seriestitle | $raw %] +
    + [% END %] + + [% IF ( BIBLIO_RESULT.subject ) %] + + Subject: [% BIBLIO_RESULT.subject | $raw %] +
    + [% END %] + + [% IF ( BIBLIO_RESULT.copyrightdate ) %] + + Copyright year: [% BIBLIO_RESULT.copyrightdate | $raw %] +
    + [% END %] + + [% IF ( BIBLIO_RESULT.notes ) %] + + Notes: [% BIBLIO_RESULT.notes | $raw %] +
    + [% END %] + + [% IF ( BIBLIO_RESULT.unititle ) %] + + Unified title: [% BIBLIO_RESULT.unititle | $raw %] +
    + [% END %] + + [% IF ( BIBLIO_RESULT.serial ) %] + + Serial: [% BIBLIO_RESULT.serial | $raw %] +
    + [% END %] + + [% IF ( BIBLIO_RESULT.dewey ) %] + + Dewey: [% BIBLIO_RESULT.dewey | $raw %] +
    + [% END %] + + [% IF ( BIBLIO_RESULT.classification ) %] + + Classification: [% BIBLIO_RESULT.classification | $raw %] +
    + [% END %] + + [% IF ( BIBLIO_RESULT.lccn ) %] + + LCCN: [% BIBLIO_RESULT.lccn | $raw %] +
    + [% END %] + + [% IF ( BIBLIO_RESULT.url ) %] + + URL: [% BIBLIO_RESULT.url | html %] + + [% END %] +

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

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

    + [% END %] + + [% IF ( BIBLIO_RESULT.ITEM_RESULTS.size ) %] +

    Items: +

      + [% FOREACH ITEM_RESULT IN BIBLIO_RESULT.ITEM_RESULTS %]
    • + [% ITEM_RESULT.branchname | $raw %] + [% ITEM_RESULT.location | $raw %] + [% IF ITEM_RESULT.itemcallnumber %]([% ITEM_RESULT.itemcallnumber | $raw %])[% END %] + [% ITEM_RESULT.barcode | $raw %] +
    • [% END %] +
    +

    + [% END %] +
    +
  2. + +[% END %] +
", 'email','default' ), + ('catalogue','CART','','Send cart',1,'Your cart',"

Hi,

+ +

[% firstname | $raw %] [% 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.

+
+ +[% IF comment %] +

[% comment | $raw %]

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

    + [% IF ( BIBLIO_RESULT.HASAUTHORS ) %] + Author(s): [% IF ( BIBLIO_RESULT.author ) %][% BIBLIO_RESULT.author | $raw %][% END %] + + [% IF ( BIBLIO_RESULT.MARCAUTHORS ) %] + [% IF ( BIBLIO_RESULT.author ) %]; [% END %] + [% FOREACH MARCAUTHOR IN BIBLIO_RESULT.MARCAUTHORS %] + [% FOREACH MARCAUTHOR_SUBFIELDS_LOO IN MARCAUTHOR.MARCAUTHOR_SUBFIELDS_LOOP %] + [% MARCAUTHOR_SUBFIELDS_LOO.separator | $raw %][% MARCAUTHOR_SUBFIELDS_LOO.value | $raw %] + [% END %] + [% UNLESS ( loop.last ) %];[% END %] + [% END %] + [% END %] +
    + [% END %] + + [% IF ( BIBLIO_RESULT.ISBN ) %] + + ISBN: [% BIBLIO_RESULT.ISBN | $raw %] +
    + [% END %] + + [% IF BIBLIO_RESULT.publishercode %] + + Published by: [% BIBLIO_RESULT.publishercode | $raw %] + [% IF ( BIBLIO_RESULT.publicationyear ) %] + in [% BIBLIO_RESULT.publicationyear | $raw %] + [% END %] + [% IF ( BIBLIO_RESULT.pages ) %] + , [% BIBLIO_RESULT.pages | $raw %] + [% END %] + [% IF BIBLIO_RESULT.item('size') %] + , [% BIBLIO_RESULT.item('size') | $raw %] + [% END %] +
    + [% END %] + + [% IF BIBLIO_RESULT.collection %] + + Collection: [% BIBLIO_RESULT.seriestitle | $raw %] +
    + [% END %] + + [% IF ( BIBLIO_RESULT.subject ) %] + + Subject: [% BIBLIO_RESULT.subject | $raw %] +
    + [% END %] + + [% IF ( BIBLIO_RESULT.copyrightdate ) %] + + Copyright year: [% BIBLIO_RESULT.copyrightdate | $raw %] +
    + [% END %] + + [% IF ( BIBLIO_RESULT.notes ) %] + + Notes: [% BIBLIO_RESULT.notes | $raw %] +
    + [% END %] + + [% IF ( BIBLIO_RESULT.unititle ) %] + + Unified title: [% BIBLIO_RESULT.unititle | $raw %] +
    + [% END %] + + [% IF ( BIBLIO_RESULT.serial ) %] + + Serial: [% BIBLIO_RESULT.serial | $raw %] +
    + [% END %] + + [% IF ( BIBLIO_RESULT.dewey ) %] + + Dewey: [% BIBLIO_RESULT.dewey | $raw %] +
    + [% END %] + + [% IF ( BIBLIO_RESULT.classification ) %] + + Classification: [% BIBLIO_RESULT.classification | $raw %] +
    + [% END %] + + [% IF ( BIBLIO_RESULT.lccn ) %] + + LCCN: [% BIBLIO_RESULT.lccn | $raw %] +
    + [% END %] + + [% IF ( BIBLIO_RESULT.url ) %] + + URL: [% BIBLIO_RESULT.url | html %] + + [% END %] +

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

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

    + [% END %] + + [% IF ( BIBLIO_RESULT.ITEM_RESULTS.size ) %] +

    Items: +

      + [% FOREACH ITEM_RESULT IN BIBLIO_RESULT.ITEM_RESULTS %]
    • + [% ITEM_RESULT.branchname | $raw %] + [% ITEM_RESULT.location | $raw %] + [% IF ITEM_RESULT.itemcallnumber %]([% ITEM_RESULT.itemcallnumber | $raw %])[% END %] + [% ITEM_RESULT.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 22385cac31..6f2ff8b35a 100644 --- a/installer/data/mysql/en/mandatory/sample_notices.yml +++ b/installer/data/mysql/en/mandatory/sample_notices.yml @@ -1442,3 +1442,10 @@ tables: - "[% ELSE %]" - "The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]" - "[% END %]" + + - module: catalogue + code: LIST + branchcode: "" + name: "Send list" + is_html: 1 + title: "Your list: [% shelfname %]" diff --git a/opac/opac-sendshelf.pl b/opac/opac-sendshelf.pl index c97aa450dc..015cc654e4 100755 --- a/opac/opac-sendshelf.pl +++ b/opac/opac-sendshelf.pl @@ -71,7 +71,7 @@ if ( $email ) { my $patron = Koha::Patrons->find( $borrowernumber ); my $borcat = $patron ? $patron->categorycode : q{}; - +=pod my $shelf = Koha::Virtualshelves->find( $shelfid ); my $contents = $shelf->get_contents; my $marcflavour = C4::Context->preference('marcflavour'); @@ -113,60 +113,44 @@ if ( $email ) { firstname => $patron->firstname, surname => $patron->surname, ); +=cut + my $shelf = Koha::Virtualshelves->find( $shelfid ); + my $contents = $shelf->get_contents; + my @biblionumbers; - # 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"; - } + while ( my $content = $contents->next ) { + push @biblionumbers, $content->biblionumber; + }; - my $email_header = ""; - if ( $template_res =~ /
(.*)/s ) { - $email_header = $1; - $email_header =~ s|\n?(.*)\n?|$1|; - } + my %loops = ( + biblio => \@biblionumbers, + ); - if ( $template_res =~ /(.*)/s ) { - $body = $1; - $body =~ s|\n?(.*)\n?|$1|; - } + my %substitute = ( + comment => $comment, + ); - 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', - ); - my $library = Koha::Patrons->find( $borrowernumber )->library; - $email->transport( $library->smtp_server->transport ); - $email->send_or_die; - $template->param( SENT => "1" ); - } - catch { - carp "Error sending mail: $_"; - $template->param( error => 1 ); - }; + my $letter = C4::Letters::GetPreparedLetter ( + module => 'catalog', + letter_code => 'LIST', + branchcode => $branch, + lang => $patron->lang, + tables => { + biblio => $biblio->biblionumber, + borrowers => $borrowernumber, + }, + message_transport_type => 'email', + loops => \%loops, + substitute => \%substite, + ) + + C4::Letters::EnqueueLetter({ + letter => $letter, + message_transport_type => 'email', + borrowernumber => $patron->borrowernumber, + to_address => $email, + reply_address => $patron->first_valid_email_address, + }); $template->param( shelfid => $shelfid, -- 2.11.0