templating Mr, Mrs, Ms...
[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.x');
58 my $delete=$input->param('delete.x');
59 if ($delete){
60   print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$member");
61
62 } else {  # this else goes down the whole script
63   if ($type ne 'Add'){
64     $template->param( header => 'Update Member Details'); # bad templating style
65   } else {
66     $template->param( header => 'Add New Member');
67   }
68
69   my $data=borrdata('',$member);
70
71   if ($type eq 'Add'){
72     $template->param( updtype => 'I');
73   } else {
74     $template->param( updtype => 'M');
75   }
76
77   my $cardnumber=C4::Members::fixup_cardnumber($data->{'cardnumber'});
78
79   if ($data->{'sex'} eq 'F'){
80     $template->param(female => 1);
81   }
82
83   my ($categories,$labels)=ethnicitycategories();
84   my $ethnicitycategoriescount=$#{$categories};
85   my $ethcatpopup;
86   if ($ethnicitycategoriescount>=0) {
87         $ethcatpopup = CGI::popup_menu(-name=>'ethnicity',
88                                 -values=>$categories,
89                                 -default=>$data->{'ethnicity'},
90                                 -labels=>$labels);
91         $template->param(ethcatpopup => $ethcatpopup); # bad style, has to be fixed
92   }
93
94   ($categories,$labels)=borrowercategories();
95   my $catcodepopup = CGI::popup_menu(-name=>'categorycode',
96                                 -values=>$categories,
97                                 -default=>$data->{'categorycode'},
98                                 -labels=>$labels);
99
100
101
102   my @relationships = ('workplace', 'relative','friend', 'neighbour');
103   my @relshipdata;
104   while (@relationships) {
105     my $relship = shift @relationships;
106     my %row = ('relationship' => $relship);
107     if ($data->{'altrelationship'} eq $relship) {
108       $row{'selected'}=' selected';
109     } else {
110       $row{'selected'}='';
111     }
112     push(@relshipdata, \%row);
113   }
114
115   # %flags: keys=$data-keys, datas=[formname, HTML-explanation]
116   my %flags = ('gonenoaddress' => ['gna', 'Gone no address'],
117                'lost'          => ['lost', 'Lost'],
118                'debarred'      => ['debarred', 'Debarred']);
119
120   my @flagdata;
121   foreach (keys(%flags)) {
122     my $key = $_;
123     my %row =  ('key'   => $key,
124                 'name'  => $flags{$key}[0],
125                 'html'  => $flags{$key}[1]);
126     if ($data->{$key}) {
127       $row{'yes'}=' checked';
128       $row{'no'}='';
129     } else {
130       $row{'yes'}='';
131       $row{'no'}=' checked';
132     }
133     push(@flagdata, \%row);
134   }
135
136   if ($modify){
137     $template->param( modify => 1 );
138   }
139
140   #Convert dateofbirth to correct format
141   $data->{'dateofbirth'} = format_date($data->{'dateofbirth'});
142
143         my @branches;
144         my @select_branch;
145         my %select_branches;
146         my $branches=getbranches();
147         foreach my $branch (keys %$branches) {
148                 push @select_branch, $branch;
149                 $select_branches{$branch} = $branches->{$branch}->{'branchname'};
150         }
151         my $CGIbranch=CGI::scrolling_list( -name     => 'branch',
152                                 -values   => \@select_branch,
153                                 -default  => $data->{'branchcode'},
154                                 -labels   => \%select_branches,
155                                 -size     => 1,
156                                 -multiple => 0 );
157
158   $template->param(
159                         member          => $member,
160                         address         => $data->{'streetaddress'},
161                         firstname       => $data->{'firstname'},
162                         surname         => $data->{'surname'},
163                         othernames      => $data->{'othernames'},
164                         initials        => $data->{'initials'},
165                         ethcatpopup     => $ethcatpopup,
166                         catcodepopup    => $catcodepopup,
167                         streetaddress   => $data->{'physstreet'},
168                         streetcity      => $data->{'streetcity'},
169                         city            => $data->{'city'},
170                         phone           => $data->{'phone'},
171                         phoneday        => $data->{'phoneday'},
172                         faxnumber       => $data->{'faxnumber'},
173                         emailaddress    => $data->{'emailaddress'},
174                         textmessaging   => $data->{'textmessaging'},
175                         contactname     => $data->{'contactname'},
176                         altphone        => $data->{'altphone'},
177                         altnotes        => $data->{'altnotes'},
178                         borrowernotes   => $data->{'borrowernotes'},
179                         flagloop        => \@flagdata,
180                         relshiploop     => \@relshipdata,
181                         "title_".$data->{'title'} => " SELECTED ",
182                         dateenrolled    => $data->{'dateenrolled'},
183                         expiry          => $data->{'expiry'},
184                         cardnumber      => $cardnumber,
185                         dateofbirth     => $data->{'dateofbirth'},
186                         dateformat      => display_date_format(),
187                         CGIbranch => $CGIbranch);
188 warn "title ==>".$data->{'title'}."<==";
189 output_html_with_http_headers $input, $cookie, $template->output;
190
191
192 }
193
194 # Local Variables:
195 # tab-width: 8
196 # End: