3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 #use warnings; FIXME - Bug 2505
23 use Koha::LibraryCategories;
25 use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
33 @EXPORT_OK = qw( &onlymine );
38 C4::Branch - Koha branch module
46 The functions in this module deal with branches.
52 $branches = &GetBranches();
54 Returns informations about ALL branches, IndependentBranches Insensitive.
56 Create a branch selector with the following code.
60 my $branches = GetBranches;
62 foreach my $thisbranch (sort keys %$branches) {
63 my $selected = 1 if $thisbranch eq $branch;
64 my %row =(value => $thisbranch,
65 selected => $selected,
66 branchname => $branches->{$thisbranch}->{branchname},
68 push @branchloop, \%row;
73 <select name="branch" id="branch">
74 <option value=""></option>
75 [% FOREACH branchloo IN branchloop %]
76 [% IF ( branchloo.selected ) %]
77 <option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>
79 <option value="[% branchloo.value %]" >[% branchloo.branchname %]</option>
89 # returns a reference to a hash of references to ALL branches...
91 my $dbh = C4::Context->dbh;
93 my $query = "SELECT * FROM branches";
95 if ( $onlymine && C4::Context->userenv && C4::Context->userenv->{branch} ) {
96 $query .= ' WHERE branchcode = ? ';
97 push @bind_parameters, C4::Context->userenv->{branch};
99 $query .= " ORDER BY branchname";
100 $sth = $dbh->prepare($query);
101 $sth->execute(@bind_parameters);
104 $dbh->prepare("SELECT branchcode,categorycode FROM branchrelations");
105 $relations_sth->execute();
107 while ( my $rel = $relations_sth->fetchrow_hashref ) {
108 push @{ $relations{ $rel->{branchcode} } }, $rel->{categorycode};
111 while ( my $branch = $sth->fetchrow_hashref ) {
112 foreach my $cat ( @{ $relations{ $branch->{branchcode} } } ) {
113 $branch->{category}{$cat} = 1;
115 $branches{ $branch->{'branchcode'} } = $branch;
117 return ( \%branches );
122 C4::Context->preference('IndependentBranches')
123 && C4::Context->userenv
124 && !C4::Context->IsSuperLibrarian()
125 && C4::Context->userenv->{branch};
130 $branch = GetBranch( $query, $branches );
135 my ( $query, $branches ) = @_; # get branch for this query from branches
136 my $branch = $query->param('branch');
137 my %cookie = $query->cookie('userenv');
138 ($branch) || ($branch = $cookie{'branchname'});
139 ( $branches->{$branch} ) || ( $branch = ( keys %$branches )[0] );
148 Koha Development Team <http://koha-community.org/>