+ $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 @bindings;
+
+ $query = '
+SELECT bookfundid,
+ bookfundname,
+ bookfundgroup,
+ branchcode
+ FROM aqbookfund
+ WHERE 1 = 1';
+ if ($input->param('filter')) {
+ if ($input->param('filter_bookfundid')) {
+ $query.= '
+ AND bookfundid = ?
+';
+ push @bindings, $input->param('filter_bookfundid');
+ }
+ if ($input->param('filter_bookfundname')) {
+ $query.= '
+ AND bookfundname like ?
+';
+ push @bindings, '%'.$input->param('filter_bookfundname').'%';
+ }
+ if ($input->param('filter_branchcode')) {
+ $query.= '
+ AND branchcode = ?
+';
+ push @bindings, $input->param('filter_branchcode');
+ }
+ }
+ $query.= '
+ ORDER BY bookfundid
+';
+
+ $sth = $dbh->prepare($query);
+ $sth->execute(@bindings);
+ my @results;
+ while (my $row = $sth->fetchrow_hashref) {
+ push @results, $row;
+ }
+
+ # does the book funds have budgets?
+ $query = '
+SELECT bookfundid,
+ COUNT(*) AS counter
+ FROM aqbudget
+ GROUP BY bookfundid
+';
+ $sth = $dbh->prepare($query);
+ $sth->execute();
+ my %nb_budgets_of;
+ while (my $row = $sth->fetchrow_hashref) {
+ $nb_budgets_of{ $row->{bookfundid} } = $row->{counter};
+ }
+
+ # 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
+$template->param(intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
+ intranetstylesheet => C4::Context->preference("intranetstylesheet"),
+ IntranetNav => C4::Context->preference("IntranetNav"),
+ );