OPAC now show a systempref variable in main/home screen => easier to change for a...
[koha.git] / insertjdata.pl
1 #!/usr/bin/perl
2
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
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 CGI;
26 use C4::Context;
27 use C4::Input;
28 use Date::Manip;
29 use strict;
30
31 my $input= new CGI;
32 #print $input->header;
33 #print $input->Dump;
34
35 #get all the data into a hash
36 my @names=$input->param;
37 my %data;
38 my $keyfld;
39 my $keyval;
40 my $problems;
41 my $env;
42 foreach my $key (@names){
43         $data{$key}=$input->param($key);
44 }
45 my $dbh = C4::Context->dbh;
46 my $query;
47 for (my $i=0;$i<1;$i++){
48         my $x = "cardnumber_child_$i";
49         my $sth=$dbh->prepare("Select * from borrowers where borrowernumber=?");
50         $sth->execute($x);
51         if (my $data=$sth->fetchrow_hashref){
52                 $query="update borrowers set title='$data{'title'}',expiry='$data{'expiry'}',
53                 cardnumber='$data{'cardnumber'}',sex='$data{'sex'}',ethnotes='$data{'ethnicnotes'}',
54                 streetaddress='$data{'address'}',faxnumber='$data{'faxnumber'}',firstname='$data{'firstname'}',
55                 altnotes='$data{'altnotes'}',dateofbirth='$data{'dateofbirth'}',contactname='$data{'contactname'}',
56                 emailaddress='$data{'emailaddress'}',dateenrolled='$data{'joining'}',streetcity='$data{'streetcity'}',
57                 altrelationship='$data{'altrelationship'}',othernames='$data{'othernames'}',phoneday='$data{'phoneday'}',
58                 categorycode='$data{'categorycode'}',city='$data{'city'}',area='$data{'area'}',phone='$data{'phone'}',
59                 borrowernotes='$data{'borrowernotes'}',altphone='$data{'altphone'}',surname='$data{'surname'}',
60                 initials='$data{'initials'}',streetaddress='$data{'streetaddress'}',ethnicity='$data{'ethnicity'}',physstreet='$data{'physstreet'}'
61                 where borrowernumber=$data{'borrowernumber'}";
62                 #  print $query;
63         }elsif ($data{"cardnumber_child_$i"} ne ''){
64                 my $dob=$data{"dateofbirth_child_$i"};
65                 $dob=ParseDate($dob);
66                 $dob=UnixDate($dob,'%Y-%m-%d');
67                 $data{'joining'}=ParseDate("today");
68                 $data{'joining'}=UnixDate($data{'joining'},'%Y-%m-%d');
69                 my $cardnumber=$data{"cardnumber_child_$i"};
70                 my $bornum=$data{"bornumber_child_$i"};
71                 my $firstname=$data{"firstname_child_$i"};
72                 my $surname=$data{"surname_child_$i"};
73                 my $school=$data{"school_child_$i"};
74                 my $guarant=$data{'borrowernumber'};
75                 my $notes=$data{"altnotes_child_$i"};
76                 my $sex=$data{"sex_child_$i"};
77                 $data{'contactname'}=$data{'firstname_guardian'}." ".$data{'surname_guardian'};
78                 $data{'altrelationship'}="Guarantor";
79                 $data{'altphone'}=$data{'phone'};
80                 $query="insert into borrowers (title,expiry,cardnumber,sex,ethnotes,streetaddress,faxnumber,
81                 firstname,altnotes,dateofbirth,contactname,emailaddress,dateenrolled,streetcity,
82                 altrelationship,othernames,phoneday,categorycode,city,area,phone,borrowernotes,altphone,surname,
83                 initials,ethnicity,borrowernumber,guarantor,school,physstreet)
84                 values ('','$data{'expiry'}',
85                 '$cardnumber',
86                 '$sex','$data{'ethnotes'}','$data{'address'}','$data{'faxnumber'}',
87                 '$firstname','$data{'altnotes'}','$dob','$data{'contactname'}','$data{'emailaddress'}',
88                 '$data{'joining'}','$data{'streetcity'}','$data{'altrelationship'}','$data{'othernames'}',
89                 '$data{'phoneday'}','C','$data{'city'}','$data{'area'}','$data{'phone'}',
90                 '$notes','$data{'altphone'}','$surname','$data{'initials'}',
91                 '$data{'ethnicity'}','$bornum','$guarant','$school','$data{'physstreet'}')";
92
93         }
94         #print $query;
95         my $sth2=$dbh->prepare($query);
96         $sth2->execute;
97         $sth2->finish;
98         $sth->finish;
99 }
100 print $input->redirect("/cgi-bin/koha/moremember.pl?bornum=$data{'borrowernumber'}");