3 # This file is part of Koha.
5 # Copyright 2016 Aleisha Amohia <aleisha@catalyst.net.nz>
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>.
22 use JSON qw( encode_json );
24 use C4::Auth qw /check_cookie_auth/;
27 use C4::Output qw(:DEFAULT :ajax);
37 svc/checkout_notes - Web service for setting patron notes on items
44 my $is_ajax = is_ajax();
46 my ( $auth_status, $sessionID ) = check_cookie_auth( $query->cookie('CGISESSID'), {} );
47 if ( $auth_status ne "ok" ) {
51 my $action = $query->param('action');
54 if ( $action eq 'issuenote' && C4::Context->preference('AllowCheckoutNotes') ) {
55 my $scrubber = C4::Scrubber->new();
56 my $note = $query->param('note');
57 my $issue_id = $query->param('issue_id');
58 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 $patron = Koha::Patrons->find( $borrowernumber );
72 $issue = Koha::Checkouts->find($issue_id);
73 if ( $issue->borrowernumber != $borrowernumber ) {
79 $issue->set({ notedate => dt_from_string(), note => $clean_note, noteseen => 0 })->store;
80 if($clean_note) { # only send email if note not empty
81 my $branch = Koha::Libraries->find( $issue->branchcode );
82 my $biblionumber = $issue->item->biblionumber;
83 my $letter = C4::Letters::GetPreparedLetter (
84 module => 'circulation',
85 letter_code => 'CHECKOUT_NOTE',
86 branchcode => $branch,
88 'biblio' => $biblionumber,
89 'borrowers' => $borrowernumber,
90 'issues' => $issue->itemnumber,
94 my $to_address = $branch->get_effective_email;
95 my $reply_address = $patron->email || $patron->emailpro || $patron->B_email;
97 C4::Letters::EnqueueLetter({
99 message_transport_type => 'email',
100 borrowernumber => $patron->borrowernumber,
101 to_address => $to_address,
102 reply_address => $reply_address,
104 } else { # note empty, i.e removed
111 my $json = encode_json ( { status => $status, note => $clean_note, issue_id => $issue_id } );
112 output_with_http_headers($query, undef, $json, 'json');