Added PODs.
[koha.git] / C4 / Maintainance.pm
1 package C4::Maintainance; #assumes C4/Maintainance
2
3 #package to deal with marking up output
4
5
6 # Copyright 2000-2002 Katipo Communications
7 #
8 # This file is part of Koha.
9 #
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.
14 #
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.
18 #
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
22
23 use strict;
24 use C4::Database;
25
26 require Exporter;
27
28 use vars qw($VERSION @ISA @EXPORT);
29
30 # set the version for version checking
31 $VERSION = 0.01;
32
33 @ISA = qw(Exporter);
34 @EXPORT = qw(&listsubjects &updatesub &shiftgroup &deletedbib &undeletebib
35 &updatetype);
36  
37 sub listsubjects {
38   my ($sub,$num,$offset)=@_;
39   my $dbh=C4Connect;
40   my $query="Select * from bibliosubject where subject like '$sub%' group by subject";
41   if ($num != 0){
42     $query.=" limit $offset,$num";
43   }
44   my $sth=$dbh->prepare($query);
45 #  print $query;
46   $sth->execute;
47   my @results;
48   my $i=0;
49   while (my $data=$sth->fetchrow_hashref){
50     $results[$i]=$data;
51     $i++;
52   }
53   $sth->finish;
54   $dbh->disconnect;
55   return($i,\@results);
56 }
57
58 sub updatesub{
59   my ($sub,$oldsub)=@_;
60   my $dbh=C4Connect;
61   $sub=$dbh->quote($sub);
62   $oldsub=$dbh->quote($oldsub);
63   my $query="update bibliosubject set subject=$sub where subject=$oldsub";
64   my $sth=$dbh->prepare($query);
65   $sth->execute;
66   $sth->finish;
67   $dbh->disconnect;
68 }
69
70 sub shiftgroup{
71   my ($bib,$bi)=@_;
72   my $dbh=C4Connect;
73   my $query="update biblioitems set biblionumber=$bib where biblioitemnumber=$bi";
74   my $sth=$dbh->prepare($query);
75   $sth->execute;
76   $sth->finish;
77   $query="update items set biblionumber=$bib where biblioitemnumber=$bi";
78   $sth=$dbh->prepare($query);
79   $sth->execute;
80   $sth->finish;
81   $dbh->disconnect;
82 }
83
84 sub deletedbib{
85   my ($title)=@_;
86   my $dbh=C4Connect;
87   my $query="Select * from deletedbiblio where title like '$title%' order by title";
88   my $sth=$dbh->prepare($query);
89   $sth->execute;
90   my @results;
91   my $i=0;
92   while (my $data=$sth->fetchrow_hashref){
93     $results[$i]=$data;
94     $i++;
95   }
96   $sth->finish;
97   $dbh->disconnect;
98   return($i,\@results);
99 }
100
101 sub undeletebib{
102   my ($bib)=@_;
103   my $dbh=C4Connect;
104   my $query="select * from deletedbiblio where biblionumber=$bib";
105   my $sth=$dbh->prepare($query);                         
106   $sth->execute;             
107   if (my @data=$sth->fetchrow_array){  
108     $sth->finish;                      
109     $query="Insert into biblio values (";    
110     foreach my $temp (@data){                
111       $temp=~ s/\'/\\\'/g;                      
112       $query=$query."'$temp',";      
113     }                
114     $query=~ s/\,$/\)/;    
115     #   print $query;                    
116     $sth=$dbh->prepare($query);    
117     $sth->execute;          
118     $sth->finish;          
119   }
120   $query="Delete from deletedbiblio where biblionumber=$bib";
121   $sth=$dbh->prepare($query);
122   $sth->execute;
123   $sth->finish;
124   $dbh->disconnect;
125 }
126
127 sub updatetype{
128   my ($bi,$type)=@_;
129   my $dbh=C4Connect;
130   my $sth=$dbh->prepare("Update biblioitems set itemtype='$type' where biblioitemnumber=$bi");
131   $sth->execute;
132   $sth->finish;
133   $dbh->disconnect;
134 }
135 END { }       # module clean-up code here (global destructor)
136