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>.
21 use Encode qw(encode);
25 use MIME::QuotedPrint;
36 my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
38 template_name => "basket/sendbasketform.tt",
42 flagsrequired => { catalogue => 1 },
46 my $bib_list = $query->param('bib_list');
47 my $email_add = $query->param('email_add');
49 my $dbh = C4::Context->dbh;
52 my $email = Koha::Email->new();
53 my %mail = $email->create_message_headers({ to => $email_add });
54 my $comment = $query->param('comment');
56 # Since we are already logged in, no need to check credentials again
57 # We only need to add OPACBaseURL
58 my $template2 = C4::Templates::gettemplate(
59 'basket/sendbasket.tt', 'intranet', $query,
61 $template2->param( OPACBaseURL => C4::Context->preference('OPACBaseURL') );
63 my @bibs = split( /\//, $bib_list );
66 my $marcflavour = C4::Context->preference('marcflavour');
67 foreach my $biblionumber (@bibs) {
68 $template2->param( biblionumber => $biblionumber );
70 my $dat = GetBiblioData($biblionumber);
72 my $record = GetMarcBiblio($biblionumber, 1);
73 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
74 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
76 my @items = GetItemsInfo( $biblionumber );
79 if($dat->{'author'} || @$marcauthorsarray) {
84 $dat->{MARCSUBJCTS} = $marcsubjctsarray;
85 $dat->{MARCAUTHORS} = $marcauthorsarray;
86 $dat->{HASAUTHORS} = $hasauthors;
87 $dat->{'biblionumber'} = $biblionumber;
88 $dat->{ITEM_RESULTS} = \@items;
90 $iso2709 .= $record->as_usmarc();
92 push( @results, $dat );
95 my $resultsarray = \@results;
97 BIBLIO_RESULTS => $resultsarray,
101 # Getting template result
102 my $template_res = $template2->output();
105 # Analysing information and getting mail properties
106 if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
108 $mail{subject} =~ s|\n?(.*)\n?|$1|;
109 $mail{subject} = Encode::encode("UTF-8", $mail{subject});
111 else { $mail{'subject'} = "no subject"; }
113 my $email_header = "";
114 if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
116 $email_header =~ s|\n?(.*)\n?|$1|;
117 $email_header = encode_qp(Encode::encode("UTF-8", $email_header));
120 my $email_file = "basket.txt";
121 if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) {
123 $email_file =~ s|\n?(.*)\n?|$1|;
126 if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
128 $body =~ s|\n?(.*)\n?|$1|;
129 $body = encode_qp(Encode::encode("UTF-8", $body));
132 my $boundary = "====" . time() . "====";
135 $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
136 my $isofile = encode_base64(encode("UTF-8", $iso2709));
137 $boundary = '--' . $boundary;
138 $mail{body} = <<END_OF_BODY;
140 Content-Type: text/plain; charset="utf-8"
141 Content-Transfer-Encoding: quoted-printable
146 Content-Type: application/octet-stream; name="basket.iso2709"
147 Content-Transfer-Encoding: base64
148 Content-Disposition: attachment; filename="basket.iso2709"
155 if ( sendmail %mail ) {
156 # do something if it works....
157 $template->param( SENT => "1" );
160 # do something if it doesnt work....
161 carp "Error sending mail: $Mail::Sendmail::error \n";
162 $template->param( error => 1 );
164 $template->param( email_add => $email_add );
165 output_html_with_http_headers $query, $cookie, $template->output;
168 $template->param( bib_list => $bib_list );
170 url => "/cgi-bin/koha/basket/sendbasket.pl",
171 suggestion => C4::Context->preference("suggestion"),
172 virtualshelves => C4::Context->preference("virtualshelves"),
174 output_html_with_http_headers $query, $cookie, $template->output;