3 # Copyright Doxulting 2004
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
25 use Try::Tiny qw( catch try );
30 use C4::Auth qw( get_template_and_user );
31 use C4::Output qw( output_html_with_http_headers );
40 my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
42 template_name => "opac-sendbasketform.tt",
48 my $bib_list = $query->param('bib_list') || '';
49 my $email_add = $query->param('email_add');
52 die "Wrong CSRF token" unless Koha::Token->new->check_csrf({
53 session_id => scalar $query->cookie('CGISESSID'),
54 token => scalar $query->param('csrf_token'),
57 my $patron = Koha::Patrons->find( $borrowernumber );
58 my $user_email = $patron->first_valid_email_address;
60 my $comment = $query->param('comment');
62 my @bibs = split( /\//, $bib_list );
64 foreach my $bib ( @bibs ) {
65 my $biblio = Koha::Biblios->find( $bib ) or next;
66 $iso2709 .= $biblio->metadata->record->as_usmarc();
69 if ( !defined $iso2709 ) {
70 carp "Error sending mail: empty basket";
71 $template->param( error => 1 );
72 } elsif ( !defined $user_email or $user_email eq '' ) {
73 carp "Error sending mail: sender's email address is invalid";
74 $template->param( error => 1 );
84 my $letter = C4::Letters::GetPreparedLetter(
85 module => 'catalogue',
86 letter_code => 'CART',
87 lang => $patron->lang,
89 borrowers => $borrowernumber,
91 message_transport_type => 'email',
93 substitute => \%substitute,
97 filename => 'basket.iso2709',
98 type => 'application/octet-stream',
99 content => Encode::encode("UTF-8", $iso2709),
102 C4::Letters::EnqueueLetter({
104 message_transport_type => 'email',
105 to_address => $email_add,
106 reply_address => $user_email,
107 attachments => [$attachment],
110 $template->param( SENT => 1 );
113 $template->param( email_add => $email_add );
114 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
117 my $new_session_id = $query->cookie('CGISESSID');
119 bib_list => $bib_list,
120 url => "/cgi-bin/koha/opac-sendbasket.pl",
121 suggestion => C4::Context->preference("suggestion"),
122 virtualshelves => C4::Context->preference("virtualshelves"),
123 csrf_token => Koha::Token->new->generate_csrf(
124 { session_id => $new_session_id, } ),
126 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };