3 # Copyright 2016 Aleisha Amohia <aleisha@catalyst.net.nz>
5 # This file is part of Koha.
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>.
26 use C4::Output qw( output_html_with_http_headers );
27 use C4::Auth qw( get_template_and_user );
30 use Koha::DateUtils qw( dt_from_string );
35 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
37 template_name => "opac-issue-note.tt",
43 my $patron = Koha::Patrons->find( $borrowernumber );
45 firstname => $patron->firstname,
46 surname => $patron->surname,
47 borrowernumber => $borrowernumber,
50 my $issue_id = $query->param('issue_id');
51 my $issue = $patron->checkouts->find( $issue_id );
55 print $query->redirect("/cgi-bin/koha/opac-user.pl");
59 my $itemnumber = $issue->itemnumber;
60 my $biblio = $issue->item->biblio;
62 issue_id => $issue_id,
63 title => $biblio->title,
64 author => $biblio->author,
66 itemnumber => $issue->itemnumber,
69 my $op = $query->param('op') || "";
70 if ( $op eq 'cud-issuenote' && C4::Context->preference('AllowCheckoutNotes') && $issue ) {
71 my $note = $query->param('note');
72 my $scrubber = C4::Scrubber->new();
73 my $clean_note = $scrubber->scrub($note);
75 if ( $issue->set({ notedate => dt_from_string(), note => $clean_note, noteseen => 0 })->store ) {
76 if ($clean_note) { # only send email if note not empty
77 my $branch = Koha::Libraries->find( $issue->branchcode );
78 my $letter = C4::Letters::GetPreparedLetter (
79 module => 'circulation',
80 letter_code => 'CHECKOUT_NOTE',
81 branchcode => $branch,
82 lang => $patron->lang,
84 'biblio' => $biblio->biblionumber,
85 'borrowers' => $borrowernumber,
89 my $to_address = $branch->inbound_email_address;
90 my $reply_address = $patron->email || $patron->emailpro || $patron->B_email;
92 C4::Letters::EnqueueLetter({
94 message_transport_type => 'cud-email',
95 borrowernumber => $patron->borrowernumber,
96 to_address => $to_address,
97 reply_address => $reply_address,
101 print $query->redirect("/cgi-bin/koha/opac-user.pl");
104 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };