Merge remote branch 'kc/new/enh/bug_5462' into kcmaster
[koha_gimpoz] / members / members-home.pl
index e497f4a..db8be4a 100755 (executable)
@@ -51,13 +51,42 @@ if($quicksearch){
                  debug => 1,
                  });
 }
-my @categories=C4::Category->all;
-$template->param(
-    branchloop=>(defined $branch?GetBranchesLoop($branch):GetBranchesLoop()),
-       categoryloop=>\@categories,
-);
+
+my $branches = GetBranches;
+my @branchloop;
+foreach (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) {
+  my $selected = 1 if $branches->{$_}->{branchcode} eq $branch;
+  my %row = ( value => $_,
+        selected => $selected,
+        branchname => $branches->{$_}->{branchname},
+      );
+  push @branchloop, \%row;
+}
+
+my @categories;
+my $no_categories;
+my $no_add = 0;
+my $branchloop = (defined $branch?GetBranchesLoop($branch):GetBranchesLoop());
+if(scalar(@$branchloop) < 1){
+    $no_add = 1;
+    $template->param(no_branches => 1);
+} else {
+    $template->param(branchloop=>\@$branchloop);
+}
+
+@categories=C4::Category->all;
+if(scalar(@categories) < 1){ $no_categories = 1; }
+if($no_categories && C4::Context->preference("AddPatronLists")=~/code/){
+    $no_add = 1;
+    $template->param(no_categories => 1);
+} else {
+    $template->param(categories=>\@categories);
+}
+
+
 $template->param( 
         "AddPatronLists_".C4::Context->preference("AddPatronLists")=> "1",
+        no_add => $no_add,
             );
 my @letters = map { {letter => $_} } ( 'A' .. 'Z');
 $template->param( letters => \@letters );