+ my @bookfundids_loop;
+ $sth = GetBookFundsId();
+
+ while (my $row = $sth->fetchrow_hashref) {
+ if (defined $input->param('filter_bookfundid') and $input->param('filter_bookfundid') eq $row->{bookfundid}){
+ $row->{selected} = 1;
+ }
+ push @bookfundids_loop, $row;
+ }
+
+ $template->param(
+ filter_bookfundids => \@bookfundids_loop,
+ filter_branches => \@branchloop,
+ filter_bookfundname => $input->param('filter_bookfundname') || undef,
+ );
+
+ # searching the bookfunds corresponding to our filtering rules
+ my @results = SearchBookFund(
+ $input->param('filter'),
+ $input->param('filter_bookfundid'),
+ $input->param('filter_bookfundname'),
+ $input->param('filter_branchcode'),
+ );
+
+ # does the book funds have budgets?
+ my @loop_id;
+ $sth = GetBookFundsId();
+ while (my $row = $sth->fetchrow){
+ push @loop_id, $row;
+ }
+
+ my ($id,%nb_budgets_of);
+ foreach $id (@loop_id){
+ my $number = Countbookfund($id);
+ $nb_budgets_of{$id} = $number;
+ }
+
+ # pagination informations
+ my $page = $input->param('page') || 1;
+ my @loop;
+
+ my $first = ($page - 1) * $pagesize;
+
+ # if we are on the last page, the number of the last word to display
+ # must not exceed the length of the results array
+ my $last = min(
+ $first + $pagesize - 1,
+ scalar(@results) - 1,
+ );
+
+ my $toggle = 0;
+ foreach my $result (@results[$first .. $last]) {
+ push(
+ @loop,
+ {
+ %{$result},
+ toggle => $toggle++%2,
+ branchname =>
+ $branches->{ $result->{branchcode} }->{branchname},
+ has_budgets => defined $nb_budgets_of{ $result->{bookfundid} },
+ }
+ );
+ }
+
+ $template->param(
+ bookfund => \@loop,
+ pagination_bar => pagination_bar(
+ $script_name,
+ getnbpages(scalar @results, $pagesize),
+ $page,
+ 'page'
+ )
+ );
+} #---- END $OP eq DEFAULT