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

(-)a/basket/sendbasket.pl (-90 / +42 lines)
Lines 54-162 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
        my ( $host, $relatedparts ) = $biblio->get_marc_host;
90
        $dat->{HOSTITEMENTRIES} = $host;
91
        $dat->{RELATEDPARTS} = $relatedparts;
92
93
        $iso2709 .= $record->as_usmarc();
94
95
        push( @results, $dat );
96
    }
97
98
    my $resultsarray = \@results;
99
    $template2->param(
100
        BIBLIO_RESULTS => $resultsarray,
101
        comment        => $comment
102
    );
103
104
    # Getting template result
105
    my $template_res = $template2->output();
106
    my $body;
107
108
    my $subject;
109
    # Analysing information and getting mail properties
110
    if ( $template_res =~ /<SUBJECT>(?<subject>.*)<END_SUBJECT>/s ) {
111
        $subject = $+{subject};
112
        $subject =~ s|\n?(.*)\n?|$1|;
113
    }
114
    else {
115
        $subject = "no subject";
116
    }
117
118
    my $email_header = "";
119
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
120
        $email_header = $1;
121
        $email_header =~ s|\n?(.*)\n?|$1|;
122
    }
123
64
124
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
65
    foreach my $bib ( @bibs ) {
125
        $body = $1;
66
        my $biblio = Koha::Biblios->find( $biblionumber ) or next;
126
        $body =~ s|\n?(.*)\n?|$1|;
67
        $iso2709 .= $biblio->metadata->record->as_usmarc();
127
    }
68
    }
128
69
129
    my $THE_body = <<END_OF_BODY;
70
    if ( !defined $iso2709 ) {
130
$email_header
71
        carp "Error sending mail: empty basket";
131
$body
72
        $template->param( error => 1 );
132
END_OF_BODY
73
    } else {
133
74
        my %loops = (
134
    try {
75
            biblio => \@bibs,
76
        );
135
77
136
        my $email = Koha::Email->create(
78
        my %substitute = (
137
            {
79
            comment => $comment,
138
                to      => $email_add,
139
                subject => $subject,
140
            }
141
        );
80
        );
142
81
143
        $email->text_body( $THE_body );
82
        my $letter = C4::Letters::GetPreparedLetter(
144
        $email->attach(
83
            module => 'catalog',
145
            Encode::encode( "UTF-8", $iso2709 ),
84
            letter_code => 'CART',
146
            content_type => 'application/octet-stream',
85
            lang => $patron->lang,
147
            name         => 'basket.iso2709',
86
            tables => {
148
            disposition  => 'attachment',
87
                borrowers => $borrowernumber,
88
            },
89
            message_transport_type => 'email',
90
            loops => \%loops,
91
            substitute => \%substitute,
149
        );
92
        );
150
93
151
        my $library = Koha::Patrons->find( $borrowernumber )->library;
94
        my $attachment = {
152
        $email->send_or_die({ transport => $library->smtp_server->transport });
95
            filename => 'basket.iso2709',
153
        $template->param( SENT => "1" );
96
            type => 'application/octet-stream',
154
    }
97
            content => Encode::encode("UTF-8", $iso2709),
155
    catch {
98
        };
156
        carp "Error sending mail: $_";
99
157
        $template->param( error => 1 );
100
        my $user_email = $patron->first_valid_email_address || C4::Context->preference('KohaAdminEmailAddress');
158
    };
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
        });
159
109
110
        $template->param( SENT => 1 );
111
    }
160
    $template->param( email_add => $email_add );
112
    $template->param( email_add => $email_add );
161
    output_html_with_http_headers $query, $cookie, $template->output;
113
    output_html_with_http_headers $query, $cookie, $template->output;
162
}
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 2186-2188 tables: Link Here
2186
            - "[% IF borrower.categorycode %]<li>Temporary patron category: [% borrower.categorycode %]</li>[% END %]"
2186
            - "[% IF borrower.categorycode %]<li>Temporary patron category: [% borrower.categorycode %]</li>[% END %]"
2187
            - "</ul>"
2187
            - "</ul>"
2188
            - "</p>"
2188
            - "</p>"
2189
2190
        - module: catalog
2191
          code: LIST
2192
          branchcode: ""
2193
          name: "Send list"
2194
          is_html: 1
2195
          title: "Your list: [% listname | html %]"
2196
          message_transport_type: email
2197
          lang: default
2198
          content:
2199
            - "[%- USE raw -%]"
2200
            - "<p>Hi,</p>"
2201
            - "<p>[% borrower.firstname | $raw %] [% borrower.surname | $raw %] sent you a list from our online catalog called: [% listname | $raw %].</p>"
2202
            - "<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>"
2203
            - "<hr/>"
2204
            - "<p>[% comment | $raw %]</p>"
2205
            - "<hr/>"
2206
            - "<ol>"
2207
            - "[% FOREACH biblio IN biblios %]"
2208
            - "<li>"
2209
            - "<span>"
2210
            - "[% biblio.title | $raw %]"
2211
            - "[% IF ( biblio.subtitle ) %]"
2212
            - "[% FOREACH subtitle IN biblio.subtitle.split(' | ') %]"
2213
            - "[% subtitle | $raw %]"
2214
            - "[% END %]"
2215
            - "[% END %]"
2216
            - "[% biblio.part_number | $raw %] [% biblio.part_name | $raw %]"
2217
            - "</span>"
2218
            - "<p>"
2219
            - "[% IF ( biblio.author || biblio.get_authors_from_MARC ) %]"
2220
            - "<span>Author(s): [% IF ( biblio.author ) %][% biblio.author | $raw %][% END %]"
2221
            - "[% IF ( biblio.get_authors_from_MARC ) %]"
2222
            - "[% IF ( biblio.author ) %]; [% END %]"
2223
            - "[% FOREACH author IN biblio.get_authors_from_MARC %]"
2224
            - "[% FOREACH subfield IN author.MARCAUTHOR_SUBFIELDS_LOOP %]"
2225
            - "[% subfield.separator | $raw %][% subfield.value | $raw %]"
2226
            - "[% END %]"
2227
            - "[% UNLESS ( loop.last ) %];[% END %]"
2228
            - "[% END %]"
2229
            - "[% END %]"
2230
            - "</span><br/>"
2231
            - "[% END %]"
2232
            - "[% SET biblioitem = biblio.biblioitem %]"
2233
            - "[% IF ( biblioitem.isbn ) %]"
2234
            - "<span>"
2235
            - "ISBN: [% FOREACH isbn IN biblioitem.isbn %]"
2236
            - "[% isbn | $raw %]"
2237
            - "[% UNLESS ( loop.last ) %]; [% END %]"
2238
            - "[% END %]"
2239
            - "</span><br/>"
2240
            - "[% END %]"
2241
            - "[% IF ( biblioitem.publishercode ) %]"
2242
            - "<span>"
2243
            - "Published by: [% biblioitem.publishercode | $raw %]"
2244
            - "[% IF ( biblioitem.publicationyear ) %]"
2245
            - "in [% biblioitem.publicationyear | $raw %]"
2246
            - "[% END %]"
2247
            - "[% IF ( biblioitem.pages ) %]"
2248
            - ", [% biblioitem.pages | $raw %]"
2249
            - "[% END %]"
2250
            - "</span><br/>"
2251
            - "[% END %]"
2252
            - "[% IF ( biblio.seriestitle ) %]"
2253
            - "<span>"
2254
            - "Collection: [% biblio.seriestitle | $raw %]"
2255
            - "</span><br/>"
2256
            - "[% END %]"
2257
            - "[% IF ( biblio.copyrightdate ) %]"
2258
            - "<span>"
2259
            - "Copyright year: [% biblio.copyrightdate | $raw %]"
2260
            - "</span><br/>"
2261
            - "[% END %]"
2262
            - "[% IF ( biblio.notes ) %]"
2263
            - "<span>"
2264
            - "Notes: [% biblio.notes | $raw %]"
2265
            - "</span><br/>"
2266
            - "[% END %]"
2267
            - "[% IF ( biblio.unititle ) %]"
2268
            - "<span>"
2269
            - "Unified title: [% biblio.unititle | $raw %]"
2270
            - "</span><br/>"
2271
            - "[% END %]"
2272
            - "[% IF ( biblio.serial ) %]"
2273
            - "<span>"
2274
            - "Serial: [% biblio.serial | $raw %]"
2275
            - "</span><br/>"
2276
            - "[% END %]"
2277
            - "[% IF ( biblioitem.lccn ) %]"
2278
            - "<span>"
2279
            - "LCCN: [% biblioitem.lccn | $raw %]"
2280
            - "</span><br/>"
2281
            - "[% END %]"
2282
            - "[% IF ( biblioitem.url ) %]"
2283
            - "<span>"
2284
            - "URL: [% biblioitem.url | html %]"
2285
            - "</span>"
2286
            - "[% END %]"
2287
            - "</p>"
2288
            - "[% SET OPACBaseURL = Koha.Preference('OPACBaseURL') %]"
2289
            - "[% IF ( OPACBaseURL ) %]"
2290
            - "<p>In online catalog: [% OPACBaseURL | $raw %]/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblio.biblionumber | html %]</p>"
2291
            - "[% END %]"
2292
            - "[% IF ( biblio.items.count > 0 ) %]"
2293
            - "<p>Items:"
2294
            - "<ul>"
2295
            - "[% FOREACH item IN biblio.items %]<li>"
2296
            - "[% item.holding_branch.branchname | $raw %]"
2297
            - "[% item.location | $raw %]"
2298
            - "[% IF item.itemcallnumber %]([% item.itemcallnumber | $raw %])[% END %]"
2299
            - "[% item.barcode | $raw %]"
2300
            - "</li>[% END %]"
2301
            - "</ul>"
2302
            - "</p>"
2303
            - "[% END %]"
2304
            - "<hr/>"
2305
            - "</li>"
2306
            - "[% END %]"
2307
            - "</ol>"
2308
2309
        - module: catalog
2310
          code: CART
2311
          branchcode: ""
2312
          name: "Send cart"
2313
          is_html: 1
2314
          title: "Your cart"
2315
          message_transport_type: email
2316
          lang: default
2317
          content:
2318
            - "[%- USE raw -%]"
2319
            - "<p>Hi,</p>"
2320
            - "<p>[% borrower.firstname | $raw %] [% borrower.surname | $raw %] sent you a cart from our online catalog.</p>"
2321
            - "<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>"
2322
            - "<hr/>"
2323
            - "<p>[% comment | $raw %]</p>"
2324
            - "<hr/>"
2325
            - "<ol>"
2326
            - "[% FOREACH biblio IN biblios %]"
2327
            - "<li>"
2328
            - "<span>"
2329
            - "[% biblio.title | $raw %]"
2330
            - "[% IF ( biblio.subtitle ) %]"
2331
            - "[% FOREACH subtitle IN biblio.subtitle.split(' | ') %]"
2332
            - "[% subtitle | $raw %]"
2333
            - "[% END %]"
2334
            - "[% END %]"
2335
            - "[% biblio.part_number | $raw %] [% biblio.part_name | $raw %]"
2336
            - "</span>"
2337
            - "<p>"
2338
            - "[% IF ( biblio.author || biblio.get_authors_from_MARC ) %]"
2339
            - "<span>Author(s): [% IF ( biblio.author ) %][% biblio.author | $raw %][% END %]"
2340
            - "[% IF ( biblio.get_authors_from_MARC ) %]"
2341
            - "[% IF ( biblio.author ) %]; [% END %]"
2342
            - "[% FOREACH author IN biblio.get_authors_from_MARC %]"
2343
            - "[% FOREACH subfield IN author.MARCAUTHOR_SUBFIELDS_LOOP %]"
2344
            - "[% subfield.separator | $raw %][% subfield.value | $raw %]"
2345
            - "[% END %]"
2346
            - "[% UNLESS ( loop.last ) %];[% END %]"
2347
            - "[% END %]"
2348
            - "[% END %]"
2349
            - "</span><br/>"
2350
            - "[% END %]"
2351
            - "[% SET biblioitem = biblio.biblioitem %]"
2352
            - "[% IF ( biblioitem.isbn ) %]"
2353
            - "<span>"
2354
            - "ISBN: [% FOREACH isbn IN biblioitem.isbn %]"
2355
            - "[% isbn | $raw %]"
2356
            - "[% UNLESS ( loop.last ) %]; [% END %]"
2357
            - "[% END %]"
2358
            - "</span><br/>"
2359
            - "[% END %]"
2360
            - "[% IF ( biblioitem.publishercode ) %]"
2361
            - "<span>"
2362
            - "Published by: [% biblioitem.publishercode | $raw %]"
2363
            - "[% IF ( biblioitem.publicationyear ) %]"
2364
            - "in [% biblioitem.publicationyear | $raw %]"
2365
            - "[% END %]"
2366
            - "[% IF ( biblioitem.pages ) %]"
2367
            - ", [% biblioitem.pages | $raw %]"
2368
            - "[% END %]"
2369
            - "</span><br/>"
2370
            - "[% END %]"
2371
            - "[% IF ( biblio.seriestitle ) %]"
2372
            - "<span>"
2373
            - "Collection: [% biblio.seriestitle | $raw %]"
2374
            - "</span><br/>"
2375
            - "[% END %]"
2376
            - "[% IF ( biblio.copyrightdate ) %]"
2377
            - "<span>"
2378
            - "Copyright year: [% biblio.copyrightdate | $raw %]"
2379
            - "</span><br/>"
2380
            - "[% END %]"
2381
            - "[% IF ( biblio.notes ) %]"
2382
            - "<span>"
2383
            - "Notes: [% biblio.notes | $raw %]"
2384
            - "</span><br/>"
2385
            - "[% END %]"
2386
            - "[% IF ( biblio.unititle ) %]"
2387
            - "<span>"
2388
            - "Unified title: [% biblio.unititle | $raw %]"
2389
            - "</span><br/>"
2390
            - "[% END %]"
2391
            - "[% IF ( biblio.serial ) %]"
2392
            - "<span>"
2393
            - "Serial: [% biblio.serial | $raw %]"
2394
            - "</span><br/>"
2395
            - "[% END %]"
2396
            - "[% IF ( biblioitem.lccn ) %]"
2397
            - "<span>"
2398
            - "LCCN: [% biblioitem.lccn | $raw %]"
2399
            - "</span><br/>"
2400
            - "[% END %]"
2401
            - "[% IF ( biblioitem.url ) %]"
2402
            - "<span>"
2403
            - "URL: [% biblioitem.url | html %]"
2404
            - "</span>"
2405
            - "[% END %]"
2406
            - "</p>"
2407
            - "[% SET OPACBaseURL = Koha.Preference('OPACBaseURL') %]"
2408
            - "[% IF ( OPACBaseURL ) %]"
2409
            - "<p>In online catalog: [% OPACBaseURL | $raw %]/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblio.biblionumber | html %]</p>"
2410
            - "[% END %]"
2411
            - "[% IF ( biblio.items.count > 0 ) %]"
2412
            - "<p>Items:"
2413
            - "<ul>"
2414
            - "[% FOREACH item IN biblio.items %]<li>"
2415
            - "[% item.holding_branch.branchname | $raw %]"
2416
            - "[% item.location | $raw %]"
2417
            - "[% IF item.itemcallnumber %]([% item.itemcallnumber | $raw %])[% END %]"
2418
            - "[% item.barcode | $raw %]"
2419
            - "</li>[% END %]"
2420
            - "</ul>"
2421
            - "</p>"
2422
            - "[% END %]"
2423
            - "<hr/>"
2424
            - "</li>"
2425
            - "[% END %]"
2426
            - "</ol>"
(-)a/opac/opac-sendbasket.pl (-111 / +42 lines)
Lines 53-180 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
        my ( $host, $relatedparts ) = $biblio->get_marc_host;
101
        $dat->{HOSTITEMENTRIES} = $host;
102
        $dat->{RELATEDPARTS} = $relatedparts;
103
104
        $iso2709 .= $record->as_usmarc();
105
106
        push( @results, $dat );
107
    }
108
109
    my $resultsarray = \@results;
110
    
111
    $template2->param(
112
        BIBLIO_RESULTS => $resultsarray,
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
67
148
    if ( !defined $iso2709 ) {
68
    if ( !defined $iso2709 ) {
149
        carp "Error sending mail: empty basket";
69
        carp "Error sending mail: empty basket";
150
        $template->param( error => 1 );
70
        $template->param( error => 1 );
151
    }
71
    } else {
152
    else {
72
        my %loops = (
153
        try {
73
            biblio => \@bibs,
154
            # if you want to use the KohaAdmin address as from, that is the default no need to set it
74
        );
155
            my $email = Koha::Email->create({
75
156
                to       => $email_add,
76
        my %substitute = (
157
                reply_to => $email_replyto,
77
            comment => $comment,
158
                subject  => $subject,
78
        );
159
            });
79
160
            $email->header( 'X-Abuse-Report' => C4::Context->preference('KohaAdminEmailAddress') );
80
        my $letter = C4::Letters::GetPreparedLetter(
161
            $email->text_body( $THE_body );
81
            module => 'catalog',
162
            $email->attach(
82
            letter_code => 'CART',
163
                Encode::encode( "UTF-8", $iso2709 ),
83
            lang => $patron->lang,
164
                content_type => 'application/octet-stream',
84
            tables => {
165
                name         => 'basket.iso2709',
85
                borrowers => $borrowernumber,
166
                disposition  => 'attachment',
86
            },
167
            );
87
            message_transport_type => 'email',
168
            my $library = $patron->library;
88
            loops => \%loops,
169
            $email->transport( $library->smtp_server->transport );
89
            substitute => \%substitute,
170
            $email->send_or_die;
90
        );
171
            $template->param( SENT => "1" );
91
172
        }
92
        my $attachment = {
173
        catch {
93
            filename => 'basket.iso2709',
174
            carp "Error sending mail: $_";
94
            type => 'application/octet-stream',
175
            $template->param( error => 1 );
95
            content => Encode::encode("UTF-8", $iso2709),
176
        };
96
        };
177
    }
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 );
178
109
179
    $template->param( email_add => $email_add );
110
    $template->param( email_add => $email_add );
180
    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 (-93 / +44 lines)
Lines 73-177 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
        my ( $host, $relatedparts ) = $biblio->get_marc_host;
106
        $dat->{HOSTITEMENTRIES} = $host;
107
        $dat->{RELATEDPARTS} = $relatedparts;
108
109
        $iso2709 .= $record->as_usmarc();
110
111
        push( @results, $dat );
112
    }
113
114
    $template2->param(
115
        BIBLIO_RESULTS => \@results,
116
        comment        => $comment,
117
        shelfname      => $shelf->shelfname,
118
        firstname      => $patron->firstname,
119
        surname        => $patron->surname,
120
    );
121
122
    # Getting template result
123
    my $template_res = $template2->output();
124
    my $body;
125
126
    my $subject;
127
    # Analysing information and getting mail properties
128
    if ( $template_res =~ /<SUBJECT>(?<subject>.*)<END_SUBJECT>/s ) {
129
        $subject = $+{subject};
130
        $subject =~ s|\n?(.*)\n?|$1|;
131
    }
132
    else {
133
        $subject = "no subject";
134
    }
135
136
    my $email_header = "";
137
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
138
        $email_header = $1;
139
        $email_header =~ s|\n?(.*)\n?|$1|;
140
    }
141
142
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
143
        $body = $1;
144
        $body =~ s|\n?(.*)\n?|$1|;
145
    }
146
83
147
    my $THE_body = <<END_OF_BODY;
84
    if ( !defined $iso2709 ) {
148
$email_header
85
        carp "Error sending mail: empty list";
149
$body
86
        $template->param( error => 1 );
150
END_OF_BODY
87
    } else {
151
88
         my %loops = (
152
    try {
89
             biblio => \@biblionumbers,
153
        my $email = Koha::Email->create(
90
         );
154
            {
91
155
                to      => $email,
92
         my %substitute = (
156
                subject => $subject,
93
             comment => $comment,
157
            }
94
             listname => $shelf->shelfname,
158
        );
95
         );
159
        $email->text_body( $THE_body );
96
160
        $email->attach(
97
        my $letter = C4::Letters::GetPreparedLetter(
161
            Encode::encode( "UTF-8", $iso2709 ),
98
            module => 'catalog',
162
            content_type => 'application/octet-stream',
99
            letter_code => 'LIST',
163
            name         => 'list.iso2709',
100
            lang => $patron->lang,
164
            disposition  => 'attachment',
101
            tables => {
102
                borrowers => $borrowernumber,
103
            },
104
            message_transport_type => 'email',
105
            loops => \%loops,
106
            substitute => \%substitute,
165
        );
107
        );
166
        my $library = Koha::Patrons->find( $borrowernumber )->library;
108
167
        $email->transport( $library->smtp_server->transport );
109
        my $attachment = {
168
        $email->send_or_die;
110
            filename => 'list.iso2709',
169
        $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 );
170
    }
125
    }
171
    catch {
172
        carp "Error sending mail: $_";
173
        $template->param( error => 1 );
174
    };
175
126
176
    $template->param(
127
    $template->param(
177
        shelfid => $shelfid,
128
        shelfid => $shelfid,
(-)a/virtualshelves/sendshelf.pl (-80 / +43 lines)
Lines 69-163 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
        my ( $host, $relatedparts ) = $biblio->get_marc_host;
94
        $dat->{HOSTITEMENTRIES} = $host;
95
        $dat->{RELATEDPARTS} = $relatedparts;
96
97
        $iso2709 .= $record->as_usmarc();
98
99
        push( @results, $dat );
100
    }
101
102
    $template2->param(
103
        BIBLIO_RESULTS => \@results,
104
        comment        => $comment,
105
        shelfname      => $shelf->shelfname,
106
    );
107
108
    # Getting template result
109
    my $template_res = $template2->output();
110
    my $body;
111
112
    my $subject;
113
    # Analysing information and getting mail properties
114
    if ( $template_res =~ /<SUBJECT>(?<subject>.*)<END_SUBJECT>/s ) {
115
        $subject = $+{subject};
116
        $subject =~ s|\n?(.*)\n?|$1|;
117
    }
118
    else {
119
        $subject = "no subject";
120
    }
121
122
    my $email_header = "";
123
    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
124
        $email_header = $1;
125
        $email_header =~ s|\n?(.*)\n?|$1|;
126
    }
127
82
128
    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
83
    if ( !defined $iso2709 ) {
129
        $body = $1;
84
        carp "Error sending mail: empty basket";
130
        $body =~ s|\n?(.*)\n?|$1|;
85
        $template->param( error => 1 );
131
    }
86
    } else {
87
        my %loops = (
88
            biblio => \@biblionumbers,
89
        );
132
90
133
    my $THE_body = <<END_OF_BODY;
91
        my %substitute = (
134
$email_header
92
            comment => $comment,
135
$body
93
            listname => $shelf->shelfname,
136
END_OF_BODY
137
138
    try {
139
        my $email = Koha::Email->create(
140
            {
141
                to      => $to_address,
142
                subject => $subject,
143
            }
144
        );
94
        );
145
        $email->text_body( $THE_body );
95
146
        $email->attach(
96
        my $letter = C4::Letters::GetPreparedLetter(
147
            Encode::encode("UTF-8", $iso2709),
97
            module => 'catalog',
148
            content_type => 'application/octet-stream',
98
            letter_code => 'LIST',
149
            name         => 'shelf.iso2709',
99
            lang => $patron->lang,
150
            disposition  => 'attachment',
100
            tables => {
101
                borrowers => $borrowernumber,
102
            },
103
            message_transport_type => 'email',
104
            loops => \%loops,
105
            substitute => \%substitute,
151
        );
106
        );
152
107
153
        my $library = Koha::Patrons->find( $borrowernumber )->library;
108
        my $attachment = {
154
        $email->send_or_die({ transport => $library->smtp_server->transport });
109
            filename => 'shelf.iso2709',
155
        $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 );
156
    }
124
    }
157
    catch {
158
        carp "Error sending mail: $_";
159
        $template->param( error => 1 );
160
    };
161
125
162
    $template->param( email => $to_address );
126
    $template->param( email => $to_address );
163
    output_html_with_http_headers $query, $cookie, $template->output;
127
    output_html_with_http_headers $query, $cookie, $template->output;
164
- 

Return to bug 3150