|
Lines 24-30
use CGI;
Link Here
|
| 24 |
use Encode qw(encode); |
24 |
use Encode qw(encode); |
| 25 |
use Carp; |
25 |
use Carp; |
| 26 |
|
26 |
|
| 27 |
use Mail::Sendmail; |
|
|
| 28 |
use MIME::QuotedPrint; |
27 |
use MIME::QuotedPrint; |
| 29 |
use MIME::Base64; |
28 |
use MIME::Base64; |
| 30 |
use C4::Auth; |
29 |
use C4::Auth; |
|
Lines 32-42
use C4::Biblio;
Link Here
|
| 32 |
use C4::Items; |
31 |
use C4::Items; |
| 33 |
use C4::Output; |
32 |
use C4::Output; |
| 34 |
use C4::VirtualShelves; |
33 |
use C4::VirtualShelves; |
|
|
34 |
use C4::Letters qw/ EnqueueLetter /; |
| 35 |
use C4::Members; |
35 |
use C4::Members; |
| 36 |
|
36 |
|
| 37 |
my $query = new CGI; |
37 |
my $query = new CGI; |
| 38 |
|
38 |
|
| 39 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( |
39 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
| 40 |
{ |
40 |
{ |
| 41 |
template_name => "opac-sendshelfform.tmpl", |
41 |
template_name => "opac-sendshelfform.tmpl", |
| 42 |
query => $query, |
42 |
query => $query, |
|
Lines 46-153
my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
Link Here
|
| 46 |
} |
46 |
} |
| 47 |
); |
47 |
); |
| 48 |
|
48 |
|
| 49 |
my $shelfid = $query->param('shelfid'); |
49 |
my $shelfid = $query->param('shelfid'); |
| 50 |
my $email = $query->param('email'); |
50 |
my $email_add = $query->param('email'); |
| 51 |
|
51 |
|
| 52 |
my $dbh = C4::Context->dbh; |
52 |
my $dbh = C4::Context->dbh; |
| 53 |
|
53 |
|
| 54 |
if ( ShelfPossibleAction( (defined($borrowernumber) ? $borrowernumber : -1), $shelfid, 'view' ) ) { |
54 |
if ( |
| 55 |
|
55 |
ShelfPossibleAction( |
| 56 |
if ( $email ) { |
56 |
( defined($borrowernumber) ? $borrowernumber : -1 ), $shelfid, |
| 57 |
my $email_from = C4::Context->preference('KohaAdminEmailAddress'); |
57 |
'view' |
| 58 |
my $sender_email |
58 |
) |
| 59 |
= C4::Context->preference('OpacSendReplyTo') |
59 |
) |
| 60 |
? GetPreferredEmailAddress($user) || $email_from |
60 |
{ |
| 61 |
: $email_from; |
61 |
|
| 62 |
my $comment = $query->param('comment'); |
62 |
if ($email_add) { |
| 63 |
|
63 |
my $email_from = C4::Context->preference('KohaAdminEmailAddress'); |
| 64 |
my %mail = ( |
64 |
my $user = GetMember( borrowernumber => $borrowernumber ); |
| 65 |
To => $email, |
65 |
my $sender_email = |
| 66 |
From => $email_from, |
66 |
C4::Context->preference('OpacSendReplyTo') |
| 67 |
'Reply-To' => $sender_email, |
67 |
? GetPreferredEmailAddress($user) || $email_from |
| 68 |
); |
68 |
: $email_from; |
| 69 |
|
69 |
my $comment = $query->param('comment'); |
| 70 |
my ( $template2, $borrowernumber, $cookie ) = get_template_and_user( |
70 |
warn "Sendreplyto is: ".C4::Context->preference('OpacSendReplyTo'); |
| 71 |
{ |
71 |
my %mail = ( |
| 72 |
template_name => "opac-sendshelf.tmpl", |
72 |
to_address => $email_add, |
| 73 |
query => $query, |
73 |
from_address => $email_from, |
| 74 |
type => "opac", |
74 |
reply_to_address => $sender_email, |
| 75 |
authnotrequired => 1, |
75 |
); |
| 76 |
flagsrequired => { borrow => 1 }, |
76 |
my %letter; |
|
|
77 |
|
| 78 |
my ( $template2, $borrowernumber, $cookie ) = get_template_and_user( |
| 79 |
{ |
| 80 |
template_name => "opac-sendshelf.tmpl", |
| 81 |
query => $query, |
| 82 |
type => "opac", |
| 83 |
authnotrequired => 1, |
| 84 |
flagsrequired => { borrow => 1 }, |
| 85 |
} |
| 86 |
); |
| 87 |
|
| 88 |
my @shelf = GetShelf($shelfid); |
| 89 |
my ( $items, $totitems ) = GetShelfContents($shelfid); |
| 90 |
my $marcflavour = C4::Context->preference('marcflavour'); |
| 91 |
my $iso2709; |
| 92 |
my @results; |
| 93 |
|
| 94 |
# retrieve biblios from shelf |
| 95 |
foreach my $biblio (@$items) { |
| 96 |
my $biblionumber = $biblio->{biblionumber}; |
| 97 |
|
| 98 |
my $dat = GetBiblioData($biblionumber); |
| 99 |
my $record = GetMarcBiblio($biblionumber); |
| 100 |
my $marcnotesarray = GetMarcNotes( $record, $marcflavour ); |
| 101 |
my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); |
| 102 |
my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); |
| 103 |
|
| 104 |
my @items = GetItemsInfo($biblionumber); |
| 105 |
|
| 106 |
$dat->{MARCNOTES} = $marcnotesarray; |
| 107 |
$dat->{MARCSUBJCTS} = $marcsubjctsarray; |
| 108 |
$dat->{MARCAUTHORS} = $marcauthorsarray; |
| 109 |
$dat->{'biblionumber'} = $biblionumber; |
| 110 |
$dat->{ITEM_RESULTS} = \@items; |
| 111 |
|
| 112 |
$iso2709 .= $record->as_usmarc(); |
| 113 |
|
| 114 |
push( @results, $dat ); |
| 77 |
} |
115 |
} |
| 78 |
); |
|
|
| 79 |
|
| 80 |
my @shelf = GetShelf($shelfid); |
| 81 |
my ($items, $totitems) = GetShelfContents($shelfid); |
| 82 |
my $marcflavour = C4::Context->preference('marcflavour'); |
| 83 |
my $iso2709; |
| 84 |
my @results; |
| 85 |
|
| 86 |
# retrieve biblios from shelf |
| 87 |
foreach my $biblio (@$items) { |
| 88 |
my $biblionumber = $biblio->{biblionumber}; |
| 89 |
|
| 90 |
my $dat = GetBiblioData($biblionumber); |
| 91 |
my $record = GetMarcBiblio($biblionumber); |
| 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 |
$dat->{MARCNOTES} = $marcnotesarray; |
| 99 |
$dat->{MARCSUBJCTS} = $marcsubjctsarray; |
| 100 |
$dat->{MARCAUTHORS} = $marcauthorsarray; |
| 101 |
$dat->{'biblionumber'} = $biblionumber; |
| 102 |
$dat->{ITEM_RESULTS} = \@items; |
| 103 |
|
| 104 |
$iso2709 .= $record->as_usmarc(); |
| 105 |
|
| 106 |
push( @results, $dat ); |
| 107 |
} |
| 108 |
|
| 109 |
my $user = GetMember(borrowernumber => $borrowernumber); |
| 110 |
|
| 111 |
$template2->param( |
| 112 |
BIBLIO_RESULTS => \@results, |
| 113 |
email_sender => $email_from, |
| 114 |
comment => $comment, |
| 115 |
shelfname => $shelf[1], |
| 116 |
firstname => $user->{firstname}, |
| 117 |
surname => $user->{surname}, |
| 118 |
); |
| 119 |
|
116 |
|
| 120 |
# Getting template result |
117 |
$template2->param( |
| 121 |
my $template_res = $template2->output(); |
118 |
BIBLIO_RESULTS => \@results, |
| 122 |
my $body; |
119 |
email_sender => $email_from, |
| 123 |
|
120 |
comment => $comment, |
| 124 |
# Analysing information and getting mail properties |
121 |
shelfname => $shelf[1], |
| 125 |
if ( $template_res =~ /<SUBJECT>\n(.*)\n<END_SUBJECT>/s ) { |
122 |
firstname => $user->{firstname}, |
| 126 |
$mail{'subject'} = $1; |
123 |
surname => $user->{surname}, |
| 127 |
} |
124 |
); |
| 128 |
else { $mail{'subject'} = "no subject"; } |
125 |
|
|
|
126 |
# Getting template result |
| 127 |
my $template_res = $template2->output(); |
| 128 |
my $body; |
| 129 |
|
| 130 |
# Analysing information and getting mail properties |
| 131 |
if ( $template_res =~ /<SUBJECT>\n(.*)\n<END_SUBJECT>/s ) { |
| 132 |
$letter{'title'} = $1; |
| 133 |
} |
| 134 |
else { $letter{'title'} = "no subject"; } |
| 129 |
|
135 |
|
| 130 |
my $email_header = ""; |
136 |
my $email_header = ""; |
| 131 |
if ( $template_res =~ /<HEADER>\n(.*)\n<END_HEADER>/s ) { |
137 |
if ( $template_res =~ /<HEADER>\n(.*)\n<END_HEADER>/s ) { |
| 132 |
$email_header = $1; |
138 |
$email_header = $1; |
| 133 |
} |
139 |
} |
| 134 |
|
140 |
|
| 135 |
my $email_file = "basket.txt"; |
141 |
my $email_file = "basket.txt"; |
| 136 |
if ( $template_res =~ /<FILENAME>\n(.*)\n<END_FILENAME>/s ) { |
142 |
if ( $template_res =~ /<FILENAME>\n(.*)\n<END_FILENAME>/s ) { |
| 137 |
$email_file = $1; |
143 |
$email_file = $1; |
| 138 |
} |
144 |
} |
| 139 |
|
145 |
|
| 140 |
if ( $template_res =~ /<MESSAGE>\n(.*)\n<END_MESSAGE>/s ) { $body = encode_qp($1); } |
146 |
if ( $template_res =~ /<MESSAGE>\n(.*)\n<END_MESSAGE>/s ) { |
|
|
147 |
$body = encode_qp($1); |
| 148 |
} |
| 141 |
|
149 |
|
| 142 |
my $boundary = "====" . time() . "===="; |
150 |
my $boundary = "====" . time() . "===="; |
| 143 |
|
151 |
|
| 144 |
# We set and put the multipart content |
152 |
# We set and put the multipart content |
| 145 |
$mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\""; |
153 |
$letter{'content-type'} = "multipart/mixed; boundary=\"$boundary\""; |
| 146 |
|
154 |
|
| 147 |
my $isofile = encode_base64(encode("UTF-8", $iso2709)); |
155 |
my $isofile = encode_base64( encode( "UTF-8", $iso2709 ) ); |
| 148 |
$boundary = '--' . $boundary; |
156 |
$boundary = '--' . $boundary; |
| 149 |
|
157 |
|
| 150 |
$mail{body} = <<END_OF_BODY; |
158 |
$letter{content} = <<END_OF_BODY; |
| 151 |
$boundary |
159 |
$boundary |
| 152 |
Content-Type: text/plain; charset="utf-8" |
160 |
Content-Type: text/plain; charset="utf-8" |
| 153 |
Content-Transfer-Encoding: quoted-printable |
161 |
Content-Transfer-Encoding: quoted-printable |
|
Lines 163-193
$isofile
Link Here
|
| 163 |
$boundary-- |
171 |
$boundary-- |
| 164 |
END_OF_BODY |
172 |
END_OF_BODY |
| 165 |
|
173 |
|
| 166 |
# Sending mail |
174 |
$mail{letter} = \%letter; |
| 167 |
if ( sendmail %mail ) { |
175 |
$mail{message_transport_type} = 'email'; |
| 168 |
# do something if it works.... |
176 |
$mail{no_local_bcc} = 1; |
| 169 |
$template->param( SENT => "1" ); |
177 |
if ( EnqueueLetter( \%mail ) ) { |
|
|
178 |
$template->param( SENT => "1" ); |
| 179 |
} |
| 180 |
else { |
| 181 |
carp "Error queueing mail\n"; |
| 182 |
$template->param( error => 1 ); |
| 183 |
} |
| 184 |
$template->param( email_add => $email_add ); |
| 185 |
output_html_with_http_headers $query, $cookie, $template->output; |
| 170 |
} |
186 |
} |
| 171 |
else { |
187 |
else { |
| 172 |
# do something if it doesnt work.... |
188 |
$template->param( |
| 173 |
carp "Error sending mail: $Mail::Sendmail::error \n"; |
189 |
shelfid => $shelfid, |
| 174 |
$template->param( error => 1 ); |
190 |
url => "/cgi-bin/koha/opac-sendshelf.pl", |
|
|
191 |
); |
| 192 |
output_html_with_http_headers $query, $cookie, $template->output; |
| 175 |
} |
193 |
} |
| 176 |
|
|
|
| 177 |
$template->param( email => $email ); |
| 178 |
output_html_with_http_headers $query, $cookie, $template->output; |
| 179 |
|
| 180 |
|
| 181 |
}else{ |
| 182 |
$template->param( shelfid => $shelfid, |
| 183 |
url => "/cgi-bin/koha/opac-sendshelf.pl", |
| 184 |
); |
| 185 |
output_html_with_http_headers $query, $cookie, $template->output; |
| 186 |
} |
194 |
} |
| 187 |
|
195 |
else { |
| 188 |
} else { |
196 |
$template->param( |
| 189 |
$template->param( invalidlist => 1, |
197 |
invalidlistshelfid => 1, |
| 190 |
url => "/cgi-bin/koha/opac-sendshelf.pl", |
198 |
$shelfid, |
|
|
199 |
url => "/cgi-bin/koha/opac-sendshelf.pl", |
| 191 |
); |
200 |
); |
| 192 |
output_html_with_http_headers $query, $cookie, $template->output; |
201 |
output_html_with_http_headers $query, $cookie, $template->output; |
| 193 |
} |
202 |
} |
| 194 |
- |
203 |
|