- $sth->finish;
-# print DEBUG "getcategoryinfo: exit: returning ".cvs(\@results)."\n";
- return \@results;
-}
-
-# FIXME This doesn't belong here; it should be moved into a module
-sub setbranchinfo {
-# sets the data from the editbranch form, and writes to the database...
- my ($data) = @_;
- my $dbh = C4::Context->dbh;
- my $query = "replace branches (branchcode,branchname,branchaddress1,branchaddress2,branchaddress3,branchphone,branchfax,branchemail) values (";
- my $tmp;
- $tmp = $data->{'branchcode'}; $query.= $dbh->quote($tmp).",";
- $tmp = $data->{'branchname'}; $query.= $dbh->quote($tmp).",";
- $tmp = $data->{'branchaddress1'}; $query.= $dbh->quote($tmp).",";
- $tmp = $data->{'branchaddress2'}; $query.= $dbh->quote($tmp).",";
- $tmp = $data->{'branchaddress3'}; $query.= $dbh->quote($tmp).",";
- $tmp = $data->{'branchphone'}; $query.= $dbh->quote($tmp).",";
- $tmp = $data->{'branchfax'}; $query.= $dbh->quote($tmp).",";
- $tmp = $data->{'branchemail'}; $query.= $dbh->quote($tmp).")";
- my $sth=$dbh->prepare($query);
- $sth->execute;
- $sth->finish;
-# sort out the categories....
- my @checkedcats;
- my $cats = getcategoryinfo();
- foreach my $cat (@$cats) {
- my $code = $cat->{'categorycode'};
- if ($data->{$code}) {
- push(@checkedcats, $code);
- }
- }
- my $branchcode = $data->{'branchcode'};
- my $branch = getbranchinfo($branchcode);
- $branch = $branch->[0];
- my $branchcats = $branch->{'categories'};
- my @addcats;
- my @removecats;
- foreach my $bcat (@$branchcats) {
- unless (grep {/^$bcat$/} @checkedcats) {
- push(@removecats, $bcat);
- }
- }
- foreach my $ccat (@checkedcats){
- unless (grep {/^$ccat$/} @$branchcats) {
- push(@addcats, $ccat);
- }
- }
- # FIXME - There's already a $dbh in this scope.
- my $dbh = C4::Context->dbh;
- foreach my $cat (@addcats) {
- my $query = "insert into branchrelations (branchcode, categorycode) values(?, ?)";
- my $sth = $dbh->prepare($query);
- $sth->execute($branchcode, $cat);
- $sth->finish;
- }
- foreach my $cat (@removecats) {
- my $query = "delete from branchrelations where branchcode=? and categorycode=?";
- my $sth = $dbh->prepare($query);
- $sth->execute($branchcode, $cat);
- $sth->finish;
- }
-}
-
-sub deletebranch {
-# delete branch...
- my ($branchcode) = @_;
- my $query = "delete from branches where branchcode = ?";
- my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare($query);
- $sth->execute($branchcode);
- $sth->finish;
-}
-
-sub checkdatabasefor {
-# check to see if the branchcode is being used in the database somewhere....
- my ($branchcode) = @_;
- my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare("select count(*) from items where holdingbranch=? or homebranch=?");
- $sth->execute($branchcode, $branchcode);
- my ($total) = $sth->fetchrow_array;
- $sth->finish;
- my $message;
- if ($total) {
- # FIXME: need to be replaced by an exported boolean parameter
- $message = "Branch cannot be deleted because there are $total items using that branch.";
- }
- return $message;