Lines 17-38
Link Here
|
17 |
# You should have received a copy of the GNU General Public License |
17 |
# You should have received a copy of the GNU General Public License |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
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 48-53
my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
Link Here
|
48 |
|
45 |
|
49 |
my $bib_list = $query->param('bib_list'); |
46 |
my $bib_list = $query->param('bib_list'); |
50 |
my $email_add = $query->param('email_add'); |
47 |
my $email_add = $query->param('email_add'); |
|
|
48 |
my $format = $query->param('format') || 'iso2709'; |
51 |
|
49 |
|
52 |
my $dbh = C4::Context->dbh; |
50 |
my $dbh = C4::Context->dbh; |
53 |
|
51 |
|
Lines 76-119
if ( $email_add ) {
Link Here
|
76 |
} |
74 |
} |
77 |
); |
75 |
); |
78 |
|
76 |
|
79 |
my @bibs = split( /\//, $bib_list ); |
77 |
my $csv_profile_id; |
80 |
my @results; |
78 |
if ( $format =~ m|^\d+$| ) { |
81 |
my $iso2709; |
79 |
$csv_profile_id = $format; |
82 |
my $marcflavour = C4::Context->preference('marcflavour'); |
80 |
$format = 'csv'; |
83 |
foreach my $biblionumber (@bibs) { |
|
|
84 |
$template2->param( biblionumber => $biblionumber ); |
85 |
|
86 |
my $dat = GetBiblioData($biblionumber); |
87 |
next unless $dat; |
88 |
my $record = GetMarcBiblio($biblionumber, 1); |
89 |
my $marcnotesarray = GetMarcNotes( $record, $marcflavour ); |
90 |
my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); |
91 |
my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); |
92 |
|
93 |
my @items = GetItemsInfo( $biblionumber ); |
94 |
|
95 |
my $hasauthors = 0; |
96 |
if($dat->{'author'} || @$marcauthorsarray) { |
97 |
$hasauthors = 1; |
98 |
} |
99 |
|
100 |
|
101 |
$dat->{MARCNOTES} = $marcnotesarray; |
102 |
$dat->{MARCSUBJCTS} = $marcsubjctsarray; |
103 |
$dat->{MARCAUTHORS} = $marcauthorsarray; |
104 |
$dat->{HASAUTHORS} = $hasauthors; |
105 |
$dat->{'biblionumber'} = $biblionumber; |
106 |
$dat->{ITEM_RESULTS} = \@items; |
107 |
|
108 |
$iso2709 .= $record->as_usmarc(); |
109 |
|
110 |
push( @results, $dat ); |
111 |
} |
81 |
} |
|
|
82 |
my @biblionumbers = split( /\//, $bib_list ); |
83 |
my $data = C4::Biblio::BuildBiblioDataForExport( |
84 |
{ |
85 |
biblionumbers => \@biblionumbers, |
86 |
format => $format, |
87 |
csv_profile_id => $csv_profile_id, |
88 |
template => 'opac', |
89 |
} |
90 |
); |
91 |
my $records_file = $data->{records_file}; |
92 |
my $records_data = $data->{records_data}; |
112 |
|
93 |
|
113 |
my $resultsarray = \@results; |
|
|
114 |
|
115 |
$template2->param( |
94 |
$template2->param( |
116 |
BIBLIO_RESULTS => $resultsarray, |
95 |
BIBLIO_RESULTS => $records_data, |
117 |
comment => $comment, |
96 |
comment => $comment, |
118 |
firstname => $user->{firstname}, |
97 |
firstname => $user->{firstname}, |
119 |
surname => $user->{surname}, |
98 |
surname => $user->{surname}, |
Lines 121-188
if ( $email_add ) {
Link Here
|
121 |
|
100 |
|
122 |
# Getting template result |
101 |
# Getting template result |
123 |
my $template_res = $template2->output(); |
102 |
my $template_res = $template2->output(); |
124 |
my $body; |
|
|
125 |
|
126 |
# Analysing information and getting mail properties |
127 |
|
128 |
if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) { |
129 |
$mail{subject} = $1; |
130 |
$mail{subject} =~ s|\n?(.*)\n?|$1|; |
131 |
$mail{subject} = Encode::encode("UTF-8", $mail{subject}); |
132 |
} |
133 |
else { $mail{'subject'} = "no subject"; } |
134 |
|
135 |
my $email_header = ""; |
136 |
if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) { |
137 |
$email_header = $1; |
138 |
$email_header =~ s|\n?(.*)\n?|$1|; |
139 |
$email_header = encode_qp(Encode::encode("UTF-8", $email_header)); |
140 |
} |
141 |
|
103 |
|
142 |
my $email_file = "basket.txt"; |
104 |
%mail = $email->fill_body_for_sending( |
143 |
if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) { |
105 |
{ |
144 |
$email_file = $1; |
106 |
template => $template_res, |
145 |
$email_file =~ s|\n?(.*)\n?|$1|; |
107 |
default_filename => "basket.$format", |
146 |
} |
108 |
attachment => $records_file, |
147 |
|
109 |
} |
148 |
if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) { |
110 |
); |
149 |
$body = $1; |
|
|
150 |
$body =~ s|\n?(.*)\n?|$1|; |
151 |
$body = encode_qp(Encode::encode("UTF-8", $body)); |
152 |
} |
153 |
|
154 |
$mail{body} = $body; |
155 |
|
156 |
my $boundary = "====" . time() . "===="; |
157 |
|
158 |
$mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\""; |
159 |
my $isofile = encode_base64(encode("UTF-8", $iso2709)); |
160 |
$boundary = '--' . $boundary; |
161 |
$mail{body} = <<END_OF_BODY; |
162 |
$boundary |
163 |
MIME-Version: 1.0 |
164 |
Content-Type: text/plain; charset="UTF-8" |
165 |
Content-Transfer-Encoding: quoted-printable |
166 |
|
167 |
$email_header |
168 |
$body |
169 |
$boundary |
170 |
Content-Type: application/octet-stream; name="basket.iso2709" |
171 |
Content-Transfer-Encoding: base64 |
172 |
Content-Disposition: attachment; filename="basket.iso2709" |
173 |
|
174 |
$isofile |
175 |
$boundary-- |
176 |
END_OF_BODY |
177 |
|
111 |
|
178 |
# Sending mail (if not empty basket) |
112 |
# Sending mail (if not empty basket) |
179 |
if ( defined($iso2709) && sendmail %mail ) { |
113 |
if ( defined($records_file) && sendmail %mail ) { |
180 |
# do something if it works.... |
114 |
# do something if it works.... |
181 |
$template->param( SENT => "1" ); |
115 |
$template->param( SENT => "1" ); |
182 |
} |
116 |
} |
183 |
else { |
117 |
else { |
184 |
# do something if it doesnt work.... |
118 |
# do something if it doesnt work.... |
185 |
carp "Error sending mail: empty basket" if !defined($iso2709); |
119 |
carp "Error sending mail: empty basket" unless defined($records_file); |
186 |
carp "Error sending mail: $Mail::Sendmail::error" if $Mail::Sendmail::error; |
120 |
carp "Error sending mail: $Mail::Sendmail::error" if $Mail::Sendmail::error; |
187 |
$template->param( error => 1 ); |
121 |
$template->param( error => 1 ); |
188 |
} |
122 |
} |
Lines 195-200
else {
Link Here
|
195 |
url => "/cgi-bin/koha/opac-sendbasket.pl", |
129 |
url => "/cgi-bin/koha/opac-sendbasket.pl", |
196 |
suggestion => C4::Context->preference("suggestion"), |
130 |
suggestion => C4::Context->preference("suggestion"), |
197 |
virtualshelves => C4::Context->preference("virtualshelves"), |
131 |
virtualshelves => C4::Context->preference("virtualshelves"), |
|
|
132 |
csv_profiles => GetCsvProfilesLoop('marc'), |
198 |
); |
133 |
); |
199 |
output_html_with_http_headers $query, $cookie, $template->output; |
134 |
output_html_with_http_headers $query, $cookie, $template->output; |
200 |
} |
135 |
} |