+sub onlymine {
+ return
+ C4::Context->preference('IndependantBranches') &&
+ C4::Context->userenv &&
+ C4::Context->userenv->{flags} %2 != 1 &&
+ C4::Context->userenv->{branch} ;
+}
+
+# always returns a string for OK comparison via "eq" or "ne"
+sub mybranch {
+ C4::Context->userenv or return '';
+ return C4::Context->userenv->{branch} || '';
+}
+
+sub GetBranchesLoop (;$$) { # since this is what most pages want anyway
+ my $branch = @_ ? shift : mybranch(); # optional first argument is branchcode of "my branch", if preselection is wanted.
+ my $onlymine = @_ ? shift : onlymine();
+ my $branches = GetBranches($onlymine);
+ my @loop;
+ foreach (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) {
+ push @loop, {
+ value => $_,
+ selected => ($_ eq $branch) ? 1 : 0,
+ branchname => $branches->{$_}->{branchname},
+ };
+ }
+ return \@loop;
+}
+