3 #script to set up screen for modification of borrower details
4 #written 20/12/99 by chris@katipo.co.nz
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA 02111-1307 USA
34 my $theme = $input->param('theme'); # only used if allowthemeoverride is set
35 my %tmpldata = pathtotemplate ( template => 'memberentry.tmpl', theme => $theme );
36 my $template = HTML::Template->new(filename => $tmpldata{'path'}, die_on_bad_params => 0);
38 my $member=$input->param('bornum');
40 $member=NewBorrowerNumber();
42 my $type=$input->param('type') || '';
43 my $modify=$input->param('modify.x');
44 my $delete=$input->param('delete.x');
46 print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$member");
48 } else { # this else goes down the whole script
50 $template->param( header => 'Update Member Details'); # bad templating style
52 $template->param( header => 'Add New Member');
55 my $data=borrdata('',$member);
58 $template->param( updtype => 'I');
60 $template->param( updtype => 'M');
63 my $cardnumber=$data->{'cardnumber'};
64 my %systemprefs=systemprefs();
66 # This logic should probably be moved out of the presentation code.
69 if ($cardnumber eq '' && $systemprefs{'autoMemberNum'} eq '1') {
71 my $query="select max(substring(borrowers.cardnumber,2,7)) from borrowers";
72 my $sth=$dbh->prepare($query);
74 my $data=$sth->fetchrow_hashref;
75 $cardnumber=$data->{'max(substring(borrowers.cardnumber,2,7))'};
78 # purpose: generate checksum'd member numbers.
79 # We'll assume we just got the max value of digits 2-8 of member #'s from the database and our job is to
80 # increment that by one, determine the 1st and 9th digits and return the full string.
81 my @weightings = (8,4,6,3,5,2,1);
84 if (! $cardnumber) { # If DB has no values, start at 1000000
85 $cardnumber = 1000000;
87 $cardnumber = $cardnumber + 1;
90 while ($i <8) { # step from char 1 to 7.
91 my $temp1 = $weightings[$i]; # read weightings, left to right, 1 char at a time
92 my $temp2 = substr($cardnumber,$i,1); # sequence left to right, 1 char at a time
94 $sum = $sum + ($temp1*$temp2); # mult each char 1-7 by its corresponding weighting
95 $i++; # increment counter
97 my $rem = ($sum%11); # remainder of sum/11 (eg. 9999999/11, remainder=2)
98 if ($rem == 10) { # if remainder is 10, use X instead
101 $cardnumber="V$cardnumber$rem";
103 $cardnumber=$data->{'cardnumber'};
106 if ($data->{'sex'} eq 'F'){
107 $template->param(female => 1);
110 my @titles = ('Miss', 'Mrs', 'Ms', 'Mr', 'Dr', 'Sir');
111 # FIXME - Assumes English. This ought to be made part of i18n.
115 my $title = shift @titles;
116 $row{'title'} = $title;
117 if ($data->{'title'} eq $title) {
118 $row{'selected'}=' selected';
122 push(@titledata, \%row);
125 my ($categories,$labels)=ethnicitycategories();
126 my $ethnicitycategoriescount=$#{$categories};
128 if ($ethnicitycategoriescount>=0) {
129 $ethcatpopup = popup_menu(-name=>'ethnicity',
130 -values=>$categories,
131 -default=>$data->{'ethnicity'},
133 $template->param(ethcatpopup => $ethcatpopup); # bad style, has to be fixed
136 ($categories,$labels)=borrowercategories();
137 my $catcodepopup = CGI::popup_menu(-name=>'categorycode',
138 -values=>$categories,
139 -default=>$data->{'categorycode'},
142 my @areas = ('L','F','S','H','K','O','X','Z','V');
143 my %arealabels = ('L' => 'Levin',
148 'O' => 'Out of District',
149 'X' => 'Temporary Visitor',
150 'Z' => 'Interloan Libraries',
156 my $shortcut = shift @areas;
157 $row{'shortcut'} = $shortcut;
158 if ($data->{'area'} eq $shortcut) {
159 $row{'selected'}=' selected';
163 $row{'area'}=$arealabels{$shortcut};
164 push(@areadata, \%row);
168 my @relationships = ('workplace', 'relative','friend', 'neighbour');
170 while (@relationships) {
171 my $relship = shift @relationships;
172 my %row = ('relationship' => $relship);
173 if ($data->{'altrelationship'} eq $relship) {
174 $row{'selected'}=' selected';
178 push(@relshipdata, \%row);
181 # %flags: keys=$data-keys, datas=[formname, HTML-explanation]
182 my %flags = ('gonenoaddress' => ['gna', 'Gone no address'],
183 'lost' => ['lost', 'Lost'],
184 'debarred' => ['debarred', 'Debarred']);
187 foreach (keys(%flags)) {
189 my %row = ('key' => $key,
190 'name' => $flags{$key}[0],
191 'html' => $flags{$key}[1]);
193 $row{'yes'}=' checked';
197 $row{'no'}=' checked';
199 push(@flagdata, \%row);
203 $template->param( modify => 1 );
206 $template->param( startmenumember => join ('', startmenu('member')),
207 endmenumember => join ('', endmenu('member')),
209 firstname => $data->{'firstname'},
210 surname => $data->{'surname'},
211 othernames => $data->{'othernames'},
212 initials => $data->{'initials'},
213 ethcatpopup => $ethcatpopup,
214 catcodepopup => $catcodepopup,
215 streetaddress => $data->{'physstreet'},
216 streetcity => $data->{'streetcity'},
217 city => $data->{'city'},
218 phone => $data->{'phone'},
219 phoneday => $data->{'phoneday'},
220 faxnumber => $data->{'faxnumber'},
221 emailaddress => $data->{'emailaddress'},
222 contactname => $data->{'contactname'},
223 altphone => $data->{'altphone'},
224 altnotes => $data->{'altnotes'},
225 borrowernotes => $data->{'borrowernotes'},
226 flagloop => \@flagdata,
227 relshiploop => \@relshipdata,
228 titleloop => \@titledata,
229 arealoop => \@areadata,
230 dateenrolled => $data->{'dateenrolled'},
231 expiry => $data->{'expiry'},
232 cardnumber => $cardnumber,
233 dateofbirth => $data->{'dateofbirth'});
235 print "Content-Type: text/html\n\n", $template->output;