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

(-)a/basket/sendbasket.pl (-87 / +42 lines)
Lines 54-159 if ( $email_add ) { Link Here
54
            session_id => scalar $query->cookie('CGISESSID'),
54
            session_id => scalar $query->cookie('CGISESSID'),
55
            token  => scalar $query->param('csrf_token'),
55
            token  => scalar $query->param('csrf_token'),
56
        });
56
        });
57
    my $comment = $query->param('comment');
58
57
59
    # Since we are already logged in, no need to check credentials again
58
    my $patron = Koha:::Patrons->find( $borrowernumber );
60
    # when loading a second template.
59
61
    my $template2 = C4::Templates::gettemplate(
60
    my $comment = $query->param('comment');
62
        'basket/sendbasket.tt', 'intranet', $query,
63
    );
64
61
65
    my @bibs = split( /\//, $bib_list );
62
    my @bibs = split( /\//, $bib_list );
66
    my @results;
67
    my $iso2709;
63
    my $iso2709;
68
    my $marcflavour = C4::Context->preference('marcflavour');
69
    foreach my $biblionumber (@bibs) {
70
        $template2->param( biblionumber => $biblionumber );
71
72
        my $biblio           = Koha::Biblios->find( $biblionumber ) or next;
73
        my $dat              = $biblio->unblessed;
74
        my $record           = $biblio->metadata->record({ embed_items => 1 });
75
        my $marcauthorsarray = $biblio->get_marc_contributors;
76
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
77
78
        my $hasauthors = 0;
79
        if($dat->{'author'} || @$marcauthorsarray) {
80
          $hasauthors = 1;
81
        }
82
	
83
84
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
85
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
86
        $dat->{HASAUTHORS}     = $hasauthors;
87
        $dat->{'biblionumber'} = $biblionumber;
88
        $dat->{ITEM_RESULTS}   = $biblio->items->search_ordered;
89
90
        $iso2709 .= $record->as_usmarc();
91
92
        push( @results, $dat );
93
    }
94
95
    my $resultsarray = \@results;
96
    $template2->param(
97
        BIBLIO_RESULTS => $resultsarray,
98
        comment        => $comment
99
    );
100
101
    # Getting template result
102
    my $template_res = $template2->output();
103
    my $body;
104
105
    my $subject;
106
    # Analysing information and getting mail properties
107
    if ( $template_res =~ /<SUBJECT>(?<subject>.*)<END_SUBJECT>/s ) {
108
        $subject = $+{subject};
109
        $subject =~ s|\n?(.*)\n?|$1|;
110
    }
111
    else {
112
        $subject = "no subject";
113
    }
114
115
    my $email_header = "";
116
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
117
        $email_header = $1;
118
        $email_header =~ s|\n?(.*)\n?|$1|;
119
    }
120
64
121
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
65
    foreach my $bib ( @bibs ) {
122
        $body = $1;
66
        my $biblio = Koha::Biblios->find( $biblionumber ) or next;
123
        $body =~ s|\n?(.*)\n?|$1|;
67
        $iso2709 .= $biblio->metadata->record->as_usmarc();
124
    }
68
    }
125
69
126
    my $THE_body = <<END_OF_BODY;
70
    if ( !defined $iso2709 ) {
127
$email_header
71
        carp "Error sending mail: empty basket";
128
$body
72
        $template->param( error => 1 );
129
END_OF_BODY
73
    } else {
130
74
        my %loops = (
131
    try {
75
            biblio => \@bibs,
76
        );
132
77
133
        my $email = Koha::Email->create(
78
        my %substitute = (
134
            {
79
            comment => $comment,
135
                to      => $email_add,
136
                subject => $subject,
137
            }
138
        );
80
        );
139
81
140
        $email->text_body( $THE_body );
82
        my $letter = C4::Letters::GetPreparedLetter(
141
        $email->attach(
83
            module => 'catalog',
142
            Encode::encode( "UTF-8", $iso2709 ),
84
            letter_code => 'CART',
143
            content_type => 'application/octet-stream',
85
            lang => $patron->lang,
144
            name         => 'basket.iso2709',
86
            tables => {
145
            disposition  => 'attachment',
87
                borrowers => $borrowernumber,
88
            },
89
            message_transport_type => 'email',
90
            loops => \%loops,
91
            substitute => \%substitute,
146
        );
92
        );
147
93
148
        my $library = Koha::Patrons->find( $borrowernumber )->library;
94
        my $attachment = {
149
        $email->send_or_die({ transport => $library->smtp_server->transport });
95
            filename => 'basket.iso2709',
150
        $template->param( SENT => "1" );
96
            type => 'application/octet-stream',
151
    }
97
            content => Encode::encode("UTF-8", $iso2709),
152
    catch {
98
        };
153
        carp "Error sending mail: $_";
99
154
        $template->param( error => 1 );
100
        my $user_email = $patron->first_valid_email_address || C4::Context->preference('KohaAdminEmailAddress');
155
    };
101
        C4::Letters::EnqueueLetter({
102
            letter => $letter,
103
            message_transport_type => 'email',
104
            borrowernumber => $patron->borrowernumber,
105
            to_address => $email_add,
106
            reply_address => $user_email,
107
            attachments => [$attachment],
108
        });
156
109
110
        $template->param( SENT => 1 );
111
    }
157
    $template->param( email_add => $email_add );
112
    $template->param( email_add => $email_add );
158
    output_html_with_http_headers $query, $cookie, $template->output;
113
    output_html_with_http_headers $query, $cookie, $template->output;
159
}
114
}
(-)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 1745-1747 tables: Link Here
1745
            - "<p>This is to confirm that someone enabled two factor authentication on your account.</p>"
1745
            - "<p>This is to confirm that someone enabled two factor authentication on your account.</p>"
1746
            - "<p>If you did not do this, someone else may be using your account. Please contact technical support.</p>"
1746
            - "<p>If you did not do this, someone else may be using your account. Please contact technical support.</p>"
1747
            - "<p>Your library</p>"
1747
            - "<p>Your library</p>"
1748
1749
        - module: catalog
1750
          code: LIST
1751
          branchcode: ""
1752
          name: "Send list"
1753
          is_html: 1
1754
          title: "Your list: [% listname | html %]"
1755
          message_transport_type: email
1756
          lang: default
1757
          content:
1758
            - "[%- USE raw -%]"
1759
            - "<p>Hi,</p>"
1760
            - "<p>[% borrower.firstname | $raw %] [% borrower.surname | $raw %] sent you a list from our online catalog called: [% listname | $raw %].</p>"
1761
            - "<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>"
1762
            - "<hr/>"
1763
            - "<p>[% comment | $raw %]</p>"
1764
            - "<hr/>"
1765
            - "<ol>"
1766
            - "[% FOREACH biblio IN biblios %]"
1767
            - "<li>"
1768
            - "<span>"
1769
            - "[% biblio.title | $raw %]"
1770
            - "[% IF ( biblio.subtitle ) %]"
1771
            - "[% FOREACH subtitle IN biblio.subtitle.split(' | ') %]"
1772
            - "[% subtitle | $raw %]"
1773
            - "[% END %]"
1774
            - "[% END %]"
1775
            - "[% biblio.part_number | $raw %] [% biblio.part_name | $raw %]"
1776
            - "</span>"
1777
            - "<p>"
1778
            - "[% IF ( biblio.author || biblio.get_authors_from_MARC ) %]"
1779
            - "<span>Author(s): [% IF ( biblio.author ) %][% biblio.author | $raw %][% END %]"
1780
            - "[% IF ( biblio.get_authors_from_MARC ) %]"
1781
            - "[% IF ( biblio.author ) %]; [% END %]"
1782
            - "[% FOREACH author IN biblio.get_authors_from_MARC %]"
1783
            - "[% FOREACH subfield IN author.MARCAUTHOR_SUBFIELDS_LOOP %]"
1784
            - "[% subfield.separator | $raw %][% subfield.value | $raw %]"
1785
            - "[% END %]"
1786
            - "[% UNLESS ( loop.last ) %];[% END %]"
1787
            - "[% END %]"
1788
            - "[% END %]"
1789
            - "</span><br/>"
1790
            - "[% END %]"
1791
            - "[% SET biblioitem = biblio.biblioitem %]"
1792
            - "[% IF ( biblioitem.isbn ) %]"
1793
            - "<span>"
1794
            - "ISBN: [% FOREACH isbn IN biblioitem.isbn %]"
1795
            - "[% isbn | $raw %]"
1796
            - "[% UNLESS ( loop.last ) %]; [% END %]"
1797
            - "[% END %]"
1798
            - "</span><br/>"
1799
            - "[% END %]"
1800
            - "[% IF ( biblioitem.publishercode ) %]"
1801
            - "<span>"
1802
            - "Published by: [% biblioitem.publishercode | $raw %]"
1803
            - "[% IF ( biblioitem.publicationyear ) %]"
1804
            - "in [% biblioitem.publicationyear | $raw %]"
1805
            - "[% END %]"
1806
            - "[% IF ( biblioitem.pages ) %]"
1807
            - ", [% biblioitem.pages | $raw %]"
1808
            - "[% END %]"
1809
            - "</span><br/>"
1810
            - "[% END %]"
1811
            - "[% IF ( biblio.seriestitle ) %]"
1812
            - "<span>"
1813
            - "Collection: [% biblio.seriestitle | $raw %]"
1814
            - "</span><br/>"
1815
            - "[% END %]"
1816
            - "[% IF ( biblio.copyrightdate ) %]"
1817
            - "<span>"
1818
            - "Copyright year: [% biblio.copyrightdate | $raw %]"
1819
            - "</span><br/>"
1820
            - "[% END %]"
1821
            - "[% IF ( biblio.notes ) %]"
1822
            - "<span>"
1823
            - "Notes: [% biblio.notes | $raw %]"
1824
            - "</span><br/>"
1825
            - "[% END %]"
1826
            - "[% IF ( biblio.unititle ) %]"
1827
            - "<span>"
1828
            - "Unified title: [% biblio.unititle | $raw %]"
1829
            - "</span><br/>"
1830
            - "[% END %]"
1831
            - "[% IF ( biblio.serial ) %]"
1832
            - "<span>"
1833
            - "Serial: [% biblio.serial | $raw %]"
1834
            - "</span><br/>"
1835
            - "[% END %]"
1836
            - "[% IF ( biblioitem.lccn ) %]"
1837
            - "<span>"
1838
            - "LCCN: [% biblioitem.lccn | $raw %]"
1839
            - "</span><br/>"
1840
            - "[% END %]"
1841
            - "[% IF ( biblioitem.url ) %]"
1842
            - "<span>"
1843
            - "URL: [% biblioitem.url | html %]"
1844
            - "</span>"
1845
            - "[% END %]"
1846
            - "</p>"
1847
            - "[% SET OPACBaseURL = Koha.Preference('OPACBaseURL') %]"
1848
            - "[% IF ( OPACBaseURL ) %]"
1849
            - "<p>In online catalog: [% OPACBaseURL | $raw %]/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblio.biblionumber | html %]</p>"
1850
            - "[% END %]"
1851
            - "[% IF ( biblio.items.count > 0 ) %]"
1852
            - "<p>Items:"
1853
            - "<ul>"
1854
            - "[% FOREACH item IN biblio.items %]<li>"
1855
            - "[% item.holding_branch.branchname | $raw %]"
1856
            - "[% item.location | $raw %]"
1857
            - "[% IF item.itemcallnumber %]([% item.itemcallnumber | $raw %])[% END %]"
1858
            - "[% item.barcode | $raw %]"
1859
            - "</li>[% END %]"
1860
            - "</ul>"
1861
            - "</p>"
1862
            - "[% END %]"
1863
            - "<hr/>"
1864
            - "</li>"
1865
            - "[% END %]"
1866
            - "</ol>"
1867
1868
        - module: catalog
1869
          code: CART
1870
          branchcode: ""
1871
          name: "Send cart"
1872
          is_html: 1
1873
          title: "Your cart"
1874
          message_transport_type: email
1875
          lang: default
1876
          content:
1877
            - "[%- USE raw -%]"
1878
            - "<p>Hi,</p>"
1879
            - "<p>[% borrower.firstname | $raw %] [% borrower.surname | $raw %] sent you a cart from our online catalog.</p>"
1880
            - "<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>"
1881
            - "<hr/>"
1882
            - "<p>[% comment | $raw %]</p>"
1883
            - "<hr/>"
1884
            - "<ol>"
1885
            - "[% FOREACH biblio IN biblios %]"
1886
            - "<li>"
1887
            - "<span>"
1888
            - "[% biblio.title | $raw %]"
1889
            - "[% IF ( biblio.subtitle ) %]"
1890
            - "[% FOREACH subtitle IN biblio.subtitle.split(' | ') %]"
1891
            - "[% subtitle | $raw %]"
1892
            - "[% END %]"
1893
            - "[% END %]"
1894
            - "[% biblio.part_number | $raw %] [% biblio.part_name | $raw %]"
1895
            - "</span>"
1896
            - "<p>"
1897
            - "[% IF ( biblio.author || biblio.get_authors_from_MARC ) %]"
1898
            - "<span>Author(s): [% IF ( biblio.author ) %][% biblio.author | $raw %][% END %]"
1899
            - "[% IF ( biblio.get_authors_from_MARC ) %]"
1900
            - "[% IF ( biblio.author ) %]; [% END %]"
1901
            - "[% FOREACH author IN biblio.get_authors_from_MARC %]"
1902
            - "[% FOREACH subfield IN author.MARCAUTHOR_SUBFIELDS_LOOP %]"
1903
            - "[% subfield.separator | $raw %][% subfield.value | $raw %]"
1904
            - "[% END %]"
1905
            - "[% UNLESS ( loop.last ) %];[% END %]"
1906
            - "[% END %]"
1907
            - "[% END %]"
1908
            - "</span><br/>"
1909
            - "[% END %]"
1910
            - "[% SET biblioitem = biblio.biblioitem %]"
1911
            - "[% IF ( biblioitem.isbn ) %]"
1912
            - "<span>"
1913
            - "ISBN: [% FOREACH isbn IN biblioitem.isbn %]"
1914
            - "[% isbn | $raw %]"
1915
            - "[% UNLESS ( loop.last ) %]; [% END %]"
1916
            - "[% END %]"
1917
            - "</span><br/>"
1918
            - "[% END %]"
1919
            - "[% IF ( biblioitem.publishercode ) %]"
1920
            - "<span>"
1921
            - "Published by: [% biblioitem.publishercode | $raw %]"
1922
            - "[% IF ( biblioitem.publicationyear ) %]"
1923
            - "in [% biblioitem.publicationyear | $raw %]"
1924
            - "[% END %]"
1925
            - "[% IF ( biblioitem.pages ) %]"
1926
            - ", [% biblioitem.pages | $raw %]"
1927
            - "[% END %]"
1928
            - "</span><br/>"
1929
            - "[% END %]"
1930
            - "[% IF ( biblio.seriestitle ) %]"
1931
            - "<span>"
1932
            - "Collection: [% biblio.seriestitle | $raw %]"
1933
            - "</span><br/>"
1934
            - "[% END %]"
1935
            - "[% IF ( biblio.copyrightdate ) %]"
1936
            - "<span>"
1937
            - "Copyright year: [% biblio.copyrightdate | $raw %]"
1938
            - "</span><br/>"
1939
            - "[% END %]"
1940
            - "[% IF ( biblio.notes ) %]"
1941
            - "<span>"
1942
            - "Notes: [% biblio.notes | $raw %]"
1943
            - "</span><br/>"
1944
            - "[% END %]"
1945
            - "[% IF ( biblio.unititle ) %]"
1946
            - "<span>"
1947
            - "Unified title: [% biblio.unititle | $raw %]"
1948
            - "</span><br/>"
1949
            - "[% END %]"
1950
            - "[% IF ( biblio.serial ) %]"
1951
            - "<span>"
1952
            - "Serial: [% biblio.serial | $raw %]"
1953
            - "</span><br/>"
1954
            - "[% END %]"
1955
            - "[% IF ( biblioitem.lccn ) %]"
1956
            - "<span>"
1957
            - "LCCN: [% biblioitem.lccn | $raw %]"
1958
            - "</span><br/>"
1959
            - "[% END %]"
1960
            - "[% IF ( biblioitem.url ) %]"
1961
            - "<span>"
1962
            - "URL: [% biblioitem.url | html %]"
1963
            - "</span>"
1964
            - "[% END %]"
1965
            - "</p>"
1966
            - "[% SET OPACBaseURL = Koha.Preference('OPACBaseURL') %]"
1967
            - "[% IF ( OPACBaseURL ) %]"
1968
            - "<p>In online catalog: [% OPACBaseURL | $raw %]/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblio.biblionumber | html %]</p>"
1969
            - "[% END %]"
1970
            - "[% IF ( biblio.items.count > 0 ) %]"
1971
            - "<p>Items:"
1972
            - "<ul>"
1973
            - "[% FOREACH item IN biblio.items %]<li>"
1974
            - "[% item.holding_branch.branchname | $raw %]"
1975
            - "[% item.location | $raw %]"
1976
            - "[% IF item.itemcallnumber %]([% item.itemcallnumber | $raw %])[% END %]"
1977
            - "[% item.barcode | $raw %]"
1978
            - "</li>[% END %]"
1979
            - "</ul>"
1980
            - "</p>"
1981
            - "[% END %]"
1982
            - "<hr/>"
1983
            - "</li>"
1984
            - "[% END %]"
1985
            - "</ol>"
(-)a/opac/opac-sendbasket.pl (-108 / +42 lines)
Lines 53-177 if ( $email_add ) { Link Here
53
        session_id => scalar $query->cookie('CGISESSID'),
53
        session_id => scalar $query->cookie('CGISESSID'),
54
        token  => scalar $query->param('csrf_token'),
54
        token  => scalar $query->param('csrf_token'),
55
    });
55
    });
56
56
    my $patron = Koha::Patrons->find( $borrowernumber );
57
    my $patron = Koha::Patrons->find( $borrowernumber );
57
    my $user_email = $patron->first_valid_email_address
58
    || C4::Context->preference('KohaAdminEmailAddress');
59
58
60
    my $email_replyto = $patron->firstname . " " . $patron->surname . " <$user_email>";
61
    my $comment    = $query->param('comment');
59
    my $comment    = $query->param('comment');
62
60
63
    # Since we are already logged in, no need to check credentials again
64
    # when loading a second template.
65
    my $template2 = C4::Templates::gettemplate(
66
        'opac-sendbasket.tt', 'opac', $query,
67
    );
68
69
    my @bibs = split( /\//, $bib_list );
61
    my @bibs = split( /\//, $bib_list );
70
    my @results;
71
    my $iso2709;
62
    my $iso2709;
72
    my $marcflavour = C4::Context->preference('marcflavour');
63
    foreach my $bib ( @bibs ) {
73
    foreach my $biblionumber (@bibs) {
64
        my $biblio = Koha::Biblios->find( $biblionumber ) or next;
74
        $template2->param( biblionumber => $biblionumber );
65
        $iso2709 .= $biblio->metadata->record->as_usmarc();
75
66
    };
76
        my $biblio           = Koha::Biblios->find( $biblionumber ) or next;
77
        my $dat              = $biblio->unblessed;
78
        my $record = $biblio->metadata->record(
79
            {
80
                embed_items => 1,
81
                opac        => 1,
82
                patron      => $patron,
83
            }
84
        );
85
        my $marcauthorsarray = $biblio->get_marc_contributors;
86
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
87
88
        my $items = $biblio->items->search_ordered->filter_by_visible_in_opac({ patron => $patron });
89
90
        my $hasauthors = 0;
91
        if($dat->{'author'} || @$marcauthorsarray) {
92
          $hasauthors = 1;
93
        }
94
95
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
96
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
97
        $dat->{HASAUTHORS}     = $hasauthors;
98
        $dat->{'biblionumber'} = $biblionumber;
99
        $dat->{ITEM_RESULTS}   = $items;
100
101
        $iso2709 .= $record->as_usmarc();
102
103
        push( @results, $dat );
104
    }
105
106
    my $resultsarray = \@results;
107
    
108
    $template2->param(
109
        BIBLIO_RESULTS => $resultsarray,
110
        comment        => $comment,
111
        firstname      => $patron->firstname,
112
        surname        => $patron->surname,
113
    );
114
115
    # Getting template result
116
    my $template_res = $template2->output();
117
    my $body;
118
119
    # Analysing information and getting mail properties
120
    my $subject;
121
    if ( $template_res =~ /\<SUBJECT\>(?<subject>.*)\<END_SUBJECT\>/s ) {
122
        $subject = $+{subject};
123
        $subject =~ s|\n?(.*)\n?|$1|;
124
    }
125
    else {
126
        $subject = "no subject";
127
    }
128
129
    my $email_header = "";
130
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
131
        $email_header = $1;
132
        $email_header =~ s|\n?(.*)\n?|$1|;
133
    }
134
135
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
136
        $body = $1;
137
        $body =~ s|\n?(.*)\n?|$1|;
138
    }
139
140
    my $THE_body = <<END_OF_BODY;
141
$email_header
142
$body
143
END_OF_BODY
144
67
145
    if ( !defined $iso2709 ) {
68
    if ( !defined $iso2709 ) {
146
        carp "Error sending mail: empty basket";
69
        carp "Error sending mail: empty basket";
147
        $template->param( error => 1 );
70
        $template->param( error => 1 );
148
    }
71
    } else {
149
    else {
72
        my %loops = (
150
        try {
73
            biblio => \@bibs,
151
            # if you want to use the KohaAdmin address as from, that is the default no need to set it
74
        );
152
            my $email = Koha::Email->create({
75
153
                to       => $email_add,
76
        my %substitute = (
154
                reply_to => $email_replyto,
77
            comment => $comment,
155
                subject  => $subject,
78
        );
156
            });
79
157
            $email->header( 'X-Abuse-Report' => C4::Context->preference('KohaAdminEmailAddress') );
80
        my $letter = C4::Letters::GetPreparedLetter(
158
            $email->text_body( $THE_body );
81
            module => 'catalog',
159
            $email->attach(
82
            letter_code => 'CART',
160
                Encode::encode( "UTF-8", $iso2709 ),
83
            lang => $patron->lang,
161
                content_type => 'application/octet-stream',
84
            tables => {
162
                name         => 'basket.iso2709',
85
                borrowers => $borrowernumber,
163
                disposition  => 'attachment',
86
            },
164
            );
87
            message_transport_type => 'email',
165
            my $library = $patron->library;
88
            loops => \%loops,
166
            $email->transport( $library->smtp_server->transport );
89
            substitute => \%substitute,
167
            $email->send_or_die;
90
        );
168
            $template->param( SENT => "1" );
91
169
        }
92
        my $attachment = {
170
        catch {
93
            filename => 'basket.iso2709',
171
            carp "Error sending mail: $_";
94
            type => 'application/octet-stream',
172
            $template->param( error => 1 );
95
            content => Encode::encode("UTF-8", $iso2709),
173
        };
96
        };
174
    }
97
98
        my $user_email = $patron->first_valid_email_address || C4::Context->preference('KohaAdminEmailAddress');
99
        C4::Letters::EnqueueLetter({
100
            letter => $letter,
101
            message_transport_type => 'email',
102
            borrowernumber => $patron->borrowernumber,
103
            to_address => $email_add,
104
            reply_address => $user_email,
105
            attachments => [$attachment],
106
        });
107
108
        $template->param( SENT => 1 );
175
109
176
    $template->param( email_add => $email_add );
110
    $template->param( email_add => $email_add );
177
    output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
111
    output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
(-)a/opac/opac-sendshelf.pl (-90 / +44 lines)
Lines 73-174 if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { Link Here
73
73
74
    my $shelf = Koha::Virtualshelves->find( $shelfid );
74
    my $shelf = Koha::Virtualshelves->find( $shelfid );
75
    my $contents = $shelf->get_contents;
75
    my $contents = $shelf->get_contents;
76
    my $marcflavour         = C4::Context->preference('marcflavour');
77
    my $iso2709;
76
    my $iso2709;
78
    my @results;
79
77
80
    while ( my $content = $contents->next ) {
78
    while ( my $content = $contents->next ) {
81
        my $biblionumber = $content->biblionumber;
79
        push @biblionumbers, $content->biblionumber;
82
        my $biblio       = Koha::Biblios->find( $biblionumber ) or next;
80
        my $biblio = Koha::Biblios->find($content->biblionumber);
83
        my $dat          = $biblio->unblessed;
81
        $iso2709 .= $biblio->metadata->record->as_usmarc();
84
        my $record = $biblio->metadata->record(
82
    };
85
            {
86
                embed_items => 1,
87
                opac        => 1,
88
                patron      => $patron,
89
            }
90
        );
91
        next unless $record;
92
        my $fw               = GetFrameworkCode($biblionumber);
93
94
        my $marcauthorsarray = $biblio->get_marc_contributors;
95
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
96
97
        my $items = $biblio->items->search_ordered->filter_by_visible_in_opac({ patron => $patron });
98
99
        $dat->{ISBN}           = GetMarcISBN($record, $marcflavour);
100
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
101
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
102
        $dat->{'biblionumber'} = $biblionumber;
103
        $dat->{ITEM_RESULTS}   = $items;
104
        $dat->{HASAUTHORS}     = $dat->{'author'} || @$marcauthorsarray;
105
106
        $iso2709 .= $record->as_usmarc();
107
108
        push( @results, $dat );
109
    }
110
111
    $template2->param(
112
        BIBLIO_RESULTS => \@results,
113
        comment        => $comment,
114
        shelfname      => $shelf->shelfname,
115
        firstname      => $patron->firstname,
116
        surname        => $patron->surname,
117
    );
118
119
    # Getting template result
120
    my $template_res = $template2->output();
121
    my $body;
122
123
    my $subject;
124
    # Analysing information and getting mail properties
125
    if ( $template_res =~ /<SUBJECT>(?<subject>.*)<END_SUBJECT>/s ) {
126
        $subject = $+{subject};
127
        $subject =~ s|\n?(.*)\n?|$1|;
128
    }
129
    else {
130
        $subject = "no subject";
131
    }
132
133
    my $email_header = "";
134
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
135
        $email_header = $1;
136
        $email_header =~ s|\n?(.*)\n?|$1|;
137
    }
138
139
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
140
        $body = $1;
141
        $body =~ s|\n?(.*)\n?|$1|;
142
    }
143
83
144
    my $THE_body = <<END_OF_BODY;
84
    if ( !defined $iso2709 ) {
145
$email_header
85
        carp "Error sending mail: empty list";
146
$body
86
        $template->param( error => 1 );
147
END_OF_BODY
87
    } else {
148
88
         my %loops = (
149
    try {
89
             biblio => \@biblionumbers,
150
        my $email = Koha::Email->create(
90
         );
151
            {
91
152
                to      => $email,
92
         my %substitute = (
153
                subject => $subject,
93
             comment => $comment,
154
            }
94
             listname => $shelf->shelfname,
155
        );
95
         );
156
        $email->text_body( $THE_body );
96
157
        $email->attach(
97
        my $letter = C4::Letters::GetPreparedLetter(
158
            Encode::encode( "UTF-8", $iso2709 ),
98
            module => 'catalog',
159
            content_type => 'application/octet-stream',
99
            letter_code => 'LIST',
160
            name         => 'list.iso2709',
100
            lang => $patron->lang,
161
            disposition  => 'attachment',
101
            tables => {
102
                borrowers => $borrowernumber,
103
            },
104
            message_transport_type => 'email',
105
            loops => \%loops,
106
            substitute => \%substitute,
162
        );
107
        );
163
        my $library = Koha::Patrons->find( $borrowernumber )->library;
108
164
        $email->transport( $library->smtp_server->transport );
109
        my $attachment = {
165
        $email->send_or_die;
110
            filename => 'list.iso2709',
166
        $template->param( SENT => "1" );
111
            type => 'application/octet-stream',
112
            content => Encode::encode("UTF-8", $iso2709),
113
        };
114
115
        C4::Letters::EnqueueLetter({
116
            letter => $letter,
117
            message_transport_type => 'email',
118
            borrowernumber => $patron->borrowernumber,
119
            to_address => $email,
120
            reply_address => $patron->first_valid_email_address,
121
            attachments => [$attachment],
122
        });
123
124
        $template->param( SENT => 1 );
167
    }
125
    }
168
    catch {
169
        carp "Error sending mail: $_";
170
        $template->param( error => 1 );
171
    };
172
126
173
    $template->param(
127
    $template->param(
174
        shelfid => $shelfid,
128
        shelfid => $shelfid,
(-)a/virtualshelves/sendshelf.pl (-77 / +43 lines)
Lines 69-160 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           = $biblio->metadata->record({ embed_items => 1 });
81
    };
82
        my $marcauthorsarray = $biblio->get_marc_contributors;
83
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
84
85
        my $items = $biblio->items->search_ordered;
86
87
        $dat->{ISBN}           = GetMarcISBN($record, $marcflavour);
88
        $dat->{MARCSUBJCTS}    = $marcsubjctsarray;
89
        $dat->{MARCAUTHORS}    = $marcauthorsarray;
90
        $dat->{'biblionumber'} = $biblionumber;
91
        $dat->{ITEM_RESULTS}   = $items;
92
        $dat->{HASAUTHORS}     = $dat->{'author'} || @$marcauthorsarray;
93
94
        $iso2709 .= $record->as_usmarc();
95
96
        push( @results, $dat );
97
    }
98
99
    $template2->param(
100
        BIBLIO_RESULTS => \@results,
101
        comment        => $comment,
102
        shelfname      => $shelf->shelfname,
103
    );
104
105
    # Getting template result
106
    my $template_res = $template2->output();
107
    my $body;
108
109
    my $subject;
110
    # Analysing information and getting mail properties
111
    if ( $template_res =~ /<SUBJECT>(?<subject>.*)<END_SUBJECT>/s ) {
112
        $subject = $+{subject};
113
        $subject =~ s|\n?(.*)\n?|$1|;
114
    }
115
    else {
116
        $subject = "no subject";
117
    }
118
119
    my $email_header = "";
120
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
121
        $email_header = $1;
122
        $email_header =~ s|\n?(.*)\n?|$1|;
123
    }
124
82
125
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
83
    if ( !defined $iso2709 ) {
126
        $body = $1;
84
        carp "Error sending mail: empty basket";
127
        $body =~ s|\n?(.*)\n?|$1|;
85
        $template->param( error => 1 );
128
    }
86
    } else {
87
        my %loops = (
88
            biblio => \@biblionumbers,
89
        );
129
90
130
    my $THE_body = <<END_OF_BODY;
91
        my %substitute = (
131
$email_header
92
            comment => $comment,
132
$body
93
            listname => $shelf->shelfname,
133
END_OF_BODY
134
135
    try {
136
        my $email = Koha::Email->create(
137
            {
138
                to      => $to_address,
139
                subject => $subject,
140
            }
141
        );
94
        );
142
        $email->text_body( $THE_body );
95
143
        $email->attach(
96
        my $letter = C4::Letters::GetPreparedLetter(
144
            Encode::encode("UTF-8", $iso2709),
97
            module => 'catalog',
145
            content_type => 'application/octet-stream',
98
            letter_code => 'LIST',
146
            name         => 'shelf.iso2709',
99
            lang => $patron->lang,
147
            disposition  => 'attachment',
100
            tables => {
101
                borrowers => $borrowernumber,
102
            },
103
            message_transport_type => 'email',
104
            loops => \%loops,
105
            substitute => \%substitute,
148
        );
106
        );
149
107
150
        my $library = Koha::Patrons->find( $borrowernumber )->library;
108
        my $attachment = {
151
        $email->send_or_die({ transport => $library->smtp_server->transport });
109
            filename => 'shelf.iso2709',
152
        $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 );
153
    }
124
    }
154
    catch {
155
        carp "Error sending mail: $_";
156
        $template->param( error => 1 );
157
    };
158
125
159
    $template->param( email => $to_address );
126
    $template->param( email => $to_address );
160
    output_html_with_http_headers $query, $cookie, $template->output;
127
    output_html_with_http_headers $query, $cookie, $template->output;
161
- 

Return to bug 3150