+my $onlymine=C4::Context->preference('IndependantBranches') &&
+ C4::Context->userenv &&
+ C4::Context->userenv->{flags}!=1 &&
+ C4::Context->userenv->{branch};
+my $branches = GetBranches($onlymine);
+my @branchloop;
+for my $thisbranch (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) {
+ my $selected = 1 if ($thisbranch eq C4::Context->userenv->{'branch'});
+ my $selected = 1 if (defined($subs) && $thisbranch eq $subs->{'branchcode'});
+ my %row =(value => $thisbranch,
+ selected => $selected,
+ branchname => $branches->{$thisbranch}->{'branchname'},
+ );
+ push @branchloop, \%row;
+}
+$template->param(branchloop => \@branchloop,
+ DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
+);