|
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-122
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 |
next unless $dat; |
| 91 |
my $record = GetMarcBiblio($biblionumber, 1); |
| 92 |
my $marcnotesarray = GetMarcNotes( $record, $marcflavour ); |
| 93 |
my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); |
| 94 |
my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); |
| 95 |
|
| 96 |
my @items = GetItemsInfo( $biblionumber ); |
| 97 |
|
| 98 |
my $hasauthors = 0; |
| 99 |
if($dat->{'author'} || @$marcauthorsarray) { |
| 100 |
$hasauthors = 1; |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
$dat->{MARCNOTES} = $marcnotesarray; |
| 105 |
$dat->{MARCSUBJCTS} = $marcsubjctsarray; |
| 106 |
$dat->{MARCAUTHORS} = $marcauthorsarray; |
| 107 |
$dat->{HASAUTHORS} = $hasauthors; |
| 108 |
$dat->{'biblionumber'} = $biblionumber; |
| 109 |
$dat->{ITEM_RESULTS} = \@items; |
| 110 |
|
| 111 |
$iso2709 .= $record->as_usmarc(); |
| 112 |
|
| 113 |
push( @results, $dat ); |
| 114 |
} |
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 |
template => 'opac', |
| 92 |
} |
| 93 |
); |
| 94 |
my $records_file = $data->{records_file}; |
| 95 |
my $records_data = $data->{records_data}; |
| 115 |
|
96 |
|
| 116 |
my $resultsarray = \@results; |
|
|
| 117 |
|
| 118 |
$template2->param( |
97 |
$template2->param( |
| 119 |
BIBLIO_RESULTS => $resultsarray, |
98 |
BIBLIO_RESULTS => $records_data, |
| 120 |
email_sender => $email_sender, |
99 |
email_sender => $email_sender, |
| 121 |
comment => $comment, |
100 |
comment => $comment, |
| 122 |
firstname => $user->{firstname}, |
101 |
firstname => $user->{firstname}, |
|
Lines 125-192
if ( $email_add ) {
Link Here
|
| 125 |
|
104 |
|
| 126 |
# Getting template result |
105 |
# Getting template result |
| 127 |
my $template_res = $template2->output(); |
106 |
my $template_res = $template2->output(); |
| 128 |
my $body; |
|
|
| 129 |
|
| 130 |
# Analysing information and getting mail properties |
| 131 |
|
| 132 |
if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) { |
| 133 |
$mail{subject} = $1; |
| 134 |
$mail{subject} =~ s|\n?(.*)\n?|$1|; |
| 135 |
$mail{subject} = Encode::encode("UTF-8", $mail{subject}); |
| 136 |
} |
| 137 |
else { $mail{'subject'} = "no subject"; } |
| 138 |
|
| 139 |
my $email_header = ""; |
| 140 |
if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) { |
| 141 |
$email_header = $1; |
| 142 |
$email_header =~ s|\n?(.*)\n?|$1|; |
| 143 |
$email_header = encode_qp(Encode::encode("UTF-8", $email_header)); |
| 144 |
} |
| 145 |
|
107 |
|
| 146 |
my $email_file = "basket.txt"; |
108 |
%mail = $email->fill_body_for_sending( |
| 147 |
if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) { |
109 |
{ |
| 148 |
$email_file = $1; |
110 |
template => $template_res, |
| 149 |
$email_file =~ s|\n?(.*)\n?|$1|; |
111 |
default_filename => "basket.$format", |
| 150 |
} |
112 |
attachment => $records_file, |
| 151 |
|
113 |
} |
| 152 |
if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) { |
114 |
); |
| 153 |
$body = $1; |
|
|
| 154 |
$body =~ s|\n?(.*)\n?|$1|; |
| 155 |
$body = encode_qp(Encode::encode("UTF-8", $body)); |
| 156 |
} |
| 157 |
|
| 158 |
$mail{body} = $body; |
| 159 |
|
| 160 |
my $boundary = "====" . time() . "===="; |
| 161 |
|
| 162 |
$mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\""; |
| 163 |
my $isofile = encode_base64(encode("UTF-8", $iso2709)); |
| 164 |
$boundary = '--' . $boundary; |
| 165 |
$mail{body} = <<END_OF_BODY; |
| 166 |
$boundary |
| 167 |
MIME-Version: 1.0 |
| 168 |
Content-Type: text/plain; charset="UTF-8" |
| 169 |
Content-Transfer-Encoding: quoted-printable |
| 170 |
|
| 171 |
$email_header |
| 172 |
$body |
| 173 |
$boundary |
| 174 |
Content-Type: application/octet-stream; name="basket.iso2709" |
| 175 |
Content-Transfer-Encoding: base64 |
| 176 |
Content-Disposition: attachment; filename="basket.iso2709" |
| 177 |
|
| 178 |
$isofile |
| 179 |
$boundary-- |
| 180 |
END_OF_BODY |
| 181 |
|
115 |
|
| 182 |
# Sending mail (if not empty basket) |
116 |
# Sending mail (if not empty basket) |
| 183 |
if ( defined($iso2709) && sendmail %mail ) { |
117 |
if ( defined($records_file) && sendmail %mail ) { |
| 184 |
# do something if it works.... |
118 |
# do something if it works.... |
| 185 |
$template->param( SENT => "1" ); |
119 |
$template->param( SENT => "1" ); |
| 186 |
} |
120 |
} |
| 187 |
else { |
121 |
else { |
| 188 |
# do something if it doesnt work.... |
122 |
# do something if it doesnt work.... |
| 189 |
carp "Error sending mail: empty basket" if !defined($iso2709); |
123 |
carp "Error sending mail: empty basket" unless defined($records_file); |
| 190 |
carp "Error sending mail: $Mail::Sendmail::error" if $Mail::Sendmail::error; |
124 |
carp "Error sending mail: $Mail::Sendmail::error" if $Mail::Sendmail::error; |
| 191 |
$template->param( error => 1 ); |
125 |
$template->param( error => 1 ); |
| 192 |
} |
126 |
} |
|
Lines 199-204
else {
Link Here
|
| 199 |
url => "/cgi-bin/koha/opac-sendbasket.pl", |
133 |
url => "/cgi-bin/koha/opac-sendbasket.pl", |
| 200 |
suggestion => C4::Context->preference("suggestion"), |
134 |
suggestion => C4::Context->preference("suggestion"), |
| 201 |
virtualshelves => C4::Context->preference("virtualshelves"), |
135 |
virtualshelves => C4::Context->preference("virtualshelves"), |
|
|
136 |
csv_profiles => GetCsvProfilesLoop('marc'), |
| 202 |
); |
137 |
); |
| 203 |
output_html_with_http_headers $query, $cookie, $template->output; |
138 |
output_html_with_http_headers $query, $cookie, $template->output; |
| 204 |
} |
139 |
} |