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>.
24 use Encode
qw(encode);
28 use MIME
::QuotedPrint
;
40 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
42 template_name
=> "opac-sendbasketform.tt",
49 my $bib_list = $query->param('bib_list');
50 my $email_add = $query->param('email_add');
52 my $dbh = C4
::Context
->dbh;
55 my $email = Koha
::Email
->new();
56 my $user = GetMember
(borrowernumber
=> $borrowernumber);
57 my $user_email = GetFirstValidEmailAddress
($borrowernumber)
58 || C4
::Context
->preference('KohaAdminEmailAddress');
60 my $email_replyto = "$user->{firstname} $user->{surname} <$user_email>";
61 my $comment = $query->param('comment');
63 # if you want to use the KohaAdmin address as from, that is the default no need to set it
64 my %mail = $email->create_message_headers({
66 replyto
=> $email_replyto,
68 $mail{'X-Abuse-Report'} = C4
::Context
->preference('KohaAdminEmailAddress');
70 my ( $template2, $borrowernumber, $cookie ) = get_template_and_user
(
72 template_name
=> "opac-sendbasket.tt",
79 my @bibs = split( /\//, $bib_list );
82 my $marcflavour = C4
::Context
->preference('marcflavour');
83 foreach my $biblionumber (@bibs) {
84 $template2->param( biblionumber
=> $biblionumber );
86 my $dat = GetBiblioData
($biblionumber);
88 my $record = GetMarcBiblio
($biblionumber, 1);
89 my $marcnotesarray = GetMarcNotes
( $record, $marcflavour );
90 my $marcauthorsarray = GetMarcAuthors
( $record, $marcflavour );
91 my $marcsubjctsarray = GetMarcSubjects
( $record, $marcflavour );
93 my @items = GetItemsInfo
( $biblionumber );
96 if($dat->{'author'} || @
$marcauthorsarray) {
101 $dat->{MARCNOTES
} = $marcnotesarray;
102 $dat->{MARCSUBJCTS
} = $marcsubjctsarray;
103 $dat->{MARCAUTHORS
} = $marcauthorsarray;
104 $dat->{HASAUTHORS
} = $hasauthors;
105 $dat->{'biblionumber'} = $biblionumber;
106 $dat->{ITEM_RESULTS
} = \
@items;
108 $iso2709 .= $record->as_usmarc();
110 push( @results, $dat );
113 my $resultsarray = \
@results;
116 BIBLIO_RESULTS
=> $resultsarray,
118 firstname
=> $user->{firstname
},
119 surname
=> $user->{surname
},
122 # Getting template result
123 my $template_res = $template2->output();
126 # Analysing information and getting mail properties
128 if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
130 $mail{subject
} =~ s
|\n?
(.*)\n?
|$1|;
131 $mail{subject
} = Encode
::encode
("UTF-8", $mail{subject
});
133 else { $mail{'subject'} = "no subject"; }
135 my $email_header = "";
136 if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
138 $email_header =~ s
|\n?
(.*)\n?
|$1|;
139 $email_header = encode_qp
(Encode
::encode
("UTF-8", $email_header));
142 my $email_file = "basket.txt";
143 if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) {
145 $email_file =~ s
|\n?
(.*)\n?
|$1|;
148 if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
150 $body =~ s
|\n?
(.*)\n?
|$1|;
151 $body = encode_qp
(Encode
::encode
("UTF-8", $body));
156 my $boundary = "====" . time() . "====";
158 $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
159 my $isofile = encode_base64
(encode
("UTF-8", $iso2709));
160 $boundary = '--' . $boundary;
161 $mail{body
} = <<END_OF_BODY;
164 Content-Type: text/plain; charset="UTF-8"
165 Content-Transfer-Encoding: quoted-printable
170 Content-Type: application/octet-stream; name="basket.iso2709"
171 Content-Transfer-Encoding: base64
172 Content-Disposition: attachment; filename="basket.iso2709"
178 # Sending mail (if not empty basket)
179 if ( defined($iso2709) && sendmail %mail ) {
180 # do something if it works....
181 $template->param( SENT => "1" );
184 # do something if it doesnt work....
185 carp "Error sending mail: empty basket" if !defined($iso2709);
186 carp "Error sending mail: $Mail::Sendmail::error" if $Mail::Sendmail::error;
187 $template->param( error => 1 );
189 $template->param( email_add => $email_add );
190 output_html_with_http_headers $query, $cookie, $template->output;
193 $template->param( bib_list => $bib_list );
195 url => "/cgi-bin/koha/opac-sendbasket.pl",
196 suggestion => C4::Context->preference("suggestion"),
197 virtualshelves => C4::Context->preference("virtualshelves"),
199 output_html_with_http_headers $query, $cookie, $template->output;