View | Details | Raw Unified | Return to bug 3150
Collapse All | Expand All

(-)a/basket/sendbasket.pl (-91 / +42 lines)
Lines 55-164 if ( $email_add ) { Link Here
55
            session_id => scalar $query->cookie('CGISESSID'),
55
            session_id => scalar $query->cookie('CGISESSID'),
56
            token  => scalar $query->param('csrf_token'),
56
            token  => scalar $query->param('csrf_token'),
57
        });
57
        });
58
    my $comment = $query->param('comment');
59
58
60
    # Since we are already logged in, no need to check credentials again
59
    my $patron = Koha:::Patrons->find( $borrowernumber );
61
    # when loading a second template.
60
62
    my $template2 = C4::Templates::gettemplate(
61
    my $comment = $query->param('comment');
63
        'basket/sendbasket.tt', 'intranet', $query,
64
    );
65
62
66
    my @bibs = split( /\//, $bib_list );
63
    my @bibs = split( /\//, $bib_list );
67
    my @results;
68
    my $iso2709;
64
    my $iso2709;
69
    my $marcflavour = C4::Context->preference('marcflavour');
70
    foreach my $biblionumber (@bibs) {
71
        $template2->param( biblionumber => $biblionumber );
72
73
        my $biblio           = Koha::Biblios->find( $biblionumber ) or next;
74
        my $dat              = $biblio->unblessed;
75
        my $record           = GetMarcBiblio({
76
            biblionumber => $biblionumber,
77
            embed_items => 1 });
78
        my $marcauthorsarray = $biblio->get_marc_authors;
79
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
80
81
        my @items = GetItemsInfo( $biblionumber );
82
83
        my $hasauthors = 0;
84
        if($dat->{'author'} || @$marcauthorsarray) {
85
          $hasauthors = 1;
86
        }
87
	
88
89
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
90
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
91
        $dat->{HASAUTHORS}     = $hasauthors;
92
        $dat->{'biblionumber'} = $biblionumber;
93
        $dat->{ITEM_RESULTS}   = \@items;
94
95
        $iso2709 .= $record->as_usmarc();
96
97
        push( @results, $dat );
98
    }
99
100
    my $resultsarray = \@results;
101
    $template2->param(
102
        BIBLIO_RESULTS => $resultsarray,
103
        comment        => $comment
104
    );
105
106
    # Getting template result
107
    my $template_res = $template2->output();
108
    my $body;
109
110
    my $subject;
111
    # Analysing information and getting mail properties
112
    if ( $template_res =~ /<SUBJECT>(?<subject>.*)<END_SUBJECT>/s ) {
113
        $subject = $+{subject};
114
        $subject =~ s|\n?(.*)\n?|$1|;
115
    }
116
    else {
117
        $subject = "no subject";
118
    }
119
120
    my $email_header = "";
121
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
122
        $email_header = $1;
123
        $email_header =~ s|\n?(.*)\n?|$1|;
124
    }
125
65
126
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
66
    foreach my $bib ( @bibs ) {
127
        $body = $1;
67
        my $biblio = Koha::Biblios->find( $biblionumber ) or next;
128
        $body =~ s|\n?(.*)\n?|$1|;
68
        $iso2709 .= $biblio->metadata->record->as_usmarc();
129
    }
69
    }
130
70
131
    my $THE_body = <<END_OF_BODY;
71
    if ( !defined $iso2709 ) {
132
$email_header
72
        carp "Error sending mail: empty basket";
133
$body
73
        $template->param( error => 1 );
134
END_OF_BODY
74
    } else {
135
75
        my %loops = (
136
    try {
76
            biblio => \@bibs,
77
        );
137
78
138
        my $email = Koha::Email->create(
79
        my %substitute = (
139
            {
80
            comment => $comment,
140
                to      => $email_add,
141
                subject => $subject,
142
            }
143
        );
81
        );
144
82
145
        $email->text_body( $THE_body );
83
        my $letter = C4::Letters::GetPreparedLetter(
146
        $email->attach(
84
            module => 'catalog',
147
            Encode::encode( "UTF-8", $iso2709 ),
85
            letter_code => 'CART',
148
            content_type => 'application/octet-stream',
86
            lang => $patron->lang,
149
            name         => 'basket.iso2709',
87
            tables => {
150
            disposition  => 'attachment',
88
                borrowers => $borrowernumber,
89
            },
90
            message_transport_type => 'email',
91
            loops => \%loops,
92
            substitute => \%substitute,
151
        );
93
        );
152
94
153
        my $library = Koha::Patrons->find( $borrowernumber )->library;
95
        my $attachment = {
154
        $email->send_or_die({ transport => $library->smtp_server->transport });
96
            filename => 'basket.iso2709',
155
        $template->param( SENT => "1" );
97
            type => 'application/octet-stream',
156
    }
98
            content => Encode::encode("UTF-8", $iso2709),
157
    catch {
99
        };
158
        carp "Error sending mail: $_";
100
159
        $template->param( error => 1 );
101
        my $user_email = $patron->first_valid_email_address || C4::Context->preference('KohaAdminEmailAddress');
160
    };
102
        C4::Letters::EnqueueLetter({
103
            letter => $letter,
104
            message_transport_type => 'email',
105
            borrowernumber => $patron->borrowernumber,
106
            to_address => $email_add,
107
            reply_address => $user_email,
108
            attachments => [$attachment],
109
        });
161
110
111
        $template->param( SENT => 1 );
112
    }
162
    $template->param( email_add => $email_add );
113
    $template->param( email_add => $email_add );
163
    output_html_with_http_headers $query, $cookie, $template->output;
114
    output_html_with_http_headers $query, $cookie, $template->output;
164
}
115
}
(-)a/installer/data/mysql/atomicupdate/bug_3150_-_add_LIST_and_CART_notices.perl (+224 lines)
Line 0 Link Here
1
$DBversion = 'XXX';
2
if( CheckVersion( $DBversion ) ) {
3
    $dbh->do(q{ INSERT IGNORE INTO letter (module, code, branchcode, name, is_html, title, content, message_transport_type, lang) VALUES
4
        ('catalog','LIST','','Send list',1,'Your list: [% listname | html %]',"[%- USE raw -%]
5
<p>Hi,</p>
6
<p>[% borrower.firstname | $raw %] [% borrower.surname | $raw %] sent you a list from our online catalog called: [% listname | $raw %].</p>
7
<p>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.</p>
8
<hr/>
9
<p>[% comment | $raw %]</p>
10
<hr/>
11
<ol>
12
[% FOREACH biblio IN biblios %]
13
    <li>
14
        <span>
15
            [% biblio.title | $raw %]
16
            [% IF ( biblio.subtitle ) %]
17
                [% FOREACH subtitle IN biblio.subtitle.split(' | ') %]
18
                    [% subtitle | $raw %]
19
                [% END %]
20
            [% END %]
21
            [% biblio.part_number | $raw %] [% biblio.part_name | $raw %]
22
        </span>
23
        <p>
24
            [% IF ( biblio.author || biblio.get_authors_from_MARC ) %]
25
                <span>Author(s): [% IF ( biblio.author ) %][% biblio.author | $raw %][% END %]
26
                [% IF ( biblio.get_authors_from_MARC ) %]
27
                    [% IF ( biblio.author ) %]; [% END %]
28
                    [% FOREACH author IN biblio.get_authors_from_MARC %]
29
                        [% FOREACH subfield IN author.MARCAUTHOR_SUBFIELDS_LOOP %]
30
                            [% subfield.separator | $raw %][% subfield.value | $raw %]
31
                        [% END %]
32
                        [% UNLESS ( loop.last ) %];[% END %]
33
                    [% END %]
34
                [% END %]
35
                </span><br/>
36
            [% END %]
37
            [% SET biblioitem = biblio.biblioitem %]
38
            [% IF ( biblioitem.isbn ) %]
39
                <span>
40
                    ISBN: [% FOREACH isbn IN biblioitem.isbn %]
41
                        [% isbn | $raw %]
42
                        [% UNLESS ( loop.last ) %]; [% END %]
43
                    [% END %]
44
                </span><br/>
45
            [% END %]
46
            [% IF ( biblioitem.publishercode ) %]
47
                <span>
48
                    Published by: [% biblioitem.publishercode | $raw %]
49
                    [% IF ( biblioitem.publicationyear ) %]
50
                        in [% biblioitem.publicationyear | $raw %]
51
                    [% END %]
52
                    [% IF ( biblioitem.pages ) %]
53
                        , [% biblioitem.pages | $raw %]
54
                    [% END %]
55
                </span><br/>
56
            [% END %]
57
            [% IF ( biblio.seriestitle ) %]
58
                <span>
59
                    Collection: [% biblio.seriestitle | $raw %]
60
                </span><br/>
61
            [% END %]
62
            [% IF ( biblio.copyrightdate ) %]
63
                <span>
64
                    Copyright year: [% biblio.copyrightdate | $raw %]
65
                </span><br/>
66
            [% END %]
67
            [% IF ( biblio.notes ) %]
68
                <span>
69
                    Notes: [% biblio.notes | $raw %]
70
                </span><br/>
71
            [% END %]
72
            [% IF ( biblio.unititle ) %]
73
                <span>
74
                    Unified title: [% biblio.unititle | $raw %]
75
                </span><br/>
76
            [% END %]
77
            [% IF ( biblio.serial ) %]
78
                <span>
79
                    Serial: [% biblio.serial | $raw %]
80
                </span><br/>
81
            [% END %]
82
            [% IF ( biblioitem.lccn ) %]
83
                <span>
84
                    LCCN: [% biblioitem.lccn | $raw %]
85
                </span><br/>
86
            [% END %]
87
            [% IF ( biblioitem.url ) %]
88
                <span>
89
                    URL: [% biblioitem.url | html %]
90
                </span>
91
            [% END %]
92
        </p>
93
        [% SET OPACBaseURL = Koha.Preference('OPACBaseURL') %]
94
        [% IF ( OPACBaseURL ) %]
95
            <p>In online catalog: [% OPACBaseURL | $raw %]/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblio.biblionumber | html %]</p>
96
        [% END %]
97
        [% IF ( biblio.items.count > 0 ) %]
98
            <p>Items:
99
                <ul>
100
                    [% FOREACH item IN biblio.items %]<li>
101
                        [% item.holding_branch.branchname | $raw %]
102
                        [% item.location | $raw %]
103
                        [% IF item.itemcallnumber %]([% item.itemcallnumber | $raw %])[% END %]
104
                        [% item.barcode | $raw %]
105
                    </li>[% END %]
106
                </ul>
107
            </p>
108
        [% END %]
109
        <hr/>
110
    </li>
111
[% END %]
112
</ol>", 'email','default' ),
113
        ('catalog','CART','','Send cart',1,'Your cart',"[%- USE raw -%]
114
<p>Hi,</p>
115
<p>[% borrower.firstname | $raw %] [% borrower.surname | $raw %] sent you a cart from our online catalog.</p>
116
<p>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.</p>
117
<hr/>
118
<p>[% comment | $raw %]</p>
119
<hr/>
120
<ol>
121
[% FOREACH biblio IN biblios %]
122
    <li>
123
        <span>
124
            [% biblio.title | $raw %]
125
            [% IF ( biblio.subtitle ) %]
126
                [% FOREACH subtitle IN biblio.subtitle.split(' | ') %]
127
                    [% subtitle | $raw %]
128
                [% END %]
129
            [% END %]
130
            [% biblio.part_number | $raw %] [% biblio.part_name | $raw %]
131
        </span>
132
        <p>
133
            [% IF ( biblio.author || biblio.get_authors_from_MARC ) %]
134
                <span>Author(s): [% IF ( biblio.author ) %][% biblio.author | $raw %][% END %]
135
                [% IF ( biblio.get_authors_from_MARC ) %]
136
                    [% IF ( biblio.author ) %]; [% END %]
137
                    [% FOREACH author IN biblio.get_authors_from_MARC %]
138
                        [% FOREACH subfield IN author.MARCAUTHOR_SUBFIELDS_LOOP %]
139
                            [% subfield.separator | $raw %][% subfield.value | $raw %]
140
                        [% END %]
141
                        [% UNLESS ( loop.last ) %];[% END %]
142
                    [% END %]
143
                [% END %]
144
                </span><br/>
145
            [% END %]
146
            [% SET biblioitem = biblio.biblioitem %]
147
            [% IF ( biblioitem.isbn ) %]
148
                <span>
149
                    ISBN: [% FOREACH isbn IN biblioitem.isbn %]
150
                        [% isbn | $raw %]
151
                        [% UNLESS ( loop.last ) %]; [% END %]
152
                    [% END %]
153
                </span><br/>
154
            [% END %]
155
            [% IF ( biblioitem.publishercode ) %]
156
                <span>
157
                    Published by: [% biblioitem.publishercode | $raw %]
158
                    [% IF ( biblioitem.publicationyear ) %]
159
                        in [% biblioitem.publicationyear | $raw %]
160
                    [% END %]
161
                    [% IF ( biblioitem.pages ) %]
162
                        , [% biblioitem.pages | $raw %]
163
                    [% END %]
164
                </span><br/>
165
            [% END %]
166
            [% IF ( biblio.seriestitle ) %]
167
                <span>
168
                    Collection: [% biblio.seriestitle | $raw %]
169
                </span><br/>
170
            [% END %]
171
            [% IF ( biblio.copyrightdate ) %]
172
                <span>
173
                    Copyright year: [% biblio.copyrightdate | $raw %]
174
                </span><br/>
175
            [% END %]
176
            [% IF ( biblio.notes ) %]
177
                <span>
178
                    Notes: [% biblio.notes | $raw %]
179
                </span><br/>
180
            [% END %]
181
            [% IF ( biblio.unititle ) %]
182
                <span>
183
                    Unified title: [% biblio.unititle | $raw %]
184
                </span><br/>
185
            [% END %]
186
            [% IF ( biblio.serial ) %]
187
                <span>
188
                    Serial: [% biblio.serial | $raw %]
189
                </span><br/>
190
            [% END %]
191
            [% IF ( biblioitem.lccn ) %]
192
                <span>
193
                    LCCN: [% biblioitem.lccn | $raw %]
194
                </span><br/>
195
            [% END %]
196
            [% IF ( biblioitem.url ) %]
197
                <span>
198
                    URL: [% biblioitem.url | html %]
199
                </span>
200
            [% END %]
201
        </p>
202
        [% SET OPACBaseURL = Koha.Preference('OPACBaseURL') %]
203
        [% IF ( OPACBaseURL ) %]
204
            <p>In online catalog: [% OPACBaseURL | $raw %]/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblio.biblionumber | html %]</p>
205
        [% END %]
206
        [% IF ( biblio.items.count > 0 ) %]
207
            <p>Items:
208
                <ul>
209
                    [% FOREACH item IN biblio.items %]<li>
210
                        [% item.holding_branch.branchname | $raw %]
211
                        [% item.location | $raw %]
212
                        [% IF item.itemcallnumber %]([% item.itemcallnumber | $raw %])[% END %]
213
                        [% item.barcode | $raw %]
214
                    </li>[% END %]
215
                </ul>
216
            </p>
217
        [% END %]
218
        <hr/>
219
    </li>
220
[% END %]
221
</ol>",'email','default') });
222
223
    NewVersion( $DBversion, 3150, 'Add LIST and CART notices' );
224
}
(-)a/installer/data/mysql/en/mandatory/sample_notices.yml (+238 lines)
Lines 1632-1634 tables: Link Here
1632
            - "Callnumber: <<items.itemcallnumber>>"
1632
            - "Callnumber: <<items.itemcallnumber>>"
1633
            - "Waiting since: <<recalls.waitingdate>>"
1633
            - "Waiting since: <<recalls.waitingdate>>"
1634
            - "Notes: <<recalls.recallnotes>>"
1634
            - "Notes: <<recalls.recallnotes>>"
1635
1636
        - module: catalog
1637
          code: LIST
1638
          branchcode: ""
1639
          name: "Send list"
1640
          is_html: 1
1641
          title: "Your list: [% listname | html %]"
1642
          message_transport_type: email
1643
          lang: default
1644
          content:
1645
            - "[%- USE raw -%]"
1646
            - "<p>Hi,</p>"
1647
            - "<p>[% borrower.firstname | $raw %] [% borrower.surname | $raw %] sent you a list from our online catalog called: [% listname | $raw %].</p>"
1648
            - "<p>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.</p>"
1649
            - "<hr/>"
1650
            - "<p>[% comment | $raw %]</p>"
1651
            - "<hr/>"
1652
            - "<ol>"
1653
            - "[% FOREACH biblio IN biblios %]"
1654
            - "<li>"
1655
            - "<span>"
1656
            - "[% biblio.title | $raw %]"
1657
            - "[% IF ( biblio.subtitle ) %]"
1658
            - "[% FOREACH subtitle IN biblio.subtitle.split(' | ') %]"
1659
            - "[% subtitle | $raw %]"
1660
            - "[% END %]"
1661
            - "[% END %]"
1662
            - "[% biblio.part_number | $raw %] [% biblio.part_name | $raw %]"
1663
            - "</span>"
1664
            - "<p>"
1665
            - "[% IF ( biblio.author || biblio.get_authors_from_MARC ) %]"
1666
            - "<span>Author(s): [% IF ( biblio.author ) %][% biblio.author | $raw %][% END %]"
1667
            - "[% IF ( biblio.get_authors_from_MARC ) %]"
1668
            - "[% IF ( biblio.author ) %]; [% END %]"
1669
            - "[% FOREACH author IN biblio.get_authors_from_MARC %]"
1670
            - "[% FOREACH subfield IN author.MARCAUTHOR_SUBFIELDS_LOOP %]"
1671
            - "[% subfield.separator | $raw %][% subfield.value | $raw %]"
1672
            - "[% END %]"
1673
            - "[% UNLESS ( loop.last ) %];[% END %]"
1674
            - "[% END %]"
1675
            - "[% END %]"
1676
            - "</span><br/>"
1677
            - "[% END %]"
1678
            - "[% SET biblioitem = biblio.biblioitem %]"
1679
            - "[% IF ( biblioitem.isbn ) %]"
1680
            - "<span>"
1681
            - "ISBN: [% FOREACH isbn IN biblioitem.isbn %]"
1682
            - "[% isbn | $raw %]"
1683
            - "[% UNLESS ( loop.last ) %]; [% END %]"
1684
            - "[% END %]"
1685
            - "</span><br/>"
1686
            - "[% END %]"
1687
            - "[% IF ( biblioitem.publishercode ) %]"
1688
            - "<span>"
1689
            - "Published by: [% biblioitem.publishercode | $raw %]"
1690
            - "[% IF ( biblioitem.publicationyear ) %]"
1691
            - "in [% biblioitem.publicationyear | $raw %]"
1692
            - "[% END %]"
1693
            - "[% IF ( biblioitem.pages ) %]"
1694
            - ", [% biblioitem.pages | $raw %]"
1695
            - "[% END %]"
1696
            - "</span><br/>"
1697
            - "[% END %]"
1698
            - "[% IF ( biblio.seriestitle ) %]"
1699
            - "<span>"
1700
            - "Collection: [% biblio.seriestitle | $raw %]"
1701
            - "</span><br/>"
1702
            - "[% END %]"
1703
            - "[% IF ( biblio.copyrightdate ) %]"
1704
            - "<span>"
1705
            - "Copyright year: [% biblio.copyrightdate | $raw %]"
1706
            - "</span><br/>"
1707
            - "[% END %]"
1708
            - "[% IF ( biblio.notes ) %]"
1709
            - "<span>"
1710
            - "Notes: [% biblio.notes | $raw %]"
1711
            - "</span><br/>"
1712
            - "[% END %]"
1713
            - "[% IF ( biblio.unititle ) %]"
1714
            - "<span>"
1715
            - "Unified title: [% biblio.unititle | $raw %]"
1716
            - "</span><br/>"
1717
            - "[% END %]"
1718
            - "[% IF ( biblio.serial ) %]"
1719
            - "<span>"
1720
            - "Serial: [% biblio.serial | $raw %]"
1721
            - "</span><br/>"
1722
            - "[% END %]"
1723
            - "[% IF ( biblioitem.lccn ) %]"
1724
            - "<span>"
1725
            - "LCCN: [% biblioitem.lccn | $raw %]"
1726
            - "</span><br/>"
1727
            - "[% END %]"
1728
            - "[% IF ( biblioitem.url ) %]"
1729
            - "<span>"
1730
            - "URL: [% biblioitem.url | html %]"
1731
            - "</span>"
1732
            - "[% END %]"
1733
            - "</p>"
1734
            - "[% SET OPACBaseURL = Koha.Preference('OPACBaseURL') %]"
1735
            - "[% IF ( OPACBaseURL ) %]"
1736
            - "<p>In online catalog: [% OPACBaseURL | $raw %]/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblio.biblionumber | html %]</p>"
1737
            - "[% END %]"
1738
            - "[% IF ( biblio.items.count > 0 ) %]"
1739
            - "<p>Items:"
1740
            - "<ul>"
1741
            - "[% FOREACH item IN biblio.items %]<li>"
1742
            - "[% item.holding_branch.branchname | $raw %]"
1743
            - "[% item.location | $raw %]"
1744
            - "[% IF item.itemcallnumber %]([% item.itemcallnumber | $raw %])[% END %]"
1745
            - "[% item.barcode | $raw %]"
1746
            - "</li>[% END %]"
1747
            - "</ul>"
1748
            - "</p>"
1749
            - "[% END %]"
1750
            - "<hr/>"
1751
            - "</li>"
1752
            - "[% END %]"
1753
            - "</ol>"
1754
1755
        - module: catalog
1756
          code: CART
1757
          branchcode: ""
1758
          name: "Send cart"
1759
          is_html: 1
1760
          title: "Your cart"
1761
          message_transport_type: email
1762
          lang: default
1763
          content:
1764
            - "[%- USE raw -%]"
1765
            - "<p>Hi,</p>"
1766
            - "<p>[% borrower.firstname | $raw %] [% borrower.surname | $raw %] sent you a cart from our online catalog.</p>"
1767
            - "<p>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.</p>"
1768
            - "<hr/>"
1769
            - "<p>[% comment | $raw %]</p>"
1770
            - "<hr/>"
1771
            - "<ol>"
1772
            - "[% FOREACH biblio IN biblios %]"
1773
            - "<li>"
1774
            - "<span>"
1775
            - "[% biblio.title | $raw %]"
1776
            - "[% IF ( biblio.subtitle ) %]"
1777
            - "[% FOREACH subtitle IN biblio.subtitle.split(' | ') %]"
1778
            - "[% subtitle | $raw %]"
1779
            - "[% END %]"
1780
            - "[% END %]"
1781
            - "[% biblio.part_number | $raw %] [% biblio.part_name | $raw %]"
1782
            - "</span>"
1783
            - "<p>"
1784
            - "[% IF ( biblio.author || biblio.get_authors_from_MARC ) %]"
1785
            - "<span>Author(s): [% IF ( biblio.author ) %][% biblio.author | $raw %][% END %]"
1786
            - "[% IF ( biblio.get_authors_from_MARC ) %]"
1787
            - "[% IF ( biblio.author ) %]; [% END %]"
1788
            - "[% FOREACH author IN biblio.get_authors_from_MARC %]"
1789
            - "[% FOREACH subfield IN author.MARCAUTHOR_SUBFIELDS_LOOP %]"
1790
            - "[% subfield.separator | $raw %][% subfield.value | $raw %]"
1791
            - "[% END %]"
1792
            - "[% UNLESS ( loop.last ) %];[% END %]"
1793
            - "[% END %]"
1794
            - "[% END %]"
1795
            - "</span><br/>"
1796
            - "[% END %]"
1797
            - "[% SET biblioitem = biblio.biblioitem %]"
1798
            - "[% IF ( biblioitem.isbn ) %]"
1799
            - "<span>"
1800
            - "ISBN: [% FOREACH isbn IN biblioitem.isbn %]"
1801
            - "[% isbn | $raw %]"
1802
            - "[% UNLESS ( loop.last ) %]; [% END %]"
1803
            - "[% END %]"
1804
            - "</span><br/>"
1805
            - "[% END %]"
1806
            - "[% IF ( biblioitem.publishercode ) %]"
1807
            - "<span>"
1808
            - "Published by: [% biblioitem.publishercode | $raw %]"
1809
            - "[% IF ( biblioitem.publicationyear ) %]"
1810
            - "in [% biblioitem.publicationyear | $raw %]"
1811
            - "[% END %]"
1812
            - "[% IF ( biblioitem.pages ) %]"
1813
            - ", [% biblioitem.pages | $raw %]"
1814
            - "[% END %]"
1815
            - "</span><br/>"
1816
            - "[% END %]"
1817
            - "[% IF ( biblio.seriestitle ) %]"
1818
            - "<span>"
1819
            - "Collection: [% biblio.seriestitle | $raw %]"
1820
            - "</span><br/>"
1821
            - "[% END %]"
1822
            - "[% IF ( biblio.copyrightdate ) %]"
1823
            - "<span>"
1824
            - "Copyright year: [% biblio.copyrightdate | $raw %]"
1825
            - "</span><br/>"
1826
            - "[% END %]"
1827
            - "[% IF ( biblio.notes ) %]"
1828
            - "<span>"
1829
            - "Notes: [% biblio.notes | $raw %]"
1830
            - "</span><br/>"
1831
            - "[% END %]"
1832
            - "[% IF ( biblio.unititle ) %]"
1833
            - "<span>"
1834
            - "Unified title: [% biblio.unititle | $raw %]"
1835
            - "</span><br/>"
1836
            - "[% END %]"
1837
            - "[% IF ( biblio.serial ) %]"
1838
            - "<span>"
1839
            - "Serial: [% biblio.serial | $raw %]"
1840
            - "</span><br/>"
1841
            - "[% END %]"
1842
            - "[% IF ( biblioitem.lccn ) %]"
1843
            - "<span>"
1844
            - "LCCN: [% biblioitem.lccn | $raw %]"
1845
            - "</span><br/>"
1846
            - "[% END %]"
1847
            - "[% IF ( biblioitem.url ) %]"
1848
            - "<span>"
1849
            - "URL: [% biblioitem.url | html %]"
1850
            - "</span>"
1851
            - "[% END %]"
1852
            - "</p>"
1853
            - "[% SET OPACBaseURL = Koha.Preference('OPACBaseURL') %]"
1854
            - "[% IF ( OPACBaseURL ) %]"
1855
            - "<p>In online catalog: [% OPACBaseURL | $raw %]/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblio.biblionumber | html %]</p>"
1856
            - "[% END %]"
1857
            - "[% IF ( biblio.items.count > 0 ) %]"
1858
            - "<p>Items:"
1859
            - "<ul>"
1860
            - "[% FOREACH item IN biblio.items %]<li>"
1861
            - "[% item.holding_branch.branchname | $raw %]"
1862
            - "[% item.location | $raw %]"
1863
            - "[% IF item.itemcallnumber %]([% item.itemcallnumber | $raw %])[% END %]"
1864
            - "[% item.barcode | $raw %]"
1865
            - "</li>[% END %]"
1866
            - "</ul>"
1867
            - "</p>"
1868
            - "[% END %]"
1869
            - "<hr/>"
1870
            - "</li>"
1871
            - "[% END %]"
1872
            - "</ol>"
(-)a/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql (+219 lines)
Lines 503-505 INSERT IGNORE INTO letter (module, code, name, title, content, message_transport Link Here
503
    [% END %]
503
    [% END %]
504
[% END %]
504
[% END %]
505
", 'email');
505
", 'email');
506
507
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 -%]
508
<p>Hi,</p>
509
<p>[% borrower.firstname | $raw %] [% borrower.surname | $raw %] sent you a list from our online catalog called: [% listname | $raw %].</p>
510
<p>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.</p>
511
<hr/>
512
<p>[% comment | $raw %]</p>
513
<hr/>
514
<ol>
515
[% FOREACH biblio IN biblios %]
516
    <li>
517
        <span>
518
            [% biblio.title | $raw %]
519
            [% IF ( biblio.subtitle ) %]
520
                [% FOREACH subtitle IN biblio.subtitle.split(' | ') %]
521
                    [% subtitle | $raw %]
522
                [% END %]
523
            [% END %]
524
            [% biblio.part_number | $raw %] [% biblio.part_name | $raw %]
525
        </span>
526
        <p>
527
            [% IF ( biblio.author || biblio.get_authors_from_MARC ) %]
528
                <span>Author(s): [% IF ( biblio.author ) %][% biblio.author | $raw %][% END %]
529
                [% IF ( biblio.get_authors_from_MARC ) %]
530
                    [% IF ( biblio.author ) %]; [% END %]
531
                    [% FOREACH author IN biblio.get_authors_from_MARC %]
532
                        [% FOREACH subfield IN author.MARCAUTHOR_SUBFIELDS_LOOP %]
533
                            [% subfield.separator | $raw %][% subfield.value | $raw %]
534
                        [% END %]
535
                        [% UNLESS ( loop.last ) %];[% END %]
536
                    [% END %]
537
                [% END %]
538
                </span><br/>
539
            [% END %]
540
            [% SET biblioitem = biblio.biblioitem %]
541
            [% IF ( biblioitem.isbn ) %]
542
                <span>
543
                    ISBN: [% FOREACH isbn IN biblioitem.isbn %]
544
                        [% isbn | $raw %]
545
                        [% UNLESS ( loop.last ) %]; [% END %]
546
                    [% END %]
547
                </span><br/>
548
            [% END %]
549
            [% IF ( biblioitem.publishercode ) %]
550
                <span>
551
                    Published by: [% biblioitem.publishercode | $raw %]
552
                    [% IF ( biblioitem.publicationyear ) %]
553
                        in [% biblioitem.publicationyear | $raw %]
554
                    [% END %]
555
                    [% IF ( biblioitem.pages ) %]
556
                        , [% biblioitem.pages | $raw %]
557
                    [% END %]
558
                </span><br/>
559
            [% END %]
560
            [% IF ( biblio.seriestitle ) %]
561
                <span>
562
                    Collection: [% biblio.seriestitle | $raw %]
563
                </span><br/>
564
            [% END %]
565
            [% IF ( biblio.copyrightdate ) %]
566
                <span>
567
                    Copyright year: [% biblio.copyrightdate | $raw %]
568
                </span><br/>
569
            [% END %]
570
            [% IF ( biblio.notes ) %]
571
                <span>
572
                    Notes: [% biblio.notes | $raw %]
573
                </span><br/>
574
            [% END %]
575
            [% IF ( biblio.unititle ) %]
576
                <span>
577
                    Unified title: [% biblio.unititle | $raw %]
578
                </span><br/>
579
            [% END %]
580
            [% IF ( biblio.serial ) %]
581
                <span>
582
                    Serial: [% biblio.serial | $raw %]
583
                </span><br/>
584
            [% END %]
585
            [% IF ( biblioitem.lccn ) %]
586
                <span>
587
                    LCCN: [% biblioitem.lccn | $raw %]
588
                </span><br/>
589
            [% END %]
590
            [% IF ( biblioitem.url ) %]
591
                <span>
592
                    URL: [% biblioitem.url | html %]
593
                </span>
594
            [% END %]
595
        </p>
596
        [% SET OPACBaseURL = Koha.Preference('OPACBaseURL') %]
597
        [% IF ( OPACBaseURL ) %]
598
            <p>In online catalog: [% OPACBaseURL | $raw %]/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblio.biblionumber | html %]</p>
599
        [% END %]
600
        [% IF ( biblio.items.count > 0 ) %]
601
            <p>Items:
602
                <ul>
603
                    [% FOREACH item IN biblio.items %]<li>
604
                        [% item.holding_branch.branchname | $raw %]
605
                        [% item.location | $raw %]
606
                        [% IF item.itemcallnumber %]([% item.itemcallnumber | $raw %])[% END %]
607
                        [% item.barcode | $raw %]
608
                    </li>[% END %]
609
                </ul>
610
            </p>
611
        [% END %]
612
        <hr/>
613
    </li>
614
[% END %]
615
</ol>", 'email','default' ),
616
('catalog','CART','','Send cart',1,'Your cart',"[%- USE raw -%]
617
<p>Hi,</p>
618
<p>[% borrower.firstname | $raw %] [% borrower.surname | $raw %] sent you a cart from our online catalog.</p>
619
<p>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.</p>
620
<hr/>
621
<p>[% comment | $raw %]</p>
622
<hr/>
623
<ol>
624
[% FOREACH biblio IN biblios %]
625
    <li>
626
        <span>
627
            [% biblio.title | $raw %]
628
            [% IF ( biblio.subtitle ) %]
629
                [% FOREACH subtitle IN biblio.subtitle.split(' | ') %]
630
                    [% subtitle | $raw %]
631
                [% END %]
632
            [% END %]
633
            [% biblio.part_number | $raw %] [% biblio.part_name | $raw %]
634
        </span>
635
        <p>
636
            [% IF ( biblio.author || biblio.get_authors_from_MARC ) %]
637
                <span>Author(s): [% IF ( biblio.author ) %][% biblio.author | $raw %][% END %]
638
                [% IF ( biblio.get_authors_from_MARC ) %]
639
                    [% IF ( biblio.author ) %]; [% END %]
640
                    [% FOREACH author IN biblio.get_authors_from_MARC %]
641
                        [% FOREACH subfield IN author.MARCAUTHOR_SUBFIELDS_LOOP %]
642
                            [% subfield.separator | $raw %][% subfield.value | $raw %]
643
                        [% END %]
644
                        [% UNLESS ( loop.last ) %];[% END %]
645
                    [% END %]
646
                [% END %]
647
                </span><br/>
648
            [% END %]
649
            [% SET biblioitem = biblio.biblioitem %]
650
            [% IF ( biblioitem.isbn ) %]
651
                <span>
652
                    ISBN: [% FOREACH isbn IN biblioitem.isbn %]
653
                        [% isbn | $raw %]
654
                        [% UNLESS ( loop.last ) %]; [% END %]
655
                    [% END %]
656
                </span><br/>
657
            [% END %]
658
            [% IF ( biblioitem.publishercode ) %]
659
                <span>
660
                    Published by: [% biblioitem.publishercode | $raw %]
661
                    [% IF ( biblioitem.publicationyear ) %]
662
                        in [% biblioitem.publicationyear | $raw %]
663
                    [% END %]
664
                    [% IF ( biblioitem.pages ) %]
665
                        , [% biblioitem.pages | $raw %]
666
                    [% END %]
667
                </span><br/>
668
            [% END %]
669
            [% IF ( biblio.seriestitle ) %]
670
                <span>
671
                    Collection: [% biblio.seriestitle | $raw %]
672
                </span><br/>
673
            [% END %]
674
            [% IF ( biblio.copyrightdate ) %]
675
                <span>
676
                    Copyright year: [% biblio.copyrightdate | $raw %]
677
                </span><br/>
678
            [% END %]
679
            [% IF ( biblio.notes ) %]
680
                <span>
681
                    Notes: [% biblio.notes | $raw %]
682
                </span><br/>
683
            [% END %]
684
            [% IF ( biblio.unititle ) %]
685
                <span>
686
                    Unified title: [% biblio.unititle | $raw %]
687
                </span><br/>
688
            [% END %]
689
            [% IF ( biblio.serial ) %]
690
                <span>
691
                    Serial: [% biblio.serial | $raw %]
692
                </span><br/>
693
            [% END %]
694
            [% IF ( biblioitem.lccn ) %]
695
                <span>
696
                    LCCN: [% biblioitem.lccn | $raw %]
697
                </span><br/>
698
            [% END %]
699
            [% IF ( biblioitem.url ) %]
700
                <span>
701
                    URL: [% biblioitem.url | html %]
702
                </span>
703
            [% END %]
704
        </p>
705
        [% SET OPACBaseURL = Koha.Preference('OPACBaseURL') %]
706
        [% IF ( OPACBaseURL ) %]
707
            <p>In online catalog: [% OPACBaseURL | $raw %]/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblio.biblionumber | html %]</p>
708
        [% END %]
709
        [% IF ( biblio.items.count > 0 ) %]
710
            <p>Items:
711
                <ul>
712
                    [% FOREACH item IN biblio.items %]<li>
713
                        [% item.holding_branch.branchname | $raw %]
714
                        [% item.location | $raw %]
715
                        [% IF item.itemcallnumber %]([% item.itemcallnumber | $raw %])[% END %]
716
                        [% item.barcode | $raw %]
717
                    </li>[% END %]
718
                </ul>
719
            </p>
720
        [% END %]
721
        <hr/>
722
    </li>
723
[% END %]
724
</ol>",'email','default');
(-)a/opac/opac-sendbasket.pl (-107 / +42 lines)
Lines 56-180 if ( $email_add ) { Link Here
56
        session_id => scalar $query->cookie('CGISESSID'),
56
        session_id => scalar $query->cookie('CGISESSID'),
57
        token  => scalar $query->param('csrf_token'),
57
        token  => scalar $query->param('csrf_token'),
58
    });
58
    });
59
59
    my $patron = Koha::Patrons->find( $borrowernumber );
60
    my $patron = Koha::Patrons->find( $borrowernumber );
60
    my $borcat = $patron ? $patron->categorycode : q{};
61
    my $user_email = $patron->first_valid_email_address
62
    || C4::Context->preference('KohaAdminEmailAddress');
63
61
64
    my $email_replyto = $patron->firstname . " " . $patron->surname . " <$user_email>";
65
    my $comment    = $query->param('comment');
62
    my $comment    = $query->param('comment');
66
63
67
    # Since we are already logged in, no need to check credentials again
68
    # when loading a second template.
69
    my $template2 = C4::Templates::gettemplate(
70
        'opac-sendbasket.tt', 'opac', $query,
71
    );
72
73
    my @bibs = split( /\//, $bib_list );
64
    my @bibs = split( /\//, $bib_list );
74
    my @results;
75
    my $iso2709;
65
    my $iso2709;
76
    my $marcflavour = C4::Context->preference('marcflavour');
77
    foreach my $biblionumber (@bibs) {
78
        $template2->param( biblionumber => $biblionumber );
79
80
        my $biblio           = Koha::Biblios->find( $biblionumber ) or next;
81
        my $dat              = $biblio->unblessed;
82
        my $record           = GetMarcBiblio({
83
            biblionumber => $biblionumber,
84
            embed_items  => 1,
85
            opac         => 1,
86
            borcat       => $borcat });
87
        my $marcauthorsarray = $biblio->get_marc_authors;
88
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
89
90
        my @items = GetItemsInfo( $biblionumber );
91
92
        my $hasauthors = 0;
93
        if($dat->{'author'} || @$marcauthorsarray) {
94
          $hasauthors = 1;
95
        }
96
	
97
98
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
99
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
100
        $dat->{HASAUTHORS}     = $hasauthors;
101
        $dat->{'biblionumber'} = $biblionumber;
102
        $dat->{ITEM_RESULTS}   = \@items;
103
104
        $iso2709 .= $record->as_usmarc();
105
106
        push( @results, $dat );
107
    }
108
66
109
    my $resultsarray = \@results;
67
    foreach my $bib ( @bibs ) {
110
    
68
        my $biblio = Koha::Biblios->find( $biblionumber ) or next;
111
    $template2->param(
69
        $iso2709 .= $biblio->metadata->record->as_usmarc();
112
        BIBLIO_RESULTS => $resultsarray,
70
    };
113
        comment        => $comment,
114
        firstname      => $patron->firstname,
115
        surname        => $patron->surname,
116
    );
117
118
    # Getting template result
119
    my $template_res = $template2->output();
120
    my $body;
121
122
    # Analysing information and getting mail properties
123
    my $subject;
124
    if ( $template_res =~ /\<SUBJECT\>(?<subject>.*)\<END_SUBJECT\>/s ) {
125
        $subject = $+{subject};
126
        $subject =~ s|\n?(.*)\n?|$1|;
127
    }
128
    else {
129
        $subject = "no subject";
130
    }
131
132
    my $email_header = "";
133
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
134
        $email_header = $1;
135
        $email_header =~ s|\n?(.*)\n?|$1|;
136
    }
137
138
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
139
        $body = $1;
140
        $body =~ s|\n?(.*)\n?|$1|;
141
    }
142
143
    my $THE_body = <<END_OF_BODY;
144
$email_header
145
$body
146
END_OF_BODY
147
71
148
    if ( !defined $iso2709 ) {
72
    if ( !defined $iso2709 ) {
149
        carp "Error sending mail: empty basket";
73
        carp "Error sending mail: empty basket";
150
        $template->param( error => 1 );
74
        $template->param( error => 1 );
151
    }
75
    } else {
152
    else {
76
        my %loops = (
153
        try {
77
            biblio => \@bibs,
154
            # if you want to use the KohaAdmin address as from, that is the default no need to set it
78
        );
155
            my $email = Koha::Email->create({
79
156
                to       => $email_add,
80
        my %substitute = (
157
                reply_to => $email_replyto,
81
            comment => $comment,
158
                subject  => $subject,
82
        );
159
            });
83
160
            $email->header( 'X-Abuse-Report' => C4::Context->preference('KohaAdminEmailAddress') );
84
        my $letter = C4::Letters::GetPreparedLetter(
161
            $email->text_body( $THE_body );
85
            module => 'catalog',
162
            $email->attach(
86
            letter_code => 'CART',
163
                Encode::encode( "UTF-8", $iso2709 ),
87
            lang => $patron->lang,
164
                content_type => 'application/octet-stream',
88
            tables => {
165
                name         => 'basket.iso2709',
89
                borrowers => $borrowernumber,
166
                disposition  => 'attachment',
90
            },
167
            );
91
            message_transport_type => 'email',
168
            my $library = $patron->library;
92
            loops => \%loops,
169
            $email->transport( $library->smtp_server->transport );
93
            substitute => \%substitute,
170
            $email->send_or_die;
94
        );
171
            $template->param( SENT => "1" );
95
172
        }
96
        my $attachment = {
173
        catch {
97
            filename => 'basket.iso2709',
174
            carp "Error sending mail: $_";
98
            type => 'application/octet-stream',
175
            $template->param( error => 1 );
99
            content => Encode::encode("UTF-8", $iso2709),
176
        };
100
        };
177
    }
101
102
        my $user_email = $patron->first_valid_email_address || C4::Context->preference('KohaAdminEmailAddress');
103
        C4::Letters::EnqueueLetter({
104
            letter => $letter,
105
            message_transport_type => 'email',
106
            borrowernumber => $patron->borrowernumber,
107
            to_address => $email_add,
108
            reply_address => $user_email,
109
            attachments => [$attachment],
110
        });
111
112
        $template->param( SENT => 1 );
178
113
179
    $template->param( email_add => $email_add );
114
    $template->param( email_add => $email_add );
180
    output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
115
    output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
(-)a/opac/opac-sendshelf.pl (-89 / +44 lines)
Lines 73-176 if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { Link Here
73
    );
73
    );
74
74
75
    my $patron = Koha::Patrons->find( $borrowernumber );
75
    my $patron = Koha::Patrons->find( $borrowernumber );
76
    my $borcat = $patron ? $patron->categorycode : q{};
77
76
78
    my $shelf = Koha::Virtualshelves->find( $shelfid );
77
    my $shelf = Koha::Virtualshelves->find( $shelfid );
79
    my $contents = $shelf->get_contents;
78
    my $contents = $shelf->get_contents;
80
    my $marcflavour         = C4::Context->preference('marcflavour');
81
    my $iso2709;
79
    my $iso2709;
82
    my @results;
83
80
84
    while ( my $content = $contents->next ) {
81
    while ( my $content = $contents->next ) {
85
        my $biblionumber = $content->biblionumber;
82
        push @biblionumbers, $content->biblionumber;
86
        my $biblio       = Koha::Biblios->find( $biblionumber ) or next;
83
        my $biblio = Koha::Biblios->find($content->biblionumber);
87
        my $dat          = $biblio->unblessed;
84
        $iso2709 .= $biblio->metadata->record->as_usmarc();
88
        my $record           = GetMarcBiblio({
85
    };
89
            biblionumber => $biblionumber,
90
            embed_items  => 1,
91
            opac         => 1,
92
            borcat       => $borcat });
93
        next unless $record;
94
        my $fw               = GetFrameworkCode($biblionumber);
95
96
        my $marcauthorsarray = $biblio->get_marc_authors;
97
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
98
99
        my @items = GetItemsInfo( $biblionumber );
100
101
        $dat->{ISBN}           = GetMarcISBN($record, $marcflavour);
102
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
103
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
104
        $dat->{'biblionumber'} = $biblionumber;
105
        $dat->{ITEM_RESULTS}   = \@items;
106
        $dat->{HASAUTHORS}     = $dat->{'author'} || @$marcauthorsarray;
107
108
        $iso2709 .= $record->as_usmarc();
109
110
        push( @results, $dat );
111
    }
112
113
    $template2->param(
114
        BIBLIO_RESULTS => \@results,
115
        comment        => $comment,
116
        shelfname      => $shelf->shelfname,
117
        firstname      => $patron->firstname,
118
        surname        => $patron->surname,
119
    );
120
121
    # Getting template result
122
    my $template_res = $template2->output();
123
    my $body;
124
125
    my $subject;
126
    # Analysing information and getting mail properties
127
    if ( $template_res =~ /<SUBJECT>(?<subject>.*)<END_SUBJECT>/s ) {
128
        $subject = $+{subject};
129
        $subject =~ s|\n?(.*)\n?|$1|;
130
    }
131
    else {
132
        $subject = "no subject";
133
    }
134
135
    my $email_header = "";
136
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
137
        $email_header = $1;
138
        $email_header =~ s|\n?(.*)\n?|$1|;
139
    }
140
141
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
142
        $body = $1;
143
        $body =~ s|\n?(.*)\n?|$1|;
144
    }
145
86
146
    my $THE_body = <<END_OF_BODY;
87
    if ( !defined $iso2709 ) {
147
$email_header
88
        carp "Error sending mail: empty list";
148
$body
89
        $template->param( error => 1 );
149
END_OF_BODY
90
    } else {
150
91
         my %loops = (
151
    try {
92
             biblio => \@biblionumbers,
152
        my $email = Koha::Email->create(
93
         );
153
            {
94
154
                to      => $email,
95
         my %substitute = (
155
                subject => $subject,
96
             comment => $comment,
156
            }
97
             listname => $shelf->shelfname,
157
        );
98
         );
158
        $email->text_body( $THE_body );
99
159
        $email->attach(
100
        my $letter = C4::Letters::GetPreparedLetter(
160
            Encode::encode( "UTF-8", $iso2709 ),
101
            module => 'catalog',
161
            content_type => 'application/octet-stream',
102
            letter_code => 'LIST',
162
            name         => 'list.iso2709',
103
            lang => $patron->lang,
163
            disposition  => 'attachment',
104
            tables => {
105
                borrowers => $borrowernumber,
106
            },
107
            message_transport_type => 'email',
108
            loops => \%loops,
109
            substitute => \%substitute,
164
        );
110
        );
165
        my $library = Koha::Patrons->find( $borrowernumber )->library;
111
166
        $email->transport( $library->smtp_server->transport );
112
        my $attachment = {
167
        $email->send_or_die;
113
            filename => 'list.iso2709',
168
        $template->param( SENT => "1" );
114
            type => 'application/octet-stream',
115
            content => Encode::encode("UTF-8", $iso2709),
116
        };
117
118
        C4::Letters::EnqueueLetter({
119
            letter => $letter,
120
            message_transport_type => 'email',
121
            borrowernumber => $patron->borrowernumber,
122
            to_address => $email,
123
            reply_address => $patron->first_valid_email_address,
124
            attachments => [$attachment],
125
        });
126
127
        $template->param( SENT => 1 );
169
    }
128
    }
170
    catch {
171
        carp "Error sending mail: $_";
172
        $template->param( error => 1 );
173
    };
174
129
175
    $template->param(
130
    $template->param(
176
        shelfid => $shelfid,
131
        shelfid => $shelfid,
(-)a/virtualshelves/sendshelf.pl (-79 / +43 lines)
Lines 69-162 if ($to_address) { Link Here
69
        }
69
        }
70
    );
70
    );
71
71
72
    my $patron = Koha:::Patrons->find( $borrowernumber );
72
    my $contents = $shelf->get_contents;
73
    my $contents = $shelf->get_contents;
73
    my $marcflavour = C4::Context->preference('marcflavour');
74
    my @biblionumbers;
74
    my $iso2709;
75
    my $iso2709;
75
    my @results;
76
76
77
    while ( my $content = $contents->next ) {
77
    while ( my $content = $contents->next ) {
78
        my $biblionumber     = $content->biblionumber;
78
        push @biblionumbers, $content->biblionumber;
79
        my $biblio           = Koha::Biblios->find( $biblionumber ) or next;
79
        my $biblio = Koha::Biblios->find($content->biblionumber);
80
        my $dat              = $biblio->unblessed;
80
        $iso2709 .= $biblio->metadata->record->as_usmarc();
81
        my $record           = GetMarcBiblio({
81
    };
82
            biblionumber => $biblionumber,
83
            embed_items  => 1 });
84
        my $marcauthorsarray = $biblio->get_marc_authors;
85
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
86
87
        my @items = GetItemsInfo($biblionumber);
88
89
        $dat->{ISBN}           = GetMarcISBN($record, $marcflavour);
90
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
91
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
92
        $dat->{'biblionumber'} = $biblionumber;
93
        $dat->{ITEM_RESULTS}   = \@items;
94
        $dat->{HASAUTHORS}     = $dat->{'author'} || @$marcauthorsarray;
95
96
        $iso2709 .= $record->as_usmarc();
97
98
        push( @results, $dat );
99
    }
100
101
    $template2->param(
102
        BIBLIO_RESULTS => \@results,
103
        comment        => $comment,
104
        shelfname      => $shelf->shelfname,
105
    );
106
107
    # Getting template result
108
    my $template_res = $template2->output();
109
    my $body;
110
111
    my $subject;
112
    # Analysing information and getting mail properties
113
    if ( $template_res =~ /<SUBJECT>(?<subject>.*)<END_SUBJECT>/s ) {
114
        $subject = $+{subject};
115
        $subject =~ s|\n?(.*)\n?|$1|;
116
    }
117
    else {
118
        $subject = "no subject";
119
    }
120
121
    my $email_header = "";
122
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
123
        $email_header = $1;
124
        $email_header =~ s|\n?(.*)\n?|$1|;
125
    }
126
82
127
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
83
    if ( !defined $iso2709 ) {
128
        $body = $1;
84
        carp "Error sending mail: empty basket";
129
        $body =~ s|\n?(.*)\n?|$1|;
85
        $template->param( error => 1 );
130
    }
86
    } else {
87
        my %loops = (
88
            biblio => \@biblionumbers,
89
        );
131
90
132
    my $THE_body = <<END_OF_BODY;
91
        my %substitute = (
133
$email_header
92
            comment => $comment,
134
$body
93
            listname => $shelf->shelfname,
135
END_OF_BODY
136
137
    try {
138
        my $email = Koha::Email->create(
139
            {
140
                to      => $to_address,
141
                subject => $subject,
142
            }
143
        );
94
        );
144
        $email->text_body( $THE_body );
95
145
        $email->attach(
96
        my $letter = C4::Letters::GetPreparedLetter(
146
            Encode::encode("UTF-8", $iso2709),
97
            module => 'catalog',
147
            content_type => 'application/octet-stream',
98
            letter_code => 'LIST',
148
            name         => 'shelf.iso2709',
99
            lang => $patron->lang,
149
            disposition  => 'attachment',
100
            tables => {
101
                borrowers => $borrowernumber,
102
            },
103
            message_transport_type => 'email',
104
            loops => \%loops,
105
            substitute => \%substitute,
150
        );
106
        );
151
107
152
        my $library = Koha::Patrons->find( $borrowernumber )->library;
108
        my $attachment = {
153
        $email->send_or_die({ transport => $library->smtp_server->transport });
109
            filename => 'shelf.iso2709',
154
        $template->param( SENT => "1" );
110
            type => 'application/octet-stream',
111
            content => Encode::encode("UTF-8", $iso2709),
112
        };
113
114
        C4::Letters::EnqueueLetter({
115
            letter => $letter,
116
            message_transport_type => 'email',
117
            borrowernumber => $patron->borrowernumber,
118
            to_address => $to_address,
119
            reply_address => $patron->first_valid_email_address,
120
            attachments => [$attachment],
121
        });
122
123
        $template->param( SENT => 1 );
155
    }
124
    }
156
    catch {
157
        carp "Error sending mail: $_";
158
        $template->param( error => 1 );
159
    };
160
125
161
    $template->param( email => $to_address );
126
    $template->param( email => $to_address );
162
    output_html_with_http_headers $query, $cookie, $template->output;
127
    output_html_with_http_headers $query, $cookie, $template->output;
163
- 

Return to bug 3150