1 package C4::Authorities;
5 # Copyright 2000-2002 Katipo Communications
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA 02111-1307 USA
26 use vars qw($VERSION @ISA @EXPORT);
28 # set the version for version checking
33 C4::Accounts - Functions for dealing with Koha authorities
41 The functions in this module deal with the authorities table in koha.
42 It contains every functions to manage/find authorities.
51 @EXPORT = qw(&newauthority &searchauthority
53 # FIXME - This is never used
57 $id = &newauthority($dbh,$hash);
59 adds an authority entry in the db.
60 It calculates the level of the authority with the authoritysep and the complete hierarchy.
62 C<$dbh> is a DBI::db handle for the Koha database.
64 C<$hash> is a hash containing freelib,stdlib,category and father.
72 $id = &SearchAuthority($dbh,$category,$toponly,$branch,$searchstring,$type);
74 searches for an authority
76 C<$dbh> is a DBI::db handle for the Koha database.
78 C<$category> is the category of the authority
80 C<$toponly> if set, returns only one level of entries. If unset, returns the main level and the sub entries.
82 C<$branch> can contain a branch hierarchy. For example, if C<$branch> contains 1024|2345, SearchAuthority will return only
83 entries beginning by 1024|2345
85 C<$searchstring> contains a string. Only entries beginning by C<$searchstring> are returned
90 my ($env,$category,$toponly,$branch,$searchstring)=@_;
91 my $dbh = C4::Context->dbh;
92 $searchstring=~ s/\'/\\\'/g;
93 my $query="Select distinct stdlib,id,hierarchy,level from bibliothesaurus where (category like \"$category%\")";
94 $query .= " and hierarchy='$branch'" if ($branch && $toponly);
95 $query .= " and hierarchy like \"$branch%\"" if ($branch && !$toponly);
96 $query .= " and hierarchy=''" if (!$branch & $toponly);
97 $query .= " and stdlib like \"$searchstring%\"" if ($searchstring);
98 $query .= " order by category,stdlib";
99 my $sth=$dbh->prepare($query);
104 while (my $data=$sth->fetchrow_hashref){
105 if ($old_stdlib ne $data->{'stdlib'}) {
107 push(@results,$data);
109 $old_stdlib = $data->{'stdlib'};
112 return ($cnt,\@results);
116 END { } # module clean-up code here (global destructor)