3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use Encode
qw(encode);
26 use MIME
::QuotedPrint
;
37 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
39 template_name
=> "basket/sendbasketform.tt",
43 flagsrequired
=> { catalogue
=> 1 },
47 my $bib_list = $query->param('bib_list');
48 my $email_add = $query->param('email_add');
50 my $dbh = C4
::Context
->dbh;
53 my $email = Koha
::Email
->new();
54 my %mail = $email->create_message_headers({ to
=> $email_add });
55 my $comment = $query->param('comment');
56 my ( $template2, $borrowernumber, $cookie ) = get_template_and_user
(
58 template_name
=> "basket/sendbasket.tt",
62 flagsrequired
=> { catalogue
=> 1 },
66 my @bibs = split( /\//, $bib_list );
69 my $marcflavour = C4
::Context
->preference('marcflavour');
70 foreach my $biblionumber (@bibs) {
71 $template2->param( biblionumber
=> $biblionumber );
73 my $dat = GetBiblioData
($biblionumber);
75 my $record = GetMarcBiblio
($biblionumber, 1);
76 my $marcnotesarray = GetMarcNotes
( $record, $marcflavour );
77 my $marcauthorsarray = GetMarcAuthors
( $record, $marcflavour );
78 my $marcsubjctsarray = GetMarcSubjects
( $record, $marcflavour );
80 my @items = GetItemsInfo
( $biblionumber );
83 if($dat->{'author'} || @
$marcauthorsarray) {
88 $dat->{MARCNOTES
} = $marcnotesarray;
89 $dat->{MARCSUBJCTS
} = $marcsubjctsarray;
90 $dat->{MARCAUTHORS
} = $marcauthorsarray;
91 $dat->{HASAUTHORS
} = $hasauthors;
92 $dat->{'biblionumber'} = $biblionumber;
93 $dat->{ITEM_RESULTS
} = \
@items;
95 $iso2709 .= $record->as_usmarc();
97 push( @results, $dat );
100 my $resultsarray = \
@results;
102 BIBLIO_RESULTS
=> $resultsarray,
106 # Getting template result
107 my $template_res = $template2->output();
110 # Analysing information and getting mail properties
111 if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
113 $mail{subject
} =~ s
|\n?
(.*)\n?
|$1|;
114 $mail{subject
} = Encode
::encode
("UTF-8", $mail{subject
});
116 else { $mail{'subject'} = "no subject"; }
118 my $email_header = "";
119 if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
121 $email_header =~ s
|\n?
(.*)\n?
|$1|;
122 $email_header = encode_qp
(Encode
::encode
("UTF-8", $email_header));
125 my $email_file = "basket.txt";
126 if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) {
128 $email_file =~ s
|\n?
(.*)\n?
|$1|;
131 if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
133 $body =~ s
|\n?
(.*)\n?
|$1|;
134 $body = encode_qp
(Encode
::encode
("UTF-8", $body));
137 my $boundary = "====" . time() . "====";
140 $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
141 my $isofile = encode_base64
(encode
("UTF-8", $iso2709));
142 $boundary = '--' . $boundary;
143 $mail{body
} = <<END_OF_BODY;
145 Content-Type: text/plain; charset="utf-8"
146 Content-Transfer-Encoding: quoted-printable
151 Content-Type: application/octet-stream; name="basket.iso2709"
152 Content-Transfer-Encoding: base64
153 Content-Disposition: attachment; filename="basket.iso2709"
160 if ( sendmail %mail ) {
161 # do something if it works....
162 $template->param( SENT => "1" );
165 # do something if it doesnt work....
166 carp "Error sending mail: $Mail::Sendmail::error \n";
167 $template->param( error => 1 );
169 $template->param( email_add => $email_add );
170 output_html_with_http_headers $query, $cookie, $template->output;
173 $template->param( bib_list => $bib_list );
175 url => "/cgi-bin/koha/basket/sendbasket.pl",
176 suggestion => C4::Context->preference("suggestion"),
177 virtualshelves => C4::Context->preference("virtualshelves"),
179 output_html_with_http_headers $query, $cookie, $template->output;