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');
114 my $title = shift @titles;
115 $row{'title'} = $title;
116 if ($data->{'title'} eq $title) {
117 $row{'selected'}=' selected';
121 push(@titledata, \%row);
124 my ($categories,$labels)=ethnicitycategories();
125 my $ethnicitycategoriescount=$#{$categories};
127 if ($ethnicitycategoriescount>=0) {
128 $ethcatpopup = popup_menu(-name=>'ethnicity',
129 -values=>$categories,
130 -default=>$data->{'ethnicity'},
132 $template->param(ethcatpopup => $ethcatpopup); # bad style, has to be fixed
135 ($categories,$labels)=borrowercategories();
136 my $catcodepopup = CGI::popup_menu(-name=>'categorycode',
137 -values=>$categories,
138 -default=>$data->{'categorycode'},
141 my @areas = ('L','F','S','H','K','O','X','Z','V');
142 my %arealabels = ('L' => 'Levin',
147 'O' => 'Out of District',
148 'X' => 'Temporary Visitor',
149 'Z' => 'Interloan Libraries',
155 my $shortcut = shift @areas;
156 $row{'shortcut'} = $shortcut;
157 if ($data->{'area'} eq $shortcut) {
158 $row{'selected'}=' selected';
162 $row{'area'}=$arealabels{$shortcut};
163 push(@areadata, \%row);
167 my @relationships = ('workplace', 'relative','friend', 'neighbour');
169 while (@relationships) {
170 my $relship = shift @relationships;
171 my %row = ('relationship' => $relship);
172 if ($data->{'altrelationship'} eq $relship) {
173 $row{'selected'}=' selected';
177 push(@relshipdata, \%row);
180 # %flags: keys=$data-keys, datas=[formname, HTML-explanation]
181 my %flags = ('gonenoaddress' => ['gna', 'Gone no address'],
182 'lost' => ['lost', 'Lost'],
183 'debarred' => ['debarred', 'Debarred']);
186 foreach (keys(%flags)) {
188 my %row = ('key' => $key,
189 'name' => $flags{$key}[0],
190 'html' => $flags{$key}[1]);
192 $row{'yes'}=' checked';
196 $row{'no'}=' checked';
198 push(@flagdata, \%row);
202 $template->param( modify => 1 );
205 $template->param( startmenumember => join ('', startmenu('member')),
206 endmenumember => join ('', endmenu('member')),
208 firstname => $data->{'firstname'},
209 surname => $data->{'surname'},
210 othernames => $data->{'othernames'},
211 initials => $data->{'initials'},
212 ethcatpopup => $ethcatpopup,
213 catcodepopup => $catcodepopup,
214 streetaddress => $data->{'physstreet'},
215 streetcity => $data->{'streetcity'},
216 city => $data->{'city'},
217 phone => $data->{'phone'},
218 phoneday => $data->{'phoneday'},
219 faxnumber => $data->{'faxnumber'},
220 emailaddress => $data->{'emailaddress'},
221 contactname => $data->{'contactname'},
222 altphone => $data->{'altphone'},
223 altnotes => $data->{'altnotes'},
224 borrowernotes => $data->{'borrowernotes'},
225 flagloop => \@flagdata,
226 relshiploop => \@relshipdata,
227 titleloop => \@titledata,
228 arealoop => \@areadata,
229 dateenrolled => $data->{'dateenrolled'},
230 expiry => $data->{'expiry'},
231 cardnumber => $cardnumber,
232 dateofbirth => $data->{'dateofbirth'});
234 print "Content-Type: text/html\n\n", $template->output;