Must have been cosmetic changes...
[koha.git] / insertdata.pl
blobb88f3f96b5502af05509150c3a941bb54e55b070
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
7 use CGI;
8 use C4::Database;
9 use C4::Input;
10 use C4::Search;
11 use Date::Manip;
12 use strict;
14 my $input= new CGI;
15 #print $input->header;
16 #print $input->dump;
18 #get all the data into a hash
19 my @names=$input->param;
20 my %data;
21 my $keyfld;
22 my $keyval;
23 my $problems;
24 my $env;
25 foreach my $key (@names){
26 $data{$key}=$input->param($key);
27 $data{$key}=~ s/\'/\\\'/g;
28 $data{$key}=~ s/\"/\\\"/g;
30 my $dbh=C4Connect;
31 my $query="Select * from borrowers where borrowernumber=$data{'borrowernumber'}";
32 my $sth=$dbh->prepare($query);
33 $sth->execute;
34 if (my $data=$sth->fetchrow_hashref){
35 $query="update borrowers set title='$data{'title'}',expiry='$data{'expiry'}',
36 cardnumber='$data{'cardnumber'}',sex='$data{'sex'}',ethnotes='$data{'ethnicnotes'}',
37 streetaddress='$data{'address'}',faxnumber='$data{'faxnumber'}',firstname='$data{'firstname'}',
38 altnotes='$data{'altnotes'}',dateofbirth='$data{'dateofbirth'}',contactname='$data{'contactname'}',
39 emailaddress='$data{'emailaddress'}',dateenrolled='$data{'joining'}',streetcity='$data{'streetcity'}',
40 altrelationship='$data{'altrelationship'}',othernames='$data{'othernames'}',phoneday='$data{'phoneday'}',
41 categorycode='$data{'categorycode'}',city='$data{'city'}',area='$data{'area'}',phone='$data{'phone'}',
42 borrowernotes='$data{'borrowernotes'}',altphone='$data{'altphone'}',surname='$data{'surname'}',
43 initials='$data{'initials'}',physstreet='$data{'address'}',ethnicity='$data{'ethnicity'}',
44 gonenoaddress='$data{'gna'}',lost='$data{'lost'}',debarred='$data{'debarred'}'
45 where borrowernumber=$data{'borrowernumber'}";
46 # print $query;
48 }else{
49 $data{'dateofbirth'}=ParseDate($data{'dateofbirth'});
50 $data{'dateofbirth'}=UnixDate($data{'dateofbirth'},'%Y-%m-%d');
51 $data{'joining'}=ParseDate($data{'joining'});
52 $data{'joining'}=UnixDate($data{'joining'},'%Y-%m-%d');
53 $query="insert into borrowers (title,expiry,cardnumber,sex,ethnotes,streetaddress,faxnumber,
54 firstname,altnotes,dateofbirth,contactname,emailaddress,dateenrolled,streetcity,
55 altrelationship,othernames,phoneday,categorycode,city,area,phone,borrowernotes,altphone,surname,
56 initials,ethnicity,borrowernumber) values ('$data{'title'}','$data{'expiry'}','$data{'cardnumber'}',
57 '$data{'sex'}','$data{'ethnotes'}','$data{'address'}','$data{'faxnumber'}',
58 '$data{'firstname'}','$data{'altnotes'}','$data{'dateofbirth'}','$data{'contactname'}','$data{'emailaddress'}',
59 '$data{'joining'}','$data{'streetcity'}','$data{'altrelationship'}','$data{'othernames'}',
60 '$data{'phoneday'}','$data{'categorycode'}','$data{'city'}','$data{'area'}','$data{'phone'}',
61 '$data{'borrowernotes'}','$data{'altphone'}','$data{'surname'}','$data{'initials'}',
62 '$data{'ethnicity'}','$data{'borrowernumber'}')";
64 # ok if its an adult (type) it may have borrowers that depend on it as a guarantor
65 # so when we update information for an adult we should check for guarantees and update the relevant part
66 # of their records, ie addresses and phone numbers
68 if ($data{'categorycode'} eq 'A' || $data{'categorycode'} eq 'W'){
69 # is adult check guarantees;
70 my ($count,$guarantees)=findguarantees($data{'borrowernumber'});
71 for (my $i=0;$i<$count;$i++){
72 # FIXME
73 # It looks like the $i is only being returned to handle walking through
74 # the array, which is probably better done as a foreach loop.
76 my $guaquery="update borrowers set streetaddress='$data{'address'}',faxnumber='$data{'faxnumber'}',
77 streetcity='$data{'streetcity'}',phoneday='$data{'phoneday'}',city='$data{'city'}',area='$data{'area'}',phone='$data{'phone'}'
78 ,streetaddress='$data{'address'}'
79 where borrowernumber='$guarantees->[$i]->{'borrowernumber'}'";
80 my $sth3=$dbh->prepare($guaquery);
81 $sth3->execute;
82 $sth3->finish;
86 #print $query;
87 my $sth2=$dbh->prepare($query);
88 $sth2->execute;
89 $sth2->finish;
90 $sth->finish;
91 $dbh->disconnect;
92 print $input->redirect("/cgi-bin/koha/moremember.pl?bornum=$data{'borrowernumber'}");