Updated help files.
[koha.git] / C4 / Maintainance.pm
blobb8a23c8c3d4f6685ea1d33b0b39e6d78f17d8ccd
1 package C4::Maintainance; #assumes C4/Maintainance
3 #package to deal with marking up output
6 # Copyright 2000-2002 Katipo Communications
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA 02111-1307 USA
23 use strict;
24 use C4::Context;
26 require Exporter;
28 use vars qw($VERSION @ISA @EXPORT);
30 # set the version for version checking
31 $VERSION = 0.01;
33 =head1 NAME
35 C4::Maintenance - Koha catalog maintenance functions
37 =head1 SYNOPSIS
39 use C4::Maintenance;
41 =head1 DESCRIPTION
43 The functions in this module perform various catalog-maintenance
44 functions, including deleting and undeleting books, fixing
45 miscategorized items, etc.
47 =head1 FUNCTIONS
49 =over 2
51 =cut
53 @ISA = qw(Exporter);
54 @EXPORT = qw(&listsubjects &shiftgroup &deletedbib &undeletebib
55 &updatetype &logaction);
57 =item listsubjects
59 ($count, $results) = &listsubjects($subject, $n, $offset);
61 Finds the subjects that begin with C<$subject> in the bibliosubject
62 table of the Koha database.
64 C<&listsubjects> returns a two-element array. C<$results> is a
65 reference-to-array, in which each element is a reference-to-hash
66 giving information about the given subject. C<$count> is the number of
67 elements in C<@{$results}>.
69 Probably the only interesting field in C<$results->[$i]> is
70 C<subject>, the subject in question.
72 C<&listsubject> returns up to C<$n> items, starting at C<$offset>. If
73 C<$n> is 0, it will return all matching subjects.
75 =cut
77 # FIXME - This API is bogus. The way it's currently used, it should
78 # just return a list of strings.
79 sub listsubjects {
80 my ($sub,$num,$offset)=@_;
81 my $dbh = C4::Context->dbh;
82 my $query="Select * from bibliosubject where subject like ? group by subject";
83 my @bind = ("$sub%");
84 # FIXME - Make $num and $offset optional.
85 # If $num was given, make sure $offset was, too.
86 if ($num != 0){
87 $query.=" limit ?,?";
88 push(@bind,$offset,$num);
90 my $sth=$dbh->prepare($query);
91 # print $query;
92 $sth->execute(@bind);
93 my @results;
94 my $i=0;
95 while (my $data=$sth->fetchrow_hashref){
96 $results[$i]=$data;
97 $i++;
99 $sth->finish;
100 return($i,\@results);
103 =item shiftgroup
105 &shiftgroup($biblionumber, $biblioitemnumber);
107 Changes the biblionumber associated with a given biblioitem.
108 C<$biblioitemnumber> is the number of the biblioitem to change.
109 C<$biblionumber> is the biblionumber to associate it with.
111 =cut
113 sub shiftgroup{
114 my ($biblionumber,$bi)=@_;
115 my $dbh = C4::Context->dbh;
116 my $sth=$dbh->prepare("update biblioitems set biblionumber=? where biblioitemnumber=?");
117 $sth->execute($biblionumber,$bi);
118 $sth->finish;
119 $sth=$dbh->prepare("update items set biblionumber=? where biblioitemnumber=?");
120 $sth->execute($biblionumber,$bi);
121 $sth->finish;
124 =item deletedbib
126 ($count, $results) = &deletedbib($title);
128 Looks up deleted books whose title begins with C<$title>.
130 C<&deletedbib> returns a two-element list. C<$results> is a
131 reference-to-array; each element is a reference-to-hash whose keys are
132 the fields of the deletedbiblio table in the Koha database. C<$count>
133 is the number of elements in C<$results>.
135 =cut
137 sub deletedbib{
138 my ($title)=@_;
139 my $dbh = C4::Context->dbh;
140 my $sth=$dbh->prepare("Select * from deletedbiblio where title like ? order by title");
141 $sth->execute("$title%");
142 my @results;
143 my $i=0;
144 while (my $data=$sth->fetchrow_hashref){
145 $results[$i]=$data;
146 $i++;
148 $sth->finish;
149 return($i,\@results);
152 =item undeletebib
154 &undeletebib($biblionumber);
156 Undeletes a book. C<&undeletebib> looks up the book with the given
157 biblionumber in the deletedbiblio table of the Koha database, and
158 moves its entry to the biblio table.
160 =cut
162 sub undeletebib{
163 my ($biblionumber)=@_;
164 my $dbh = C4::Context->dbh;
165 my $sth=$dbh->prepare("select * from deletedbiblio where biblionumber=?");
166 $sth->execute($biblionumber);
167 if (my @data=$sth->fetchrow_array){
168 $sth->finish;
169 # FIXME - Doesn't this keep the same biblionumber? Isn't this
170 # forbidden by the definition of 'biblio'? Or doesn't it matter?
171 my $query="INSERT INTO biblio VALUES (";
172 my $count = @data;
173 $query .= ("?," x $count);
174 $query=~ s/\,$/\)/;
175 # print $query;
176 $sth=$dbh->prepare($query);
177 $sth->execute(@data);
178 $sth->finish;
180 $sth=$dbh->prepare("DELETE FROM deletedbiblio WHERE biblionumber=?");
181 $sth->execute($biblionumber);
182 $sth->finish;
185 =item updatetype
187 &updatetype($biblioitemnumber, $itemtype);
189 Changes the type of the item with the given biblioitemnumber to be
190 C<$itemtype>.
192 =cut
194 sub updatetype{
195 my ($bi,$type)=@_;
196 my $dbh = C4::Context->dbh;
197 my $sth=$dbh->prepare("Update biblioitems set itemtype=? where biblioitemnumber=?");
198 $sth->execute($type,$bi);
199 $sth->finish;
202 END { } # module clean-up code here (global destructor)
205 __END__
207 =back
209 =head1 AUTHOR
211 Koha Developement team <info@koha.org>
213 =cut