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 $borrowernumber=$input->param('borrowernumber');
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');
61 my $destination=$input->param('destination');
64 # if a add or modify is requested => check validity of data.
65 if ($op eq 'add' or $op eq 'modify') {
67 my @names=$input->param;
68 foreach my $key (@names){
69 $data{$key}=$input->param($key);
70 $data{$key}=~ s/\'/\\\'/g;
71 $data{$key}=~ s/\"/\\\"/g;
74 if ($data{'cardnumber'} eq ''){
75 push @errors,"ERROR_cardnumber";
78 #check cardnumber is valid
85 my $valid=checkdigit('',$data{'cardnumber'}, $nounique);
88 push @errors, "ERROR_invalid_cardnumber";
91 if ($data{'sex'} eq '' && $categorycode ne "I"){
92 push @errors, "ERROR_gender";
95 if ($data{'firstname'} eq '' && $categorycode ne "I"){
96 push @errors,"ERROR_firstname";
99 if ($data{'surname'} eq ''){
100 push @errors,"ERROR_surname";
103 if ($data{'streetaddress'} eq ''){
104 push @errors, "ERROR_address";
107 if ($data{'city'} eq ''){
108 push @errors, "ERROR_city";
112 foreach my $error (@errors) {
113 $template->param( $error => 1);
115 $template->param(nok => 1);
117 my $query="Select * from borrowers where borrowernumber=?";
118 my $sth=$dbh->prepare($query);
119 $sth->execute($data{'borrowernumber'});
120 if (my $data2=$sth->fetchrow_hashref){
123 $borrowernumber = &newmember(%data);
126 if($destination eq "circ"){
127 print $input->redirect("/cgi-bin/koha/circ/circulation.pl?findborrower=$data{'cardnumber'}");
129 print $input->redirect("/cgi-bin/koha/members/moremember.pl?bornum=$borrowernumber");
132 if($destination eq "circ"){
133 print $input->redirect("/cgi-bin/koha/circ/circulation.pl?findborrower=$data{'cardnumber'}");
135 print $input->redirect("/cgi-bin/koha/members/moremember.pl?bornum=$data{'borrowernumber'}");
140 print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$borrowernumber");
141 } else { # this else goes down the whole script
142 if ($actionType eq 'Add'){
143 $template->param( addAction => 1);
145 $template->param( addAction =>0);
147 # retrieve previous values : either in DB or in CGI, in case of errors in values
150 my @names=$input->param;
151 foreach my $key (@names){
152 $data->{$key}=$input->param($key);
155 $data=borrdata('',$borrowernumber);
157 if ($actionType eq 'Add'){
158 $template->param( updtype => 'I');
160 $template->param( updtype => 'M');
162 my $cardnumber=C4::Members::fixup_cardnumber($data->{'cardnumber'});
163 if ($data->{'sex'} eq 'F'){
164 $template->param(female => 1);
166 my ($categories,$labels)=ethnicitycategories();
167 my $ethnicitycategoriescount=$#{$categories};
169 if ($ethnicitycategoriescount>=0) {
170 $ethcatpopup = CGI::popup_menu(-name=>'ethnicity',
172 -values=>$categories,
173 -default=>$data->{'ethnicity'},
175 $template->param(ethcatpopup => $ethcatpopup); # bad style, has to be fixed
178 ($categories,$labels)=borrowercategories();
179 my $catcodepopup = CGI::popup_menu(-name=>'categorycode',
180 -id => 'categorycode',
181 -values=>$categories,
182 -default=>$data->{'categorycode'},
185 my @relationships = ('','workplace', 'relative','friend', 'neighbour');
187 while (@relationships) {
188 my $relship = shift @relationships;
189 my %row = ('relationship' => $relship);
190 if ($data->{'altrelationship'} eq $relship) {
191 $row{'selected'}=' selected';
195 push(@relshipdata, \%row);
198 # %flags: keys=$data-keys, datas=[formname, HTML-explanation]
199 my %flags = ('gonenoaddress' => ['gna', 'Gone no address'],
200 'lost' => ['lost', 'Lost'],
201 'debarred' => ['debarred', 'Debarred']);
204 foreach (keys(%flags)) {
206 my %row = ('key' => $key,
207 'name' => $flags{$key}[0],
208 'html' => $flags{$key}[1]);
210 $row{'yes'}=' checked';
214 $row{'no'}=' checked';
216 push(@flagdata, \%row);
220 $template->param( modify => 1 );
223 #Convert dateofbirth to correct format
224 $data->{'dateofbirth'} = format_date($data->{'dateofbirth'});
229 my $branches=getbranches();
230 foreach my $branch (keys %$branches) {
231 push @select_branch, $branch;
232 $select_branches{$branch} = $branches->{$branch}->{'branchname'};
234 my $CGIbranch=CGI::scrolling_list( -name => 'branchcode',
236 -values => \@select_branch,
237 -default => $data->{'branchcode'},
238 -labels => \%select_branches,
242 $template->param( actionType => $actionType,
243 destination => $destination,
245 address => $data->{'streetaddress'},
246 firstname => $data->{'firstname'},
247 surname => $data->{'surname'},
248 othernames => $data->{'othernames'},
249 initials => $data->{'initials'},
250 ethcatpopup => $ethcatpopup,
251 catcodepopup => $catcodepopup,
252 streetaddress => $data->{'streetaddress'},
253 physstreet => $data->{'physstreet'},
254 zipcode => $data->{'zipcode'},
255 streetcity => $data->{'streetcity'},
256 homezipcode => $data->{'homezipcode'},
257 city => $data->{'city'},
258 phone => $data->{'phone'},
259 phoneday => $data->{'phoneday'},
260 faxnumber => $data->{'faxnumber'},
261 emailaddress => $data->{'emailaddress'},
262 textmessaging => $data->{'textmessaging'},
263 contactname => $data->{'contactname'},
264 altphone => $data->{'altphone'},
265 altnotes => $data->{'altnotes'},
266 borrowernotes => $data->{'borrowernotes'},
267 flagloop => \@flagdata,
268 relshiploop => \@relshipdata,
269 "title_".$data->{'title'} => " SELECTED ",
270 dateenrolled => $data->{'dateenrolled'},
271 expiry => $data->{'expiry'},
272 cardnumber => $cardnumber,
273 dateofbirth => $data->{'dateofbirth'},
274 sort1 => $data->{'sort1'},
275 sort2 => $data->{'sort2'},
276 dateformat => display_date_format(),
278 CGIbranch => $CGIbranch);
279 $template->param(Institution => 1) if ($categorycode eq "I");
280 output_html_with_http_headers $input, $cookie, $template->output;