From 7650b33e3e6f09d1eb398263b1d3cdbcb790a7bb Mon Sep 17 00:00:00 2001 From: hdl Date: Mon, 21 Nov 2005 17:10:37 +0000 Subject: [PATCH] Adding getallbranches function which is not sensitive to IndependantBranches value --- C4/Koha.pm | 63 ++++++++++++++++++++++++++++++++++++++++- circ/branchtransfers.pl | 2 +- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/C4/Koha.pm b/C4/Koha.pm index af2aadc147..59474ad90d 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -60,7 +60,8 @@ Koha.pm provides many functions for Koha scripts. &getitemtypes &getitemtypeinfo &getframeworks &getframeworkinfo &getauthtypes &getauthtype - &getallthemes &getalllanguages + &getallthemes &getalllanguages + &getallbranches $DEBUG); use vars qw(); @@ -173,6 +174,8 @@ sub subfield_is_koha_internal_p ($) { $branches = &getbranches(); returns informations about branches. Create a branch selector with the following code + Is branchIndependant sensitive + When IndependantBranches is set AND user is not superlibrarian, displays only user's branch =head3 in PERL SCRIPT @@ -232,6 +235,64 @@ sub getbranches { return (\%branches); } +=head2 getallbranches + + $branches = &getallbranches(); + returns informations about ALL branches. + Create a branch selector with the following code + IndependantBranches Insensitive... + +=head3 in PERL SCRIPT + +my $branches = getallbranches; +my @branchloop; +foreach my $thisbranch (keys %$branches) { + my $selected = 1 if $thisbranch eq $branch; + my %row =(value => $thisbranch, + selected => $selected, + branchname => $branches->{$thisbranch}->{'branchname'}, + ); + push @branchloop, \%row; +} + + +=head3 in TEMPLATE + + +=cut + +sub getallbranches { +# returns a reference to a hash of references to ALL branches... + my %branches; + my $dbh = C4::Context->dbh; + my $sth; + $sth = $dbh->prepare("Select * from branches order by branchname"); + $sth->execute; + while (my $branch=$sth->fetchrow_hashref) { + my $nsth = $dbh->prepare("select categorycode from branchrelations where branchcode = ?"); + $nsth->execute($branch->{'branchcode'}); + while (my ($cat) = $nsth->fetchrow_array) { + # FIXME - This seems wrong. It ought to be + # $branch->{categorycodes}{$cat} = 1; + # otherwise, there's a namespace collision if there's a + # category with the same name as a field in the 'branches' + # table (i.e., don't create a category called "issuing"). + # In addition, the current structure doesn't really allow + # you to list the categories that a branch belongs to: + # you'd have to list keys %$branch, and remove those keys + # that aren't fields in the "branches" table. + $branch->{$cat} = 1; + } + $branches{$branch->{'branchcode'}}=$branch; + } + return (\%branches); +} + =head2 getitemtypes $itemtypes = &getitemtypes(); diff --git a/circ/branchtransfers.pl b/circ/branchtransfers.pl index fe42edec2e..f9e9f77394 100755 --- a/circ/branchtransfers.pl +++ b/circ/branchtransfers.pl @@ -39,7 +39,7 @@ my %env; my $linecolor1= 0; my $linecolor2= 1; -my $branches = getbranches(); +my $branches = getallbranches(); my $printers = getprinters(\%env);