Adding getallbranches function which is not sensitive to IndependantBranches value

This commit is contained in:
hdl 2005-11-21 17:10:37 +00:00
parent 01e8ba2de3
commit 7650b33e3e
2 changed files with 63 additions and 2 deletions

View File

@ -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
<select name="branch">
<option value="">Default</option>
<!-- TMPL_LOOP name="branchloop" -->
<option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="branchname" --></option>
<!-- /TMPL_LOOP -->
</select>
=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();

View File

@ -39,7 +39,7 @@ my %env;
my $linecolor1= 0;
my $linecolor2= 1;
my $branches = getbranches();
my $branches = getallbranches();
my $printers = getprinters(\%env);