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 1576-1578 tables: Link Here
1576
            - "This item must be renewed at the library."
1576
            - "This item must be renewed at the library."
1577
            - "[% END %]"
1577
            - "[% END %]"
1578
            - "[% END %]"
1578
            - "[% END %]"
1579
1580
        - module: catalog
1581
          code: LIST
1582
          branchcode: ""
1583
          name: "Send list"
1584
          is_html: 1
1585
          title: "Your list: [% listname | html %]"
1586
          message_transport_type: email
1587
          lang: default
1588
          content:
1589
            - "[%- USE raw -%]"
1590
            - "<p>Hi,</p>"
1591
            - "<p>[% borrower.firstname | $raw %] [% borrower.surname | $raw %] sent you a list from our online catalog called: [% listname | $raw %].</p>"
1592
            - "<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>"
1593
            - "<hr/>"
1594
            - "<p>[% comment | $raw %]</p>"
1595
            - "<hr/>"
1596
            - "<ol>"
1597
            - "[% FOREACH biblio IN biblios %]"
1598
            - "<li>"
1599
            - "<span>"
1600
            - "[% biblio.title | $raw %]"
1601
            - "[% IF ( biblio.subtitle ) %]"
1602
            - "[% FOREACH subtitle IN biblio.subtitle.split(' | ') %]"
1603
            - "[% subtitle | $raw %]"
1604
            - "[% END %]"
1605
            - "[% END %]"
1606
            - "[% biblio.part_number | $raw %] [% biblio.part_name | $raw %]"
1607
            - "</span>"
1608
            - "<p>"
1609
            - "[% IF ( biblio.author || biblio.get_authors_from_MARC ) %]"
1610
            - "<span>Author(s): [% IF ( biblio.author ) %][% biblio.author | $raw %][% END %]"
1611
            - "[% IF ( biblio.get_authors_from_MARC ) %]"
1612
            - "[% IF ( biblio.author ) %]; [% END %]"
1613
            - "[% FOREACH author IN biblio.get_authors_from_MARC %]"
1614
            - "[% FOREACH subfield IN author.MARCAUTHOR_SUBFIELDS_LOOP %]"
1615
            - "[% subfield.separator | $raw %][% subfield.value | $raw %]"
1616
            - "[% END %]"
1617
            - "[% UNLESS ( loop.last ) %];[% END %]"
1618
            - "[% END %]"
1619
            - "[% END %]"
1620
            - "</span><br/>"
1621
            - "[% END %]"
1622
            - "[% SET biblioitem = biblio.biblioitem %]"
1623
            - "[% IF ( biblioitem.isbn ) %]"
1624
            - "<span>"
1625
            - "ISBN: [% FOREACH isbn IN biblioitem.isbn %]"
1626
            - "[% isbn | $raw %]"
1627
            - "[% UNLESS ( loop.last ) %]; [% END %]"
1628
            - "[% END %]"
1629
            - "</span><br/>"
1630
            - "[% END %]"
1631
            - "[% IF ( biblioitem.publishercode ) %]"
1632
            - "<span>"
1633
            - "Published by: [% biblioitem.publishercode | $raw %]"
1634
            - "[% IF ( biblioitem.publicationyear ) %]"
1635
            - "in [% biblioitem.publicationyear | $raw %]"
1636
            - "[% END %]"
1637
            - "[% IF ( biblioitem.pages ) %]"
1638
            - ", [% biblioitem.pages | $raw %]"
1639
            - "[% END %]"
1640
            - "</span><br/>"
1641
            - "[% END %]"
1642
            - "[% IF ( biblio.seriestitle ) %]"
1643
            - "<span>"
1644
            - "Collection: [% biblio.seriestitle | $raw %]"
1645
            - "</span><br/>"
1646
            - "[% END %]"
1647
            - "[% IF ( biblio.copyrightdate ) %]"
1648
            - "<span>"
1649
            - "Copyright year: [% biblio.copyrightdate | $raw %]"
1650
            - "</span><br/>"
1651
            - "[% END %]"
1652
            - "[% IF ( biblio.notes ) %]"
1653
            - "<span>"
1654
            - "Notes: [% biblio.notes | $raw %]"
1655
            - "</span><br/>"
1656
            - "[% END %]"
1657
            - "[% IF ( biblio.unititle ) %]"
1658
            - "<span>"
1659
            - "Unified title: [% biblio.unititle | $raw %]"
1660
            - "</span><br/>"
1661
            - "[% END %]"
1662
            - "[% IF ( biblio.serial ) %]"
1663
            - "<span>"
1664
            - "Serial: [% biblio.serial | $raw %]"
1665
            - "</span><br/>"
1666
            - "[% END %]"
1667
            - "[% IF ( biblioitem.lccn ) %]"
1668
            - "<span>"
1669
            - "LCCN: [% biblioitem.lccn | $raw %]"
1670
            - "</span><br/>"
1671
            - "[% END %]"
1672
            - "[% IF ( biblioitem.url ) %]"
1673
            - "<span>"
1674
            - "URL: [% biblioitem.url | html %]"
1675
            - "</span>"
1676
            - "[% END %]"
1677
            - "</p>"
1678
            - "[% SET OPACBaseURL = Koha.Preference('OPACBaseURL') %]"
1679
            - "[% IF ( OPACBaseURL ) %]"
1680
            - "<p>In online catalog: [% OPACBaseURL | $raw %]/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblio.biblionumber | html %]</p>"
1681
            - "[% END %]"
1682
            - "[% IF ( biblio.items.count > 0 ) %]"
1683
            - "<p>Items:"
1684
            - "<ul>"
1685
            - "[% FOREACH item IN biblio.items %]<li>"
1686
            - "[% item.holding_branch.branchname | $raw %]"
1687
            - "[% item.location | $raw %]"
1688
            - "[% IF item.itemcallnumber %]([% item.itemcallnumber | $raw %])[% END %]"
1689
            - "[% item.barcode | $raw %]"
1690
            - "</li>[% END %]"
1691
            - "</ul>"
1692
            - "</p>"
1693
            - "[% END %]"
1694
            - "<hr/>"
1695
            - "</li>"
1696
            - "[% END %]"
1697
            - "</ol>"
1698
1699
        - module: catalog
1700
          code: CART
1701
          branchcode: ""
1702
          name: "Send cart"
1703
          is_html: 1
1704
          title: "Your cart"
1705
          message_transport_type: email
1706
          lang: default
1707
          content:
1708
            - "[%- USE raw -%]"
1709
            - "<p>Hi,</p>"
1710
            - "<p>[% borrower.firstname | $raw %] [% borrower.surname | $raw %] sent you a cart from our online catalog.</p>"
1711
            - "<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>"
1712
            - "<hr/>"
1713
            - "<p>[% comment | $raw %]</p>"
1714
            - "<hr/>"
1715
            - "<ol>"
1716
            - "[% FOREACH biblio IN biblios %]"
1717
            - "<li>"
1718
            - "<span>"
1719
            - "[% biblio.title | $raw %]"
1720
            - "[% IF ( biblio.subtitle ) %]"
1721
            - "[% FOREACH subtitle IN biblio.subtitle.split(' | ') %]"
1722
            - "[% subtitle | $raw %]"
1723
            - "[% END %]"
1724
            - "[% END %]"
1725
            - "[% biblio.part_number | $raw %] [% biblio.part_name | $raw %]"
1726
            - "</span>"
1727
            - "<p>"
1728
            - "[% IF ( biblio.author || biblio.get_authors_from_MARC ) %]"
1729
            - "<span>Author(s): [% IF ( biblio.author ) %][% biblio.author | $raw %][% END %]"
1730
            - "[% IF ( biblio.get_authors_from_MARC ) %]"
1731
            - "[% IF ( biblio.author ) %]; [% END %]"
1732
            - "[% FOREACH author IN biblio.get_authors_from_MARC %]"
1733
            - "[% FOREACH subfield IN author.MARCAUTHOR_SUBFIELDS_LOOP %]"
1734
            - "[% subfield.separator | $raw %][% subfield.value | $raw %]"
1735
            - "[% END %]"
1736
            - "[% UNLESS ( loop.last ) %];[% END %]"
1737
            - "[% END %]"
1738
            - "[% END %]"
1739
            - "</span><br/>"
1740
            - "[% END %]"
1741
            - "[% SET biblioitem = biblio.biblioitem %]"
1742
            - "[% IF ( biblioitem.isbn ) %]"
1743
            - "<span>"
1744
            - "ISBN: [% FOREACH isbn IN biblioitem.isbn %]"
1745
            - "[% isbn | $raw %]"
1746
            - "[% UNLESS ( loop.last ) %]; [% END %]"
1747
            - "[% END %]"
1748
            - "</span><br/>"
1749
            - "[% END %]"
1750
            - "[% IF ( biblioitem.publishercode ) %]"
1751
            - "<span>"
1752
            - "Published by: [% biblioitem.publishercode | $raw %]"
1753
            - "[% IF ( biblioitem.publicationyear ) %]"
1754
            - "in [% biblioitem.publicationyear | $raw %]"
1755
            - "[% END %]"
1756
            - "[% IF ( biblioitem.pages ) %]"
1757
            - ", [% biblioitem.pages | $raw %]"
1758
            - "[% END %]"
1759
            - "</span><br/>"
1760
            - "[% END %]"
1761
            - "[% IF ( biblio.seriestitle ) %]"
1762
            - "<span>"
1763
            - "Collection: [% biblio.seriestitle | $raw %]"
1764
            - "</span><br/>"
1765
            - "[% END %]"
1766
            - "[% IF ( biblio.copyrightdate ) %]"
1767
            - "<span>"
1768
            - "Copyright year: [% biblio.copyrightdate | $raw %]"
1769
            - "</span><br/>"
1770
            - "[% END %]"
1771
            - "[% IF ( biblio.notes ) %]"
1772
            - "<span>"
1773
            - "Notes: [% biblio.notes | $raw %]"
1774
            - "</span><br/>"
1775
            - "[% END %]"
1776
            - "[% IF ( biblio.unititle ) %]"
1777
            - "<span>"
1778
            - "Unified title: [% biblio.unititle | $raw %]"
1779
            - "</span><br/>"
1780
            - "[% END %]"
1781
            - "[% IF ( biblio.serial ) %]"
1782
            - "<span>"
1783
            - "Serial: [% biblio.serial | $raw %]"
1784
            - "</span><br/>"
1785
            - "[% END %]"
1786
            - "[% IF ( biblioitem.lccn ) %]"
1787
            - "<span>"
1788
            - "LCCN: [% biblioitem.lccn | $raw %]"
1789
            - "</span><br/>"
1790
            - "[% END %]"
1791
            - "[% IF ( biblioitem.url ) %]"
1792
            - "<span>"
1793
            - "URL: [% biblioitem.url | html %]"
1794
            - "</span>"
1795
            - "[% END %]"
1796
            - "</p>"
1797
            - "[% SET OPACBaseURL = Koha.Preference('OPACBaseURL') %]"
1798
            - "[% IF ( OPACBaseURL ) %]"
1799
            - "<p>In online catalog: [% OPACBaseURL | $raw %]/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblio.biblionumber | html %]</p>"
1800
            - "[% END %]"
1801
            - "[% IF ( biblio.items.count > 0 ) %]"
1802
            - "<p>Items:"
1803
            - "<ul>"
1804
            - "[% FOREACH item IN biblio.items %]<li>"
1805
            - "[% item.holding_branch.branchname | $raw %]"
1806
            - "[% item.location | $raw %]"
1807
            - "[% IF item.itemcallnumber %]([% item.itemcallnumber | $raw %])[% END %]"
1808
            - "[% item.barcode | $raw %]"
1809
            - "</li>[% END %]"
1810
            - "</ul>"
1811
            - "</p>"
1812
            - "[% END %]"
1813
            - "<hr/>"
1814
            - "</li>"
1815
            - "[% END %]"
1816
            - "</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 (-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