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

(-)a/basket/sendbasket.pl (-92 / +42 lines)
Lines 56-166 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
    my $comment = $query->param('comment');
60
59
61
    # Since we are already logged in, no need to check credentials again
60
    my $patron = Koha:::Patrons->find( $borrowernumber );
62
    # when loading a second template.
61
63
    my $template2 = C4::Templates::gettemplate(
62
    my $comment = $query->param('comment');
64
        'basket/sendbasket.tt', 'intranet', $query,
65
    );
66
63
67
    my @bibs = split( /\//, $bib_list );
64
    my @bibs = split( /\//, $bib_list );
68
    my @results;
69
    my $iso2709;
65
    my $iso2709;
70
    my $marcflavour = C4::Context->preference('marcflavour');
71
    foreach my $biblionumber (@bibs) {
72
        $template2->param( biblionumber => $biblionumber );
73
74
        my $dat              = GetBiblioData($biblionumber);
75
        next unless $dat;
76
        my $biblio           = Koha::Biblios->find( $biblionumber );
77
        my $record           = GetMarcBiblio({
78
            biblionumber => $biblionumber,
79
            embed_items => 1 });
80
        my $marcauthorsarray = $biblio->get_marc_authors;
81
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
82
83
        my @items = GetItemsInfo( $biblionumber );
84
85
        my $hasauthors = 0;
86
        if($dat->{'author'} || @$marcauthorsarray) {
87
          $hasauthors = 1;
88
        }
89
	
90
91
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
92
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
93
        $dat->{HASAUTHORS}     = $hasauthors;
94
        $dat->{'biblionumber'} = $biblionumber;
95
        $dat->{ITEM_RESULTS}   = \@items;
96
97
        $iso2709 .= $record->as_usmarc();
98
99
        push( @results, $dat );
100
    }
101
102
    my $resultsarray = \@results;
103
    $template2->param(
104
        BIBLIO_RESULTS => $resultsarray,
105
        comment        => $comment
106
    );
107
108
    # Getting template result
109
    my $template_res = $template2->output();
110
    my $body;
111
112
    my $subject;
113
    # Analysing information and getting mail properties
114
    if ( $template_res =~ /<SUBJECT>(?<subject>.*)<END_SUBJECT>/s ) {
115
        $subject = $+{subject};
116
        $subject =~ s|\n?(.*)\n?|$1|;
117
    }
118
    else {
119
        $subject = "no subject";
120
    }
121
122
    my $email_header = "";
123
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
124
        $email_header = $1;
125
        $email_header =~ s|\n?(.*)\n?|$1|;
126
    }
127
66
128
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
67
    foreach my $bib ( @bibs ) {
129
        $body = $1;
68
        my $biblio = Koha::Biblios->find($bib);
130
        $body =~ s|\n?(.*)\n?|$1|;
69
        $iso2709 .= $biblio->metadata->record->as_usmarc();
131
    }
70
    }
132
71
133
    my $THE_body = <<END_OF_BODY;
72
    if ( !defined $iso2709 ) {
134
$email_header
73
        carp "Error sending mail: empty basket";
135
$body
74
        $template->param( error => 1 );
136
END_OF_BODY
75
    } else {
137
76
        my %loops = (
138
    try {
77
            biblio => \@bibs,
78
        );
139
79
140
        my $email = Koha::Email->create(
80
        my %substitute = (
141
            {
81
            comment => $comment,
142
                to      => $email_add,
143
                subject => $subject,
144
            }
145
        );
82
        );
146
83
147
        $email->text_body( $THE_body );
84
        my $letter = C4::Letters::GetPreparedLetter(
148
        $email->attach(
85
            module => 'catalog',
149
            Encode::encode( "UTF-8", $iso2709 ),
86
            letter_code => 'CART',
150
            content_type => 'application/octet-stream',
87
            lang => $patron->lang,
151
            name         => 'basket.iso2709',
88
            tables => {
152
            disposition  => 'attachment',
89
                borrowers => $borrowernumber,
90
            },
91
            message_transport_type => 'email',
92
            loops => \%loops,
93
            substitute => \%substitute,
153
        );
94
        );
154
95
155
        my $library = Koha::Patrons->find( $borrowernumber )->library;
96
        my $attachment = {
156
        $email->send_or_die({ transport => $library->smtp_server->transport });
97
            filename => 'basket.iso2709',
157
        $template->param( SENT => "1" );
98
            type => 'application/octet-stream',
158
    }
99
            content => Encode::encode("UTF-8", $iso2709),
159
    catch {
100
        };
160
        carp "Error sending mail: $_";
101
161
        $template->param( error => 1 );
102
        my $user_email = $patron->first_valid_email_address || C4::Context->preference('KohaAdminEmailAddress');
162
    };
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
        });
163
111
112
        $template->param( SENT => 1 );
113
    }
164
    $template->param( email_add => $email_add );
114
    $template->param( email_add => $email_add );
165
    output_html_with_http_headers $query, $cookie, $template->output;
115
    output_html_with_http_headers $query, $cookie, $template->output;
166
}
116
}
(-)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 1571-1573 tables: Link Here
1571
            - "This item must be renewed at the library."
1571
            - "This item must be renewed at the library."
1572
            - "[% END %]"
1572
            - "[% END %]"
1573
            - "[% END %]"
1573
            - "[% END %]"
1574
1575
        - module: catalog
1576
          code: LIST
1577
          branchcode: ""
1578
          name: "Send list"
1579
          is_html: 1
1580
          title: "Your list: [% listname | html %]"
1581
          message_transport_type: email
1582
          lang: default
1583
          content:
1584
            - "[%- USE raw -%]"
1585
            - "<p>Hi,</p>"
1586
            - "<p>[% borrower.firstname | $raw %] [% borrower.surname | $raw %] sent you a list from our online catalog called: [% listname | $raw %].</p>"
1587
            - "<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>"
1588
            - "<hr/>"
1589
            - "<p>[% comment | $raw %]</p>"
1590
            - "<hr/>"
1591
            - "<ol>"
1592
            - "[% FOREACH biblio IN biblios %]"
1593
            - "<li>"
1594
            - "<span>"
1595
            - "[% biblio.title | $raw %]"
1596
            - "[% IF ( biblio.subtitle ) %]"
1597
            - "[% FOREACH subtitle IN biblio.subtitle.split(' | ') %]"
1598
            - "[% subtitle | $raw %]"
1599
            - "[% END %]"
1600
            - "[% END %]"
1601
            - "[% biblio.part_number | $raw %] [% biblio.part_name | $raw %]"
1602
            - "</span>"
1603
            - "<p>"
1604
            - "[% IF ( biblio.author || biblio.get_authors_from_MARC ) %]"
1605
            - "<span>Author(s): [% IF ( biblio.author ) %][% biblio.author | $raw %][% END %]"
1606
            - "[% IF ( biblio.get_authors_from_MARC ) %]"
1607
            - "[% IF ( biblio.author ) %]; [% END %]"
1608
            - "[% FOREACH author IN biblio.get_authors_from_MARC %]"
1609
            - "[% FOREACH subfield IN author.MARCAUTHOR_SUBFIELDS_LOOP %]"
1610
            - "[% subfield.separator | $raw %][% subfield.value | $raw %]"
1611
            - "[% END %]"
1612
            - "[% UNLESS ( loop.last ) %];[% END %]"
1613
            - "[% END %]"
1614
            - "[% END %]"
1615
            - "</span><br/>"
1616
            - "[% END %]"
1617
            - "[% SET biblioitem = biblio.biblioitem %]"
1618
            - "[% IF ( biblioitem.isbn ) %]"
1619
            - "<span>"
1620
            - "ISBN: [% FOREACH isbn IN biblioitem.isbn %]"
1621
            - "[% isbn | $raw %]"
1622
            - "[% UNLESS ( loop.last ) %]; [% END %]"
1623
            - "[% END %]"
1624
            - "</span><br/>"
1625
            - "[% END %]"
1626
            - "[% IF ( biblioitem.publishercode ) %]"
1627
            - "<span>"
1628
            - "Published by: [% biblioitem.publishercode | $raw %]"
1629
            - "[% IF ( biblioitem.publicationyear ) %]"
1630
            - "in [% biblioitem.publicationyear | $raw %]"
1631
            - "[% END %]"
1632
            - "[% IF ( biblioitem.pages ) %]"
1633
            - ", [% biblioitem.pages | $raw %]"
1634
            - "[% END %]"
1635
            - "</span><br/>"
1636
            - "[% END %]"
1637
            - "[% IF ( biblio.seriestitle ) %]"
1638
            - "<span>"
1639
            - "Collection: [% biblio.seriestitle | $raw %]"
1640
            - "</span><br/>"
1641
            - "[% END %]"
1642
            - "[% IF ( biblio.copyrightdate ) %]"
1643
            - "<span>"
1644
            - "Copyright year: [% biblio.copyrightdate | $raw %]"
1645
            - "</span><br/>"
1646
            - "[% END %]"
1647
            - "[% IF ( biblio.notes ) %]"
1648
            - "<span>"
1649
            - "Notes: [% biblio.notes | $raw %]"
1650
            - "</span><br/>"
1651
            - "[% END %]"
1652
            - "[% IF ( biblio.unititle ) %]"
1653
            - "<span>"
1654
            - "Unified title: [% biblio.unititle | $raw %]"
1655
            - "</span><br/>"
1656
            - "[% END %]"
1657
            - "[% IF ( biblio.serial ) %]"
1658
            - "<span>"
1659
            - "Serial: [% biblio.serial | $raw %]"
1660
            - "</span><br/>"
1661
            - "[% END %]"
1662
            - "[% IF ( biblioitem.lccn ) %]"
1663
            - "<span>"
1664
            - "LCCN: [% biblioitem.lccn | $raw %]"
1665
            - "</span><br/>"
1666
            - "[% END %]"
1667
            - "[% IF ( biblioitem.url ) %]"
1668
            - "<span>"
1669
            - "URL: [% biblioitem.url | html %]"
1670
            - "</span>"
1671
            - "[% END %]"
1672
            - "</p>"
1673
            - "[% SET OPACBaseURL = Koha.Preference('OPACBaseURL') %]"
1674
            - "[% IF ( OPACBaseURL ) %]"
1675
            - "<p>In online catalog: [% OPACBaseURL | $raw %]/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblio.biblionumber | html %]</p>"
1676
            - "[% END %]"
1677
            - "[% IF ( biblio.items.count > 0 ) %]"
1678
            - "<p>Items:"
1679
            - "<ul>"
1680
            - "[% FOREACH item IN biblio.items %]<li>"
1681
            - "[% item.holding_branch.branchname | $raw %]"
1682
            - "[% item.location | $raw %]"
1683
            - "[% IF item.itemcallnumber %]([% item.itemcallnumber | $raw %])[% END %]"
1684
            - "[% item.barcode | $raw %]"
1685
            - "</li>[% END %]"
1686
            - "</ul>"
1687
            - "</p>"
1688
            - "[% END %]"
1689
            - "<hr/>"
1690
            - "</li>"
1691
            - "[% END %]"
1692
            - "</ol>"
1693
1694
        - module: catalog
1695
          code: CART
1696
          branchcode: ""
1697
          name: "Send cart"
1698
          is_html: 1
1699
          title: "Your cart"
1700
          message_transport_type: email
1701
          lang: default
1702
          content:
1703
            - "[%- USE raw -%]"
1704
            - "<p>Hi,</p>"
1705
            - "<p>[% borrower.firstname | $raw %] [% borrower.surname | $raw %] sent you a cart from our online catalog.</p>"
1706
            - "<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>"
1707
            - "<hr/>"
1708
            - "<p>[% comment | $raw %]</p>"
1709
            - "<hr/>"
1710
            - "<ol>"
1711
            - "[% FOREACH biblio IN biblios %]"
1712
            - "<li>"
1713
            - "<span>"
1714
            - "[% biblio.title | $raw %]"
1715
            - "[% IF ( biblio.subtitle ) %]"
1716
            - "[% FOREACH subtitle IN biblio.subtitle.split(' | ') %]"
1717
            - "[% subtitle | $raw %]"
1718
            - "[% END %]"
1719
            - "[% END %]"
1720
            - "[% biblio.part_number | $raw %] [% biblio.part_name | $raw %]"
1721
            - "</span>"
1722
            - "<p>"
1723
            - "[% IF ( biblio.author || biblio.get_authors_from_MARC ) %]"
1724
            - "<span>Author(s): [% IF ( biblio.author ) %][% biblio.author | $raw %][% END %]"
1725
            - "[% IF ( biblio.get_authors_from_MARC ) %]"
1726
            - "[% IF ( biblio.author ) %]; [% END %]"
1727
            - "[% FOREACH author IN biblio.get_authors_from_MARC %]"
1728
            - "[% FOREACH subfield IN author.MARCAUTHOR_SUBFIELDS_LOOP %]"
1729
            - "[% subfield.separator | $raw %][% subfield.value | $raw %]"
1730
            - "[% END %]"
1731
            - "[% UNLESS ( loop.last ) %];[% END %]"
1732
            - "[% END %]"
1733
            - "[% END %]"
1734
            - "</span><br/>"
1735
            - "[% END %]"
1736
            - "[% SET biblioitem = biblio.biblioitem %]"
1737
            - "[% IF ( biblioitem.isbn ) %]"
1738
            - "<span>"
1739
            - "ISBN: [% FOREACH isbn IN biblioitem.isbn %]"
1740
            - "[% isbn | $raw %]"
1741
            - "[% UNLESS ( loop.last ) %]; [% END %]"
1742
            - "[% END %]"
1743
            - "</span><br/>"
1744
            - "[% END %]"
1745
            - "[% IF ( biblioitem.publishercode ) %]"
1746
            - "<span>"
1747
            - "Published by: [% biblioitem.publishercode | $raw %]"
1748
            - "[% IF ( biblioitem.publicationyear ) %]"
1749
            - "in [% biblioitem.publicationyear | $raw %]"
1750
            - "[% END %]"
1751
            - "[% IF ( biblioitem.pages ) %]"
1752
            - ", [% biblioitem.pages | $raw %]"
1753
            - "[% END %]"
1754
            - "</span><br/>"
1755
            - "[% END %]"
1756
            - "[% IF ( biblio.seriestitle ) %]"
1757
            - "<span>"
1758
            - "Collection: [% biblio.seriestitle | $raw %]"
1759
            - "</span><br/>"
1760
            - "[% END %]"
1761
            - "[% IF ( biblio.copyrightdate ) %]"
1762
            - "<span>"
1763
            - "Copyright year: [% biblio.copyrightdate | $raw %]"
1764
            - "</span><br/>"
1765
            - "[% END %]"
1766
            - "[% IF ( biblio.notes ) %]"
1767
            - "<span>"
1768
            - "Notes: [% biblio.notes | $raw %]"
1769
            - "</span><br/>"
1770
            - "[% END %]"
1771
            - "[% IF ( biblio.unititle ) %]"
1772
            - "<span>"
1773
            - "Unified title: [% biblio.unititle | $raw %]"
1774
            - "</span><br/>"
1775
            - "[% END %]"
1776
            - "[% IF ( biblio.serial ) %]"
1777
            - "<span>"
1778
            - "Serial: [% biblio.serial | $raw %]"
1779
            - "</span><br/>"
1780
            - "[% END %]"
1781
            - "[% IF ( biblioitem.lccn ) %]"
1782
            - "<span>"
1783
            - "LCCN: [% biblioitem.lccn | $raw %]"
1784
            - "</span><br/>"
1785
            - "[% END %]"
1786
            - "[% IF ( biblioitem.url ) %]"
1787
            - "<span>"
1788
            - "URL: [% biblioitem.url | html %]"
1789
            - "</span>"
1790
            - "[% END %]"
1791
            - "</p>"
1792
            - "[% SET OPACBaseURL = Koha.Preference('OPACBaseURL') %]"
1793
            - "[% IF ( OPACBaseURL ) %]"
1794
            - "<p>In online catalog: [% OPACBaseURL | $raw %]/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblio.biblionumber | html %]</p>"
1795
            - "[% END %]"
1796
            - "[% IF ( biblio.items.count > 0 ) %]"
1797
            - "<p>Items:"
1798
            - "<ul>"
1799
            - "[% FOREACH item IN biblio.items %]<li>"
1800
            - "[% item.holding_branch.branchname | $raw %]"
1801
            - "[% item.location | $raw %]"
1802
            - "[% IF item.itemcallnumber %]([% item.itemcallnumber | $raw %])[% END %]"
1803
            - "[% item.barcode | $raw %]"
1804
            - "</li>[% END %]"
1805
            - "</ul>"
1806
            - "</p>"
1807
            - "[% END %]"
1808
            - "<hr/>"
1809
            - "</li>"
1810
            - "[% END %]"
1811
            - "</ol>"
(-)a/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql (+219 lines)
Lines 475-477 INSERT IGNORE INTO letter (module, code, name, title, content, message_transport Link Here
475
    [% END %]
475
    [% END %]
476
[% END %]
476
[% END %]
477
", 'email');
477
", 'email');
478
479
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 -%]
480
<p>Hi,</p>
481
<p>[% borrower.firstname | $raw %] [% borrower.surname | $raw %] sent you a list from our online catalog called: [% listname | $raw %].</p>
482
<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>
483
<hr/>
484
<p>[% comment | $raw %]</p>
485
<hr/>
486
<ol>
487
[% FOREACH biblio IN biblios %]
488
    <li>
489
        <span>
490
            [% biblio.title | $raw %]
491
            [% IF ( biblio.subtitle ) %]
492
                [% FOREACH subtitle IN biblio.subtitle.split(' | ') %]
493
                    [% subtitle | $raw %]
494
                [% END %]
495
            [% END %]
496
            [% biblio.part_number | $raw %] [% biblio.part_name | $raw %]
497
        </span>
498
        <p>
499
            [% IF ( biblio.author || biblio.get_authors_from_MARC ) %]
500
                <span>Author(s): [% IF ( biblio.author ) %][% biblio.author | $raw %][% END %]
501
                [% IF ( biblio.get_authors_from_MARC ) %]
502
                    [% IF ( biblio.author ) %]; [% END %]
503
                    [% FOREACH author IN biblio.get_authors_from_MARC %]
504
                        [% FOREACH subfield IN author.MARCAUTHOR_SUBFIELDS_LOOP %]
505
                            [% subfield.separator | $raw %][% subfield.value | $raw %]
506
                        [% END %]
507
                        [% UNLESS ( loop.last ) %];[% END %]
508
                    [% END %]
509
                [% END %]
510
                </span><br/>
511
            [% END %]
512
            [% SET biblioitem = biblio.biblioitem %]
513
            [% IF ( biblioitem.isbn ) %]
514
                <span>
515
                    ISBN: [% FOREACH isbn IN biblioitem.isbn %]
516
                        [% isbn | $raw %]
517
                        [% UNLESS ( loop.last ) %]; [% END %]
518
                    [% END %]
519
                </span><br/>
520
            [% END %]
521
            [% IF ( biblioitem.publishercode ) %]
522
                <span>
523
                    Published by: [% biblioitem.publishercode | $raw %]
524
                    [% IF ( biblioitem.publicationyear ) %]
525
                        in [% biblioitem.publicationyear | $raw %]
526
                    [% END %]
527
                    [% IF ( biblioitem.pages ) %]
528
                        , [% biblioitem.pages | $raw %]
529
                    [% END %]
530
                </span><br/>
531
            [% END %]
532
            [% IF ( biblio.seriestitle ) %]
533
                <span>
534
                    Collection: [% biblio.seriestitle | $raw %]
535
                </span><br/>
536
            [% END %]
537
            [% IF ( biblio.copyrightdate ) %]
538
                <span>
539
                    Copyright year: [% biblio.copyrightdate | $raw %]
540
                </span><br/>
541
            [% END %]
542
            [% IF ( biblio.notes ) %]
543
                <span>
544
                    Notes: [% biblio.notes | $raw %]
545
                </span><br/>
546
            [% END %]
547
            [% IF ( biblio.unititle ) %]
548
                <span>
549
                    Unified title: [% biblio.unititle | $raw %]
550
                </span><br/>
551
            [% END %]
552
            [% IF ( biblio.serial ) %]
553
                <span>
554
                    Serial: [% biblio.serial | $raw %]
555
                </span><br/>
556
            [% END %]
557
            [% IF ( biblioitem.lccn ) %]
558
                <span>
559
                    LCCN: [% biblioitem.lccn | $raw %]
560
                </span><br/>
561
            [% END %]
562
            [% IF ( biblioitem.url ) %]
563
                <span>
564
                    URL: [% biblioitem.url | html %]
565
                </span>
566
            [% END %]
567
        </p>
568
        [% SET OPACBaseURL = Koha.Preference('OPACBaseURL') %]
569
        [% IF ( OPACBaseURL ) %]
570
            <p>In online catalog: [% OPACBaseURL | $raw %]/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblio.biblionumber | html %]</p>
571
        [% END %]
572
        [% IF ( biblio.items.count > 0 ) %]
573
            <p>Items:
574
                <ul>
575
                    [% FOREACH item IN biblio.items %]<li>
576
                        [% item.holding_branch.branchname | $raw %]
577
                        [% item.location | $raw %]
578
                        [% IF item.itemcallnumber %]([% item.itemcallnumber | $raw %])[% END %]
579
                        [% item.barcode | $raw %]
580
                    </li>[% END %]
581
                </ul>
582
            </p>
583
        [% END %]
584
        <hr/>
585
    </li>
586
[% END %]
587
</ol>", 'email','default' ),
588
('catalog','CART','','Send cart',1,'Your cart',"[%- USE raw -%]
589
<p>Hi,</p>
590
<p>[% borrower.firstname | $raw %] [% borrower.surname | $raw %] sent you a cart from our online catalog.</p>
591
<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>
592
<hr/>
593
<p>[% comment | $raw %]</p>
594
<hr/>
595
<ol>
596
[% FOREACH biblio IN biblios %]
597
    <li>
598
        <span>
599
            [% biblio.title | $raw %]
600
            [% IF ( biblio.subtitle ) %]
601
                [% FOREACH subtitle IN biblio.subtitle.split(' | ') %]
602
                    [% subtitle | $raw %]
603
                [% END %]
604
            [% END %]
605
            [% biblio.part_number | $raw %] [% biblio.part_name | $raw %]
606
        </span>
607
        <p>
608
            [% IF ( biblio.author || biblio.get_authors_from_MARC ) %]
609
                <span>Author(s): [% IF ( biblio.author ) %][% biblio.author | $raw %][% END %]
610
                [% IF ( biblio.get_authors_from_MARC ) %]
611
                    [% IF ( biblio.author ) %]; [% END %]
612
                    [% FOREACH author IN biblio.get_authors_from_MARC %]
613
                        [% FOREACH subfield IN author.MARCAUTHOR_SUBFIELDS_LOOP %]
614
                            [% subfield.separator | $raw %][% subfield.value | $raw %]
615
                        [% END %]
616
                        [% UNLESS ( loop.last ) %];[% END %]
617
                    [% END %]
618
                [% END %]
619
                </span><br/>
620
            [% END %]
621
            [% SET biblioitem = biblio.biblioitem %]
622
            [% IF ( biblioitem.isbn ) %]
623
                <span>
624
                    ISBN: [% FOREACH isbn IN biblioitem.isbn %]
625
                        [% isbn | $raw %]
626
                        [% UNLESS ( loop.last ) %]; [% END %]
627
                    [% END %]
628
                </span><br/>
629
            [% END %]
630
            [% IF ( biblioitem.publishercode ) %]
631
                <span>
632
                    Published by: [% biblioitem.publishercode | $raw %]
633
                    [% IF ( biblioitem.publicationyear ) %]
634
                        in [% biblioitem.publicationyear | $raw %]
635
                    [% END %]
636
                    [% IF ( biblioitem.pages ) %]
637
                        , [% biblioitem.pages | $raw %]
638
                    [% END %]
639
                </span><br/>
640
            [% END %]
641
            [% IF ( biblio.seriestitle ) %]
642
                <span>
643
                    Collection: [% biblio.seriestitle | $raw %]
644
                </span><br/>
645
            [% END %]
646
            [% IF ( biblio.copyrightdate ) %]
647
                <span>
648
                    Copyright year: [% biblio.copyrightdate | $raw %]
649
                </span><br/>
650
            [% END %]
651
            [% IF ( biblio.notes ) %]
652
                <span>
653
                    Notes: [% biblio.notes | $raw %]
654
                </span><br/>
655
            [% END %]
656
            [% IF ( biblio.unititle ) %]
657
                <span>
658
                    Unified title: [% biblio.unititle | $raw %]
659
                </span><br/>
660
            [% END %]
661
            [% IF ( biblio.serial ) %]
662
                <span>
663
                    Serial: [% biblio.serial | $raw %]
664
                </span><br/>
665
            [% END %]
666
            [% IF ( biblioitem.lccn ) %]
667
                <span>
668
                    LCCN: [% biblioitem.lccn | $raw %]
669
                </span><br/>
670
            [% END %]
671
            [% IF ( biblioitem.url ) %]
672
                <span>
673
                    URL: [% biblioitem.url | html %]
674
                </span>
675
            [% END %]
676
        </p>
677
        [% SET OPACBaseURL = Koha.Preference('OPACBaseURL') %]
678
        [% IF ( OPACBaseURL ) %]
679
            <p>In online catalog: [% OPACBaseURL | $raw %]/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblio.biblionumber | html %]</p>
680
        [% END %]
681
        [% IF ( biblio.items.count > 0 ) %]
682
            <p>Items:
683
                <ul>
684
                    [% FOREACH item IN biblio.items %]<li>
685
                        [% item.holding_branch.branchname | $raw %]
686
                        [% item.location | $raw %]
687
                        [% IF item.itemcallnumber %]([% item.itemcallnumber | $raw %])[% END %]
688
                        [% item.barcode | $raw %]
689
                    </li>[% END %]
690
                </ul>
691
            </p>
692
        [% END %]
693
        <hr/>
694
    </li>
695
[% END %]
696
</ol>",'email','default');
(-)a/opac/opac-sendbasket.pl (-108 / +42 lines)
Lines 57-182 if ( $email_add ) { Link Here
57
        session_id => scalar $query->cookie('CGISESSID'),
57
        session_id => scalar $query->cookie('CGISESSID'),
58
        token  => scalar $query->param('csrf_token'),
58
        token  => scalar $query->param('csrf_token'),
59
    });
59
    });
60
60
    my $patron = Koha::Patrons->find( $borrowernumber );
61
    my $patron = Koha::Patrons->find( $borrowernumber );
61
    my $borcat = $patron ? $patron->categorycode : q{};
62
    my $user_email = $patron->first_valid_email_address
63
    || C4::Context->preference('KohaAdminEmailAddress');
64
62
65
    my $email_replyto = $patron->firstname . " " . $patron->surname . " <$user_email>";
66
    my $comment    = $query->param('comment');
63
    my $comment    = $query->param('comment');
67
64
68
    # Since we are already logged in, no need to check credentials again
69
    # when loading a second template.
70
    my $template2 = C4::Templates::gettemplate(
71
        'opac-sendbasket.tt', 'opac', $query,
72
    );
73
74
    my @bibs = split( /\//, $bib_list );
65
    my @bibs = split( /\//, $bib_list );
75
    my @results;
76
    my $iso2709;
66
    my $iso2709;
77
    my $marcflavour = C4::Context->preference('marcflavour');
78
    foreach my $biblionumber (@bibs) {
79
        $template2->param( biblionumber => $biblionumber );
80
81
        my $dat              = GetBiblioData($biblionumber);
82
        next unless $dat;
83
        my $biblio           = Koha::Biblios->find( $biblionumber );
84
        my $record           = GetMarcBiblio({
85
            biblionumber => $biblionumber,
86
            embed_items  => 1,
87
            opac         => 1,
88
            borcat       => $borcat });
89
        my $marcauthorsarray = $biblio->get_marc_authors;
90
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
91
92
        my @items = GetItemsInfo( $biblionumber );
93
94
        my $hasauthors = 0;
95
        if($dat->{'author'} || @$marcauthorsarray) {
96
          $hasauthors = 1;
97
        }
98
	
99
100
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
101
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
102
        $dat->{HASAUTHORS}     = $hasauthors;
103
        $dat->{'biblionumber'} = $biblionumber;
104
        $dat->{ITEM_RESULTS}   = \@items;
105
106
        $iso2709 .= $record->as_usmarc();
107
108
        push( @results, $dat );
109
    }
110
67
111
    my $resultsarray = \@results;
68
    foreach my $bib ( @bibs ) {
112
    
69
        my $biblio = Koha::Biblios->find($bib);
113
    $template2->param(
70
        $iso2709 .= $biblio->metadata->record->as_usmarc();
114
        BIBLIO_RESULTS => $resultsarray,
71
    };
115
        comment        => $comment,
116
        firstname      => $patron->firstname,
117
        surname        => $patron->surname,
118
    );
119
120
    # Getting template result
121
    my $template_res = $template2->output();
122
    my $body;
123
124
    # Analysing information and getting mail properties
125
    my $subject;
126
    if ( $template_res =~ /\<SUBJECT\>(?<subject>.*)\<END_SUBJECT\>/s ) {
127
        $subject = $+{subject};
128
        $subject =~ s|\n?(.*)\n?|$1|;
129
    }
130
    else {
131
        $subject = "no subject";
132
    }
133
134
    my $email_header = "";
135
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
136
        $email_header = $1;
137
        $email_header =~ s|\n?(.*)\n?|$1|;
138
    }
139
140
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
141
        $body = $1;
142
        $body =~ s|\n?(.*)\n?|$1|;
143
    }
144
145
    my $THE_body = <<END_OF_BODY;
146
$email_header
147
$body
148
END_OF_BODY
149
72
150
    if ( !defined $iso2709 ) {
73
    if ( !defined $iso2709 ) {
151
        carp "Error sending mail: empty basket";
74
        carp "Error sending mail: empty basket";
152
        $template->param( error => 1 );
75
        $template->param( error => 1 );
153
    }
76
    } else {
154
    else {
77
        my %loops = (
155
        try {
78
            biblio => \@bibs,
156
            # if you want to use the KohaAdmin address as from, that is the default no need to set it
79
        );
157
            my $email = Koha::Email->create({
80
158
                to       => $email_add,
81
        my %substitute = (
159
                reply_to => $email_replyto,
82
            comment => $comment,
160
                subject  => $subject,
83
        );
161
            });
84
162
            $email->header( 'X-Abuse-Report' => C4::Context->preference('KohaAdminEmailAddress') );
85
        my $letter = C4::Letters::GetPreparedLetter(
163
            $email->text_body( $THE_body );
86
            module => 'catalog',
164
            $email->attach(
87
            letter_code => 'CART',
165
                Encode::encode( "UTF-8", $iso2709 ),
88
            lang => $patron->lang,
166
                content_type => 'application/octet-stream',
89
            tables => {
167
                name         => 'basket.iso2709',
90
                borrowers => $borrowernumber,
168
                disposition  => 'attachment',
91
            },
169
            );
92
            message_transport_type => 'email',
170
            my $library = $patron->library;
93
            loops => \%loops,
171
            $email->transport( $library->smtp_server->transport );
94
            substitute => \%substitute,
172
            $email->send_or_die;
95
        );
173
            $template->param( SENT => "1" );
96
174
        }
97
        my $attachment = {
175
        catch {
98
            filename => 'basket.iso2709',
176
            carp "Error sending mail: $_";
99
            type => 'application/octet-stream',
177
            $template->param( error => 1 );
100
            content => Encode::encode("UTF-8", $iso2709),
178
        };
101
        };
179
    }
102
103
        my $user_email = $patron->first_valid_email_address || C4::Context->preference('KohaAdminEmailAddress');
104
        C4::Letters::EnqueueLetter({
105
            letter => $letter,
106
            message_transport_type => 'email',
107
            borrowernumber => $patron->borrowernumber,
108
            to_address => $email_add,
109
            reply_address => $user_email,
110
            attachments => [$attachment],
111
        });
112
113
        $template->param( SENT => 1 );
180
114
181
    $template->param( email_add => $email_add );
115
    $template->param( email_add => $email_add );
182
    output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
116
    output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
(-)a/opac/opac-sendshelf.pl (-89 / +44 lines)
Lines 75-178 if ( $email ) { Link Here
75
    );
75
    );
76
76
77
    my $patron = Koha::Patrons->find( $borrowernumber );
77
    my $patron = Koha::Patrons->find( $borrowernumber );
78
    my $borcat = $patron ? $patron->categorycode : q{};
79
78
80
    my $shelf = Koha::Virtualshelves->find( $shelfid );
79
    my $shelf = Koha::Virtualshelves->find( $shelfid );
81
    my $contents = $shelf->get_contents;
80
    my $contents = $shelf->get_contents;
82
    my $marcflavour         = C4::Context->preference('marcflavour');
83
    my $iso2709;
81
    my $iso2709;
84
    my @results;
85
82
86
    while ( my $content = $contents->next ) {
83
    while ( my $content = $contents->next ) {
87
        my $biblionumber = $content->biblionumber;
84
        push @biblionumbers, $content->biblionumber;
88
        my $record           = GetMarcBiblio({
85
        my $biblio = Koha::Biblios->find($content->biblionumber);
89
            biblionumber => $biblionumber,
86
        $iso2709 .= $biblio->metadata->record->as_usmarc();
90
            embed_items  => 1,
87
    };
91
            opac         => 1,
92
            borcat       => $borcat });
93
        next unless $record;
94
        my $biblio           = Koha::Biblios->find( $biblionumber );
95
        my $fw               = GetFrameworkCode($biblionumber);
96
        my $dat              = GetBiblioData($biblionumber);
97
98
        my $marcauthorsarray = $biblio->get_marc_authors;
99
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
100
101
        my @items = GetItemsInfo( $biblionumber );
102
103
        $dat->{ISBN}           = GetMarcISBN($record, $marcflavour);
104
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
105
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
106
        $dat->{'biblionumber'} = $biblionumber;
107
        $dat->{ITEM_RESULTS}   = \@items;
108
        $dat->{HASAUTHORS}     = $dat->{'author'} || @$marcauthorsarray;
109
110
        $iso2709 .= $record->as_usmarc();
111
112
        push( @results, $dat );
113
    }
114
115
    $template2->param(
116
        BIBLIO_RESULTS => \@results,
117
        comment        => $comment,
118
        shelfname      => $shelf->shelfname,
119
        firstname      => $patron->firstname,
120
        surname        => $patron->surname,
121
    );
122
123
    # Getting template result
124
    my $template_res = $template2->output();
125
    my $body;
126
127
    my $subject;
128
    # Analysing information and getting mail properties
129
    if ( $template_res =~ /<SUBJECT>(?<subject>.*)<END_SUBJECT>/s ) {
130
        $subject = $+{subject};
131
        $subject =~ s|\n?(.*)\n?|$1|;
132
    }
133
    else {
134
        $subject = "no subject";
135
    }
136
137
    my $email_header = "";
138
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
139
        $email_header = $1;
140
        $email_header =~ s|\n?(.*)\n?|$1|;
141
    }
142
143
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
144
        $body = $1;
145
        $body =~ s|\n?(.*)\n?|$1|;
146
    }
147
88
148
    my $THE_body = <<END_OF_BODY;
89
    if ( !defined $iso2709 ) {
149
$email_header
90
        carp "Error sending mail: empty list";
150
$body
91
        $template->param( error => 1 );
151
END_OF_BODY
92
    } else {
152
93
         my %loops = (
153
    try {
94
             biblio => \@biblionumbers,
154
        my $email = Koha::Email->create(
95
         );
155
            {
96
156
                to      => $email,
97
         my %substitute = (
157
                subject => $subject,
98
             comment => $comment,
158
            }
99
             listname => $shelf->shelfname,
159
        );
100
         );
160
        $email->text_body( $THE_body );
101
161
        $email->attach(
102
        my $letter = C4::Letters::GetPreparedLetter(
162
            Encode::encode( "UTF-8", $iso2709 ),
103
            module => 'catalog',
163
            content_type => 'application/octet-stream',
104
            letter_code => 'LIST',
164
            name         => 'list.iso2709',
105
            lang => $patron->lang,
165
            disposition  => 'attachment',
106
            tables => {
107
                borrowers => $borrowernumber,
108
            },
109
            message_transport_type => 'email',
110
            loops => \%loops,
111
            substitute => \%substitute,
166
        );
112
        );
167
        my $library = Koha::Patrons->find( $borrowernumber )->library;
113
168
        $email->transport( $library->smtp_server->transport );
114
        my $attachment = {
169
        $email->send_or_die;
115
            filename => 'list.iso2709',
170
        $template->param( SENT => "1" );
116
            type => 'application/octet-stream',
117
            content => Encode::encode("UTF-8", $iso2709),
118
        };
119
120
        C4::Letters::EnqueueLetter({
121
            letter => $letter,
122
            message_transport_type => 'email',
123
            borrowernumber => $patron->borrowernumber,
124
            to_address => $email,
125
            reply_address => $patron->first_valid_email_address,
126
            attachments => [$attachment],
127
        });
128
129
        $template->param( SENT => 1 );
171
    }
130
    }
172
    catch {
173
        carp "Error sending mail: $_";
174
        $template->param( error => 1 );
175
    };
176
131
177
    $template->param(
132
    $template->param(
178
        shelfid => $shelfid,
133
        shelfid => $shelfid,
(-)a/virtualshelves/sendshelf.pl (-79 / +43 lines)
Lines 64-158 if ($to_address) { Link Here
64
        }
64
        }
65
    );
65
    );
66
66
67
    my $patron = Koha:::Patrons->find( $borrowernumber );
67
    my $shelf = Koha::Virtualshelves->find( $shelfid );
68
    my $shelf = Koha::Virtualshelves->find( $shelfid );
68
    my $contents = $shelf->get_contents;
69
    my $contents = $shelf->get_contents;
69
    my $marcflavour = C4::Context->preference('marcflavour');
70
    my @biblionumbers;
70
    my $iso2709;
71
    my $iso2709;
71
    my @results;
72
72
73
    while ( my $content = $contents->next ) {
73
    while ( my $content = $contents->next ) {
74
        my $biblionumber     = $content->biblionumber;
74
        push @biblionumbers, $content->biblionumber;
75
        my $biblio           = Koha::Biblios->find( $biblionumber );
75
        my $biblio = Koha::Biblios->find($content->biblionumber);
76
        my $dat              = GetBiblioData($biblionumber);
76
        $iso2709 .= $biblio->metadata->record->as_usmarc();
77
        my $record           = GetMarcBiblio({
77
    };
78
            biblionumber => $biblionumber,
79
            embed_items  => 1 });
80
        my $marcauthorsarray = $biblio->get_marc_authors;
81
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
82
83
        my @items = GetItemsInfo($biblionumber);
84
85
        $dat->{ISBN}           = GetMarcISBN($record, $marcflavour);
86
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
87
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
88
        $dat->{'biblionumber'} = $biblionumber;
89
        $dat->{ITEM_RESULTS}   = \@items;
90
        $dat->{HASAUTHORS}     = $dat->{'author'} || @$marcauthorsarray;
91
92
        $iso2709 .= $record->as_usmarc();
93
94
        push( @results, $dat );
95
    }
96
97
    $template2->param(
98
        BIBLIO_RESULTS => \@results,
99
        comment        => $comment,
100
        shelfname      => $shelf->shelfname,
101
    );
102
103
    # Getting template result
104
    my $template_res = $template2->output();
105
    my $body;
106
107
    my $subject;
108
    # Analysing information and getting mail properties
109
    if ( $template_res =~ /<SUBJECT>(?<subject>.*)<END_SUBJECT>/s ) {
110
        $subject = $+{subject};
111
        $subject =~ s|\n?(.*)\n?|$1|;
112
    }
113
    else {
114
        $subject = "no subject";
115
    }
116
117
    my $email_header = "";
118
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
119
        $email_header = $1;
120
        $email_header =~ s|\n?(.*)\n?|$1|;
121
    }
122
78
123
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
79
    if ( !defined $iso2709 ) {
124
        $body = $1;
80
        carp "Error sending mail: empty basket";
125
        $body =~ s|\n?(.*)\n?|$1|;
81
        $template->param( error => 1 );
126
    }
82
    } else {
83
        my %loops = (
84
            biblio => \@biblionumbers,
85
        );
127
86
128
    my $THE_body = <<END_OF_BODY;
87
        my %substitute = (
129
$email_header
88
            comment => $comment,
130
$body
89
            listname => $shelf->shelfname,
131
END_OF_BODY
132
133
    try {
134
        my $email = Koha::Email->create(
135
            {
136
                to      => $to_address,
137
                subject => $subject,
138
            }
139
        );
90
        );
140
        $email->text_body( $THE_body );
91
141
        $email->attach(
92
        my $letter = C4::Letters::GetPreparedLetter(
142
            Encode::encode("UTF-8", $iso2709),
93
            module => 'catalog',
143
            content_type => 'application/octet-stream',
94
            letter_code => 'LIST',
144
            name         => 'shelf.iso2709',
95
            lang => $patron->lang,
145
            disposition  => 'attachment',
96
            tables => {
97
                borrowers => $borrowernumber,
98
            },
99
            message_transport_type => 'email',
100
            loops => \%loops,
101
            substitute => \%substitute,
146
        );
102
        );
147
103
148
        my $library = Koha::Patrons->find( $borrowernumber )->library;
104
        my $attachment = {
149
        $email->send_or_die({ transport => $library->smtp_server->transport });
105
            filename => 'shelf.iso2709',
150
        $template->param( SENT => "1" );
106
            type => 'application/octet-stream',
107
            content => Encode::encode("UTF-8", $iso2709),
108
        };
109
110
        C4::Letters::EnqueueLetter({
111
            letter => $letter,
112
            message_transport_type => 'email',
113
            borrowernumber => $patron->borrowernumber,
114
            to_address => $to_address,
115
            reply_address => $patron->first_valid_email_address,
116
            attachments => [$attachment],
117
        });
118
119
        $template->param( SENT => 1 );
151
    }
120
    }
152
    catch {
153
        carp "Error sending mail: $_";
154
        $template->param( error => 1 );
155
    };
156
121
157
    $template->param( email => $to_address );
122
    $template->param( email => $to_address );
158
    output_html_with_http_headers $query, $cookie, $template->output;
123
    output_html_with_http_headers $query, $cookie, $template->output;
159
- 

Return to bug 3150