Few more changes... not much to look at yet, still wrapping my head around the
[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   $sub=$dbh->quote($sub);
79   $oldsub=$dbh->quote($oldsub);
80   my $query="update bibliosubject set subject=$sub where subject=$oldsub";
81   my $sth=$dbh->prepare($query);
82   $sth->execute;
83   $sth->finish;
84   $dbh->disconnect;
85 }
86
87 sub shiftgroup{
88   my ($bib,$bi)=@_;
89   my $dbh=C4Connect;
90   my $query="update biblioitems set biblionumber=$bib where biblioitemnumber=$bi";
91   my $sth=$dbh->prepare($query);
92   $sth->execute;
93   $sth->finish;
94   $query="update items set biblionumber=$bib where biblioitemnumber=$bi";
95   $sth=$dbh->prepare($query);
96   $sth->execute;
97   $sth->finish;
98   $dbh->disconnect;
99 }
100
101 sub deletedbib{
102   my ($title)=@_;
103   my $dbh=C4Connect;
104   my $query="Select * from deletedbiblio where title like '$title%' order by title";
105   my $sth=$dbh->prepare($query);
106   $sth->execute;
107   my @results;
108   my $i=0;
109   while (my $data=$sth->fetchrow_hashref){
110     $results[$i]=$data;
111     $i++;
112   }
113   $sth->finish;
114   $dbh->disconnect;
115   return($i,\@results);
116 }
117
118 sub undeletebib{
119   my ($bib)=@_;
120   my $dbh=C4Connect;
121   my $query="select * from deletedbiblio where biblionumber=$bib";
122   my $sth=$dbh->prepare($query);                         
123   $sth->execute;             
124   if (my @data=$sth->fetchrow_array){  
125     $sth->finish;                      
126     $query="Insert into biblio values (";    
127     foreach my $temp (@data){                
128       $temp=~ s/\'/\\\'/g;                      
129       $query=$query."'$temp',";      
130     }                
131     $query=~ s/\,$/\)/;    
132     #   print $query;                    
133     $sth=$dbh->prepare($query);    
134     $sth->execute;          
135     $sth->finish;          
136   }
137   $query="Delete from deletedbiblio where biblionumber=$bib";
138   $sth=$dbh->prepare($query);
139   $sth->execute;
140   $sth->finish;
141   $dbh->disconnect;
142 }
143
144 sub updatetype{
145   my ($bi,$type)=@_;
146   my $dbh=C4Connect;
147   my $sth=$dbh->prepare("Update biblioitems set itemtype='$type' where biblioitemnumber=$bi");
148   $sth->execute;
149   $sth->finish;
150   $dbh->disconnect;
151 }
152 END { }       # module clean-up code here (global destructor)
153