bugfix
[koha.git] / insertdata.pl
blob9e2f4bdfd73eddad636b77c2220a977a5ee8e659
1 #!/usr/bin/perl
3 #script to enter borrower data into the data base
4 #needs to be moved into a perl module
5 # written 9/11/99 by chris@katipo.co.nz
8 # Copyright 2000-2002 Katipo Communications
10 # This file is part of Koha.
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.
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.
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
25 use CGI;
26 use C4::Context;
27 use C4::Input;
28 use C4::Search;
29 use Date::Manip;
30 use strict;
32 my $input= new CGI;
33 #print $input->header;
34 #print $input->dump;
36 #get all the data into a hash
37 my @names=$input->param;
38 my %data;
39 my $keyfld;
40 my $keyval;
41 my $problems;
42 my $env;
43 foreach my $key (@names){
44 $data{$key}=$input->param($key);
45 $data{$key}=~ s/\'/\\\'/g;
46 $data{$key}=~ s/\"/\\\"/g;
48 my $dbh = C4::Context->dbh;
49 my $query="Select * from borrowers where borrowernumber=$data{'borrowernumber'}";
50 my $sth=$dbh->prepare($query);
51 $sth->execute;
52 if (my $data=$sth->fetchrow_hashref){
53 $query="update borrowers set title='$data{'title'}',expiry='$data{'expiry'}',
54 cardnumber='$data{'cardnumber'}',sex='$data{'sex'}',ethnotes='$data{'ethnicnotes'}',
55 streetaddress='$data{'address'}',faxnumber='$data{'faxnumber'}',firstname='$data{'firstname'}',
56 altnotes='$data{'altnotes'}',dateofbirth='$data{'dateofbirth'}',contactname='$data{'contactname'}',
57 emailaddress='$data{'emailaddress'}',dateenrolled='$data{'joining'}',streetcity='$data{'streetcity'}',
58 altrelationship='$data{'altrelationship'}',othernames='$data{'othernames'}',phoneday='$data{'phoneday'}',
59 categorycode='$data{'categorycode'}',city='$data{'city'}',area='$data{'area'}',phone='$data{'phone'}',
60 borrowernotes='$data{'borrowernotes'}',altphone='$data{'altphone'}',surname='$data{'surname'}',
61 initials='$data{'initials'}',physstreet='$data{'address'}',ethnicity='$data{'ethnicity'}',
62 gonenoaddress='$data{'gna'}',lost='$data{'lost'}',debarred='$data{'debarred'}'
63 where borrowernumber=$data{'borrowernumber'}";
64 # print $query;
66 }else{
67 $data{'dateofbirth'}=ParseDate($data{'dateofbirth'});
68 $data{'dateofbirth'}=UnixDate($data{'dateofbirth'},'%Y-%m-%d');
69 $data{'joining'}=ParseDate($data{'joining'});
70 $data{'joining'}=UnixDate($data{'joining'},'%Y-%m-%d');
71 $query="insert into borrowers (title,expiry,cardnumber,sex,ethnotes,streetaddress,faxnumber,
72 firstname,altnotes,dateofbirth,contactname,emailaddress,dateenrolled,streetcity,
73 altrelationship,othernames,phoneday,categorycode,city,area,phone,borrowernotes,altphone,surname,
74 initials,ethnicity,borrowernumber) values ('$data{'title'}','$data{'expiry'}','$data{'cardnumber'}',
75 '$data{'sex'}','$data{'ethnotes'}','$data{'address'}','$data{'faxnumber'}',
76 '$data{'firstname'}','$data{'altnotes'}','$data{'dateofbirth'}','$data{'contactname'}','$data{'emailaddress'}',
77 '$data{'joining'}','$data{'streetcity'}','$data{'altrelationship'}','$data{'othernames'}',
78 '$data{'phoneday'}','$data{'categorycode'}','$data{'city'}','$data{'area'}','$data{'phone'}',
79 '$data{'borrowernotes'}','$data{'altphone'}','$data{'surname'}','$data{'initials'}',
80 '$data{'ethnicity'}','$data{'borrowernumber'}')";
82 # ok if its an adult (type) it may have borrowers that depend on it as a guarantor
83 # so when we update information for an adult we should check for guarantees and update the relevant part
84 # of their records, ie addresses and phone numbers
86 if ($data{'categorycode'} eq 'A' || $data{'categorycode'} eq 'W'){
87 # is adult check guarantees;
88 my ($count,$guarantees)=findguarantees($data{'borrowernumber'});
89 for (my $i=0;$i<$count;$i++){
90 # FIXME
91 # It looks like the $i is only being returned to handle walking through
92 # the array, which is probably better done as a foreach loop.
94 my $guaquery="update borrowers set streetaddress='$data{'address'}',faxnumber='$data{'faxnumber'}',
95 streetcity='$data{'streetcity'}',phoneday='$data{'phoneday'}',city='$data{'city'}',area='$data{'area'}',phone='$data{'phone'}'
96 ,streetaddress='$data{'address'}'
97 where borrowernumber='$guarantees->[$i]->{'borrowernumber'}'";
98 my $sth3=$dbh->prepare($guaquery);
99 $sth3->execute;
100 $sth3->finish;
104 #print $query;
105 my $sth2=$dbh->prepare($query);
106 $sth2->execute;
107 $sth2->finish;
108 $sth->finish;
109 print $input->redirect("/cgi-bin/koha/moremember.pl?bornum=$data{'borrowernumber'}");