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('AllowIssueNotes') ) {
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);
62 my ( $template, $borrowernumber, $cookie ) = C4::Auth::get_template_and_user({
63 template_name => "opac-user.tt",
70 if ( $issue_id =~ /\d+/ ) {
71 $member = GetMember(borrowernumber => $borrowernumber);
72 $issue = Koha::Checkouts->find($issue_id);
73 if ( $issue->borrowernumber != $borrowernumber ) {
75 $error = "Invalid issue id!";
79 $error = "Invalid issue id!";
82 if ( (not $error) && $issue->set({ notedate => dt_from_string(), note => $clean_note })->store ) {
83 if($clean_note) { # only send email if note not empty
84 my $branch = Koha::Libraries->find( $issue->branchcode );
85 my $biblio = GetBiblioFromItemNumber($issue->itemnumber);
86 my $letter = C4::Letters::GetPreparedLetter (
87 module => 'circulation',
88 letter_code => 'PATRON_NOTE',
89 branchcode => $branch,
91 'biblio' => $biblio->{biblionumber},
92 'borrowers' => $member->{borrowernumber},
95 C4::Message->enqueue($letter, $member, 'email');
96 } else { # note empty, i.e removed
101 $error = "Perhaps the item has already been checked in?";
104 my $response = "{\"status\": \"$status\", \"note\": \"$clean_note\", \"issue_id\": \"$issue_id\", \"error\": \"$error\"}";
105 output_with_http_headers($query, undef, $response, 'js');