2 # NOTE: This file uses standard 8-space tabs
3 # DO NOT SET TAB SIZE TO 4
7 #script to set up screen for modification of borrower details
8 #written 20/12/99 by chris@katipo.co.nz
11 # Copyright 2000-2002 Katipo Communications
13 # This file is part of Koha.
15 # Koha is free software; you can redistribute it and/or modify it under the
16 # terms of the GNU General Public License as published by the Free Software
17 # Foundation; either version 2 of the License, or (at your option) any later
20 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
21 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
22 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License along with
25 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
26 # Suite 330, Boston, MA 02111-1307 USA
32 use C4::Interface::CGI::Output;
44 my $dbh = C4::Context->dbh;
46 my ($template, $loggedinuser, $cookie)
47 = get_template_and_user({template_name => "members/memberentry.tmpl",
51 flagsrequired => {borrowers => 1},
55 my $member=$input->param('bornum');
56 my $actionType=$input->param('actionType') || '';
57 my $modify=$input->param('modify');
58 my $delete=$input->param('delete');
59 my $op=$input->param('op');
60 my $categorycode=$input->param('categorycode');
63 # if a add or modify is requested => check validity of data.
64 if ($op eq 'add' or $op eq 'modify') {
66 my @names=$input->param;
67 foreach my $key (@names){
68 $data{$key}=$input->param($key);
69 $data{$key}=~ s/\'/\\\'/g;
70 $data{$key}=~ s/\"/\\\"/g;
73 if ($data{'cardnumber'} eq ''){
74 push @errors,"ERROR_cardnumber";
77 #check cardnumber is valid
79 if ( $data{'actionType'} eq "Add" ) {
84 my $valid=checkdigit('',$data{'cardnumber'}, $nounique);
87 push @errors, "ERROR_invalid_cardnumber";
90 if ($data{'sex'} eq '' && $categorycode ne "I"){
91 push @errors, "ERROR_gender";
94 if ($data{'firstname'} eq '' && $categorycode ne "I"){
95 push @errors,"ERROR_firstname";
98 if ($data{'surname'} eq ''){
99 push @errors,"ERROR_surname";
102 if ($data{'address'} eq ''){
103 push @errors, "ERROR_address";
106 if ($data{'city'} eq ''){
107 push @errors, "ERROR_city";
111 foreach my $error (@errors) {
112 $template->param( $error => 1);
114 $template->param(nok => 1);
116 my $query="Select * from borrowers where borrowernumber=?";
117 my $sth=$dbh->prepare($query);
118 $sth->execute($data{'borrowernumber'});
119 if (my $data2=$sth->fetchrow_hashref){
120 $data{'dateofbirth'}=format_date_in_iso($data{'dateofbirth'});
121 $data{'joining'}=format_date_in_iso($data{'joining'});
122 $data{'expiry'}=format_date_in_iso($data{'expiry'});
123 $query="update borrowers set title='$data{'title'}',expiry='$data{'expiry'}',
124 cardnumber='$data{'cardnumber'}',sex='$data{'sex'}',ethnotes='$data{'ethnicnotes'}',
125 streetaddress='$data{'address'}',faxnumber='$data{'faxnumber'}',firstname='$data{'firstname'}',
126 altnotes='$data{'altnotes'}',dateofbirth='$data{'dateofbirth'}',contactname='$data{'contactname'}',
127 emailaddress='$data{'emailaddress'}',dateenrolled='$data{'joining'}',streetcity='$data{'streetcity'}',
128 altrelationship='$data{'altrelationship'}',othernames='$data{'othernames'}',phoneday='$data{'phoneday'}',
129 categorycode='$data{'categorycode'}',city='$data{'city'}',area='$data{'area'}',phone='$data{'phone'}',
130 borrowernotes='$data{'borrowernotes'}',altphone='$data{'altphone'}',surname='$data{'surname'}',
131 initials='$data{'initials'}',physstreet='$data{'streetaddress'}',ethnicity='$data{'ethnicity'}',
132 gonenoaddress='$data{'gna'}',lost='$data{'lost'}',debarred='$data{'debarred'}',
133 textmessaging='$data{'textmessaging'}', branchcode = '$data{'branchcode'}',
134 zipcode = '$data{'zipcode'}',homezipcode='$data{'homezipcode'}'
135 where borrowernumber=$data{'borrowernumber'}";
137 $data{'dateofbirth'}=format_date_in_iso($data{'dateofbirth'});
138 $data{'joining'}=format_date_in_iso($data{'joining'});
139 $data{'expiry'}=format_date_in_iso($data{'expiry'});
140 $data{'borrowernumber'}=NewBorrowerNumber();
141 $query="insert into borrowers (title,expiry,cardnumber,sex,ethnotes,streetaddress,faxnumber,
142 firstname,altnotes,dateofbirth,contactname,emailaddress,textmessaging,dateenrolled,streetcity,
143 altrelationship,othernames,phoneday,categorycode,city,area,phone,borrowernotes,altphone,surname,
144 initials,ethnicity,physstreet,branchcode,zipcode,homezipcode) values ('$data{'title'}','$data{'expiry'}','$data{'cardnumber'}',
145 '$data{'sex'}','$data{'ethnotes'}','$data{'address'}','$data{'faxnumber'}',
146 '$data{'firstname'}','$data{'altnotes'}','$data{'dateofbirth'}','$data{'contactname'}','$data{'emailaddress'}','$data{'textmessaging'}',
147 '$data{'joining'}','$data{'streetcity'}','$data{'altrelationship'}','$data{'othernames'}',
148 '$data{'phoneday'}','$data{'categorycode'}','$data{'city'}','$data{'area'}','$data{'phone'}',
149 '$data{'borrowernotes'}','$data{'altphone'}','$data{'surname'}','$data{'initials'}',
150 '$data{'ethnicity'}','$data{'streetaddress'}','$data{'branchcode'}','$data{'zipcode'}','$data{'homezipcode'}')";
152 # ok if its an adult (type) it may have borrowers that depend on it as a guarantor
153 # so when we update information for an adult we should check for guarantees and update the relevant part
154 # of their records, ie addresses and phone numbers
155 if ($data{'categorycode'} eq 'A' || $data{'categorycode'} eq 'W'){
156 # is adult check guarantees;
157 my ($count,$guarantees)=findguarantees($data{'borrowernumber'});
158 for (my $i=0;$i<$count;$i++){
160 # It looks like the $i is only being returned to handle walking through
161 # the array, which is probably better done as a foreach loop.
163 my $guaquery="update borrowers set streetaddress='$data{'address'}',faxnumber='$data{'faxnumber'}',
164 streetcity='$data{'streetcity'}',phoneday='$data{'phoneday'}',city='$data{'city'}',area='$data{'area'}',phone='$data{'phone'}'
165 ,streetaddress='$data{'address'}'
166 where borrowernumber='$guarantees->[$i]->{'borrowernumber'}'";
167 my $sth3=$dbh->prepare($guaquery);
172 my $sth2=$dbh->prepare($query);
176 print $input->redirect("/cgi-bin/koha/members/moremember.pl?bornum=$data{'borrowernumber'}"); }
179 print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$member");
180 } else { # this else goes down the whole script
181 if ($actionType eq 'Add'){
182 $template->param( addAction => 1);
184 $template->param( addAction =>0);
186 # retrieve previous values : either in DB or in CGI, in case of errors in values
189 my @names=$input->param;
190 foreach my $key (@names){
191 $data->{$key}=$input->param($key);
194 $data=borrdata('',$member);
196 if ($actionType eq 'Add'){
197 $template->param( updtype => 'I');
199 $template->param( updtype => 'M');
201 my $cardnumber=C4::Members::fixup_cardnumber($data->{'cardnumber'});
202 if ($data->{'sex'} eq 'F'){
203 $template->param(female => 1);
205 my ($categories,$labels)=ethnicitycategories();
206 my $ethnicitycategoriescount=$#{$categories};
208 if ($ethnicitycategoriescount>=0) {
209 $ethcatpopup = CGI::popup_menu(-name=>'ethnicity',
211 -values=>$categories,
212 -default=>$data->{'ethnicity'},
214 $template->param(ethcatpopup => $ethcatpopup); # bad style, has to be fixed
217 ($categories,$labels)=borrowercategories();
218 my $catcodepopup = CGI::popup_menu(-name=>'categorycode',
219 -id => 'categorycode',
220 -values=>$categories,
221 -default=>$data->{'categorycode'},
224 my @relationships = ('workplace', 'relative','friend', 'neighbour');
226 while (@relationships) {
227 my $relship = shift @relationships;
228 my %row = ('relationship' => $relship);
229 if ($data->{'altrelationship'} eq $relship) {
230 $row{'selected'}=' selected';
234 push(@relshipdata, \%row);
237 # %flags: keys=$data-keys, datas=[formname, HTML-explanation]
238 my %flags = ('gonenoaddress' => ['gna', 'Gone no address'],
239 'lost' => ['lost', 'Lost'],
240 'debarred' => ['debarred', 'Debarred']);
243 foreach (keys(%flags)) {
245 my %row = ('key' => $key,
246 'name' => $flags{$key}[0],
247 'html' => $flags{$key}[1]);
249 $row{'yes'}=' checked';
253 $row{'no'}=' checked';
255 push(@flagdata, \%row);
259 $template->param( modify => 1 );
262 #Convert dateofbirth to correct format
263 $data->{'dateofbirth'} = format_date($data->{'dateofbirth'});
268 my $branches=getbranches();
269 foreach my $branch (keys %$branches) {
270 push @select_branch, $branch;
271 $select_branches{$branch} = $branches->{$branch}->{'branchname'};
273 my $CGIbranch=CGI::scrolling_list( -name => 'branchcode',
275 -values => \@select_branch,
276 -default => $data->{'branchcode'},
277 -labels => \%select_branches,
281 $template->param( actionType => $actionType,
283 address => $data->{'streetaddress'},
284 firstname => $data->{'firstname'},
285 surname => $data->{'surname'},
286 othernames => $data->{'othernames'},
287 initials => $data->{'initials'},
288 ethcatpopup => $ethcatpopup,
289 catcodepopup => $catcodepopup,
290 streetaddress => $data->{'physstreet'},
291 zipcode => $data->{'zipcode'},
292 streetcity => $data->{'streetcity'},
293 homezipcode => $data->{'homezipcode'},
294 city => $data->{'city'},
295 phone => $data->{'phone'},
296 phoneday => $data->{'phoneday'},
297 faxnumber => $data->{'faxnumber'},
298 emailaddress => $data->{'emailaddress'},
299 textmessaging => $data->{'textmessaging'},
300 contactname => $data->{'contactname'},
301 altphone => $data->{'altphone'},
302 altnotes => $data->{'altnotes'},
303 borrowernotes => $data->{'borrowernotes'},
304 flagloop => \@flagdata,
305 relshiploop => \@relshipdata,
306 "title_".$data->{'title'} => " SELECTED ",
307 dateenrolled => $data->{'dateenrolled'},
308 expiry => $data->{'expiry'},
309 cardnumber => $cardnumber,
310 dateofbirth => $data->{'dateofbirth'},
311 dateformat => display_date_format(),
313 CGIbranch => $CGIbranch);
314 $template->param(Institution => 1) if ($categorycode eq "I");
315 output_html_with_http_headers $input, $cookie, $template->output;