Bug 23594: Restore previous view after delete or update itemtype
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 22 Oct 2019 10:00:18 +0000 (12:00 +0200)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 30 Jan 2020 10:56:57 +0000 (10:56 +0000)
We want to restore the previous view when suggestions are deleted or
their itemtypes are updated.
To avoid c/p the code is moved to a new subroutine.

Sponsored-by: BULAC - http://www.bulac.fr/
Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

suggestion/suggestion.pl

index bc9c14c..365e1d1 100755 (executable)
@@ -246,25 +246,12 @@ elsif ($op eq "update_status" ) {
         $suggestion->{suggestionid} = $suggestionid;
         &ModSuggestion($suggestion);
     }
-    my $params = '';
-    foreach my $key (
-        qw(
-        displayby branchcode title author isbn publishercode copyrightdate
-        collectiontitle suggestedby suggesteddate_from suggesteddate_to
-        manageddate_from manageddate_to accepteddate_from
-        accepteddate_to budgetid
-        )
-      )
-    {
-        $params .= $key . '=' . uri_escape($input->param($key)) . '&'
-          if defined($input->param($key));
-    }
-    print $input->redirect("/cgi-bin/koha/suggestion/suggestion.pl?$params");
+    redirect_with_params($input);
 }elsif ($op eq "delete" ) {
     foreach my $delete_field (@editsuggestions) {
         &DelSuggestion( $borrowernumber, $delete_field,'intranet' );
     }
-    $op = 'else';
+    redirect_with_params($input);
 }
 elsif ( $op eq 'update_itemtype' ) {
     my $new_itemtype = $input->param('suggestion_itemtype');
@@ -272,6 +259,7 @@ elsif ( $op eq 'update_itemtype' ) {
         next unless $suggestionid;
         &ModSuggestion({ suggestionid => $suggestionid, itemtype => $new_itemtype });
     }
+    redirect_with_params($input);
 }
 elsif ( $op eq 'show' ) {
     $suggestion_ref=&GetSuggestion($$suggestion_ref{'suggestionid'});
@@ -428,3 +416,21 @@ $template->param(
     SuggestionStatuses       => GetAuthorisedValues('SUGGEST_STATUS'),
 );
 output_html_with_http_headers $input, $cookie, $template->output;
+
+sub redirect_with_params {
+    my ( $input ) = @_;
+    my $params = '';
+    foreach my $key (
+        qw(
+        displayby branchcode title author isbn publishercode copyrightdate
+        collectiontitle suggestedby suggesteddate_from suggesteddate_to
+        manageddate_from manageddate_to accepteddate_from
+        accepteddate_to budgetid
+        )
+      )
+    {
+        $params .= $key . '=' . uri_escape(scalar $input->param($key)) . '&'
+          if defined($input->param($key));
+    }
+    print $input->redirect("/cgi-bin/koha/suggestion/suggestion.pl?$params");
+}