Lines 22-38
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; |
|
|
41 |
use C4::Branch; # GetBranches |
42 |
use Koha::Email; |
36 |
use Koha::DateUtils; |
43 |
use Koha::DateUtils; |
37 |
use Koha::Holds; |
44 |
use Koha::Holds; |
38 |
use Koha::Database; |
45 |
use Koha::Database; |
Lines 57-62
BEGIN {
Link Here
|
57 |
} |
64 |
} |
58 |
} |
65 |
} |
59 |
|
66 |
|
|
|
67 |
sub ajax_auth_cgi { # returns CGI object |
68 |
my $needed_flags = shift; |
69 |
my %cookies = fetch CGI::Cookie; |
70 |
my $input = CGI->new; |
71 |
my $sessid = $cookies{'CGISESSID'}->value; |
72 |
my ($auth_status, $auth_sessid) = check_cookie_auth($sessid, $needed_flags); |
73 |
if ($auth_status ne "ok") { |
74 |
output_with_http_headers $input, undef, |
75 |
"window.alert('Your CGI session cookie ($sessid) is not current. " . |
76 |
"Please refresh the page and try again.');\n", 'js'; |
77 |
exit 0; |
78 |
} |
79 |
return $input; |
80 |
} |
81 |
|
82 |
# AJAX requests |
83 |
my $is_ajax = is_ajax(); |
84 |
my $query = ($is_ajax) ? &ajax_auth_cgi({}) : CGI->new(); |
85 |
if ($is_ajax) { |
86 |
my $action = $query->param('action'); |
87 |
|
88 |
# Issue Note |
89 |
if ( $action == 'issuenote' && C4::Context->preference('AllowIssueNotes') ) { |
90 |
my $scrubber = C4::Scrubber->new(); |
91 |
my $note = $query->param('note'); |
92 |
my $issue_id = $query->param('issue_id'); |
93 |
my $clean_note = $scrubber->scrub($note); |
94 |
my $status = "saved"; |
95 |
my $error = ""; |
96 |
my ($error, $member, $issue); |
97 |
|
98 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
99 |
{ |
100 |
template_name => "opac-sendissuenote.tt", |
101 |
query => $query, |
102 |
type => "opac", |
103 |
authnotrequired => 1, |
104 |
} |
105 |
); |
106 |
|
107 |
# verify issue_id |
108 |
if ( $issue_id =~ /\d+/ ) { |
109 |
$member = GetMember(borrowernumber => $borrowernumber); |
110 |
($issue) = @{C4::Circulation::GetIssues({issue_id => $issue_id})}; |
111 |
|
112 |
if ( $issue->{'borrowernumber'} != $borrowernumber ) { |
113 |
$status = "fail"; |
114 |
$error = "Invalid issue id!"; |
115 |
} |
116 |
} else { |
117 |
$status = "fail"; |
118 |
$error = "Invalid issue id!"; |
119 |
} |
120 |
|
121 |
if ( (not $error) && SetIssueNote($issue_id, $clean_note) ) { |
122 |
if($clean_note) { # only send email if note not empty |
123 |
my $branch = GetBranchDetail($issue->{'branchcode'}); |
124 |
|
125 |
if ( $branch->{'branchemail'} ) { |
126 |
my $biblio = GetBiblioFromItemNumber($issue->{'itemnumber'}); |
127 |
my $message = Koha::Email->new(); |
128 |
my %mail = $message->create_message_headers(); |
129 |
|
130 |
$template->param( |
131 |
author => $biblio->{'author'}, |
132 |
title => $biblio->{'title'}, |
133 |
MEMBER => $member, |
134 |
note => $clean_note, |
135 |
); |
136 |
|
137 |
# Getting template result |
138 |
my $template_res = $template->output(); |
139 |
my $body; |
140 |
|
141 |
# Analysing information and getting mail properties |
142 |
if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) { |
143 |
$mail{subject} = $1; |
144 |
$mail{subject} =~ s|\n?(.*)\n?|$1|; |
145 |
} |
146 |
else { $mail{'subject'} = "no subject"; } |
147 |
$mail{subject} = Encode::encode("UTF-8", $mail{subject}); |
148 |
|
149 |
my $email_header = ""; |
150 |
if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) { |
151 |
$email_header = $1; |
152 |
$email_header =~ s|\n?(.*)\n?|$1|; |
153 |
$email_header = encode_qp(Encode::encode("UTF-8", $email_header)); |
154 |
} |
155 |
|
156 |
if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) { |
157 |
$body = $1; |
158 |
$body =~ s|\n?(.*)\n?|$1|; |
159 |
$body = encode_qp(Encode::encode("UTF-8", $body)); |
160 |
} |
161 |
|
162 |
$mail{to} = $branch->{'branchemail'}; |
163 |
$mail{from} = $member->{'email'} || ($branch->{'branchemail'}=~s/^.+@/noreply@/ && $branch->{'branchemail'}); |
164 |
$mail{body} = $email_header . $body; |
165 |
|
166 |
unless ( sendmail(%mail) ) { |
167 |
$status = "fail"; |
168 |
$error = "Could not send message to library. Message will still show at check in."; |
169 |
carp "Error sending mail: $Mail::Sendmail::error \n"; |
170 |
} |
171 |
} |
172 |
} else { # note empty, i.e removed |
173 |
$status = "removed"; |
174 |
} |
175 |
} else { |
176 |
$status = "fail"; |
177 |
$error = "Perhaps the item has already been check in?"; |
178 |
} |
179 |
|
180 |
my $response = "{\"status\": \"$status\", \"note\": \"$clean_note\", \"issue_id\": \"$issue_id\", \"error\": \"$error\"}"; |
181 |
output_with_http_headers($query, undef, $response, 'js'); |
182 |
exit; |
183 |
} # END Issue Note |
184 |
} |
185 |
|
186 |
|
60 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
187 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
61 |
{ |
188 |
{ |
62 |
template_name => "opac-user.tt", |
189 |
template_name => "opac-user.tt", |
Lines 258-263
if ($issues){
Link Here
|
258 |
} |
385 |
} |
259 |
my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing'); |
386 |
my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing'); |
260 |
$canrenew = 0 if ($overduesblockrenewing ne 'allow' and $overdues_count == $count); |
387 |
$canrenew = 0 if ($overduesblockrenewing ne 'allow' and $overdues_count == $count); |
|
|
388 |
|
389 |
$template->param( AllowIssueNotes => C4::Context->preference('AllowIssueNotes') ); |
261 |
$template->param( ISSUES => \@issuedat ); |
390 |
$template->param( ISSUES => \@issuedat ); |
262 |
$template->param( issues_count => $count ); |
391 |
$template->param( issues_count => $count ); |
263 |
$template->param( canrenew => $canrenew ); |
392 |
$template->param( canrenew => $canrenew ); |
264 |
- |
|
|