Bug 11030 - Add 359, 947 and 969 fields in french unimarc_complete framework - followup
[koha_fer] / suggestion / suggestion.pl
index c90ffcc..949cca3 100755 (executable)
@@ -31,6 +31,7 @@ use C4::Search;
 use C4::Dates qw(format_date);
 use C4::Members;
 use C4::Debug;
+use URI::Escape;
 
 sub Init{
     my $suggestion= shift @_;
@@ -104,11 +105,14 @@ my ( $template, $borrowernumber, $cookie, $userflags ) = get_template_and_user(
         }
     );
 
+$borrowernumber = $input->param('borrowernumber') if ( $input->param('borrowernumber') );
+$template->param('borrowernumber' => $borrowernumber);
+
 #########################################
 ##  Operations
 ##
 if ( $op =~ /save/i ) {
-       if ( $$suggestion_ref{"STATUS"} ) {
+        if ( $$suggestion_ref{"STATUS"} ) {
         if ( my $tmpstatus = lc( $$suggestion_ref{"STATUS"} ) =~ /ACCEPTED|REJECTED/i ) {
             $$suggestion_ref{ lc( $$suggestion_ref{"STATUS"}) . "date" } = C4::Dates->today;
             $$suggestion_ref{ lc( $$suggestion_ref{"STATUS"}) . "by" }   = C4::Context->userenv->{number};
@@ -123,7 +127,7 @@ if ( $op =~ /save/i ) {
         my $suggestions_loop =
             SearchSuggestion( $suggestion_ref );
         if (@$suggestions_loop>=1){
-            #some suggestion are answering the request Donot Add       
+            #some suggestion are answering the request Donot Add
         } 
         else {    
             ## Adding some informations related to suggestion
@@ -134,8 +138,8 @@ if ( $op =~ /save/i ) {
     map{delete $$suggestion_ref{$_}} keys %$suggestion_ref;
     $op = 'else';
 
-    if( $redirect ) {
-        print $input->redirect("/cgi-bin/koha/members/purchase-suggestions.pl?borrowernumber=$redirect");
+    if( $redirect eq 'purchase_suggestions' ) {
+        print $input->redirect("/cgi-bin/koha/members/purchase-suggestions.pl?borrowernumber=$borrowernumber");
     }
 
 }
@@ -160,26 +164,39 @@ elsif ($op eq "change" ) {
         $$suggestion_ref{"rejecteddate"}=C4::Dates->today;
         $$suggestion_ref{"rejectedby"}=C4::Context->userenv->{number};
     }
-       if ($$suggestion_ref{"STATUS"}){
-               $$suggestion_ref{"manageddate"}=C4::Dates->today;
-               $$suggestion_ref{"managedby"}=C4::Context->userenv->{number};
-       }
-       if ( my $reason = $$suggestion_ref{"reason$tabcode"}){
-               if ( $reason eq "other" ) {
-                               $reason = $$suggestion_ref{"other_reason$tabcode"};
-               }
-               $$suggestion_ref{'reason'}=$reason;
-       }
-       delete $$suggestion_ref{$_} foreach ("reason$tabcode", "other_reason$tabcode");
-       foreach (keys %$suggestion_ref){
-               delete $$suggestion_ref{$_} unless ($$suggestion_ref{$_});
-       }
+    if ($$suggestion_ref{"STATUS"}){
+        $$suggestion_ref{"manageddate"}=C4::Dates->today;
+        $$suggestion_ref{"managedby"}=C4::Context->userenv->{number};
+    }
+    if ( my $reason = $$suggestion_ref{"reason$tabcode"}){
+        if ( $reason eq "other" ) {
+                $reason = $$suggestion_ref{"other_reason$tabcode"};
+        }
+        $$suggestion_ref{'reason'}=$reason;
+    }
+    delete $$suggestion_ref{$_} foreach ("reason$tabcode", "other_reason$tabcode");
+     foreach (keys %$suggestion_ref){
+        delete $$suggestion_ref{$_} unless ($$suggestion_ref{$_});
+    }
     foreach my $suggestionid (@editsuggestions) {
         next unless $suggestionid;
         $$suggestion_ref{'suggestionid'}=$suggestionid;
         &ModSuggestion($suggestion_ref);
     }
-    $op = 'else';
+    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");
 }elsif ($op eq "delete" ) {
     foreach my $delete_field (@editsuggestions) {
         &DelSuggestion( $borrowernumber, $delete_field,'intranet' );
@@ -277,7 +294,7 @@ $template->param(
 
 if(defined($returnsuggested) and $returnsuggested ne "noone")
 {
-       print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=".$returnsuggested."#suggestions");
+    print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=".$returnsuggested."#suggestions");
 }
 
 ####################
@@ -285,10 +302,11 @@ if(defined($returnsuggested) and $returnsuggested ne "noone")
 
 #branch display management
 my $branchfilter = ($displayby ne "branchcode") ? $input->param('branchcode') : '';
-my $onlymine=C4::Context->preference('IndependentBranches') &&
-            C4::Context->userenv && 
-            C4::Context->userenv->{flags}!=1 && 
-            C4::Context->userenv->{branch};
+my $onlymine =
+     C4::Context->preference('IndependentBranches')
+  && C4::Context->userenv
+  && !C4::Context->IsSuperLibrarian()
+  && C4::Context->userenv->{branch};
 my $branches = GetBranches($onlymine);
 my @branchloop;
 
@@ -365,13 +383,13 @@ for ( my $i = 0 ; $i < $count ; $i++ ) {
     my %line;
     $line{currcode} = $rates[$i]->{'currency'};
     $line{rate}     = $rates[$i]->{'rate'};
-       $line{selected} = 1 if ($line{'currcode'} eq $selected_currency);
+    $line{selected} = 1 if ($line{'currcode'} eq $selected_currency);
     push @loop_currency, \%line;
 }
 $template->param(
-        loop_currency => \@loop_currency,
-       price        => sprintf("%.2f", $$suggestion_ref{'price'}||0),
-       total            => sprintf("%.2f", $$suggestion_ref{'total'}||0),
+    loop_currency => \@loop_currency,
+    price        => sprintf("%.2f", $$suggestion_ref{'price'}||0),
+    total            => sprintf("%.2f", $$suggestion_ref{'total'}||0),
 );
 
 # lists of distinct values (without empty) for filters
@@ -389,11 +407,9 @@ foreach my $field ( qw(managedby acceptedby suggestedby budgetid) ) {
     } @$values_list;
     $hashlists{ lc($field) . "_loop" } = \@codes_list;
 }
-$template->param(%hashlists);
 
 $template->param(
     %hashlists,
-    DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
     borrowernumber           => $input->param('borrowernumber'),
     SuggestionStatuses       => GetAuthorisedValues('SUGGEST_STATUS'),
 );