Adding a parameter to allow acces to people with management/tools flags
[koha.git] / members / 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 my $sth2;
43 foreach my $key (@names){
44   $data{$key}=$input->param($key);
45 }
46 my $dbh = C4::Context->dbh;
47 my $sth=$dbh->prepare("Select * from borrowers where borrowernumber=?");
48 $sth->execute($data{'borrowernumber'});
49 if (my $data2=$sth->fetchrow_hashref){
50         $sth2=$dbh->prepare("update borrowers set title=?,expiry=?,
51         cardnumber=?,sex=?,ethnotes=?,
52         streetaddress=?,faxnumber=?,firstname=?,
53         altnotes=?,dateofbirth=?,contactname=?,
54         emailaddress=?,dateenrolled=?,streetcity=?,
55         altrelationship=?,othernames=?,phoneday=?,
56         city=?,area=?,phone=?,
57         borrowernotes=?,altphone=?,surname=?,
58         initials=?,physstreet=?,ethnicity=?,
59         gonenoaddress=?,lost=?,debarred=?,
60         textmessaging=?, branchcode = ?,
61         zipcode = ?,homezipcode=?
62         where borrowernumber=?");
63         $sth2->execute($data{'title'},$data{'expiry'},
64         $data{'cardnumber_institution'},$data{'sex'},$data{'ethnicnotes'},
65         $data{'address'},$data{'faxnumber'},$data{'firstname'},
66         $data{'altnotes'},$data{'dateofbirth'},$data{'contactname'},
67         $data{'emailaddress'},$data{'joining'},$data{'streetcity'},
68         $data{'altrelationship'},$data{'othernames'},$data{'phoneday'},
69         $data{'city'},$data{'area'},$data{'phone'},
70         $data{'borrowernotes'},$data{'altphone'},$data{'institution_name'},
71         $data{'initials'},$data{'streetaddress'},$data{'ethnicity'},
72         $data{'gna'},$data{'lost'},$data{'debarred'},
73         $data{'textmessaging'},$data{'branchcode'},
74         $data{'zipcode'},$data{'homezipcode'},
75         $data{'borrowernumber'});
76 } else {
77         my $surname=$data{'institution_name'};
78         # note for code reading : 5 on each line
79         $sth2=$dbh->prepare("insert into borrowers (
80                         title,                  expiry,         cardnumber,     sex,            ethnotes,
81                         streetaddress,  faxnumber,      firstname,              altnotes,       dateofbirth,
82                         contactname,    emailaddress,   dateenrolled,   streetcity,     altrelationship,
83                         othernames,     phoneday,               categorycode,   city,           area,
84                         phone,          borrowernotes,  altphone,               surname,        initials,
85                         ethnicity,              borrowernumber,guarantor,               school, branchcode,
86                         zipcode,                homezipcode)
87         values (        ?,?,?,?,?,
88                         ?,?,?,?,?,
89                         ?,?,now(),?,?,
90                         ?,?,?,?,?,
91                         ?,?,?,?,?,
92                         ?,?,?,?,?,
93                         ?,?
94                         )");
95         $sth2->execute('',                              $data{'expiry'},                        $data{'cardnumber_institution'},        '',                             $data{'ethnotes'},
96                                 $data{'address'},       $data{'faxnumber'},             $surname,                                       $data{'altnotes'},      '',
97                                 $data{'contactname'},$data{'emailaddress'},     $data{'streetcity'},                    $data{'altrelationship'}, # only 4 because of now()
98                                 $data{'othernames'},    $data{'phoneday'},              'I',                                            $data{'city'},          $data{'area'},
99                                 ''.$data{'phone'},              $data{'borrowernotes'}, $data{'altphone'},                      $surname,                       ''.$data{'initials'},
100                                 $data{'ethnicity'},     $data{'borrowernumber'},        '',                                             '',                             $data{'branchcode'},
101                                 $data{'zipcode'},       $data{'homezipcode'});
102 }
103
104 $sth2->finish;
105 $sth->finish;
106
107 print $input->redirect("/cgi-bin/koha/members/moremember.pl?bornum=$data{'borrowernumber'}");