Bug 30214: (QA follow-up) Clarify code comment
[srvgit] / opac / opac-issue-note.pl
index 781a532..b59e838 100755 (executable)
@@ -23,12 +23,11 @@ use CGI qw ( -utf8 );
 use C4::Koha;
 use C4::Context;
 use C4::Scrubber;
-use C4::Output;
-use C4::Auth;
-use C4::Biblio;
+use C4::Output qw( output_html_with_http_headers );
+use C4::Auth qw( get_template_and_user );
 use C4::Letters;
 use Koha::Checkouts;
-use Koha::DateUtils;
+use Koha::DateUtils qw( dt_from_string );
 use Koha::Patrons;
 
 my $query = CGI->new;
@@ -38,7 +37,6 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
         template_name   => "opac-issue-note.tt",
         query           => $query,
         type            => "opac",
-        debug           => 1,
     }
 );
 
@@ -50,7 +48,14 @@ $template->param(
 );
 
 my $issue_id = $query->param('issue_id');
-my $issue = Koha::Checkouts->find( $issue_id );
+my $issue = $patron->checkouts->find( $issue_id );
+
+unless ( $issue ) {
+    # exit early
+    print $query->redirect("/cgi-bin/koha/opac-user.pl");
+    exit;
+}
+
 my $itemnumber = $issue->itemnumber;
 my $biblio = $issue->item->biblio;
 $template->param(
@@ -62,10 +67,11 @@ $template->param(
 );
 
 my $action = $query->param('action') || "";
-if ( $action eq 'issuenote' && C4::Context->preference('AllowCheckoutNotes') ) {
+if ( $action eq 'issuenote' && C4::Context->preference('AllowCheckoutNotes') && $issue ) {
     my $note = $query->param('note');
     my $scrubber = C4::Scrubber->new();
     my $clean_note = $scrubber->scrub($note);
+
     if ( $issue->set({ notedate => dt_from_string(), note => $clean_note, noteseen => 0 })->store ) {
         if ($clean_note) { # only send email if note not empty
             my $branch = Koha::Libraries->find( $issue->branchcode );