Bug Fixing:
[koha.git] / opac / opac-main.pl
index f9714a3..e878d0f 100755 (executable)
@@ -34,22 +34,6 @@ my $dbh   = C4::Context->dbh;
 
 my $limit = $input->param('recentacqui');
 
-my @branches;
-my @select_branch;
-my %select_branches;
-my $branches = GetBranches();
-my @branchloop;
-foreach my $thisbranch ( keys %$branches ) {
-    my $selected = 1
-      if ( C4::Context->userenv
-        && ( $thisbranch eq C4::Context->userenv->{branch} ) );
-    my %row = (
-        value      => $thisbranch,
-        selected   => $selected,
-        branchname => $branches->{$thisbranch}->{'branchname'},
-    );
-    push @branchloop, \%row;
-}
 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
     {
         template_name   => "opac-main.tmpl",
@@ -68,7 +52,31 @@ if($limit) {
     );
 }
 
-my $borrower = GetMember( $borrowernumber,'borrowernumber' );
+# SearchMyLibraryFirst
+if (C4::Context->preference("SearchMyLibraryFirst")){
+  if (C4::Context->userenv){
+  my $branches = GetBranches();
+  my @branchloop;  
+  
+  foreach my $thisbranch (keys %$branches) {
+        my $selected = 1 if (C4::Context->userenv && ($thisbranch eq C4::Context->userenv->{branch}));
+#         warn $thisbranch;
+#         warn C4::Context->userenv;
+#         warn C4::Context->userenv->{branch};
+#         warn " => ".C4::Context->userenv && ($thisbranch eq C4::Context->userenv->{branch});
+        my %row =(value => $thisbranch,
+                                selected => $selected,
+                                branchname => $branches->{$thisbranch}->{'branchname'},
+                        );
+        push @branchloop, \%row;
+  }
+    $template->param("mylibraryfirst"=>1,branchloop=>\@branchloop);
+  } else {
+    $template->param("mylibraryfirst"=>0)
+   }
+}
+
+    my $borrower = GetMember( $borrowernumber,'borrowernumber' );
 my @languages;
 my $counter = 0;
 my $langavail = getTranslatedLanguages('opac');
@@ -85,7 +93,6 @@ if ( $counter > 1 ) {
 }
 
 $template->param(
-    branchloop           => \@branchloop,
     textmessaging        => $borrower->{textmessaging},
     opaclanguagesdisplay => 0,
 );
@@ -96,6 +103,7 @@ my $news_lang = $input->cookie('KohaOpacLanguage') || C4::Context->preference('o
 my  $all_koha_news  = &GetNewsToDisplay( $news_lang );
 my $koha_news_count = scalar @$all_koha_news;
 
+
 $template->param(
     koha_news       => $all_koha_news,
     koha_news_count => $koha_news_count