Added copyright statement to all .pl and .pm files
[koha.git] / misc / fixborrower.pl
1 #!/usr/bin/perl
2
3 # This script will convert a database into the newer, proper
4 # form ... I think.
5
6
7
8 # Copyright 2000-2002 Katipo Communications
9 #
10 # This file is part of Koha.
11 #
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
15 # version.
16 #
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License along with
22 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA  02111-1307 USA
24
25 use C4::Database;
26 use strict;
27
28 my $dbh=C4Connect;
29
30 my $query = "Select * from categories where (categorycode like 'L%' or categorycode like 'F%'
31 or categorycode like 'S%' or categorycode like 'O%' or categorycode like 'H%') and (categorycode <>'HR' 
32 and categorycode <> 'ST')";
33
34 my $sth=$dbh->prepare($query);
35 $sth->execute;
36
37 while (my $data=$sth->fetchrow_hashref){
38   #update borrowers corresponding
39   #update categories
40
41     my $temp=substr($data->{'categorycode'},0,1);
42     $query="update borrowers set area='$temp' where categorycode='$data->{'categorycode'}'";
43     my $sth2=$dbh->prepare($query);
44     $sth2->execute;
45     $sth2->finish;
46  
47    $temp=substr($data->{'categorycode'},1,1);
48     $query="update borrowers set categorycode='$temp' where categorycode='$data->{'categorycode'}'"; 
49     $sth2=$dbh->prepare($query);
50     $sth2->execute;
51     $sth2->finish;
52
53     $query="delete from categories where categorycode='$data->{'categorycode'}'";
54     $sth2=$dbh->prepare($query);
55     $sth2->execute;
56     $sth2->finish;
57     
58 }
59
60 $query = "Select * from categories where (categorycode like 'V%') and (categorycode <>'HR' 
61 and categorycode <> 'ST')";
62
63 my $sth=$dbh->prepare($query);
64 $sth->execute;
65
66 while (my $data=$sth->fetchrow_hashref){
67   #update borrowers corresponding
68   #update categories
69 #    my $temp=substr($data->{'categorycode'},0,1);
70     $query="update borrowers set area='V' where categorycode='$data->{'categorycode'}'";
71     my $sth2=$dbh->prepare($query);
72     $sth2->execute;
73     $sth2->finish;
74
75     my $temp=substr($data->{'categorycode'},1,1);
76     $query="update borrowers set categorycode='$temp' where categorycode='$data->{'categorycode'}'"; 
77     $sth2=$dbh->prepare($query);
78     $sth2->execute;
79     $sth2->finish;
80
81     $query="delete from categories where categorycode='$data->{'categorycode'}'";
82     $sth2=$dbh->prepare($query);
83     $sth2->execute;
84     $sth2->finish;
85
86 }
87
88 my $query = "Select * from categories where categorycode = 'ST'";
89 my $sth=$dbh->prepare($query);
90 $sth->execute;
91
92 while (my $data=$sth->fetchrow_hashref){
93   #update borrowers corresponding
94   #update categories
95     $query="update borrowers set area='' where categorycode='$data->{'categorycode'}'";
96     my $sth2=$dbh->prepare($query);
97     $sth2->execute;
98     $sth2->finish;
99
100     $query="update borrowers set categorycode='W' where categorycode='$data->{'categorycode'}'"; 
101     $sth2=$dbh->prepare($query);
102     $sth2->execute;
103     $sth2->finish;
104
105     $query="delete from categories where categorycode='$data->{'categorycode'}'";
106     $sth2=$dbh->prepare($query);
107     $sth2->execute;
108     $sth2->finish;
109
110 }
111
112 my $query = "Select * from categories where categorycode = 'BR' or categorycode='CO' or categorycode='IS'";
113 my $sth=$dbh->prepare($query);
114 $sth->execute;
115
116 while (my $data=$sth->fetchrow_hashref){
117   #update borrowers corresponding
118   #update categories
119     $query="update borrowers set area='' where categorycode='$data->{'categorycode'}'";
120     my $sth2=$dbh->prepare($query);
121     $sth2->execute;
122     $sth2->finish;
123
124     $query="update borrowers set categorycode='I' where categorycode='$data->{'categorycode'}'"; 
125     $sth2=$dbh->prepare($query);
126     $sth2->execute;
127     $sth2->finish;
128
129     $query="delete from categories where categorycode='$data->{'categorycode'}'";
130     $sth2=$dbh->prepare($query);
131     $sth2->execute;
132     $sth2->finish;
133
134 }
135
136 my $query = "Select * from categories where categorycode = 'TD'  or categorycode='TR'";
137 my $sth=$dbh->prepare($query);
138 $sth->execute;
139
140 while (my $data=$sth->fetchrow_hashref){
141   #update borrowers corresponding
142   #update categories
143     $query="update borrowers set area='X' where categorycode='$data->{'categorycode'}'";
144     my $sth2=$dbh->prepare($query);
145     $sth2->execute;
146     $sth2->finish;
147
148     $query="update borrowers set categorycode='A' where categorycode='$data->{'categorycode'}'"; 
149     $sth2=$dbh->prepare($query);
150     $sth2->execute;
151     $sth2->finish;
152
153     $query="delete from categories where categorycode='$data->{'categorycode'}'";
154     $sth2=$dbh->prepare($query);
155     $sth2->execute;
156     $sth2->finish;
157
158 }
159
160 my $query = "Select * from categories where categorycode = 'HR'";
161 my $sth=$dbh->prepare($query);
162 $sth->execute;
163
164 while (my $data=$sth->fetchrow_hashref){
165   #update borrowers corresponding
166   #update categories
167     $query="update borrowers set area='K' where categorycode='$data->{'categorycode'}'";
168     my $sth2=$dbh->prepare($query);
169     $sth2->execute;
170     $sth2->finish;
171
172     $query="update borrowers set categorycode='A' where categorycode='$data->{'categorycode'}'"; 
173     $sth2=$dbh->prepare($query);
174     $sth2->execute;
175     $sth2->finish;
176
177     $query="delete from categories where categorycode='$data->{'categorycode'}'";
178     $sth2=$dbh->prepare($query);
179     $sth2->execute;
180     $sth2->finish;
181
182 }
183
184 my $query = "Select * from categories where categorycode = 'IL'";
185 my $sth=$dbh->prepare($query);
186 $sth->execute;
187
188 while (my $data=$sth->fetchrow_hashref){
189   #update borrowers corresponding
190   #update categories
191     $query="update borrowers set area='Z' where categorycode='$data->{'categorycode'}'";
192     my $sth2=$dbh->prepare($query);
193     $sth2->execute;
194     $sth2->finish;
195
196     $query="update borrowers set categorycode='L' where categorycode='$data->{'categorycode'}'"; 
197     $sth2=$dbh->prepare($query);
198     $sth2->execute;
199     $sth2->finish;
200
201     $query="delete from categories where categorycode='$data->{'categorycode'}'";
202     $sth2=$dbh->prepare($query);
203     $sth2->execute;
204     $sth2->finish;
205
206 }
207
208 my $query = "Select * from categories where categorycode = 'TB'";
209 my $sth=$dbh->prepare($query);
210 $sth->execute;
211 while (my $data=$sth->fetchrow_hashref){
212   #update borrowers corresponding
213   #update categories
214
215     $query="update borrowers set area='' where categorycode='$data->{'categorycode'}'";
216     my $sth2=$dbh->prepare($query);
217     $sth2->execute;
218     $sth2->finish;
219     
220     $query="update borrowers set categorycode='P' where categorycode='$data->{'categorycode'}'"; 
221     $sth2=$dbh->prepare($query);
222     $sth2->execute;
223     $sth2->finish;
224
225     $query="delete from categories where categorycode='$data->{'categorycode'}'";
226     $sth2=$dbh->prepare($query);
227     $sth2->execute;
228     $sth2->finish;
229
230 }
231
232 $sth->finish;
233
234 my @queryValues = 
235     ("insert into categories values ('E','Senior Citizen',5,99,0,'A',0,0,0,99,1)",
236      "insert into categories values ('A','Adult',5,99,0,'A',0,0,0,99,1)",
237      "insert into categories values ('C','Child',5,16,0,'A',0,0,0,99,0)",
238      "insert into categories values ('B','Housebound',5,99,0,'E',0,0,0,99,0)",
239      "insert into categories values ('F','Family',5,99,0,'A',0,0,0,99,1)",
240      "insert into categories values ('W','Workers',5,99,0,'A',0,0,0,99,0)",
241      "insert into categories values ('I','Institution',5,99,0,'A',0,0,0,99,0)",
242      "insert into categories values ('P','Privileged',5,99,0,'A',0,0,0,99,0)",
243      "insert into categories values ('L','Library',5,99,0,'A',0,0,0,99,0)"
244      );   
245
246 foreach $query (@queryValues) {
247     $sth=$dbh->prepare($query);
248     $sth->execute;
249     $sth->finish;
250 }
251
252 $dbh->disconnect;