minor html modif
[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 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         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                                         -values=>$categories,
84                                         -default=>$data->{'ethnicity'},
85                                         -labels=>$labels);
86                 $template->param(ethcatpopup => $ethcatpopup); # bad style, has to be fixed
87         }
88
89         ($categories,$labels)=borrowercategories();
90         my $catcodepopup = CGI::popup_menu(-name=>'categorycode',
91                                         -values=>$categories,
92                                         -default=>$data->{'categorycode'},
93                                         -labels=>$labels);
94
95         my @relationships = ('workplace', 'relative','friend', 'neighbour');
96         my @relshipdata;
97         while (@relationships) {
98                 my $relship = shift @relationships;
99                 my %row = ('relationship' => $relship);
100                 if ($data->{'altrelationship'} eq $relship) {
101                         $row{'selected'}=' selected';
102                 } else {
103                         $row{'selected'}='';
104                 }
105                 push(@relshipdata, \%row);
106         }
107
108         # %flags: keys=$data-keys, datas=[formname, HTML-explanation]
109         my %flags = ('gonenoaddress' => ['gna', 'Gone no address'],
110                                 'lost'          => ['lost', 'Lost'],
111                                 'debarred'      => ['debarred', 'Debarred']);
112
113         my @flagdata;
114         foreach (keys(%flags)) {
115         my $key = $_;
116         my %row =  ('key'   => $key,
117                         'name'  => $flags{$key}[0],
118                         'html'  => $flags{$key}[1]);
119         if ($data->{$key}) {
120                 $row{'yes'}=' checked';
121                 $row{'no'}='';
122         } else {
123                 $row{'yes'}='';
124                 $row{'no'}=' checked';
125         }
126         push(@flagdata, \%row);
127         }
128
129         if ($modify){
130         $template->param( modify => 1 );
131         }
132
133         #Convert dateofbirth to correct format
134         $data->{'dateofbirth'} = format_date($data->{'dateofbirth'});
135
136         my @branches;
137         my @select_branch;
138         my %select_branches;
139         my $branches=getbranches();
140         foreach my $branch (keys %$branches) {
141                 push @select_branch, $branch;
142                 $select_branches{$branch} = $branches->{$branch}->{'branchname'};
143         }
144         my $CGIbranch=CGI::scrolling_list( -name     => 'branchcode',
145                                 -values   => \@select_branch,
146                                 -default  => $data->{'branchcode'},
147                                 -labels   => \%select_branches,
148                                 -size     => 1,
149                                 -multiple => 0 );
150
151         $template->param(       type            => $type,
152                                 member          => $member,
153                                 address         => $data->{'streetaddress'},
154                                 firstname       => $data->{'firstname'},
155                                 surname         => $data->{'surname'},
156                                 othernames      => $data->{'othernames'},
157                                 initials        => $data->{'initials'},
158                                 ethcatpopup     => $ethcatpopup,
159                                 catcodepopup    => $catcodepopup,
160                                 streetaddress   => $data->{'physstreet'},
161                                 zipcode => $data->{'zipcode'},
162                                 streetcity      => $data->{'streetcity'},
163                                 homezipcode => $data->{'homezipcode'},
164                                 city            => $data->{'city'},
165                                 phone           => $data->{'phone'},
166                                 phoneday        => $data->{'phoneday'},
167                                 faxnumber       => $data->{'faxnumber'},
168                                 emailaddress    => $data->{'emailaddress'},
169                                 textmessaging   => $data->{'textmessaging'},
170                                 contactname     => $data->{'contactname'},
171                                 altphone        => $data->{'altphone'},
172                                 altnotes        => $data->{'altnotes'},
173                                 borrowernotes   => $data->{'borrowernotes'},
174                                 flagloop        => \@flagdata,
175                                 relshiploop     => \@relshipdata,
176                                 "title_".$data->{'title'} => " SELECTED ",
177                                 dateenrolled    => $data->{'dateenrolled'},
178                                 expiry          => $data->{'expiry'},
179                                 cardnumber      => $cardnumber,
180                                 dateofbirth     => $data->{'dateofbirth'},
181                                 dateformat      => display_date_format(),
182                                 modify          => $modify,
183                                 CGIbranch => $CGIbranch);
184         output_html_with_http_headers $input, $cookie, $template->output;
185
186
187 }
188
189 # Local Variables:
190 # tab-width: 8
191 # End: