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 $email_from = C4::Context->preference('KohaAdminEmailAddress');
57 my $comment = $query->param('comment');
63 my ( $template2, $borrowernumber, $cookie ) = get_template_and_user(
65 template_name => "opac-sendbasket.tmpl",
69 flagsrequired => { borrow => 1 },
73 my @bibs = split( /\//, $bib_list );
76 my $marcflavour = C4::Context->preference('marcflavour');
77 foreach my $biblionumber (@bibs) {
78 $template2->param( biblionumber => $biblionumber );
80 my $dat = GetBiblioData($biblionumber);
81 my $record = GetMarcBiblio($biblionumber);
82 my $marcnotesarray = GetMarcNotes( $record, $marcflavour );
83 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
84 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
86 my @items = GetItemsInfo( $biblionumber );
89 if($dat->{'author'} || @$marcauthorsarray) {
94 $dat->{MARCNOTES} = $marcnotesarray;
95 $dat->{MARCSUBJCTS} = $marcsubjctsarray;
96 $dat->{MARCAUTHORS} = $marcauthorsarray;
97 $dat->{HASAUTHORS} = $hasauthors;
98 $dat->{'biblionumber'} = $biblionumber;
99 $dat->{ITEM_RESULTS} = \@items;
101 $iso2709 .= $record->as_usmarc();
103 push( @results, $dat );
106 my $resultsarray = \@results;
108 my $user = GetMember(borrowernumber => $borrowernumber);
111 BIBLIO_RESULTS => $resultsarray,
112 email_sender => $email_sender,
114 firstname => $user->{firstname},
115 surname => $user->{surname},
118 # Getting template result
119 my $template_res = $template2->output();
122 # Analysing information and getting mail properties
123 if ( $template_res =~ /<SUBJECT>\n(.*)\n?<END_SUBJECT>/s ) {
124 $mail{'subject'} = $1;
126 else { $mail{'subject'} = "no subject"; }
128 my $email_header = "";
129 if ( $template_res =~ /<HEADER>\n(.*)\n?<END_HEADER>/s ) {
133 my $email_file = "basket.txt";
134 if ( $template_res =~ /<FILENAME>\n(.*)\n?<END_FILENAME>/s ) {
138 if ( $template_res =~ /<MESSAGE>\n(.*)\n?<END_MESSAGE>/s ) {
142 my $boundary = "====" . time() . "====";
144 $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
145 my $isofile = encode_base64(encode("UTF-8", $iso2709));
146 $boundary = '--' . $boundary;
147 $mail{body} = <<END_OF_BODY;
150 Content-Type: text/plain; charset="UTF-8"
151 Content-Transfer-Encoding: quoted-printable
156 Content-Type: application/octet-stream; name="basket.iso2709"
157 Content-Transfer-Encoding: base64
158 Content-Disposition: attachment; filename="basket.iso2709"
165 if ( sendmail %mail ) {
166 # do something if it works....
167 $template->param( SENT => "1" );
170 # do something if it doesnt work....
171 carp "Error sending mail: $Mail::Sendmail::error \n";
172 $template->param( error => 1 );
174 $template->param( email_add => $email_add );
175 output_html_with_http_headers $query, $cookie, $template->output;
178 $template->param( bib_list => $bib_list );
180 url => "/cgi-bin/koha/opac-sendbasket.pl",
181 suggestion => C4::Context->preference("suggestion"),
182 virtualshelves => C4::Context->preference("virtualshelves"),
184 output_html_with_http_headers $query, $cookie, $template->output;