Bug 10080 - Change system pref IndependantBranches to IndependentBranches
[koha.git] / reserve / request.pl
index e7191a9..54f2755 100755 (executable)
@@ -47,7 +47,7 @@ use Koha::DateUtils;
 my $dbh = C4::Context->dbh;
 my $sth;
 my $input = new CGI;
-my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
+my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user(
     {
         template_name   => "reserve/request.tmpl",
         query           => $input,
@@ -65,23 +65,11 @@ my $showallitems = $input->param('showallitems');
 my $branches = GetBranches();
 my $itemtypes = GetItemTypes();
 
-my $default = C4::Context->userenv->{branch};
-my @values;
-my %label_of;
-
-foreach my $branchcode (sort keys %{$branches} ) {
-    push @values, $branchcode;
-    $label_of{$branchcode} = $branches->{$branchcode}->{branchname};
+my $userbranch = '';
+if (C4::Context->userenv && C4::Context->userenv->{'branch'}) {
+    $userbranch = C4::Context->userenv->{'branch'};
 }
-my $CGIbranch = CGI::scrolling_list(
-                                    -name     => 'pickup',
-                                    -id          => 'pickup',
-                                    -values   => \@values,
-                                    -default  => $default,
-                                    -labels   => \%label_of,
-                                    -size     => 1,
-                                    -multiple => 0,
-                                   );
+
 
 # Select borrowers infos
 my $findborrower = $input->param('findborrower');
@@ -244,9 +232,16 @@ foreach my $biblionumber (@biblionumbers) {
     my $dat          = GetBiblioData($biblionumber);
 
     unless ( CanBookBeReserved($borrowerinfo->{borrowernumber}, $biblionumber) ) {
-               $warnings = 1;
+               $warnings = 1;
         $maxreserves = 1;
     }
+
+    my $alreadypossession;
+    if (not C4::Context->preference('AllowHoldsOnPatronsPossessions') and CheckIfIssuedToPatron($borrowerinfo->{borrowernumber},$biblionumber)) {
+        $warnings = 1;
+        $alreadypossession = 1;
+    }
+
     # get existing reserves .....
     my ( $count, $reserves ) = GetReservesFromBiblionumber($biblionumber,1);
     my $totalcount = $count;
@@ -268,7 +263,8 @@ foreach my $biblionumber (@biblionumbers) {
     $template->param( alreadyreserved => $alreadyreserved,
                       messages => $messages,
                       warnings => $warnings,
-                                         maxreserves=>$maxreserves
+                 maxreserves=>$maxreserves,
+                     alreadypossession => $alreadypossession,
                                          );
 
 
@@ -430,7 +426,7 @@ foreach my $biblionumber (@biblionumbers) {
 
             # if independent branches is on we need to check if the person can reserve
             # for branches they arent logged in to
-            if ( C4::Context->preference("IndependantBranches") ) {
+            if ( C4::Context->preference("IndependentBranches") ) {
                 if (! C4::Context->preference("canreservefromotherbranches")){
                     # cant reserve items so need to check if item homebranch and userenv branch match if not we cant reserve
                     my $userenv = C4::Context->userenv;
@@ -571,10 +567,16 @@ foreach my $biblionumber (@biblionumbers) {
         $reserve{'barcode'}         = $res->{'barcode'};
         $reserve{'priority'}    = $res->{'priority'};
         $reserve{'lowestPriority'}    = $res->{'lowestPriority'};
-        $reserve{'branchloop'} = GetBranchesLoop($res->{'branchcode'});
         $reserve{'optionloop'} = \@optionloop;
         $reserve{'suspend'} = $res->{'suspend'};
         $reserve{'suspend_until'} = $res->{'suspend_until'};
+
+        if ( C4::Context->preference('IndependantBranches') && $flags->{'superlibrarian'} != 1 ) {
+              $reserve{'branchloop'} = [ GetBranchDetail($res->{'branchcode'}) ];
+        } else {
+              $reserve{'branchloop'} = GetBranchesLoop($res->{'branchcode'});
+        }
+
         push( @reserveloop, \%reserve );
     }
 
@@ -582,8 +584,7 @@ foreach my $biblionumber (@biblionumbers) {
     my $time = time();
 
     $template->param(
-                     CGIbranch   => $CGIbranch,
-
+                     branchloop  => GetBranchesLoop($userbranch),
                      time        => $time,
                      fixedRank   => $fixedRank,
                     );
@@ -623,7 +624,6 @@ foreach my $biblionumber (@biblionumbers) {
 
 $template->param( biblioloop => \@biblioloop );
 $template->param( biblionumbers => $biblionumbers );
-$template->param( DHTMLcalendar_dateformat  => C4::Dates->DHTMLcalendar() );
 
 if ($multihold) {
     $template->param( multi_hold => 1 );