-=head2 ModBranch
-
-$error = &ModBranch($newvalue);
-
-This function modify an existing branch
-
-C<$newvalue> is a ref to an array wich is containt all the column from branches table.
-
-=cut
-
-sub ModBranch {
- my ($data) = @_;
-
- my $dbh = C4::Context->dbh;
- if ($data->{add}) {
- my $query = "
- INSERT INTO branches
- (branchcode,branchname,branchaddress1,
- branchaddress2,branchaddress3,branchzip,branchcity,branchstate,
- branchcountry,branchphone,branchfax,branchemail,
- branchurl,branchip,branchprinter,branchnotes,opac_info)
- VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
- ";
- my $sth = $dbh->prepare($query);
- $sth->execute(
- $data->{'branchcode'}, $data->{'branchname'},
- $data->{'branchaddress1'}, $data->{'branchaddress2'},
- $data->{'branchaddress3'}, $data->{'branchzip'},
- $data->{'branchcity'}, $data->{'branchstate'},
- $data->{'branchcountry'},
- $data->{'branchphone'}, $data->{'branchfax'},
- $data->{'branchemail'}, $data->{'branchurl'},
- $data->{'branchip'}, $data->{'branchprinter'},
- $data->{'branchnotes'}, $data->{opac_info},
- );
- return 1 if $dbh->err;
- } else {
- my $query = "
- UPDATE branches
- SET branchname=?,branchaddress1=?,
- branchaddress2=?,branchaddress3=?,branchzip=?,
- branchcity=?,branchstate=?,branchcountry=?,branchphone=?,
- branchfax=?,branchemail=?,branchurl=?,branchip=?,
- branchprinter=?,branchnotes=?,opac_info=?
- WHERE branchcode=?
- ";
- my $sth = $dbh->prepare($query);
- $sth->execute(
- $data->{'branchname'},
- $data->{'branchaddress1'}, $data->{'branchaddress2'},
- $data->{'branchaddress3'}, $data->{'branchzip'},
- $data->{'branchcity'}, $data->{'branchstate'},
- $data->{'branchcountry'},
- $data->{'branchphone'}, $data->{'branchfax'},
- $data->{'branchemail'}, $data->{'branchurl'},
- $data->{'branchip'}, $data->{'branchprinter'},
- $data->{'branchnotes'}, $data->{opac_info},
- $data->{'branchcode'},
- );
- }
- # sort out the categories....
- my @checkedcats;
- my $cats = GetBranchCategory();
- foreach my $cat (@$cats) {
- my $code = $cat->{'categorycode'};
- if ( $data->{$code} ) {
- push( @checkedcats, $code );
- }
- }
- my $branchcode = uc( $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 );
- }
- }
- foreach my $cat (@addcats) {
- my $sth =
- $dbh->prepare(
-"insert into branchrelations (branchcode, categorycode) values(?, ?)"
- );
- $sth->execute( $branchcode, $cat );
- $sth->finish;
- }
- foreach my $cat (@removecats) {
- my $sth =
- $dbh->prepare(
- "delete from branchrelations where branchcode=? and categorycode=?"
- );
- $sth->execute( $branchcode, $cat );
- $sth->finish;
- }
-}
-
-=head2 GetBranchCategory
-
-$results = GetBranchCategory($categorycode);
-
-C<$results> is an ref to an array.
-
-=cut
-
-sub GetBranchCategory {
-
- # returns a reference to an array of hashes containing branches,
- my ($catcode) = @_;
- my $dbh = C4::Context->dbh;
- my $sth;
-
- # print DEBUG "GetBranchCategory: entry: catcode=".cvs($catcode)."\n";
- if ($catcode) {
- $sth =
- $dbh->prepare(
- "select * from branchcategories where categorycode = ?");
- $sth->execute($catcode);
- }
- else {
- $sth = $dbh->prepare("Select * from branchcategories");
- $sth->execute();
- }
- my @results;
- while ( my $data = $sth->fetchrow_hashref ) {
- push( @results, $data );
- }
- $sth->finish;
-
- # print DEBUG "GetBranchCategory: exit: returning ".cvs(\@results)."\n";
- return \@results;
-}
-
-=head2 GetBranchCategories
-
- my $categories = GetBranchCategories($branchcode,$categorytype);
-
-Returns a list ref of anon hashrefs with keys eq columns of branchcategories table,
-i.e. categorycode, categorydescription, categorytype, categoryname.
-if $branchcode and/or $categorytype are passed, limit set to categories that
-$branchcode is a member of , and to $categorytype.
-
-=cut
-
-sub GetBranchCategories {
- my ($branchcode,$categorytype) = @_;
- my $dbh = C4::Context->dbh();
- my $query = "SELECT c.* FROM branchcategories c";
- my (@where, @bind);
- if($branchcode) {
- $query .= ",branchrelations r, branches b ";
- push @where, "c.categorycode=r.categorycode and r.branchcode=? ";
- push @bind , $branchcode;
- }
- if ($categorytype) {
- push @where, " c.categorytype=? ";
- push @bind, $categorytype;
- }
- $query .= " where " . join(" and ", @where) if(@where);
- $query .= " order by categorytype,c.categorycode";
- my $sth=$dbh->prepare( $query);
- $sth->execute(@bind);
-
- my $branchcats = $sth->fetchall_arrayref({});
- $sth->finish();
- return( $branchcats );
-}
-
-=head2 GetCategoryTypes
-
-$categorytypes = GetCategoryTypes;
-returns a list of category types.
-Currently these types are HARDCODED.
-type: 'searchdomain' defines a group of agencies that the calling library may search in.
-Other usage of agency categories falls under type: 'properties'.
- to allow for other uses of categories.
-The searchdomain bit may be better implemented as a separate module, but
-the categories were already here, and minimally used.
-=cut
-
- #TODO manage category types. rename possibly to 'agency domains' ? as borrowergroups are called categories.
-sub GetCategoryTypes {
- return ( 'searchdomain','properties');
-}
-