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>.
23 use Encode
qw(encode);
26 use MIME
::QuotedPrint
;
41 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
43 template_name
=> "opac-sendbasketform.tt",
50 my $bib_list = $query->param('bib_list') || '';
51 my $email_add = $query->param('email_add');
53 my $dbh = C4
::Context
->dbh;
56 die "Wrong CSRF token" unless Koha
::Token
->new->check_csrf({
57 session_id
=> scalar $query->cookie('CGISESSID'),
58 token
=> scalar $query->param('csrf_token'),
60 my $email = Koha
::Email
->new();
61 my $patron = Koha
::Patrons
->find( $borrowernumber );
62 my $user_email = $patron->first_valid_email_address
63 || C4
::Context
->preference('KohaAdminEmailAddress');
65 my $email_replyto = $patron->firstname . " " . $patron->surname . " <$user_email>";
66 my $comment = $query->param('comment');
68 # if you want to use the KohaAdmin address as from, that is the default no need to set it
69 my %mail = $email->create_message_headers({
71 replyto
=> $email_replyto,
73 $mail{'X-Abuse-Report'} = C4
::Context
->preference('KohaAdminEmailAddress');
75 # Since we are already logged in, no need to check credentials again
76 # when loading a second template.
77 my $template2 = C4
::Templates
::gettemplate
(
78 'opac-sendbasket.tt', 'opac', $query,
81 my @bibs = split( /\//, $bib_list );
84 my $marcflavour = C4
::Context
->preference('marcflavour');
85 foreach my $biblionumber (@bibs) {
86 $template2->param( biblionumber
=> $biblionumber );
88 my $dat = GetBiblioData
($biblionumber);
90 my $record = GetMarcBiblio
({
91 biblionumber
=> $biblionumber,
93 my $marcauthorsarray = GetMarcAuthors
( $record, $marcflavour );
94 my $marcsubjctsarray = GetMarcSubjects
( $record, $marcflavour );
96 my @items = GetItemsInfo
( $biblionumber );
99 if($dat->{'author'} || @
$marcauthorsarray) {
104 $dat->{MARCSUBJCTS
} = $marcsubjctsarray;
105 $dat->{MARCAUTHORS
} = $marcauthorsarray;
106 $dat->{HASAUTHORS
} = $hasauthors;
107 $dat->{'biblionumber'} = $biblionumber;
108 $dat->{ITEM_RESULTS
} = \
@items;
110 $iso2709 .= $record->as_usmarc();
112 push( @results, $dat );
115 my $resultsarray = \
@results;
118 BIBLIO_RESULTS
=> $resultsarray,
120 firstname
=> $patron->firstname,
121 surname
=> $patron->surname,
124 # Getting template result
125 my $template_res = $template2->output();
128 # Analysing information and getting mail properties
130 if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
132 $mail{subject
} =~ s
|\n?
(.*)\n?
|$1|;
133 $mail{subject
} = Encode
::encode
("UTF-8", $mail{subject
});
135 else { $mail{'subject'} = "no subject"; }
137 my $email_header = "";
138 if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
140 $email_header =~ s
|\n?
(.*)\n?
|$1|;
141 $email_header = encode_qp
(Encode
::encode
("UTF-8", $email_header));
144 my $email_file = "basket.txt";
145 if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) {
147 $email_file =~ s
|\n?
(.*)\n?
|$1|;
150 if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
152 $body =~ s
|\n?
(.*)\n?
|$1|;
153 $body = encode_qp
(Encode
::encode
("UTF-8", $body));
158 my $boundary = "====" . time() . "====";
160 $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
161 my $isofile = encode_base64
(encode
("UTF-8", $iso2709));
162 $boundary = '--' . $boundary;
163 $mail{body
} = <<END_OF_BODY;
166 Content-Type: text/plain; charset="UTF-8"
167 Content-Transfer-Encoding: quoted-printable
172 Content-Type: application/octet-stream; name="basket.iso2709"
173 Content-Transfer-Encoding: base64
174 Content-Disposition: attachment; filename="basket.iso2709"
180 # Sending mail (if not empty basket)
181 if ( defined($iso2709) && sendmail %mail ) {
182 # do something if it works....
183 $template->param( SENT => "1" );
186 # do something if it doesnt work....
187 carp "Error sending mail: empty basket" if !defined($iso2709);
188 carp "Error sending mail: $Mail::Sendmail::error" if $Mail::Sendmail::error;
189 $template->param( error => 1 );
191 $template->param( email_add => $email_add );
192 output_html_with_http_headers $query, $cookie, $template->output;
196 bib_list => $bib_list,
197 url => "/cgi-bin/koha/opac-sendbasket.pl",
198 suggestion => C4::Context->preference("suggestion"),
199 virtualshelves => C4::Context->preference("virtualshelves"),
200 csrf_token => Koha::Token->new->generate_csrf(
201 { session_id => scalar $query->cookie('CGISESSID'), } ),
203 output_html_with_http_headers $query, $cookie, $template->output;