Koha 3.8.0 Translation Update
[koha.git] / opac / opac-sendbasket.pl
blob6a6e8253ba35a003095bbc1f1e1ccf83a23ff56e
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 use warnings;
21 use CGI;
22 use Encode qw(encode);
23 use Carp;
25 use Mail::Sendmail;
26 use MIME::QuotedPrint;
27 use MIME::Base64;
28 use C4::Biblio;
29 use C4::Items;
30 use C4::Auth;
31 use C4::Output;
32 use C4::Biblio;
33 use C4::Members;
35 my $query = new CGI;
37 my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
39 template_name => "opac-sendbasketform.tmpl",
40 query => $query,
41 type => "opac",
42 authnotrequired => 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;
53 if ( $email_add ) {
54 my $email_from = C4::Context->preference('KohaAdminEmailAddress');
55 my $comment = $query->param('comment');
56 my %mail = (
57 To => $email_add,
58 From => $email_from
61 my ( $template2, $borrowernumber, $cookie ) = get_template_and_user(
63 template_name => "opac-sendbasket.tmpl",
64 query => $query,
65 type => "opac",
66 authnotrequired => 1,
67 flagsrequired => { borrow => 1 },
71 my @bibs = split( /\//, $bib_list );
72 my @results;
73 my $iso2709;
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 );
86 my $hasauthors = 0;
87 if($dat->{'author'} || @$marcauthorsarray) {
88 $hasauthors = 1;
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);
108 $template2->param(
109 BIBLIO_RESULTS => $resultsarray,
110 email_sender => $email_sender,
111 comment => $comment,
112 firstname => $user->{firstname},
113 surname => $user->{surname},
116 # Getting template result
117 my $template_res = $template2->output();
118 my $body;
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 ) {
128 $email_header = $1;
131 my $email_file = "basket.txt";
132 if ( $template_res =~ /<FILENAME>\n(.*)\n<END_FILENAME>/s ) {
133 $email_file = $1;
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;
146 # # Writing mail
147 # $mail{body} =
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;
152 $boundary
153 Content-Type: text/plain; charset="utf-8"
154 Content-Transfer-Encoding: quoted-printable
156 $email_header
157 $body
158 $boundary
159 Content-Type: application/octet-stream; name="basket.iso2709"
160 Content-Transfer-Encoding: base64
161 Content-Disposition: attachment; filename="basket.iso2709"
163 $isofile
164 $boundary--
165 END_OF_BODY
167 # Sending mail
168 if ( sendmail %mail ) {
169 # do something if it works....
170 $template->param( SENT => "1" );
172 else {
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;
180 else {
181 $template->param( bib_list => $bib_list );
182 $template->param(
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;