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
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
35 #get all the data into a hash
36 my @names=$input->param;
42 foreach my $key (@names){
43 $data{$key}=$input->param($key);
44 $data{$key}=~ s/\'/\\\'/g;
45 $data{$key}=~ s/\"/\\\"/g;
47 my $dbh = C4::Context->dbh;
48 my $query="Select * from borrowers where borrowernumber=$data{'borrowernumber'}";
49 my $sth=$dbh->prepare($query);
51 if (my $data=$sth->fetchrow_hashref){
52 $data{'dateofbirth'}=format_date_in_iso($data{'dateofbirth'});
53 $data{'joining'}=format_date_in_iso($data{'joining'});
54 $data{'expiry'}=format_date_in_iso($data{'expiry'});
55 $query="update borrowers set title='$data{'title'}',expiry='$data{'expiry'}',
56 cardnumber='$data{'cardnumber'}',sex='$data{'sex'}',ethnotes='$data{'ethnicnotes'}',
57 streetaddress='$data{'address'}',faxnumber='$data{'faxnumber'}',firstname='$data{'firstname'}',
58 altnotes='$data{'altnotes'}',dateofbirth='$data{'dateofbirth'}',contactname='$data{'contactname'}',
59 emailaddress='$data{'emailaddress'}',dateenrolled='$data{'joining'}',streetcity='$data{'streetcity'}',
60 altrelationship='$data{'altrelationship'}',othernames='$data{'othernames'}',phoneday='$data{'phoneday'}',
61 categorycode='$data{'categorycode'}',city='$data{'city'}',area='$data{'area'}',phone='$data{'phone'}',
62 borrowernotes='$data{'borrowernotes'}',altphone='$data{'altphone'}',surname='$data{'surname'}',
63 initials='$data{'initials'}',physstreet='$data{'streetaddress'}',ethnicity='$data{'ethnicity'}',
64 gonenoaddress='$data{'gna'}',lost='$data{'lost'}',debarred='$data{'debarred'}',textmessaging='$data{'textmessaging'}', branchcode = '$data{'branchcode'}'
65 where borrowernumber=$data{'borrowernumber'}";
69 $data{'dateofbirth'}=format_date_in_iso($data{'dateofbirth'});
70 $data{'joining'}=format_date_in_iso($data{'joining'});
71 $data{'expiry'}=format_date_in_iso($data{'expiry'});
72 $query="insert into borrowers (title,expiry,cardnumber,sex,ethnotes,streetaddress,faxnumber,
73 firstname,altnotes,dateofbirth,contactname,emailaddress,textmessaging,dateenrolled,streetcity,
74 altrelationship,othernames,phoneday,categorycode,city,area,phone,borrowernotes,altphone,surname,
75 initials,ethnicity,borrowernumber,physstreet,branchcode) values ('$data{'title'}','$data{'expiry'}','$data{'cardnumber'}',
76 '$data{'sex'}','$data{'ethnotes'}','$data{'address'}','$data{'faxnumber'}',
77 '$data{'firstname'}','$data{'altnotes'}','$data{'dateofbirth'}','$data{'contactname'}','$data{'emailaddress'}','$data{'textmessaging'}',
78 '$data{'joining'}','$data{'streetcity'}','$data{'altrelationship'}','$data{'othernames'}',
79 '$data{'phoneday'}','$data{'categorycode'}','$data{'city'}','$data{'area'}','$data{'phone'}',
80 '$data{'borrowernotes'}','$data{'altphone'}','$data{'surname'}','$data{'initials'}',
81 '$data{'ethnicity'}','$data{'borrowernumber'}','$data{'streetaddress'}','$data{'branchcode'}')";
83 # ok if its an adult (type) it may have borrowers that depend on it as a guarantor
84 # so when we update information for an adult we should check for guarantees and update the relevant part
85 # of their records, ie addresses and phone numbers
87 if ($data{'categorycode'} eq 'A' || $data{'categorycode'} eq 'W'){
88 # is adult check guarantees;
89 my ($count,$guarantees)=findguarantees($data{'borrowernumber'});
90 for (my $i=0;$i<$count;$i++){
92 # It looks like the $i is only being returned to handle walking through
93 # the array, which is probably better done as a foreach loop.
95 my $guaquery="update borrowers set streetaddress='$data{'address'}',faxnumber='$data{'faxnumber'}',
96 streetcity='$data{'streetcity'}',phoneday='$data{'phoneday'}',city='$data{'city'}',area='$data{'area'}',phone='$data{'phone'}'
97 ,streetaddress='$data{'address'}'
98 where borrowernumber='$guarantees->[$i]->{'borrowernumber'}'";
99 my $sth3=$dbh->prepare($guaquery);
106 my $sth2=$dbh->prepare($query);
110 print $input->redirect("/cgi-bin/koha/moremember.pl?bornum=$data{'borrowernumber'}");