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
15 #print $input->header;
18 #get all the data into a hash
19 my @names=$input->param;
25 foreach my $key (@names){
26 $data{$key}=$input->param($key);
27 $data{$key}=~ s/\'/\\\'/g;
28 $data{$key}=~ s/\"/\\\"/g;
31 my $query="Select * from borrowers where borrowernumber=$data{'borrowernumber'}";
32 my $sth=$dbh->prepare($query);
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'}";
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++){
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);
87 my $sth2=$dbh->prepare($query);
92 print $input->redirect("/cgi-bin/koha/moremember.pl?bornum=$data{'borrowernumber'}");