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