+=head2 GetBranchCategories
+
+ my $categories = GetBranchCategories($branchcode,$categorytype);
+
+Returns a list ref of anon hashrefs with keys eq columns of branchcategories table,
+i.e. categorycode, categorydescription, categorytype, categoryname.
+if $branchcode and/or $categorytype are passed, limit set to categories that
+$branchcode is a member of , and to $categorytype.
+
+=cut
+
+sub GetBranchCategories {
+ 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 );
+}
+