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;
40 my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
42 template_name => "opac-sendbasketform.tmpl",
46 flagsrequired => { borrow => 1 },
50 my $bib_list = $query->param('bib_list');
51 my $email_add = $query->param('email_add');
52 my $email_sender = $query->param('email_sender');
54 my $dbh = C4::Context->dbh;
57 my $email_from = C4::Context->preference('KohaAdminEmailAddress');
58 my $comment = $query->param('comment');
64 my ( $template2, $borrowernumber, $cookie ) = get_template_and_user(
66 template_name => "opac-sendbasket.tmpl",
70 flagsrequired => { borrow => 1 },
74 my @bibs = split( /\//, $bib_list );
77 my $marcflavour = C4::Context->preference('marcflavour');
78 foreach my $biblionumber (@bibs) {
79 $template2->param( biblionumber => $biblionumber );
81 my $dat = GetBiblioData($biblionumber);
82 my $record = GetMarcBiblio($biblionumber);
83 my $marcnotesarray = GetMarcNotes( $record, $marcflavour );
84 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
85 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
87 my @items = GetItemsInfo( $biblionumber );
90 if($dat->{'author'} || @$marcauthorsarray) {
95 $dat->{MARCNOTES} = $marcnotesarray;
96 $dat->{MARCSUBJCTS} = $marcsubjctsarray;
97 $dat->{MARCAUTHORS} = $marcauthorsarray;
98 $dat->{HASAUTHORS} = $hasauthors;
99 $dat->{'biblionumber'} = $biblionumber;
100 $dat->{ITEM_RESULTS} = \@items;
102 $iso2709 .= $record->as_usmarc();
104 push( @results, $dat );
107 my $resultsarray = \@results;
109 my $user = GetMember(borrowernumber => $borrowernumber);
112 BIBLIO_RESULTS => $resultsarray,
113 email_sender => $email_sender,
115 firstname => $user->{firstname},
116 surname => $user->{surname},
119 # Getting template result
120 my $template_res = $template2->output();
123 # Analysing information and getting mail properties
124 if ( $template_res =~ /<SUBJECT>\n(.*)\n?<END_SUBJECT>/s ) {
125 $mail{'subject'} = $1;
127 else { $mail{'subject'} = "no subject"; }
129 my $email_header = "";
130 if ( $template_res =~ /<HEADER>\n(.*)\n?<END_HEADER>/s ) {
134 my $email_file = "basket.txt";
135 if ( $template_res =~ /<FILENAME>\n(.*)\n?<END_FILENAME>/s ) {
139 if ( $template_res =~ /<MESSAGE>\n(.*)\n?<END_MESSAGE>/s ) {
143 my $boundary = "====" . time() . "====";
145 $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
146 my $isofile = encode_base64(encode("UTF-8", $iso2709));
147 $boundary = '--' . $boundary;
148 $mail{body} = <<END_OF_BODY;
151 Content-Type: text/plain; charset="UTF-8"
152 Content-Transfer-Encoding: quoted-printable
157 Content-Type: application/octet-stream; name="basket.iso2709"
158 Content-Transfer-Encoding: base64
159 Content-Disposition: attachment; filename="basket.iso2709"
166 if ( sendmail %mail ) {
167 # do something if it works....
168 $template->param( SENT => "1" );
171 # do something if it doesnt work....
172 carp "Error sending mail: $Mail::Sendmail::error \n";
173 $template->param( error => 1 );
175 $template->param( email_add => $email_add );
176 output_html_with_http_headers $query, $cookie, $template->output;
179 $template->param( bib_list => $bib_list );
181 url => "/cgi-bin/koha/opac-sendbasket.pl",
182 suggestion => C4::Context->preference("suggestion"),
183 virtualshelves => C4::Context->preference("virtualshelves"),
185 output_html_with_http_headers $query, $cookie, $template->output;