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 |
my $is_ajax = is_ajax(); |
79 |
my $query = ($is_ajax) ? &ajax_auth_cgi({}) : CGI->new(); |
80 |
if ($is_ajax) { |
81 |
my $scrubber = C4::Scrubber->new(); |
82 |
my $note = $query->param('note'); |
83 |
my $issue_id = $query->param('issue_id'); |
84 |
my $clean_note = $scrubber->scrub($note); |
85 |
my $status = "success"; |
86 |
my $error = ""; |
87 |
my ($error, $member, $issue); |
88 |
|
89 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
90 |
{ |
91 |
template_name => "opac-sendissuenote.tt", |
92 |
query => $query, |
93 |
type => "opac", |
94 |
authnotrequired => 1, |
95 |
} |
96 |
); |
97 |
|
98 |
# verify issue_id |
99 |
if ( $issue_id =~ /\d+/ ) { |
100 |
$member = GetMember(borrowernumber => $borrowernumber); |
101 |
($issue) = @{C4::Circulation::GetIssues({issue_id => $issue_id})}; |
102 |
|
103 |
if ( $issue->{'borrowernumber'} != $borrowernumber ) { |
104 |
$status = "fail"; |
105 |
$error = "Invalid issue id!"; |
106 |
} |
107 |
} else { |
108 |
$status = "fail"; |
109 |
$error = "Invalid issue id!"; |
110 |
} |
111 |
|
112 |
if ( (not $error) && SetIssueNote($issue_id, $clean_note) ) { |
113 |
my $branch = GetBranchDetail($issue->{'branchcode'}); |
114 |
|
115 |
if ( $branch->{'branchemail'} ) { |
116 |
my $biblio = GetBiblioFromItemNumber($issue->{'itemnumber'}); |
117 |
my $message = Koha::Email->new(); |
118 |
my %mail = $message->create_message_headers(); |
119 |
|
120 |
$template->param( |
121 |
author => $biblio->{'author'}, |
122 |
title => $biblio->{'title'}, |
123 |
MEMBER => $member, |
124 |
note => $clean_note, |
125 |
); |
126 |
|
127 |
# Getting template result |
128 |
my $template_res = $template->output(); |
129 |
my $body; |
130 |
|
131 |
# Analysing information and getting mail properties |
132 |
if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) { |
133 |
$mail{subject} = $1; |
134 |
$mail{subject} =~ s|\n?(.*)\n?|$1|; |
135 |
} |
136 |
else { $mail{'subject'} = "no subject"; } |
137 |
$mail{subject} = Encode::encode("UTF-8", $mail{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 |
|
146 |
if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) { |
147 |
$body = $1; |
148 |
$body =~ s|\n?(.*)\n?|$1|; |
149 |
$body = encode_qp(Encode::encode("UTF-8", $body)); |
150 |
} |
151 |
|
152 |
$mail{to} = $branch->{'branchemail'}; |
153 |
$mail{from} = $member->{'email'} || ($branch->{'branchemail'}=~s/^.+@/noreply@/ && $branch->{'branchemail'}); |
154 |
$mail{body} = $email_header . $body; |
155 |
|
156 |
unless ( sendmail(%mail) ) { |
157 |
$status = "fail"; |
158 |
$error = "Could not send message to library. Message will still show at check in."; |
159 |
carp "Error sending mail: $Mail::Sendmail::error \n"; |
160 |
} |
161 |
} |
162 |
} else { |
163 |
$status = "fail"; |
164 |
$error = "Could not save note. Invalid issue id or empty note."; |
165 |
} |
166 |
|
167 |
my $response = "{\"status\": \"$status\", \"note\": \"$clean_note\", \"issue_id\": \"$issue_id\", \"error\": \"$error\"}"; |
168 |
output_with_http_headers($query, undef, $response, 'js'); |
169 |
exit; |
170 |
} |
171 |
|
172 |
|
57 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
173 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
58 |
{ |
174 |
{ |
59 |
template_name => "opac-user.tt", |
175 |
template_name => "opac-user.tt", |
60 |
- |
|
|