Merge remote branch 'kc/new/enh/bug_3659' into kcmaster
[koha.git] / catalogue / search.pl
index 8cb737d..f3f6008 100755 (executable)
@@ -145,6 +145,7 @@ use C4::Auth qw(:DEFAULT get_session);
 use C4::Search;
 use C4::Languages qw(getAllLanguages);
 use C4::Koha;
+use C4::Members qw(GetMember);
 use C4::VirtualShelves qw(GetRecentShelves);
 use POSIX qw(ceil floor);
 use C4::Branch; # GetBranches
@@ -181,6 +182,16 @@ if (C4::Context->preference("marcflavour") eq "UNIMARC" ) {
     $template->param('UNIMARC' => 1);
 }
 
+if($cgi->cookie("holdfor")){ 
+    my $holdfor_patron = GetMember('borrowernumber' => $cgi->cookie("holdfor"));
+    $template->param(
+        holdfor => $cgi->cookie("holdfor"),
+        holdfor_surname => $holdfor_patron->{'surname'},
+        holdfor_firstname => $holdfor_patron->{'firstname'},
+        holdfor_cardnumber => $holdfor_patron->{'cardnumber'},
+    );
+}
+
 ## URI Re-Writing
 # Deprecated, but preserved because it's interesting :-)
 # The same thing can be accomplished with mod_rewrite in
@@ -207,16 +218,20 @@ if (C4::Context->preference("marcflavour") eq "UNIMARC" ) {
 
 # load the branches
 my $branches = GetBranches();
-my @branch_loop;
 
-# we need to know the borrower branch code to set a default branch
-my $borrowerbranchcode = C4::Context->userenv->{'branch'};
-
-for my $branch_hash (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) {
-    # if independantbranches is activated, set the default branch to the borrower branch
-    my $selected = (C4::Context->preference("independantbranches") and ($borrowerbranchcode eq $branch_hash)) ? 1 : undef;
-    push @branch_loop, {value => "$branch_hash" , branchname => $branches->{$branch_hash}->{'branchname'}, selected => $selected};
-}
+# Populate branch_loop with all branches sorted by their name.  If
+# independantbranches is activated, set the default branch to the borrower
+# branch, except for superlibrarian who need to search all libraries.
+my $user = C4::Context->userenv;
+my @branch_loop = map {
+     {
+        value      => $_,
+        branchname => $branches->{$_}->{branchname},
+        selected   => $user->{branch} eq $_ && C4::Branch::onlymine(),
+     }
+} sort {
+    $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname}
+} keys %$branches;
 
 my $categories = GetBranchCategories(undef,'searchdomain');