3 # Copyright Doxulting 2004
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 use Encode qw(encode);
28 use MIME::QuotedPrint;
39 my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
41 template_name => "opac-sendbasketform.tmpl",
45 flagsrequired => { borrow => 1 },
49 my $bib_list = $query->param('bib_list');
50 my $email_add = $query->param('email_add');
51 my $email_sender = $query->param('email_sender');
53 my $dbh = C4::Context->dbh;
56 my $user = GetMember(borrowernumber => $borrowernumber);
57 my $user_email = GetFirstValidEmailAddress($borrowernumber)
58 || C4::Context->preference('KohaAdminEmailAddress');
60 my $email_from = C4::Context->preference('KohaAdminEmailAddress');
61 my $email_replyto = "$user->{firstname} $user->{surname} <$user_email>";
62 my $comment = $query->param('comment');
66 'Reply-To' => $email_replyto,
67 # 'X-Orig-IP' => $ENV{'REMOTE_ADDR'},
68 # FIXME Commented out for now: discussion on privacy issue
69 'X-Abuse-Report' => C4::Context->preference('KohaAdminEmailAddress'),
72 my ( $template2, $borrowernumber, $cookie ) = get_template_and_user(
74 template_name => "opac-sendbasket.tmpl",
78 flagsrequired => { borrow => 1 },
82 my @bibs = split( /\//, $bib_list );
85 my $marcflavour = C4::Context->preference('marcflavour');
86 foreach my $biblionumber (@bibs) {
87 $template2->param( biblionumber => $biblionumber );
89 my $dat = GetBiblioData($biblionumber);
90 my $record = GetMarcBiblio($biblionumber);
91 my $marcnotesarray = GetMarcNotes( $record, $marcflavour );
92 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
93 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
95 my @items = GetItemsInfo( $biblionumber );
98 if($dat->{'author'} || @$marcauthorsarray) {
103 $dat->{MARCNOTES} = $marcnotesarray;
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,
119 email_sender => $email_sender,
121 firstname => $user->{firstname},
122 surname => $user->{surname},
125 # Getting template result
126 my $template_res = $template2->output();
129 # Analysing information and getting mail properties
131 if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
133 $mail{subject} =~ s|\n?(.*)\n?|$1|;
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|;
143 my $email_file = "basket.txt";
144 if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) {
146 $email_file =~ s|\n?(.*)\n?|$1|;
149 if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
151 $body =~ s|\n?(.*)\n?|$1|;
152 $body = encode("UTF-8", encode_qp($body));
157 my $boundary = "====" . time() . "====";
159 $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
160 my $isofile = encode_base64(encode("UTF-8", $iso2709));
161 $boundary = '--' . $boundary;
162 $mail{body} = <<END_OF_BODY;
165 Content-Type: text/plain; charset="UTF-8"
166 Content-Transfer-Encoding: quoted-printable
171 Content-Type: application/octet-stream; name="basket.iso2709"
172 Content-Transfer-Encoding: base64
173 Content-Disposition: attachment; filename="basket.iso2709"
179 # Sending mail (if not empty basket)
180 if ( defined($iso2709) && sendmail %mail ) {
181 # do something if it works....
182 $template->param( SENT => "1" );
185 # do something if it doesnt work....
186 carp "Error sending mail: empty basket" if !defined($iso2709);
187 carp "Error sending mail: $Mail::Sendmail::error" if $Mail::Sendmail::error;
188 $template->param( error => 1 );
190 $template->param( email_add => $email_add );
191 output_html_with_http_headers $query, $cookie, $template->output;
194 $template->param( bib_list => $bib_list );
196 url => "/cgi-bin/koha/opac-sendbasket.pl",
197 suggestion => C4::Context->preference("suggestion"),
198 virtualshelves => C4::Context->preference("virtualshelves"),
200 output_html_with_http_headers $query, $cookie, $template->output;