3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
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
=> { borrow
=> 1 },
47 my $bib_list = $query->param('bib_list');
48 my $email_add = $query->param('email_add');
49 my $email_sender = $query->param('email_sender');
51 my $dbh = C4
::Context
->dbh;
54 my $email = Koha
::Email
->new();
55 my %mail = $email->create_message_headers({ to
=> $email_add });
56 my $comment = $query->param('comment');
57 my ( $template2, $borrowernumber, $cookie ) = get_template_and_user
(
59 template_name
=> "basket/sendbasket.tt",
63 flagsrequired
=> { borrow
=> 1 },
67 my @bibs = split( /\//, $bib_list );
70 my $marcflavour = C4
::Context
->preference('marcflavour');
71 foreach my $biblionumber (@bibs) {
72 $template2->param( biblionumber
=> $biblionumber );
74 my $dat = GetBiblioData
($biblionumber);
75 my $record = GetMarcBiblio
($biblionumber);
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,
103 email_sender
=> $email_sender,
107 # Getting template result
108 my $template_res = $template2->output();
111 # Analysing information and getting mail properties
112 if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
114 $mail{subject
} =~ s
|\n?
(.*)\n?
|$1|;
115 $mail{subject
} = Encode
::encode
("UTF-8", $mail{subject
});
117 else { $mail{'subject'} = "no subject"; }
119 my $email_header = "";
120 if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
122 $email_header =~ s
|\n?
(.*)\n?
|$1|;
123 $email_header = encode_qp
(Encode
::encode
("UTF-8", $email_header));
126 my $email_file = "basket.txt";
127 if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) {
129 $email_file =~ s
|\n?
(.*)\n?
|$1|;
132 if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
134 $body =~ s
|\n?
(.*)\n?
|$1|;
135 $body = encode_qp
(Encode
::encode
("UTF-8", $body));
138 my $boundary = "====" . time() . "====";
141 $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
142 my $isofile = encode_base64
(encode
("UTF-8", $iso2709));
143 $boundary = '--' . $boundary;
144 $mail{body
} = <<END_OF_BODY;
146 Content-Type: text/plain; charset="utf-8"
147 Content-Transfer-Encoding: quoted-printable
152 Content-Type: application/octet-stream; name="basket.iso2709"
153 Content-Transfer-Encoding: base64
154 Content-Disposition: attachment; filename="basket.iso2709"
161 if ( sendmail %mail ) {
162 # do something if it works....
163 $template->param( SENT => "1" );
166 # do something if it doesnt work....
167 carp "Error sending mail: $Mail::Sendmail::error \n";
168 $template->param( error => 1 );
170 $template->param( email_add => $email_add );
171 output_html_with_http_headers $query, $cookie, $template->output;
174 $template->param( bib_list => $bib_list );
176 url => "/cgi-bin/koha/basket/sendbasket.pl",
177 suggestion => C4::Context->preference("suggestion"),
178 virtualshelves => C4::Context->preference("virtualshelves"),
180 output_html_with_http_headers $query, $cookie, $template->output;