Bug 19899: Restore Item floats feature - do not crash
[koha.git] / circ / add_message.pl
index e0ffc40..4233e90 100755 (executable)
@@ -41,6 +41,7 @@ my $borrowernumber   = $input->param('borrowernumber');
 my $branchcode       = $input->param('branchcode');
 my $message_type     = $input->param('message_type');
 my $borrower_message = $input->param('borrower_message');
+my $batch            = $input->param('batch');
 
 Koha::Patron::Message->new(
     {
@@ -49,7 +50,16 @@ Koha::Patron::Message->new(
         message_type   => $message_type,
         message        => $borrower_message,
     }
-);
+)->store;
 
-print $input->redirect(
-    "/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber");
+my $url = $input->referer;
+if ( $url ) {
+    if ( $url =~ m|circulation\.pl$| ) {
+        # Trick for POST form from batch checkouts
+        $url .= "?borrowernumber=$borrowernumber";
+        $url .= "&batch=1" if $batch;
+    }
+} else {
+    $url = "/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber";
+}
+print $input->redirect($url);