bugfix
[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
40 my $input = new CGI;
41
42 my ($template, $loggedinuser, $cookie)
43     = get_template_and_user({template_name => "members/memberentry.tmpl",
44                              query => $input,
45                              type => "intranet",
46                              authnotrequired => 0,
47                              flagsrequired => {borrowers => 1},
48                              debug => 1,
49                              });
50
51 my $member=$input->param('bornum');
52 if ($member eq ''){
53   $member=NewBorrowerNumber();
54 }
55 my $type=$input->param('type') || '';
56 my $modify=$input->param('modify.x');
57 my $delete=$input->param('delete.x');
58 if ($delete){
59   print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$member");
60
61 } else {  # this else goes down the whole script
62   if ($type ne 'Add'){
63     $template->param( header => 'Update Member Details'); # bad templating style
64   } else {
65     $template->param( header => 'Add New Member');
66   }
67
68   my $data=borrdata('',$member);
69
70   if ($type eq 'Add'){
71     $template->param( updtype => 'I');
72   } else {
73     $template->param( updtype => 'M');
74   }
75
76   my $cardnumber=C4::Members::fixup_cardnumber($data->{'cardnumber'});
77
78   if ($data->{'sex'} eq 'F'){
79     $template->param(female => 1);
80   }
81
82   my @titles = ('Miss', 'Mrs', 'Ms', 'Mr', 'Dr', 'Sir');
83         # FIXME - Assumes English. This ought to be made part of i18n.
84   my @titledata;
85   while (@titles) {
86     my %row;
87     my $title = shift @titles;
88     $row{'title'} = $title;
89     if ($data->{'title'} eq $title) {
90       $row{'selected'}=' selected';
91     } else {
92       $row{'selected'}='';
93     }
94     push(@titledata, \%row);
95   }
96
97   my ($categories,$labels)=ethnicitycategories();
98   my $ethnicitycategoriescount=$#{$categories};
99   my $ethcatpopup;
100   if ($ethnicitycategoriescount>=0) {
101         $ethcatpopup = CGI::popup_menu(-name=>'ethnicity',
102                                 -values=>$categories,
103                                 -default=>$data->{'ethnicity'},
104                                 -labels=>$labels);
105         $template->param(ethcatpopup => $ethcatpopup); # bad style, has to be fixed
106   }
107
108   ($categories,$labels)=borrowercategories();
109   my $catcodepopup = CGI::popup_menu(-name=>'categorycode',
110                                 -values=>$categories,
111                                 -default=>$data->{'categorycode'},
112                                 -labels=>$labels);
113
114   my @areas = ('L','F','S','H','K','O','X','Z','V');
115   my %arealabels = ('L' => 'Levin',
116                   'F' => 'Foxton',
117                   'S' => 'Shannon',
118                   'H' => 'Horowhenua',
119                   'K' => 'Kapiti',
120                   'O' => 'Out of District',
121                   'X' => 'Temporary Visitor',
122                   'Z' => 'Interloan Libraries',
123                   'V' => 'Village');
124
125   my @areadata;
126   while (@areas) {
127     my %row;
128     my $shortcut = shift @areas;
129     $row{'shortcut'} = $shortcut;
130     if ($data->{'area'} eq $shortcut) {
131       $row{'selected'}=' selected';
132     } else {
133       $row{'selected'}='';
134     }
135     $row{'area'}=$arealabels{$shortcut};
136     push(@areadata, \%row);
137   }
138
139
140   my @relationships = ('workplace', 'relative','friend', 'neighbour');
141   my @relshipdata;
142   while (@relationships) {
143     my $relship = shift @relationships;
144     my %row = ('relationship' => $relship);
145     if ($data->{'altrelationship'} eq $relship) {
146       $row{'selected'}=' selected';
147     } else {
148       $row{'selected'}='';
149     }
150     push(@relshipdata, \%row);
151   }
152
153   # %flags: keys=$data-keys, datas=[formname, HTML-explanation]
154   my %flags = ('gonenoaddress' => ['gna', 'Gone no address'],
155                'lost'          => ['lost', 'Lost'],
156                'debarred'      => ['debarred', 'Debarred']);
157
158   my @flagdata;
159   foreach (keys(%flags)) {
160     my $key = $_;
161     my %row =  ('key'   => $key,
162                 'name'  => $flags{$key}[0],
163                 'html'  => $flags{$key}[1]);
164     if ($data->{$key}) {
165       $row{'yes'}=' checked';
166       $row{'no'}='';
167     } else {
168       $row{'yes'}='';
169       $row{'no'}=' checked';
170     }
171     push(@flagdata, \%row);
172   }
173
174   if ($modify){
175     $template->param( modify => 1 );
176   }
177
178   #Convert dateofbirth to correct format
179   $data->{'dateofbirth'}=ParseDate($data->{'dateofbirth'});
180   $data->{'dateofbirth'}=UnixDate($data->{'dateofbirth'},'%d/%m/%Y');
181
182
183   $template->param( 
184                         member          => $member,
185                         firstname       => $data->{'firstname'},
186                         surname         => $data->{'surname'},
187                         othernames      => $data->{'othernames'},
188                         initials        => $data->{'initials'},
189                         ethcatpopup     => $ethcatpopup,
190                         catcodepopup    => $catcodepopup,
191                         streetaddress   => $data->{'streetaddress'},
192                         streetcity      => $data->{'streetcity'},
193                         city            => $data->{'city'},
194                         phone           => $data->{'phone'},
195                         phoneday        => $data->{'phoneday'},
196                         faxnumber       => $data->{'faxnumber'},
197                         emailaddress    => $data->{'emailaddress'},
198                         contactname     => $data->{'contactname'},
199                         altphone        => $data->{'altphone'},
200                         altnotes        => $data->{'altnotes'},
201                         borrowernotes   => $data->{'borrowernotes'},
202                         flagloop        => \@flagdata,
203                         relshiploop     => \@relshipdata,
204                         titleloop       => \@titledata,
205                         arealoop        => \@areadata,
206                         dateenrolled    => $data->{'dateenrolled'},
207                         expiry          => $data->{'expiry'},
208                         cardnumber      => $cardnumber,
209                         dateofbirth     => $data->{'dateofbirth'});
210
211 output_html_with_http_headers $input, $cookie, $template->output;
212
213
214 }
215
216 # Local Variables:
217 # tab-width: 8
218 # End: