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
30 use C4::Interface::CGI::Output;
38 my ($template, $loggedinuser, $cookie)
39 = get_template_and_user({template_name => "members/memberentry.tmpl",
43 flagsrequired => {borrowers => 1},
47 my $member=$input->param('bornum');
49 $member=NewBorrowerNumber();
51 my $type=$input->param('type') || '';
52 my $modify=$input->param('modify.x');
53 my $delete=$input->param('delete.x');
55 print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$member");
57 } else { # this else goes down the whole script
59 $template->param( header => 'Update Member Details'); # bad templating style
61 $template->param( header => 'Add New Member');
64 my $data=borrdata('',$member);
67 $template->param( updtype => 'I');
69 $template->param( updtype => 'M');
72 my $cardnumber=$data->{'cardnumber'};
73 my $autonumber_members = C4::Context->preference("autoMemberNum") || 0;
74 # Find out whether member numbers should be generated
75 # automatically. Should be either "1" or something else.
76 # Defaults to "0", which is interpreted as "no".
78 # This logic should probably be moved out of the presentation code.
81 if ($cardnumber eq '' && $autonumber_members eq '1') {
82 my $dbh = C4::Context->dbh;
83 my $query="select max(substring(borrowers.cardnumber,2,7)) from borrowers";
84 my $sth=$dbh->prepare($query);
86 my $data=$sth->fetchrow_hashref;
87 $cardnumber=$data->{'max(substring(borrowers.cardnumber,2,7))'};
89 # purpose: generate checksum'd member numbers.
90 # We'll assume we just got the max value of digits 2-8 of member #'s from the database and our job is to
91 # increment that by one, determine the 1st and 9th digits and return the full string.
92 my @weightings = (8,4,6,3,5,2,1);
95 if (! $cardnumber) { # If DB has no values, start at 1000000
96 $cardnumber = 1000000;
98 $cardnumber = $cardnumber + 1; # FIXME - $cardnumber++;
101 while ($i <8) { # step from char 1 to 7.
102 my $temp1 = $weightings[$i]; # read weightings, left to right, 1 char at a time
103 my $temp2 = substr($cardnumber,$i,1); # sequence left to right, 1 char at a time
105 $sum += $temp1*$temp2; # mult each char 1-7 by its corresponding weighting
106 $i++; # increment counter
108 my $rem = ($sum%11); # remainder of sum/11 (eg. 9999999/11, remainder=2)
109 if ($rem == 10) { # if remainder is 10, use X instead
112 $cardnumber="V$cardnumber$rem";
114 $cardnumber=$data->{'cardnumber'};
117 if ($data->{'sex'} eq 'F'){
118 $template->param(female => 1);
121 my @titles = ('Miss', 'Mrs', 'Ms', 'Mr', 'Dr', 'Sir');
122 # FIXME - Assumes English. This ought to be made part of i18n.
126 my $title = shift @titles;
127 $row{'title'} = $title;
128 if ($data->{'title'} eq $title) {
129 $row{'selected'}=' selected';
133 push(@titledata, \%row);
136 my ($categories,$labels)=ethnicitycategories();
137 my $ethnicitycategoriescount=$#{$categories};
139 if ($ethnicitycategoriescount>=0) {
140 $ethcatpopup = CGI::popup_menu(-name=>'ethnicity',
141 -values=>$categories,
142 -default=>$data->{'ethnicity'},
144 $template->param(ethcatpopup => $ethcatpopup); # bad style, has to be fixed
147 ($categories,$labels)=borrowercategories();
148 my $catcodepopup = CGI::popup_menu(-name=>'categorycode',
149 -values=>$categories,
150 -default=>$data->{'categorycode'},
153 my @areas = ('L','F','S','H','K','O','X','Z','V');
154 my %arealabels = ('L' => 'Levin',
159 'O' => 'Out of District',
160 'X' => 'Temporary Visitor',
161 'Z' => 'Interloan Libraries',
167 my $shortcut = shift @areas;
168 $row{'shortcut'} = $shortcut;
169 if ($data->{'area'} eq $shortcut) {
170 $row{'selected'}=' selected';
174 $row{'area'}=$arealabels{$shortcut};
175 push(@areadata, \%row);
179 my @relationships = ('workplace', 'relative','friend', 'neighbour');
181 while (@relationships) {
182 my $relship = shift @relationships;
183 my %row = ('relationship' => $relship);
184 if ($data->{'altrelationship'} eq $relship) {
185 $row{'selected'}=' selected';
189 push(@relshipdata, \%row);
192 # %flags: keys=$data-keys, datas=[formname, HTML-explanation]
193 my %flags = ('gonenoaddress' => ['gna', 'Gone no address'],
194 'lost' => ['lost', 'Lost'],
195 'debarred' => ['debarred', 'Debarred']);
198 foreach (keys(%flags)) {
200 my %row = ('key' => $key,
201 'name' => $flags{$key}[0],
202 'html' => $flags{$key}[1]);
204 $row{'yes'}=' checked';
208 $row{'no'}=' checked';
210 push(@flagdata, \%row);
214 $template->param( modify => 1 );
219 firstname => $data->{'firstname'},
220 surname => $data->{'surname'},
221 othernames => $data->{'othernames'},
222 initials => $data->{'initials'},
223 ethcatpopup => $ethcatpopup,
224 catcodepopup => $catcodepopup,
225 streetaddress => $data->{'streetaddress'},
226 streetcity => $data->{'streetcity'},
227 city => $data->{'city'},
228 phone => $data->{'phone'},
229 phoneday => $data->{'phoneday'},
230 faxnumber => $data->{'faxnumber'},
231 emailaddress => $data->{'emailaddress'},
232 contactname => $data->{'contactname'},
233 altphone => $data->{'altphone'},
234 altnotes => $data->{'altnotes'},
235 borrowernotes => $data->{'borrowernotes'},
236 flagloop => \@flagdata,
237 relshiploop => \@relshipdata,
238 titleloop => \@titledata,
239 arealoop => \@areadata,
240 dateenrolled => $data->{'dateenrolled'},
241 expiry => $data->{'expiry'},
242 cardnumber => $cardnumber,
243 dateofbirth => $data->{'dateofbirth'});
245 output_html_with_http_headers $input, $cookie, $template->output;