5 #script to set up screen for modification of borrower details
6 #written 20/12/99 by chris@katipo.co.nz
9 # Copyright 2000-2002 Katipo Communications
11 # This file is part of Koha.
13 # Koha is free software; you can redistribute it and/or modify it under the
14 # terms of the GNU General Public License as published by the Free Software
15 # Foundation; either version 2 of the License, or (at your option) any later
18 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
19 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
20 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License along with
23 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
24 # Suite 330, Boston, MA 02111-1307 USA
36 my $theme = $input->param('theme'); # only used if allowthemeoverride is set
37 my %tmpldata = pathtotemplate ( template => 'memberentry.tmpl', theme => $theme );
38 my $template = HTML::Template->new(filename => $tmpldata{'path'}, die_on_bad_params => 0);
40 my $member=$input->param('bornum');
42 $member=NewBorrowerNumber();
44 my $type=$input->param('type') || '';
45 my $modify=$input->param('modify.x');
46 my $delete=$input->param('delete.x');
48 print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$member");
50 } else { # this else goes down the whole script
52 $template->param( header => 'Update Member Details'); # bad templating style
54 $template->param( header => 'Add New Member');
57 my $data=borrdata('',$member);
60 $template->param( updtype => 'I');
62 $template->param( updtype => 'M');
65 my $cardnumber=$data->{'cardnumber'};
66 my $autonumber_members = C4::Context->preference("autoMemberNum") || 0;
67 # Find out whether member numbers should be generated
68 # automatically. Should be either "1" or something else.
69 # Defaults to "0", which is interpreted as "no".
71 # This logic should probably be moved out of the presentation code.
74 if ($cardnumber eq '' && $autonumber_members eq '1') {
75 my $dbh = C4::Context->dbh;
76 my $query="select max(substring(borrowers.cardnumber,2,7)) from borrowers";
77 my $sth=$dbh->prepare($query);
79 my $data=$sth->fetchrow_hashref;
80 $cardnumber=$data->{'max(substring(borrowers.cardnumber,2,7))'};
82 # purpose: generate checksum'd member numbers.
83 # We'll assume we just got the max value of digits 2-8 of member #'s from the database and our job is to
84 # increment that by one, determine the 1st and 9th digits and return the full string.
85 my @weightings = (8,4,6,3,5,2,1);
88 if (! $cardnumber) { # If DB has no values, start at 1000000
89 $cardnumber = 1000000;
91 $cardnumber = $cardnumber + 1; # FIXME - $cardnumber++;
94 while ($i <8) { # step from char 1 to 7.
95 my $temp1 = $weightings[$i]; # read weightings, left to right, 1 char at a time
96 my $temp2 = substr($cardnumber,$i,1); # sequence left to right, 1 char at a time
98 $sum = $sum + ($temp1*$temp2); # mult each char 1-7 by its corresponding weighting
100 $i++; # increment counter
102 my $rem = ($sum%11); # remainder of sum/11 (eg. 9999999/11, remainder=2)
103 if ($rem == 10) { # if remainder is 10, use X instead
106 $cardnumber="V$cardnumber$rem";
108 $cardnumber=$data->{'cardnumber'};
111 if ($data->{'sex'} eq 'F'){
112 $template->param(female => 1);
115 my @titles = ('Miss', 'Mrs', 'Ms', 'Mr', 'Dr', 'Sir');
116 # FIXME - Assumes English. This ought to be made part of i18n.
120 my $title = shift @titles;
121 $row{'title'} = $title;
122 if ($data->{'title'} eq $title) {
123 $row{'selected'}=' selected';
127 push(@titledata, \%row);
130 my ($categories,$labels)=ethnicitycategories();
131 my $ethnicitycategoriescount=$#{$categories};
133 if ($ethnicitycategoriescount>=0) {
134 $ethcatpopup = popup_menu(-name=>'ethnicity',
135 -values=>$categories,
136 -default=>$data->{'ethnicity'},
138 $template->param(ethcatpopup => $ethcatpopup); # bad style, has to be fixed
141 ($categories,$labels)=borrowercategories();
142 my $catcodepopup = CGI::popup_menu(-name=>'categorycode',
143 -values=>$categories,
144 -default=>$data->{'categorycode'},
147 my @areas = ('L','F','S','H','K','O','X','Z','V');
148 my %arealabels = ('L' => 'Levin',
153 'O' => 'Out of District',
154 'X' => 'Temporary Visitor',
155 'Z' => 'Interloan Libraries',
161 my $shortcut = shift @areas;
162 $row{'shortcut'} = $shortcut;
163 if ($data->{'area'} eq $shortcut) {
164 $row{'selected'}=' selected';
168 $row{'area'}=$arealabels{$shortcut};
169 push(@areadata, \%row);
173 my @relationships = ('workplace', 'relative','friend', 'neighbour');
175 while (@relationships) {
176 my $relship = shift @relationships;
177 my %row = ('relationship' => $relship);
178 if ($data->{'altrelationship'} eq $relship) {
179 $row{'selected'}=' selected';
183 push(@relshipdata, \%row);
186 # %flags: keys=$data-keys, datas=[formname, HTML-explanation]
187 my %flags = ('gonenoaddress' => ['gna', 'Gone no address'],
188 'lost' => ['lost', 'Lost'],
189 'debarred' => ['debarred', 'Debarred']);
192 foreach (keys(%flags)) {
194 my %row = ('key' => $key,
195 'name' => $flags{$key}[0],
196 'html' => $flags{$key}[1]);
198 $row{'yes'}=' checked';
202 $row{'no'}=' checked';
204 push(@flagdata, \%row);
208 $template->param( modify => 1 );
211 $template->param( startmenumember => join ('', startmenu('member')),
212 endmenumember => join ('', endmenu('member')),
214 firstname => $data->{'firstname'},
215 surname => $data->{'surname'},
216 othernames => $data->{'othernames'},
217 initials => $data->{'initials'},
218 ethcatpopup => $ethcatpopup,
219 catcodepopup => $catcodepopup,
220 streetaddress => $data->{'physstreet'},
221 streetcity => $data->{'streetcity'},
222 city => $data->{'city'},
223 phone => $data->{'phone'},
224 phoneday => $data->{'phoneday'},
225 faxnumber => $data->{'faxnumber'},
226 emailaddress => $data->{'emailaddress'},
227 contactname => $data->{'contactname'},
228 altphone => $data->{'altphone'},
229 altnotes => $data->{'altnotes'},
230 borrowernotes => $data->{'borrowernotes'},
231 flagloop => \@flagdata,
232 relshiploop => \@relshipdata,
233 titleloop => \@titledata,
234 arealoop => \@areadata,
235 dateenrolled => $data->{'dateenrolled'},
236 expiry => $data->{'expiry'},
237 cardnumber => $cardnumber,
238 dateofbirth => $data->{'dateofbirth'});
240 print "Content-Type: text/html\n\n", $template->output;