Lines 20-30
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 Mail::Sendmail; |
24 |
use Mail::Sendmail; |
26 |
use MIME::QuotedPrint; |
|
|
27 |
use MIME::Base64; |
28 |
|
25 |
|
29 |
use C4::Biblio; |
26 |
use C4::Biblio; |
30 |
use C4::Items; |
27 |
use C4::Items; |
Lines 35-40
use C4::Templates ();
Link Here
|
35 |
use Koha::Email; |
32 |
use Koha::Email; |
36 |
use Koha::Patrons; |
33 |
use Koha::Patrons; |
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-124
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({ |
92 |
biblionumber => $biblionumber, |
93 |
embed_items => 1, |
94 |
opac => 1, |
95 |
borcat => $borcat }); |
96 |
my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); |
97 |
my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); |
98 |
|
99 |
my @items = GetItemsInfo( $biblionumber ); |
100 |
|
101 |
my $hasauthors = 0; |
102 |
if($dat->{'author'} || @$marcauthorsarray) { |
103 |
$hasauthors = 1; |
104 |
} |
105 |
|
106 |
|
107 |
$dat->{MARCSUBJCTS} = $marcsubjctsarray; |
108 |
$dat->{MARCAUTHORS} = $marcauthorsarray; |
109 |
$dat->{HASAUTHORS} = $hasauthors; |
110 |
$dat->{'biblionumber'} = $biblionumber; |
111 |
$dat->{ITEM_RESULTS} = \@items; |
112 |
|
113 |
$iso2709 .= $record->as_usmarc(); |
114 |
|
115 |
push( @results, $dat ); |
116 |
} |
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}; |
117 |
|
97 |
|
118 |
my $resultsarray = \@results; |
|
|
119 |
|
120 |
$template2->param( |
98 |
$template2->param( |
121 |
BIBLIO_RESULTS => $resultsarray, |
99 |
BIBLIO_RESULTS => $records_data, |
122 |
comment => $comment, |
100 |
comment => $comment, |
123 |
firstname => $patron->firstname, |
101 |
firstname => $patron->firstname, |
124 |
surname => $patron->surname, |
102 |
surname => $patron->surname, |
Lines 126-193
if ( $email_add ) {
Link Here
|
126 |
|
104 |
|
127 |
# Getting template result |
105 |
# Getting template result |
128 |
my $template_res = $template2->output(); |
106 |
my $template_res = $template2->output(); |
129 |
my $body; |
|
|
130 |
|
131 |
# Analysing information and getting mail properties |
132 |
|
133 |
if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) { |
134 |
$mail{subject} = $1; |
135 |
$mail{subject} =~ s|\n?(.*)\n?|$1|; |
136 |
$mail{subject} = encode('MIME-Header',$mail{subject}); |
137 |
} |
138 |
else { $mail{'subject'} = "no subject"; } |
139 |
|
140 |
my $email_header = ""; |
141 |
if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) { |
142 |
$email_header = $1; |
143 |
$email_header =~ s|\n?(.*)\n?|$1|; |
144 |
$email_header = encode_qp(Encode::encode("UTF-8", $email_header)); |
145 |
} |
146 |
|
147 |
my $email_file = "basket.txt"; |
148 |
if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) { |
149 |
$email_file = $1; |
150 |
$email_file =~ s|\n?(.*)\n?|$1|; |
151 |
} |
152 |
|
153 |
if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) { |
154 |
$body = $1; |
155 |
$body =~ s|\n?(.*)\n?|$1|; |
156 |
$body = encode_qp(Encode::encode("UTF-8", $body)); |
157 |
} |
158 |
|
159 |
$mail{body} = $body; |
160 |
|
161 |
my $boundary = "====" . time() . "===="; |
162 |
|
163 |
$mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\""; |
164 |
my $isofile = encode_base64(encode("UTF-8", $iso2709)); |
165 |
$boundary = '--' . $boundary; |
166 |
$mail{body} = <<END_OF_BODY; |
167 |
$boundary |
168 |
MIME-Version: 1.0 |
169 |
Content-Type: text/plain; charset="UTF-8" |
170 |
Content-Transfer-Encoding: quoted-printable |
171 |
|
172 |
$email_header |
173 |
$body |
174 |
$boundary |
175 |
Content-Type: application/octet-stream; name="basket.iso2709" |
176 |
Content-Transfer-Encoding: base64 |
177 |
Content-Disposition: attachment; filename="basket.iso2709" |
178 |
|
107 |
|
179 |
$isofile |
108 |
%mail = (%mail, $email->fill_body_for_sending({ |
180 |
$boundary-- |
109 |
template => $template_res, |
181 |
END_OF_BODY |
110 |
default_filename => "basket.$format", |
|
|
111 |
attachment => $records_file, |
112 |
})); |
182 |
|
113 |
|
183 |
# Sending mail (if not empty basket) |
114 |
# Sending mail (if not empty basket) |
184 |
if ( defined($iso2709) && sendmail %mail ) { |
115 |
if ( defined($records_file) && sendmail %mail ) { |
185 |
# do something if it works.... |
116 |
# do something if it works.... |
186 |
$template->param( SENT => "1" ); |
117 |
$template->param( SENT => "1" ); |
187 |
} |
118 |
} |
188 |
else { |
119 |
else { |
189 |
# do something if it doesn't work.... |
120 |
# do something if it doesn't work.... |
190 |
carp "Error sending mail: empty basket" if !defined($iso2709); |
121 |
carp "Error sending mail: empty basket" unless defined($records_file); |
191 |
carp "Error sending mail: $Mail::Sendmail::error" if $Mail::Sendmail::error; |
122 |
carp "Error sending mail: $Mail::Sendmail::error" if $Mail::Sendmail::error; |
192 |
$template->param( error => 1 ); |
123 |
$template->param( error => 1 ); |
193 |
} |
124 |
} |
Lines 203-208
else {
Link Here
|
203 |
virtualshelves => C4::Context->preference("virtualshelves"), |
134 |
virtualshelves => C4::Context->preference("virtualshelves"), |
204 |
csrf_token => Koha::Token->new->generate_csrf( |
135 |
csrf_token => Koha::Token->new->generate_csrf( |
205 |
{ session_id => $new_session_id, } ), |
136 |
{ session_id => $new_session_id, } ), |
|
|
137 |
csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc' }) ], |
206 |
); |
138 |
); |
207 |
output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; |
139 |
output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; |
208 |
} |
140 |
} |