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 => "opac-sendbasketform.tmpl",
42 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
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_from = C4::Context->preference('KohaAdminEmailAddress');
55 my $comment = $query->param('comment');
61 my ( $template2, $borrowernumber, $cookie ) = get_template_and_user(
63 template_name => "opac-sendbasket.tmpl",
67 flagsrequired => { borrow => 1 },
71 my @bibs = split( /\//, $bib_list );
74 my $marcflavour = C4::Context->preference('marcflavour');
75 foreach my $biblionumber (@bibs) {
76 $template2->param( biblionumber => $biblionumber );
78 my $dat = GetBiblioData($biblionumber);
79 my $record = GetMarcBiblio($biblionumber);
80 my $marcnotesarray = GetMarcNotes( $record, $marcflavour );
81 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
82 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
84 my @items = &GetItemsInfo( $biblionumber, 'opac' );
87 if($dat->{'author'} || @$marcauthorsarray) {
92 $dat->{MARCNOTES} = $marcnotesarray;
93 $dat->{MARCSUBJCTS} = $marcsubjctsarray;
94 $dat->{MARCAUTHORS} = $marcauthorsarray;
95 $dat->{HASAUTHORS} = $hasauthors;
96 $dat->{'biblionumber'} = $biblionumber;
97 $dat->{ITEM_RESULTS} = \@items;
99 $iso2709 .= $record->as_usmarc();
101 push( @results, $dat );
104 my $resultsarray = \@results;
106 my $user = GetMember(borrowernumber => $borrowernumber);
109 BIBLIO_RESULTS => $resultsarray,
110 email_sender => $email_sender,
112 firstname => $user->{firstname},
113 surname => $user->{surname},
116 # Getting template result
117 my $template_res = $template2->output();
120 # Analysing information and getting mail properties
121 if ( $template_res =~ /<SUBJECT>\n(.*)\n<END_SUBJECT>/s ) {
122 $mail{'subject'} = $1;
124 else { $mail{'subject'} = "no subject"; }
126 my $email_header = "";
127 if ( $template_res =~ /<HEADER>\n(.*)\n<END_HEADER>/s ) {
131 my $email_file = "basket.txt";
132 if ( $template_res =~ /<FILENAME>\n(.*)\n<END_FILENAME>/s ) {
136 if ( $template_res =~ /<MESSAGE>\n(.*)\n<END_MESSAGE>/s ) { $body = encode_qp($1); }
138 my $boundary = "====" . time() . "====";
140 # $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
142 # $email_header = encode_qp($email_header);
144 # $boundary = "--".$boundary;
148 $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
149 my $isofile = encode_base64(encode("UTF-8", $iso2709));
150 $boundary = '--' . $boundary;
151 $mail{body} = <<END_OF_BODY;
153 Content-Type: text/plain; charset="utf-8"
154 Content-Transfer-Encoding: quoted-printable
159 Content-Type: application/octet-stream; name="basket.iso2709"
160 Content-Transfer-Encoding: base64
161 Content-Disposition: attachment; filename="basket.iso2709"
168 if ( sendmail %mail ) {
169 # do something if it works....
170 $template->param( SENT => "1" );
173 # do something if it doesnt work....
174 carp "Error sending mail: $Mail::Sendmail::error \n";
175 $template->param( error => 1 );
177 $template->param( email_add => $email_add );
178 output_html_with_http_headers $query, $cookie, $template->output;
181 $template->param( bib_list => $bib_list );
183 url => "/cgi-bin/koha/opac-sendbasket.pl",
184 suggestion => C4::Context->preference("suggestion"),
185 virtualshelves => C4::Context->preference("virtualshelves"),
187 output_html_with_http_headers $query, $cookie, $template->output;