Continuing work on Z39.50 search tool. Daemon now forks up to 12 processes
[koha.git] / C4 / Maintainance.pm
1 package C4::Maintainance; #asummes C4/Maintainance
2
3 #package to deal with marking up output
4
5 use strict;
6 use C4::Database;
7
8 require Exporter;
9
10 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
11
12 # set the version for version checking
13 $VERSION = 0.01;
14
15 @ISA = qw(Exporter);
16 @EXPORT = qw(&listsubjects &updatesub &shiftgroup &deletedbib &undeletebib
17 &updatetype);
18 %EXPORT_TAGS = ( );     # eg: TAG => [ qw!name1 name2! ],
19
20 # your exported package globals go here,
21 # as well as any optionally exported functions
22
23 @EXPORT_OK   = qw($Var1 %Hashit);
24
25
26 # non-exported package globals go here
27 use vars qw(@more $stuff);
28
29 # initalize package globals, first exported ones
30
31 my $Var1   = '';
32 my %Hashit = ();
33
34
35 # then the others (which are still accessible as $Some::Module::stuff)
36 my $stuff  = '';
37 my @more   = ();
38
39 # all file-scoped lexicals must be created before
40 # the functions below that use them.
41
42 # file-private lexicals go here
43 my $priv_var    = '';
44 my %secret_hash = ();
45
46 # here's a file-private function as a closure,
47 # callable as &$priv_func;  it cannot be prototyped.
48 my $priv_func = sub {
49 # stuff goes here.
50   };
51    
52 # make all your functions, whether exported or not;
53  
54 sub listsubjects {
55   my ($sub,$num,$offset)=@_;
56   my $dbh=C4Connect;
57   my $query="Select * from bibliosubject where subject like '$sub%' group by subject";
58   if ($num != 0){
59     $query.=" limit $offset,$num";
60   }
61   my $sth=$dbh->prepare($query);
62 #  print $query;
63   $sth->execute;
64   my @results;
65   my $i=0;
66   while (my $data=$sth->fetchrow_hashref){
67     $results[$i]=$data;
68     $i++;
69   }
70   $sth->finish;
71   $dbh->disconnect;
72   return($i,\@results);
73 }
74
75 sub updatesub{
76   my ($sub,$oldsub)=@_;
77   my $dbh=C4Connect;
78   my $query="update bibliosubject set subject='$sub' where subject='$oldsub'";
79   my $sth=$dbh->prepare($query);
80   $sth->execute;
81   $sth->finish;
82   $dbh->disconnect;
83 }
84
85 sub shiftgroup{
86   my ($bib,$bi)=@_;
87   my $dbh=C4Connect;
88   my $query="update biblioitems set biblionumber=$bib where biblioitemnumber=$bi";
89   my $sth=$dbh->prepare($query);
90   $sth->execute;
91   $sth->finish;
92   $query="update items set biblionumber=$bib where biblioitemnumber=$bi";
93   $sth=$dbh->prepare($query);
94   $sth->execute;
95   $sth->finish;
96   $dbh->disconnect;
97 }
98
99 sub deletedbib{
100   my ($title)=@_;
101   my $dbh=C4Connect;
102   my $query="Select * from deletedbiblio where title like '$title%' order by title";
103   my $sth=$dbh->prepare($query);
104   $sth->execute;
105   my @results;
106   my $i=0;
107   while (my $data=$sth->fetchrow_hashref){
108     $results[$i]=$data;
109     $i++;
110   }
111   $sth->finish;
112   $dbh->disconnect;
113   return($i,\@results);
114 }
115
116 sub undeletebib{
117   my ($bib)=@_;
118   my $dbh=C4Connect;
119   my $query="select * from deletedbiblio where biblionumber=$bib";
120   my $sth=$dbh->prepare($query);                         
121   $sth->execute;             
122   if (my @data=$sth->fetchrow_array){  
123     $sth->finish;                      
124     $query="Insert into biblio values (";    
125     foreach my $temp (@data){                
126       $temp=~ s/\'/\\\'/g;                      
127       $query=$query."'$temp',";      
128     }                
129     $query=~ s/\,$/\)/;    
130     #   print $query;                    
131     $sth=$dbh->prepare($query);    
132     $sth->execute;          
133     $sth->finish;          
134   }
135   $query="Delete from deletedbiblio where biblionumber=$bib";
136   $sth=$dbh->prepare($query);
137   $sth->execute;
138   $sth->finish;
139   $dbh->disconnect;
140 }
141
142 sub updatetype{
143   my ($bi,$type)=@_;
144   my $dbh=C4Connect;
145   my $sth=$dbh->prepare("Update biblioitems set itemtype='$type' where biblioitemnumber=$bi");
146   $sth->execute;
147   $sth->finish;
148   $dbh->disconnect;
149 }
150 END { }       # module clean-up code here (global destructor)
151