3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 use Encode
qw(encode);
35 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
37 template_name
=> "basket/sendbasketform.tt",
40 flagsrequired
=> { catalogue
=> 1 },
44 my $bib_list = $query->param('bib_list') || '';
45 my $email_add = $query->param('email_add');
47 my $dbh = C4
::Context
->dbh;
50 output_and_exit
( $query, $cookie, $template, 'wrong_csrf_token' )
51 unless Koha
::Token
->new->check_csrf({
52 session_id
=> scalar $query->cookie('CGISESSID'),
53 token
=> scalar $query->param('csrf_token'),
55 my $comment = $query->param('comment');
57 # Since we are already logged in, no need to check credentials again
58 # when loading a second template.
59 my $template2 = C4
::Templates
::gettemplate
(
60 'basket/sendbasket.tt', 'intranet', $query,
63 my @bibs = split( /\//, $bib_list );
66 my $marcflavour = C4
::Context
->preference('marcflavour');
67 foreach my $biblionumber (@bibs) {
68 $template2->param( biblionumber
=> $biblionumber );
70 my $dat = GetBiblioData
($biblionumber);
72 my $record = GetMarcBiblio
({
73 biblionumber
=> $biblionumber,
75 my $marcauthorsarray = GetMarcAuthors
( $record, $marcflavour );
76 my $marcsubjctsarray = GetMarcSubjects
( $record, $marcflavour );
78 my @items = GetItemsInfo
( $biblionumber );
81 if($dat->{'author'} || @
$marcauthorsarray) {
86 $dat->{MARCSUBJCTS
} = $marcsubjctsarray;
87 $dat->{MARCAUTHORS
} = $marcauthorsarray;
88 $dat->{HASAUTHORS
} = $hasauthors;
89 $dat->{'biblionumber'} = $biblionumber;
90 $dat->{ITEM_RESULTS
} = \
@items;
92 $iso2709 .= $record->as_usmarc();
94 push( @results, $dat );
97 my $resultsarray = \
@results;
99 BIBLIO_RESULTS
=> $resultsarray,
103 # Getting template result
104 my $template_res = $template2->output();
108 # Analysing information and getting mail properties
109 if ( $template_res =~ /<SUBJECT>(?<subject>.*)<END_SUBJECT>/s ) {
110 $subject = $+{subject
};
111 $subject =~ s
|\n?
(.*)\n?
|$1|;
114 $subject = "no subject";
117 my $email_header = "";
118 if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
120 $email_header =~ s
|\n?
(.*)\n?
|$1|;
123 if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
125 $body =~ s
|\n?
(.*)\n?
|$1|;
128 my $THE_body = <<END_OF_BODY;
135 my $email = Koha::Email->create(
142 $email->text_body( $THE_body );
144 Encode::encode( "UTF-8", $iso2709 ),
145 content_type => 'application/octet-stream',
146 name => 'basket.iso2709',
147 disposition => 'attachment',
150 my $library = Koha::Patrons->find( $borrowernumber )->library;
151 $email->send_or_die({ transport => $library->smtp_server->transport });
152 $template->param( SENT => "1" );
155 carp "Error sending mail: $_";
156 $template->param( error => 1 );
159 $template->param( email_add => $email_add );
160 output_html_with_http_headers $query, $cookie, $template->output;
164 bib_list => $bib_list,
165 url => "/cgi-bin/koha/basket/sendbasket.pl",
166 suggestion => C4::Context->preference("suggestion"),
167 virtualshelves => C4::Context->preference("virtualshelves"),
168 csrf_token => Koha::Token->new->generate_csrf({ session_id => scalar $query->cookie('CGISESSID'), }),
170 output_html_with_http_headers $query, $cookie, $template->output;