Lines 22-39
use strict;
Link Here
|
22 |
|
22 |
|
23 |
use CGI qw ( -utf8 ); |
23 |
use CGI qw ( -utf8 ); |
24 |
|
24 |
|
25 |
use C4::Auth; |
25 |
use Mail::Sendmail; |
|
|
26 |
use MIME::QuotedPrint; |
27 |
use Carp; |
28 |
use C4::Auth qw(:DEFAULT check_cookie_auth); |
26 |
use C4::Koha; |
29 |
use C4::Koha; |
27 |
use C4::Circulation; |
30 |
use C4::Circulation; |
28 |
use C4::Reserves; |
31 |
use C4::Reserves; |
29 |
use C4::Members; |
32 |
use C4::Members; |
30 |
use C4::Members::AttributeTypes; |
33 |
use C4::Members::AttributeTypes; |
31 |
use C4::Members::Attributes qw/GetBorrowerAttributeValue/; |
34 |
use C4::Members::Attributes qw/GetBorrowerAttributeValue/; |
32 |
use C4::Output; |
35 |
use CGI::Cookie; # need to check cookies before having CGI parse the POST request |
|
|
36 |
use C4::Output qw(:DEFAULT :ajax); |
37 |
use C4::Scrubber; |
33 |
use C4::Biblio; |
38 |
use C4::Biblio; |
34 |
use C4::Items; |
39 |
use C4::Items; |
35 |
use C4::Letters; |
40 |
use C4::Letters; |
36 |
use C4::Branch; # GetBranches |
41 |
use C4::Branch; # GetBranches |
|
|
42 |
use Koha::Email; |
37 |
use Koha::DateUtils; |
43 |
use Koha::DateUtils; |
38 |
use Koha::Borrower::Debarments qw(IsDebarred); |
44 |
use Koha::Borrower::Debarments qw(IsDebarred); |
39 |
|
45 |
|
Lines 54-59
BEGIN {
Link Here
|
54 |
} |
60 |
} |
55 |
} |
61 |
} |
56 |
|
62 |
|
|
|
63 |
sub ajax_auth_cgi { # returns CGI object |
64 |
my $needed_flags = shift; |
65 |
my %cookies = fetch CGI::Cookie; |
66 |
my $input = CGI->new; |
67 |
my $sessid = $cookies{'CGISESSID'}->value; |
68 |
my ($auth_status, $auth_sessid) = check_cookie_auth($sessid, $needed_flags); |
69 |
if ($auth_status ne "ok") { |
70 |
output_with_http_headers $input, undef, |
71 |
"window.alert('Your CGI session cookie ($sessid) is not current. " . |
72 |
"Please refresh the page and try again.');\n", 'js'; |
73 |
exit 0; |
74 |
} |
75 |
return $input; |
76 |
} |
77 |
|
78 |
# AJAX requests |
79 |
my $is_ajax = is_ajax(); |
80 |
my $query = ($is_ajax) ? &ajax_auth_cgi({}) : CGI->new(); |
81 |
if ($is_ajax) { |
82 |
my $action = $query->param('action'); |
83 |
|
84 |
# Issue Note |
85 |
if ( $action == 'issuenote' && C4::Context->preference('AllowIssueNotes') ) { |
86 |
my $scrubber = C4::Scrubber->new(); |
87 |
my $note = $query->param('note'); |
88 |
my $issue_id = $query->param('issue_id'); |
89 |
my $clean_note = $scrubber->scrub($note); |
90 |
my $status = "saved"; |
91 |
my $error = ""; |
92 |
my ($error, $member, $issue); |
93 |
|
94 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
95 |
{ |
96 |
template_name => "opac-sendissuenote.tt", |
97 |
query => $query, |
98 |
type => "opac", |
99 |
authnotrequired => 1, |
100 |
} |
101 |
); |
102 |
|
103 |
# verify issue_id |
104 |
if ( $issue_id =~ /\d+/ ) { |
105 |
$member = GetMember(borrowernumber => $borrowernumber); |
106 |
($issue) = @{C4::Circulation::GetIssues({issue_id => $issue_id})}; |
107 |
|
108 |
if ( $issue->{'borrowernumber'} != $borrowernumber ) { |
109 |
$status = "fail"; |
110 |
$error = "Invalid issue id!"; |
111 |
} |
112 |
} else { |
113 |
$status = "fail"; |
114 |
$error = "Invalid issue id!"; |
115 |
} |
116 |
|
117 |
if ( (not $error) && SetIssueNote($issue_id, $clean_note) ) { |
118 |
if($clean_note) { # only send email if note not empty |
119 |
my $branch = GetBranchDetail($issue->{'branchcode'}); |
120 |
|
121 |
if ( $branch->{'branchemail'} ) { |
122 |
my $biblio = GetBiblioFromItemNumber($issue->{'itemnumber'}); |
123 |
my $message = Koha::Email->new(); |
124 |
my %mail = $message->create_message_headers(); |
125 |
|
126 |
$template->param( |
127 |
author => $biblio->{'author'}, |
128 |
title => $biblio->{'title'}, |
129 |
MEMBER => $member, |
130 |
note => $clean_note, |
131 |
); |
132 |
|
133 |
# Getting template result |
134 |
my $template_res = $template->output(); |
135 |
my $body; |
136 |
|
137 |
# Analysing information and getting mail properties |
138 |
if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) { |
139 |
$mail{subject} = $1; |
140 |
$mail{subject} =~ s|\n?(.*)\n?|$1|; |
141 |
} |
142 |
else { $mail{'subject'} = "no subject"; } |
143 |
$mail{subject} = Encode::encode("UTF-8", $mail{subject}); |
144 |
|
145 |
my $email_header = ""; |
146 |
if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) { |
147 |
$email_header = $1; |
148 |
$email_header =~ s|\n?(.*)\n?|$1|; |
149 |
$email_header = encode_qp(Encode::encode("UTF-8", $email_header)); |
150 |
} |
151 |
|
152 |
if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) { |
153 |
$body = $1; |
154 |
$body =~ s|\n?(.*)\n?|$1|; |
155 |
$body = encode_qp(Encode::encode("UTF-8", $body)); |
156 |
} |
157 |
|
158 |
$mail{to} = $branch->{'branchemail'}; |
159 |
$mail{from} = $member->{'email'} || ($branch->{'branchemail'}=~s/^.+@/noreply@/ && $branch->{'branchemail'}); |
160 |
$mail{body} = $email_header . $body; |
161 |
|
162 |
unless ( sendmail(%mail) ) { |
163 |
$status = "fail"; |
164 |
$error = "Could not send message to library. Message will still show at check in."; |
165 |
carp "Error sending mail: $Mail::Sendmail::error \n"; |
166 |
} |
167 |
} |
168 |
} else { # note empty, i.e removed |
169 |
$status = "removed"; |
170 |
} |
171 |
} else { |
172 |
$status = "fail"; |
173 |
$error = "Perhaps the item has already been check in?"; |
174 |
} |
175 |
|
176 |
my $response = "{\"status\": \"$status\", \"note\": \"$clean_note\", \"issue_id\": \"$issue_id\", \"error\": \"$error\"}"; |
177 |
output_with_http_headers($query, undef, $response, 'js'); |
178 |
exit; |
179 |
} # END Issue Note |
180 |
} |
181 |
|
182 |
|
57 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
183 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
58 |
{ |
184 |
{ |
59 |
template_name => "opac-user.tt", |
185 |
template_name => "opac-user.tt", |
Lines 244-249
if ($issues){
Link Here
|
244 |
} |
370 |
} |
245 |
} |
371 |
} |
246 |
} |
372 |
} |
|
|
373 |
$template->param( AllowIssueNotes => C4::Context->preference('AllowIssueNotes') ); |
247 |
$template->param( ISSUES => \@issuedat ); |
374 |
$template->param( ISSUES => \@issuedat ); |
248 |
$template->param( issues_count => $count ); |
375 |
$template->param( issues_count => $count ); |
249 |
$template->param( canrenew => $canrenew ); |
376 |
$template->param( canrenew => $canrenew ); |
250 |
- |
|
|