3 # Copyright Doxulting 2004
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 use Encode qw(encode);
27 use MIME::QuotedPrint;
39 my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
41 template_name => "opac-sendbasketform.tt",
48 my $bib_list = $query->param('bib_list');
49 my $email_add = $query->param('email_add');
51 my $dbh = C4::Context->dbh;
54 my $email = Koha::Email->new();
55 my $user = GetMember(borrowernumber => $borrowernumber);
56 my $user_email = GetFirstValidEmailAddress($borrowernumber)
57 || C4::Context->preference('KohaAdminEmailAddress');
59 my $email_replyto = "$user->{firstname} $user->{surname} <$user_email>";
60 my $comment = $query->param('comment');
62 # if you want to use the KohaAdmin address as from, that is the default no need to set it
63 my %mail = $email->create_message_headers({
65 replyto => $email_replyto,
67 $mail{'X-Abuse-Report'} = C4::Context->preference('KohaAdminEmailAddress');
69 # Since we are already logged in, no need to check credentials again
70 # We only need to add OPACBaseURL
71 my $template2 = C4::Templates::gettemplate(
72 'opac-sendbasket.tt', 'opac', $query,
74 $template2->param( OPACBaseURL => C4::Context->preference('OPACBaseURL') );
76 my @bibs = split( /\//, $bib_list );
79 my $marcflavour = C4::Context->preference('marcflavour');
80 foreach my $biblionumber (@bibs) {
81 $template2->param( biblionumber => $biblionumber );
83 my $dat = GetBiblioData($biblionumber);
85 my $record = GetMarcBiblio($biblionumber, 1);
86 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
87 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
89 my @items = GetItemsInfo( $biblionumber );
92 if($dat->{'author'} || @$marcauthorsarray) {
97 $dat->{MARCSUBJCTS} = $marcsubjctsarray;
98 $dat->{MARCAUTHORS} = $marcauthorsarray;
99 $dat->{HASAUTHORS} = $hasauthors;
100 $dat->{'biblionumber'} = $biblionumber;
101 $dat->{ITEM_RESULTS} = \@items;
103 $iso2709 .= $record->as_usmarc();
105 push( @results, $dat );
108 my $resultsarray = \@results;
111 BIBLIO_RESULTS => $resultsarray,
113 firstname => $user->{firstname},
114 surname => $user->{surname},
117 # Getting template result
118 my $template_res = $template2->output();
121 # Analysing information and getting mail properties
123 if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
125 $mail{subject} =~ s|\n?(.*)\n?|$1|;
126 $mail{subject} = Encode::encode("UTF-8", $mail{subject});
128 else { $mail{'subject'} = "no subject"; }
130 my $email_header = "";
131 if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
133 $email_header =~ s|\n?(.*)\n?|$1|;
134 $email_header = encode_qp(Encode::encode("UTF-8", $email_header));
137 my $email_file = "basket.txt";
138 if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) {
140 $email_file =~ s|\n?(.*)\n?|$1|;
143 if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
145 $body =~ s|\n?(.*)\n?|$1|;
146 $body = encode_qp(Encode::encode("UTF-8", $body));
151 my $boundary = "====" . time() . "====";
153 $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
154 my $isofile = encode_base64(encode("UTF-8", $iso2709));
155 $boundary = '--' . $boundary;
156 $mail{body} = <<END_OF_BODY;
159 Content-Type: text/plain; charset="UTF-8"
160 Content-Transfer-Encoding: quoted-printable
165 Content-Type: application/octet-stream; name="basket.iso2709"
166 Content-Transfer-Encoding: base64
167 Content-Disposition: attachment; filename="basket.iso2709"
173 # Sending mail (if not empty basket)
174 if ( defined($iso2709) && sendmail %mail ) {
175 # do something if it works....
176 $template->param( SENT => "1" );
179 # do something if it doesnt work....
180 carp "Error sending mail: empty basket" if !defined($iso2709);
181 carp "Error sending mail: $Mail::Sendmail::error" if $Mail::Sendmail::error;
182 $template->param( error => 1 );
184 $template->param( email_add => $email_add );
185 output_html_with_http_headers $query, $cookie, $template->output;
188 $template->param( bib_list => $bib_list );
190 url => "/cgi-bin/koha/opac-sendbasket.pl",
191 suggestion => C4::Context->preference("suggestion"),
192 virtualshelves => C4::Context->preference("virtualshelves"),
194 output_html_with_http_headers $query, $cookie, $template->output;