Don't extract purely-numeric strings like "1" either
[koha.git] / memberentry.pl
1 #!/usr/bin/perl
2 # NOTE: This file uses standard 8-space tabs
3 #       DO NOT SET TAB SIZE TO 4
4
5 # $Id$
6
7 #script to set up screen for modification of borrower details
8 #written 20/12/99 by chris@katipo.co.nz
9
10
11 # Copyright 2000-2002 Katipo Communications
12 #
13 # This file is part of Koha.
14 #
15 # Koha is free software; you can redistribute it and/or modify it under the
16 # terms of the GNU General Public License as published by the Free Software
17 # Foundation; either version 2 of the License, or (at your option) any later
18 # version.
19 #
20 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
21 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
22 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License along with
25 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
26 # Suite 330, Boston, MA  02111-1307 USA
27
28 use strict;
29 use C4::Auth;
30 use C4::Context;
31 use C4::Output;
32 use C4::Interface::CGI::Output;
33 use CGI;
34 use C4::Search;
35 use C4::Members;
36 use C4::Koha;
37 use HTML::Template;
38 use Date::Manip;
39 use C4::Date;
40
41 my $input = new CGI;
42
43 my ($template, $loggedinuser, $cookie)
44     = get_template_and_user({template_name => "members/memberentry.tmpl",
45                              query => $input,
46                              type => "intranet",
47                              authnotrequired => 0,
48                              flagsrequired => {borrowers => 1},
49                              debug => 1,
50                              });
51
52 my $member=$input->param('bornum');
53 # if ($member eq ''){
54 #       $member=NewBorrowerNumber();
55 # }
56 my $type=$input->param('type') || '';
57 my $modify=$input->param('modify');
58 my $delete=$input->param('delete');
59 if ($delete){
60         print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$member");
61 } else {  # this else goes down the whole script
62         if ($type eq 'Add'){
63                 $template->param( addAction => 1);
64         } else {
65                 $template->param( addAction =>0);
66         }
67
68         my $data=borrdata('',$member);
69         if ($type eq 'Add'){
70                 $template->param( updtype => 'I');
71         } else {
72                 $template->param( updtype => 'M');
73         }
74         my $cardnumber=C4::Members::fixup_cardnumber($data->{'cardnumber'});
75         if ($data->{'sex'} eq 'F'){
76                 $template->param(female => 1);
77         }
78         my ($categories,$labels)=ethnicitycategories();
79         my $ethnicitycategoriescount=$#{$categories};
80         my $ethcatpopup;
81         if ($ethnicitycategoriescount>=0) {
82                 $ethcatpopup = CGI::popup_menu(-name=>'ethnicity',
83                                         -id => 'ethnicity',
84                                         -values=>$categories,
85                                         -default=>$data->{'ethnicity'},
86                                         -labels=>$labels);
87                 $template->param(ethcatpopup => $ethcatpopup); # bad style, has to be fixed
88         }
89
90         ($categories,$labels)=borrowercategories();
91         my $catcodepopup = CGI::popup_menu(-name=>'categorycode',
92                                         -id => 'categorycode',
93                                         -values=>$categories,
94                                         -default=>$data->{'categorycode'},
95                                         -labels=>$labels);
96
97         my @relationships = ('workplace', 'relative','friend', 'neighbour');
98         my @relshipdata;
99         while (@relationships) {
100                 my $relship = shift @relationships;
101                 my %row = ('relationship' => $relship);
102                 if ($data->{'altrelationship'} eq $relship) {
103                         $row{'selected'}=' selected';
104                 } else {
105                         $row{'selected'}='';
106                 }
107                 push(@relshipdata, \%row);
108         }
109
110         # %flags: keys=$data-keys, datas=[formname, HTML-explanation]
111         my %flags = ('gonenoaddress' => ['gna', 'Gone no address'],
112                                 'lost'          => ['lost', 'Lost'],
113                                 'debarred'      => ['debarred', 'Debarred']);
114
115         my @flagdata;
116         foreach (keys(%flags)) {
117         my $key = $_;
118         my %row =  ('key'   => $key,
119                         'name'  => $flags{$key}[0],
120                         'html'  => $flags{$key}[1]);
121         if ($data->{$key}) {
122                 $row{'yes'}=' checked';
123                 $row{'no'}='';
124         } else {
125                 $row{'yes'}='';
126                 $row{'no'}=' checked';
127         }
128         push(@flagdata, \%row);
129         }
130
131         if ($modify){
132         $template->param( modify => 1 );
133         }
134
135         #Convert dateofbirth to correct format
136         $data->{'dateofbirth'} = format_date($data->{'dateofbirth'});
137
138         my @branches;
139         my @select_branch;
140         my %select_branches;
141         my $branches=getbranches();
142         foreach my $branch (keys %$branches) {
143                 push @select_branch, $branch;
144                 $select_branches{$branch} = $branches->{$branch}->{'branchname'};
145         }
146         my $CGIbranch=CGI::scrolling_list( -name     => 'branchcode',
147                                 -id => 'branchcode',
148                                 -values   => \@select_branch,
149                                 -default  => $data->{'branchcode'},
150                                 -labels   => \%select_branches,
151                                 -size     => 1,
152                                 -multiple => 0 );
153
154         $template->param(       type            => $type,
155                                 member          => $member,
156                                 address         => $data->{'streetaddress'},
157                                 firstname       => $data->{'firstname'},
158                                 surname         => $data->{'surname'},
159                                 othernames      => $data->{'othernames'},
160                                 initials        => $data->{'initials'},
161                                 ethcatpopup     => $ethcatpopup,
162                                 catcodepopup    => $catcodepopup,
163                                 streetaddress   => $data->{'physstreet'},
164                                 zipcode => $data->{'zipcode'},
165                                 streetcity      => $data->{'streetcity'},
166                                 homezipcode => $data->{'homezipcode'},
167                                 city            => $data->{'city'},
168                                 phone           => $data->{'phone'},
169                                 phoneday        => $data->{'phoneday'},
170                                 faxnumber       => $data->{'faxnumber'},
171                                 emailaddress    => $data->{'emailaddress'},
172                                 textmessaging   => $data->{'textmessaging'},
173                                 contactname     => $data->{'contactname'},
174                                 altphone        => $data->{'altphone'},
175                                 altnotes        => $data->{'altnotes'},
176                                 borrowernotes   => $data->{'borrowernotes'},
177                                 flagloop        => \@flagdata,
178                                 relshiploop     => \@relshipdata,
179                                 "title_".$data->{'title'} => " SELECTED ",
180                                 dateenrolled    => $data->{'dateenrolled'},
181                                 expiry          => $data->{'expiry'},
182                                 cardnumber      => $cardnumber,
183                                 dateofbirth     => $data->{'dateofbirth'},
184                                 dateformat      => display_date_format(),
185                                 modify          => $modify,
186                                 CGIbranch => $CGIbranch);
187         output_html_with_http_headers $input, $cookie, $template->output;
188
189
190 }
191
192 # Local Variables:
193 # tab-width: 8
194 # End: