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 += $temp1*$temp2; # mult each char 1-7 by its corresponding weighting
99 $i++; # increment counter
101 my $rem = ($sum%11); # remainder of sum/11 (eg. 9999999/11, remainder=2)
102 if ($rem == 10) { # if remainder is 10, use X instead
105 $cardnumber="V$cardnumber$rem";
107 $cardnumber=$data->{'cardnumber'};
110 if ($data->{'sex'} eq 'F'){
111 $template->param(female => 1);
114 my @titles = ('Miss', 'Mrs', 'Ms', 'Mr', 'Dr', 'Sir');
115 # FIXME - Assumes English. This ought to be made part of i18n.
119 my $title = shift @titles;
120 $row{'title'} = $title;
121 if ($data->{'title'} eq $title) {
122 $row{'selected'}=' selected';
126 push(@titledata, \%row);
129 my ($categories,$labels)=ethnicitycategories();
130 my $ethnicitycategoriescount=$#{$categories};
132 if ($ethnicitycategoriescount>=0) {
133 $ethcatpopup = popup_menu(-name=>'ethnicity',
134 -values=>$categories,
135 -default=>$data->{'ethnicity'},
137 $template->param(ethcatpopup => $ethcatpopup); # bad style, has to be fixed
140 ($categories,$labels)=borrowercategories();
141 my $catcodepopup = CGI::popup_menu(-name=>'categorycode',
142 -values=>$categories,
143 -default=>$data->{'categorycode'},
146 my @areas = ('L','F','S','H','K','O','X','Z','V');
147 my %arealabels = ('L' => 'Levin',
152 'O' => 'Out of District',
153 'X' => 'Temporary Visitor',
154 'Z' => 'Interloan Libraries',
160 my $shortcut = shift @areas;
161 $row{'shortcut'} = $shortcut;
162 if ($data->{'area'} eq $shortcut) {
163 $row{'selected'}=' selected';
167 $row{'area'}=$arealabels{$shortcut};
168 push(@areadata, \%row);
172 my @relationships = ('workplace', 'relative','friend', 'neighbour');
174 while (@relationships) {
175 my $relship = shift @relationships;
176 my %row = ('relationship' => $relship);
177 if ($data->{'altrelationship'} eq $relship) {
178 $row{'selected'}=' selected';
182 push(@relshipdata, \%row);
185 # %flags: keys=$data-keys, datas=[formname, HTML-explanation]
186 my %flags = ('gonenoaddress' => ['gna', 'Gone no address'],
187 'lost' => ['lost', 'Lost'],
188 'debarred' => ['debarred', 'Debarred']);
191 foreach (keys(%flags)) {
193 my %row = ('key' => $key,
194 'name' => $flags{$key}[0],
195 'html' => $flags{$key}[1]);
197 $row{'yes'}=' checked';
201 $row{'no'}=' checked';
203 push(@flagdata, \%row);
207 $template->param( modify => 1 );
210 $template->param( startmenumember => join ('', startmenu('member')),
211 endmenumember => join ('', endmenu('member')),
213 firstname => $data->{'firstname'},
214 surname => $data->{'surname'},
215 othernames => $data->{'othernames'},
216 initials => $data->{'initials'},
217 ethcatpopup => $ethcatpopup,
218 catcodepopup => $catcodepopup,
219 streetaddress => $data->{'physstreet'},
220 streetcity => $data->{'streetcity'},
221 city => $data->{'city'},
222 phone => $data->{'phone'},
223 phoneday => $data->{'phoneday'},
224 faxnumber => $data->{'faxnumber'},
225 emailaddress => $data->{'emailaddress'},
226 contactname => $data->{'contactname'},
227 altphone => $data->{'altphone'},
228 altnotes => $data->{'altnotes'},
229 borrowernotes => $data->{'borrowernotes'},
230 flagloop => \@flagdata,
231 relshiploop => \@relshipdata,
232 titleloop => \@titledata,
233 arealoop => \@areadata,
234 dateenrolled => $data->{'dateenrolled'},
235 expiry => $data->{'expiry'},
236 cardnumber => $cardnumber,
237 dateofbirth => $data->{'dateofbirth'});
239 print "Content-Type: text/html\n\n", $template->output;