correct path to 404.pl in opac-details.pl
[koha.git] / opac / opac-sendbasket.pl
blobeee5eac49bb6d24a690fe9a57ddcc0d9e9b5ff5f
1 #!/usr/bin/perl
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
8 # version.
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
18 use strict;
19 require Exporter;
20 use CGI;
21 use Mail::Sendmail;
22 use MIME::QuotedPrint;
23 use MIME::Base64;
24 use C4::Biblio;
25 use C4::Items;
26 use C4::Auth;
27 use C4::Output;
28 use C4::Biblio;
30 my $query = new CGI;
32 my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
34 template_name => "opac-sendbasketform.tmpl",
35 query => $query,
36 type => "opac",
37 authnotrequired => 1,
38 flagsrequired => { borrow => 1 },
42 my $bib_list = $query->param('bib_list');
43 my $email_add = $query->param('email_add');
44 my $email_sender = $query->param('email_sender');
46 my $dbh = C4::Context->dbh;
48 if ( $email_add ) {
49 my $email_from = C4::Context->preference('KohaAdminEmailAddress');
50 my $comment = $query->param('comment');
51 my %mail = (
52 To => $email_add,
53 From => $email_from
56 my ( $template2, $borrowernumber, $cookie ) = get_template_and_user(
58 template_name => "opac-sendbasket.tmpl",
59 query => $query,
60 type => "opac",
61 authnotrequired => 1,
62 flagsrequired => { borrow => 1 },
66 my @bibs = split( /\//, $bib_list );
67 my @results;
68 my $iso2709;
69 my $marcflavour = C4::Context->preference('marcflavour');
70 foreach my $biblionumber (@bibs) {
71 $template2->param( biblionumber => $biblionumber );
73 my $dat = GetBiblioData($biblionumber);
74 my $record = GetMarcBiblio($biblionumber);
75 my $marcnotesarray = GetMarcNotes( $record, $marcflavour );
76 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
77 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
79 my @items = &GetItemsInfo( $biblionumber, 'opac' );
81 $dat->{MARCNOTES} = $marcnotesarray;
82 $dat->{MARCSUBJCTS} = $marcsubjctsarray;
83 $dat->{MARCAUTHORS} = $marcauthorsarray;
84 $dat->{'biblionumber'} = $biblionumber;
85 $dat->{ITEM_RESULTS} = \@items;
87 $iso2709 .= $record->as_usmarc();
89 push( @results, $dat );
92 my $resultsarray = \@results;
93 $template2->param(
94 BIBLIO_RESULTS => $resultsarray,
95 email_sender => $email_sender,
96 comment => $comment
99 # Getting template result
100 my $template_res = $template2->output();
101 my $body;
103 # Analysing information and getting mail properties
104 if ( $template_res =~ /<SUBJECT>\n(.*)\n<END_SUBJECT>/s ) {
105 $mail{'subject'} = $1;
107 else { $mail{'subject'} = "no subject"; }
109 my $email_header = "";
110 if ( $template_res =~ /<HEADER>\n(.*)\n<END_HEADER>/s ) {
111 $email_header = $1;
114 my $email_file = "basket.txt";
115 if ( $template_res =~ /<FILENAME>\n(.*)\n<END_FILENAME>/s ) {
116 $email_file = $1;
119 if ( $template_res =~ /<MESSAGE>\n(.*)\n<END_MESSAGE>/s ) { $body = $1; }
121 my $boundary = "====" . time() . "====";
123 # $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
125 # $email_header = encode_qp($email_header);
127 # $boundary = "--".$boundary;
129 # # Writing mail
130 # $mail{body} =
131 $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
132 my $isofile = encode_base64($iso2709);
133 $boundary = '--' . $boundary;
134 $mail{body} = <<END_OF_BODY;
135 $boundary
136 Content-Type: text/plain; charset="utf-8"
137 Content-Transfer-Encoding: quoted-printable
139 $body
140 $boundary
141 Content-Type: application/octet-stream; name="basket.iso2709"
142 Content-Transfer-Encoding: base64
143 Content-Disposition: attachment; filename="basket.iso2709"
145 $isofile
146 $boundary--
147 END_OF_BODY
149 # Sending mail
150 if ( sendmail %mail ) {
151 # do something if it works....
152 $template->param( SENT => "1" );
154 else {
155 # do something if it doesnt work....
156 warn "Error sending mail: $Mail::Sendmail::error \n";
157 $template->param( error => 1 );
159 $template->param( email_add => $email_add );
160 output_html_with_http_headers $query, $cookie, $template->output;
162 else {
163 $template->param( bib_list => $bib_list );
164 $template->param(
165 url => "/cgi-bin/koha/opac-sendbasket.pl",
166 suggestion => C4::Context->preference("suggestion"),
167 virtualshelves => C4::Context->preference("virtualshelves"),
169 output_html_with_http_headers $query, $cookie, $template->output;