Lines 17-38
Link Here
|
17 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
17 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
18 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
18 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19 |
|
19 |
|
20 |
use strict; |
20 |
use Modern::Perl; |
21 |
use warnings; |
|
|
22 |
|
21 |
|
23 |
use CGI qw ( -utf8 ); |
22 |
use CGI qw ( -utf8 ); |
24 |
use Encode qw(encode); |
|
|
25 |
use Carp; |
23 |
use Carp; |
26 |
|
24 |
|
27 |
use Mail::Sendmail; |
25 |
use Mail::Sendmail; |
28 |
use MIME::QuotedPrint; |
|
|
29 |
use MIME::Base64; |
30 |
use C4::Biblio; |
26 |
use C4::Biblio; |
31 |
use C4::Items; |
27 |
use C4::Items; |
32 |
use C4::Auth; |
28 |
use C4::Auth; |
33 |
use C4::Output; |
29 |
use C4::Output; |
34 |
use C4::Biblio; |
30 |
use C4::Biblio; |
35 |
use C4::Members; |
31 |
use C4::Members; |
|
|
32 |
use C4::Csv qw( GetCsvProfilesLoop ); |
36 |
use Koha::Email; |
33 |
use Koha::Email; |
37 |
|
34 |
|
38 |
my $query = new CGI; |
35 |
my $query = new CGI; |
Lines 50-55
my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
Link Here
|
50 |
my $bib_list = $query->param('bib_list'); |
47 |
my $bib_list = $query->param('bib_list'); |
51 |
my $email_add = $query->param('email_add'); |
48 |
my $email_add = $query->param('email_add'); |
52 |
my $email_sender = $query->param('email_sender'); |
49 |
my $email_sender = $query->param('email_sender'); |
|
|
50 |
my $format = $query->param('format') || 'iso2709'; |
53 |
|
51 |
|
54 |
my $dbh = C4::Context->dbh; |
52 |
my $dbh = C4::Context->dbh; |
55 |
|
53 |
|
Lines 79-121
if ( $email_add ) {
Link Here
|
79 |
} |
77 |
} |
80 |
); |
78 |
); |
81 |
|
79 |
|
82 |
my @bibs = split( /\//, $bib_list ); |
80 |
my $csv_profile_id; |
83 |
my @results; |
81 |
if ( $format =~ m|^\d+$| ) { |
84 |
my $iso2709; |
82 |
$csv_profile_id = $format; |
85 |
my $marcflavour = C4::Context->preference('marcflavour'); |
83 |
$format = 'csv'; |
86 |
foreach my $biblionumber (@bibs) { |
|
|
87 |
$template2->param( biblionumber => $biblionumber ); |
88 |
|
89 |
my $dat = GetBiblioData($biblionumber); |
90 |
my $record = GetMarcBiblio($biblionumber, 1); |
91 |
my $marcnotesarray = GetMarcNotes( $record, $marcflavour ); |
92 |
my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); |
93 |
my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); |
94 |
|
95 |
my @items = GetItemsInfo( $biblionumber ); |
96 |
|
97 |
my $hasauthors = 0; |
98 |
if($dat->{'author'} || @$marcauthorsarray) { |
99 |
$hasauthors = 1; |
100 |
} |
101 |
|
102 |
|
103 |
$dat->{MARCNOTES} = $marcnotesarray; |
104 |
$dat->{MARCSUBJCTS} = $marcsubjctsarray; |
105 |
$dat->{MARCAUTHORS} = $marcauthorsarray; |
106 |
$dat->{HASAUTHORS} = $hasauthors; |
107 |
$dat->{'biblionumber'} = $biblionumber; |
108 |
$dat->{ITEM_RESULTS} = \@items; |
109 |
|
110 |
$iso2709 .= $record->as_usmarc(); |
111 |
|
112 |
push( @results, $dat ); |
113 |
} |
84 |
} |
|
|
85 |
my @biblionumbers = split( /\//, $bib_list ); |
86 |
my $data = C4::Biblio::BuildBiblioDataForExport( |
87 |
{ |
88 |
biblionumbers => \@biblionumbers, |
89 |
format => $format, |
90 |
csv_profile_id => $csv_profile_id |
91 |
} |
92 |
); |
93 |
my $records_file = $data->{records_file}; |
94 |
my $records_data = $data->{records_data}; |
114 |
|
95 |
|
115 |
my $resultsarray = \@results; |
|
|
116 |
|
117 |
$template2->param( |
96 |
$template2->param( |
118 |
BIBLIO_RESULTS => $resultsarray, |
97 |
BIBLIO_RESULTS => $records_data, |
119 |
email_sender => $email_sender, |
98 |
email_sender => $email_sender, |
120 |
comment => $comment, |
99 |
comment => $comment, |
121 |
firstname => $user->{firstname}, |
100 |
firstname => $user->{firstname}, |
Lines 124-191
if ( $email_add ) {
Link Here
|
124 |
|
103 |
|
125 |
# Getting template result |
104 |
# Getting template result |
126 |
my $template_res = $template2->output(); |
105 |
my $template_res = $template2->output(); |
127 |
my $body; |
|
|
128 |
|
129 |
# Analysing information and getting mail properties |
130 |
|
131 |
if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) { |
132 |
$mail{subject} = $1; |
133 |
$mail{subject} =~ s|\n?(.*)\n?|$1|; |
134 |
$mail{subject} = Encode::encode("UTF-8", $mail{subject}); |
135 |
} |
136 |
else { $mail{'subject'} = "no subject"; } |
137 |
|
106 |
|
138 |
my $email_header = ""; |
107 |
%mail = $email->fill_body_for_sending( |
139 |
if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) { |
108 |
{ |
140 |
$email_header = $1; |
109 |
template => $template_res, |
141 |
$email_header =~ s|\n?(.*)\n?|$1|; |
110 |
default_filename => "basket.$format", |
142 |
$email_header = encode_qp(Encode::encode("UTF-8", $email_header)); |
111 |
attachment => $records_file, |
143 |
} |
112 |
} |
144 |
|
113 |
); |
145 |
my $email_file = "basket.txt"; |
|
|
146 |
if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) { |
147 |
$email_file = $1; |
148 |
$email_file =~ s|\n?(.*)\n?|$1|; |
149 |
} |
150 |
|
151 |
if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) { |
152 |
$body = $1; |
153 |
$body =~ s|\n?(.*)\n?|$1|; |
154 |
$body = encode_qp(Encode::encode("UTF-8", $body)); |
155 |
} |
156 |
|
157 |
$mail{body} = $body; |
158 |
|
159 |
my $boundary = "====" . time() . "===="; |
160 |
|
161 |
$mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\""; |
162 |
my $isofile = encode_base64(encode("UTF-8", $iso2709)); |
163 |
$boundary = '--' . $boundary; |
164 |
$mail{body} = <<END_OF_BODY; |
165 |
$boundary |
166 |
MIME-Version: 1.0 |
167 |
Content-Type: text/plain; charset="UTF-8" |
168 |
Content-Transfer-Encoding: quoted-printable |
169 |
|
170 |
$email_header |
171 |
$body |
172 |
$boundary |
173 |
Content-Type: application/octet-stream; name="basket.iso2709" |
174 |
Content-Transfer-Encoding: base64 |
175 |
Content-Disposition: attachment; filename="basket.iso2709" |
176 |
|
177 |
$isofile |
178 |
$boundary-- |
179 |
END_OF_BODY |
180 |
|
114 |
|
181 |
# Sending mail (if not empty basket) |
115 |
# Sending mail (if not empty basket) |
182 |
if ( defined($iso2709) && sendmail %mail ) { |
116 |
if ( defined($records_file) && sendmail %mail ) { |
183 |
# do something if it works.... |
117 |
# do something if it works.... |
184 |
$template->param( SENT => "1" ); |
118 |
$template->param( SENT => "1" ); |
185 |
} |
119 |
} |
186 |
else { |
120 |
else { |
187 |
# do something if it doesnt work.... |
121 |
# do something if it doesnt work.... |
188 |
carp "Error sending mail: empty basket" if !defined($iso2709); |
122 |
carp "Error sending mail: empty basket" unless defined($records_file); |
189 |
carp "Error sending mail: $Mail::Sendmail::error" if $Mail::Sendmail::error; |
123 |
carp "Error sending mail: $Mail::Sendmail::error" if $Mail::Sendmail::error; |
190 |
$template->param( error => 1 ); |
124 |
$template->param( error => 1 ); |
191 |
} |
125 |
} |
Lines 198-203
else {
Link Here
|
198 |
url => "/cgi-bin/koha/opac-sendbasket.pl", |
132 |
url => "/cgi-bin/koha/opac-sendbasket.pl", |
199 |
suggestion => C4::Context->preference("suggestion"), |
133 |
suggestion => C4::Context->preference("suggestion"), |
200 |
virtualshelves => C4::Context->preference("virtualshelves"), |
134 |
virtualshelves => C4::Context->preference("virtualshelves"), |
|
|
135 |
csv_profiles => GetCsvProfilesLoop('marc'), |
201 |
); |
136 |
); |
202 |
output_html_with_http_headers $query, $cookie, $template->output; |
137 |
output_html_with_http_headers $query, $cookie, $template->output; |
203 |
} |
138 |
} |