Added 'id' attribute to branchcode select list
[koha.git] / insertidata.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="Select * from borrowers where borrowernumber=$data{'borrowernumber'}";
47 my $sth=$dbh->prepare($query);
48 $sth->execute;
49 if (my $data2=$sth->fetchrow_hashref){
50         $query="update borrowers set title='$data{'title'}',expiry='$data{'expiry'}',
51         cardnumber='$data{'cardnumber_institution'}',sex='$data{'sex'}',ethnotes='$data{'ethnicnotes'}',
52         streetaddress='$data{'address'}',faxnumber='$data{'faxnumber'}',firstname='$data{'firstname'}',
53         altnotes='$data{'altnotes'}',dateofbirth='$data{'dateofbirth'}',contactname='$data{'contactname'}',
54         emailaddress='$data{'emailaddress'}',dateenrolled='$data{'joining'}',streetcity='$data{'streetcity'}',
55         altrelationship='$data{'altrelationship'}',othernames='$data{'othernames'}',phoneday='$data{'phoneday'}',
56         city='$data{'city'}',area='$data{'area'}',phone='$data{'phone'}',
57         borrowernotes='$data{'borrowernotes'}',altphone='$data{'altphone'}',surname='$data{'institution_name'}',
58         initials='$data{'initials'}',physstreet='$data{'streetaddress'}',ethnicity='$data{'ethnicity'}',
59         gonenoaddress='$data{'gna'}',lost='$data{'lost'}',debarred='$data{'debarred'}',
60         textmessaging='$data{'textmessaging'}', branchcode = '$data{'branchcode'}',
61         zipcode = '$data{'zipcode'}',homezipcode='$data{'homezipcode'}'
62         where borrowernumber=$data{'borrowernumber'}";
63 } else {
64         my $surname=$data{'institution_name'};
65         $query="insert into borrowers (title,expiry,cardnumber,sex,ethnotes,streetaddress,faxnumber,
66         firstname,altnotes,dateofbirth,contactname,emailaddress,dateenrolled,streetcity,
67         altrelationship,othernames,phoneday,categorycode,city,area,phone,borrowernotes,altphone,surname,
68         initials,ethnicity,borrowernumber,guarantor,school,branchcode,zipcode,homezipcode)
69         values ('','$data{'expiry'}','$data{'cardnumber_institution'}',
70         '','$data{'ethnotes'}','$data{'address'}','$data{'faxnumber'}',
71         '$data{'firstname'}','$data{'altnotes'}','','$data{'contactname'}',
72         '$data{'emailaddress'}',
73         now(),'$data{'streetcity'}','$data{'altrelationship'}','$data{'othernames'}',
74         '$data{'phoneday'}','I','$data{'city'}','$data{'area'}','$data{'phone'}',
75         '$data{'borrowernotes'}','$data{'altphone'}','$surname','$data{'initials'}',
76         '$data{'ethnicity'}','$data{'borrowernumber'}','','','$data{'branchcode'}','$data{'zipcode'}','$data{'homezipcode'}')";
77 }
78
79 #print $query;
80 my $sth2=$dbh->prepare($query);
81 warn "==> $query";
82 $sth2->execute;
83 $sth2->finish;
84 #$sth->finish;
85
86 print $input->redirect("/cgi-bin/koha/moremember.pl?bornum=$data{'borrowernumber'}");