3 # This file is part of Koha.
5 # Copyright 2014 BibLibre
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 use C4::Auth qw /check_cookie_auth/;
26 use C4::Output qw(:DEFAULT :ajax);
36 svc/patron_notes - Web service for setting patron notes on items
43 my $is_ajax = is_ajax();
45 my ( $auth_status, $sessionID ) = check_cookie_auth( $query->cookie('CGISESSID'), {} );
46 if ( $auth_status ne "ok" ) {
50 my $action = $query->param('action');
53 if ( $action eq 'issuenote' && C4::Context->preference('AllowCheckoutNotes') ) {
54 my $scrubber = C4::Scrubber->new();
55 my $note = $query->param('note');
56 my $issue_id = $query->param('issue_id');
57 my $clean_note = $scrubber->scrub($note);
61 my ( $template, $borrowernumber, $cookie ) = C4::Auth::get_template_and_user({
62 template_name => "opac-user.tt",
69 if ( $issue_id =~ /\d+/ ) {
70 $member = GetMember(borrowernumber => $borrowernumber);
71 $issue = Koha::Checkouts->find($issue_id);
72 if ( $issue->borrowernumber != $borrowernumber ) {
78 $issue->set({ notedate => dt_from_string(), note => $clean_note })->store;
79 if($clean_note) { # only send email if note not empty
80 my $branch = Koha::Libraries->find( $issue->branchcode );
81 my $biblio = GetBiblioFromItemNumber($issue->itemnumber);
82 my $letter = C4::Letters::GetPreparedLetter (
83 module => 'circulation',
84 letter_code => 'PATRON_NOTE',
85 branchcode => $branch,
87 'biblio' => $biblio->{biblionumber},
88 'borrowers' => $member->{borrowernumber},
91 C4::Message->enqueue($letter, $member, 'email');
92 } else { # note empty, i.e removed
99 my $response = "{\"status\": \"$status\", \"note\": \"$clean_note\", \"issue_id\": \"$issue_id\"}";
100 output_with_http_headers($query, undef, $response, 'js');