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