- my ($branchcode,$categorytype) = @_;
- my $dbh = C4::Context->dbh();
- my $query = "SELECT c.* FROM branchcategories c";
- my (@where, @bind);
- if($branchcode) {
- $query .= ",branchrelations r, branches b ";
- push @where, "c.categorycode=r.categorycode and r.branchcode=? ";
- push @bind , $branchcode;
- }
- if ($categorytype) {
- push @where, " c.categorytype=? ";
- push @bind, $categorytype;
- }
- $query .= " where " . join(" and ", @where) if(@where);
- $query .= " order by categorytype,c.categorycode";
- my $sth=$dbh->prepare( $query);
- $sth->execute(@bind);
-
- my $branchcats = $sth->fetchall_arrayref({});
- $sth->finish();
- return( $branchcats );
+ my ( $branchcode, $categorytype, $show_in_pulldown, $selected_in_pulldown ) = @_;
+ my $dbh = C4::Context->dbh();
+
+ my $query = "SELECT c.* FROM branchcategories c";
+ my ( @where, @bind );
+
+ if( $branchcode ) {
+ $query .= ",branchrelations r, branches b ";
+ push @where, "c.categorycode = r.categorycode AND r.branchcode = ? ";
+ push @bind , $branchcode;
+ }
+
+ if ( $categorytype ) {
+ push @where, " c.categorytype = ? ";
+ push @bind, $categorytype;
+ }
+
+ if ( defined( $show_in_pulldown ) ) {
+ push( @where, " c.show_in_pulldown = ? " );
+ push( @bind, $show_in_pulldown );
+ }
+
+ $query .= " WHERE " . join(" AND ", @where) if(@where);
+ $query .= " ORDER BY categorytype,c.categorycode";
+ my $sth=$dbh->prepare( $query);
+ $sth->execute(@bind);
+
+ my $branchcats = $sth->fetchall_arrayref({});
+ $sth->finish();
+
+ if ( $selected_in_pulldown ) {
+ foreach my $bc ( @$branchcats ) {
+ $bc->{'selected'} = 1 if ( $bc->{'categorycode'} eq $selected_in_pulldown );
+ }
+ }
+
+ return( $branchcats );