Bug 10277 - Add C4::Context->IsSuperLibrarian()
[koha_fer] / acqui / basket.pl
index df37788..e546948 100755 (executable)
@@ -115,20 +115,36 @@ if ( $op eq 'delete_confirm' ) {
 #Delete all orders included in that basket, and all items received.
     foreach my $myorder (@orders){
         DelOrder($myorder->{biblionumber},$myorder->{ordernumber});
-        warn "suppression de ".$myorder->{biblionumber}.'  '.$myorder->{ordernumber};
     }
 # if $delbiblio = 1, delete the records if possible
     if ((defined $delbiblio)and ($delbiblio ==1)){
+        my @cannotdelbiblios ;
         foreach my $myorder (@orders){
             my $biblionumber = $myorder->{'biblionumber'};
             my $countbiblio = CountBiblioInOrders($biblionumber);
             my $ordernumber = $myorder->{'ordernumber'};
-            my @subscriptions = GetSubscriptionsId ($biblionumber);
+            my $subscriptions = scalar GetSubscriptionsId ($biblionumber);
             my $itemcount = GetItemsCount($biblionumber);
-            DelBiblio($myorder->{biblionumber}) if ($countbiblio == 0 && $itemcount == 0 && !(@subscriptions));
-        warn "suppression de la notice ".$myorder->{biblionumber}};
+            my $error;
+            if ($countbiblio == 0 && $itemcount == 0 && $subscriptions == 0) {
+                $error = DelBiblio($myorder->{biblionumber}) }
+            else {
+                push @cannotdelbiblios, {biblionumber=> ($myorder->{biblionumber}),
+                                         title=> $myorder->{'title'},
+                                         author=> $myorder->{'author'},
+                                         countbiblio=> $countbiblio,
+                                         itemcount=>$itemcount,
+                                         subscriptions=>$subscriptions};
+            }
+            if ($error) {
+                push @cannotdelbiblios, {biblionumber=> ($myorder->{biblionumber}),
+                                         title=> $myorder->{'title'},
+                                         author=> $myorder->{'author'},
+                                         othererror=> $error};
+            }
+        }
+        $template->param( cannotdelbiblios => \@cannotdelbiblios );
     }
-
  # delete the basket
     DelBasket($basketno,);
     $template->param( delete_confirmed => 1 );
@@ -138,7 +154,7 @@ if ( $op eq 'delete_confirm' ) {
     $template->param( delete_confirm => 1 );
     if ( C4::Context->preference("IndependentBranches") ) {
         my $userenv = C4::Context->userenv;
-        unless ( $userenv->{flags} == 1 ) {
+        unless ( C4::Context->IsSuperLibrarian() ) {
             my $validtest = ( $basket->{creationdate} eq '' )
               || ( $userenv->{branch} eq $basket->{branch} )
               || ( $userenv->{branch} eq '' )
@@ -241,7 +257,7 @@ if ( $op eq 'delete_confirm' ) {
     # get librarian branch...
     if ( C4::Context->preference("IndependentBranches") ) {
         my $userenv = C4::Context->userenv;
-        unless ( $userenv->{flags} == 1 ) {
+        unless ( C4::Context->IsSuperLibrarian() ) {
             my $validtest = ( $basket->{creationdate} eq '' )
               || ( $userenv->{branch} eq $basket->{branch} )
               || ( $userenv->{branch} eq '' )