Bug 27209: (follow-up) Add ->is_pickup_location_valid
[koha-ffzg.git] / circ / add_message.pl
index 317f34b..455791b 100755 (executable)
@@ -25,14 +25,13 @@ use C4::Auth;
 use C4::Output;
 use Koha::Patron::Message;
 
-my $input = new CGI;
+my $input = CGI->new;
 
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {   template_name   => "circ/circulation.tt",
         query           => $input,
         type            => "intranet",
-        authnotrequired => 0,
-        flagsrequired   => { borrowers => 1 },
+        flagsrequired   => { borrowers => 'edit_borrowers' },
         debug           => 1,
     }
 );
@@ -41,6 +40,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(
     {
@@ -51,5 +51,14 @@ Koha::Patron::Message->new(
     }
 )->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);