$branches = &GetBranches();
Returns informations about ALL branches, IndependentBranches Insensitive.
-GetBranchInfo() returns the same information without the problems of this function
-(namespace collision, mainly).
+GetBranchInfo() returns the same information.
Create a branch selector with the following code.
=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 name="branch" id="branch">
+ <option value=""></option>
+ [% FOREACH branchloo IN branchloop %]
+ [% IF ( branchloo.selected ) %]
+ <option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>
+ [% ELSE %]
+ <option value="[% branchloo.value %]" >[% branchloo.branchname %]</option>
+ [% END %]
+ [% END %]
</select>
=head4 Note that you often will want to just use GetBranchesLoop, for exactly the example above.
=cut
sub GetBranches {
- my ($onlymine)=@_;
+ my ($onlymine) = @_;
+
# returns a reference to a hash of references to ALL branches...
my %branches;
my $dbh = C4::Context->dbh;
my $sth;
- my $query="SELECT * FROM branches";
+ my $query = "SELECT * FROM branches";
my @bind_parameters;
- if ($onlymine && C4::Context->userenv && C4::Context->userenv->{branch}){
- $query .= ' WHERE branchcode = ? ';
- push @bind_parameters, C4::Context->userenv->{branch};
+ if ( $onlymine && C4::Context->userenv && C4::Context->userenv->{branch} ) {
+ $query .= ' WHERE branchcode = ? ';
+ push @bind_parameters, C4::Context->userenv->{branch};
}
- $query.=" ORDER BY branchname";
+ $query .= " ORDER BY branchname";
$sth = $dbh->prepare($query);
- $sth->execute( @bind_parameters );
-
- my $nsth = $dbh->prepare(
- "SELECT categorycode FROM branchrelations WHERE branchcode = ?"
- ); # prepare once, outside while loop
+ $sth->execute(@bind_parameters);
+
+ my $relations_sth =
+ $dbh->prepare("SELECT branchcode,categorycode FROM branchrelations");
+ $relations_sth->execute();
+ my %relations;
+ while ( my $rel = $relations_sth->fetchrow_hashref ) {
+ push @{ $relations{ $rel->{branchcode} } }, $rel->{categorycode};
+ }
while ( my $branch = $sth->fetchrow_hashref ) {
- $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;
+ foreach my $cat ( @{ $relations{ $branch->{branchcode} } } ) {
$branch->{category}{$cat} = 1;
}
$branches{ $branch->{'branchcode'} } = $branch;
}
sub onlymine {
- return
- C4::Context->preference('IndependentBranches') &&
- C4::Context->userenv &&
- C4::Context->userenv->{flags} %2 != 1 &&
- C4::Context->userenv->{branch} ;
+ return
+ C4::Context->preference('IndependentBranches')
+ && C4::Context->userenv
+ && !C4::Context->IsSuperLibrarian()
+ && C4::Context->userenv->{branch};
}
# always returns a string for OK comparison via "eq" or "ne"
$sth = $dbh->prepare("Select branchname from branches where branchcode=?");
$sth->execute($branchcode);
my $branchname = $sth->fetchrow_array;
- $sth->finish;
return ($branchname);
}
(branchcode,branchname,branchaddress1,
branchaddress2,branchaddress3,branchzip,branchcity,branchstate,
branchcountry,branchphone,branchfax,branchemail,
- branchurl,branchip,branchprinter,branchnotes,opac_info)
- VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
+ branchurl,branchip,branchprinter,branchnotes,opac_info,
+ branchreplyto, branchreturnpath)
+ VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
";
my $sth = $dbh->prepare($query);
$sth->execute(
$data->{'branchemail'}, $data->{'branchurl'},
$data->{'branchip'}, $data->{'branchprinter'},
$data->{'branchnotes'}, $data->{opac_info},
+ $data->{'branchreplyto'}, $data->{'branchreturnpath'}
);
return 1 if $dbh->err;
} else {
branchaddress2=?,branchaddress3=?,branchzip=?,
branchcity=?,branchstate=?,branchcountry=?,branchphone=?,
branchfax=?,branchemail=?,branchurl=?,branchip=?,
- branchprinter=?,branchnotes=?,opac_info=?
+ branchprinter=?,branchnotes=?,opac_info=?,
+ branchreplyto=?, branchreturnpath=?
WHERE branchcode=?
";
my $sth = $dbh->prepare($query);
$data->{'branchemail'}, $data->{'branchurl'},
$data->{'branchip'}, $data->{'branchprinter'},
$data->{'branchnotes'}, $data->{opac_info},
+ $data->{'branchreplyto'}, $data->{'branchreturnpath'},
$data->{'branchcode'},
);
}
"insert into branchrelations (branchcode, categorycode) values(?, ?)"
);
$sth->execute( $branchcode, $cat );
- $sth->finish;
}
foreach my $cat (@removecats) {
my $sth =
"delete from branchrelations where branchcode=? and categorycode=?"
);
$sth->execute( $branchcode, $cat );
- $sth->finish;
}
}
while (my $branch = $sth->fetchrow) {
push @branches, $branch;
}
- $sth->finish();
return( \@branches );
}
while ( my ($cat) = $nsth->fetchrow_array ) {
push( @cats, $cat );
}
- $nsth->finish;
$data->{'categories'} = \@cats;
push( @results, $data );
}
- $sth->finish;
return \@results;
}
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare("delete from branches where branchcode = ?");
$sth->execute($branchcode);
- $sth->finish;
}
=head2 ModBranchCategoryInfo
# we are doing an insert
my $sth = $dbh->prepare("INSERT INTO branchcategories (categorycode,categoryname,codedescription,categorytype,show_in_pulldown) VALUES (?,?,?,?,?)");
$sth->execute(uc( $data->{'categorycode'} ),$data->{'categoryname'}, $data->{'codedescription'},$data->{'categorytype'},$data->{'show_in_pulldown'} );
- $sth->finish();
}
else {
# modifying
my $sth = $dbh->prepare("UPDATE branchcategories SET categoryname=?,codedescription=?,categorytype=?,show_in_pulldown=? WHERE categorycode=?");
$sth->execute($data->{'categoryname'}, $data->{'codedescription'},$data->{'categorytype'},$data->{'show_in_pulldown'},uc( $data->{'categorycode'} ) );
- $sth->finish();
}
}
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare("delete from branchcategories where categorycode = ?");
$sth->execute($categorycode);
- $sth->finish;
}
=head2 CheckBranchCategorycode