Lines 102-122
Create a branch selector with the following code.
Link Here
|
102 |
=cut |
102 |
=cut |
103 |
|
103 |
|
104 |
sub GetBranches { |
104 |
sub GetBranches { |
105 |
my ($onlymine)=@_; |
105 |
my ($onlymine,$onlythis)=@_; |
106 |
# returns a reference to a hash of references to ALL branches... |
106 |
# returns a reference to a hash of references to ALL branches... |
107 |
my %branches; |
107 |
my %branches; |
108 |
my $dbh = C4::Context->dbh; |
108 |
my $dbh = C4::Context->dbh; |
109 |
my $sth; |
109 |
my $sth; |
110 |
my $query="SELECT * FROM branches"; |
110 |
my $query="SELECT * FROM branches"; |
111 |
my @bind_parameters; |
111 |
my @bind_parameters; |
112 |
if ($onlymine && C4::Context->userenv && C4::Context->userenv->{branch}){ |
112 |
if ($onlythis){ |
|
|
113 |
$query .= ' WHERE branchcode = ? '; |
114 |
push @bind_parameters, $onlythis; |
115 |
} |
116 |
elsif ($onlymine && C4::Context->userenv && C4::Context->userenv->{branch}){ |
113 |
$query .= ' WHERE branchcode = ? '; |
117 |
$query .= ' WHERE branchcode = ? '; |
114 |
push @bind_parameters, C4::Context->userenv->{branch}; |
118 |
push @bind_parameters, C4::Context->userenv->{branch}; |
115 |
} |
119 |
} |
116 |
$query.=" ORDER BY branchname"; |
120 |
$query.=" ORDER BY branchname"; |
117 |
$sth = $dbh->prepare($query); |
121 |
$sth = $dbh->prepare($query); |
118 |
$sth->execute( @bind_parameters ); |
122 |
$sth->execute( @bind_parameters ); |
119 |
|
|
|
120 |
my $nsth = $dbh->prepare( |
123 |
my $nsth = $dbh->prepare( |
121 |
"SELECT categorycode FROM branchrelations WHERE branchcode = ?" |
124 |
"SELECT categorycode FROM branchrelations WHERE branchcode = ?" |
122 |
); # prepare once, outside while loop |
125 |
); # prepare once, outside while loop |
Lines 158-164
sub mybranch {
Link Here
|
158 |
sub GetBranchesLoop { # since this is what most pages want anyway |
161 |
sub GetBranchesLoop { # since this is what most pages want anyway |
159 |
my $branch = @_ ? shift : mybranch(); # optional first argument is branchcode of "my branch", if preselection is wanted. |
162 |
my $branch = @_ ? shift : mybranch(); # optional first argument is branchcode of "my branch", if preselection is wanted. |
160 |
my $onlymine = @_ ? shift : onlymine(); |
163 |
my $onlymine = @_ ? shift : onlymine(); |
161 |
my $branches = GetBranches($onlymine); |
164 |
my $onlythis = shift; |
|
|
165 |
my $branches = GetBranches($onlymine, $onlythis); |
162 |
my @loop; |
166 |
my @loop; |
163 |
foreach my $branchcode ( sort { uc($branches->{$a}->{branchname}) cmp uc($branches->{$b}->{branchname}) } keys %$branches ) { |
167 |
foreach my $branchcode ( sort { uc($branches->{$a}->{branchname}) cmp uc($branches->{$b}->{branchname}) } keys %$branches ) { |
164 |
push @loop, { |
168 |
push @loop, { |