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');
66 # if a add or modify is requested => check validity of data.
67 if ($op eq 'add' or $op eq 'modify') {
69 my @names=$input->param;
70 foreach my $key (@names){
71 $data{$key}=$input->param($key);
72 $data{$key}=~ s/\'/\\\'/g;
73 $data{$key}=~ s/\"/\\\"/g;
76 if ($data{'cardnumber'} eq ''){
77 push @errors,"ERROR_cardnumber";
80 #check cardnumber is valid
87 my $valid=checkdigit('',$data{'cardnumber'}, $nounique);
90 push @errors, "ERROR_invalid_cardnumber";
93 if ($data{'sex'} eq '' && $categorycode ne "I"){
94 push @errors, "ERROR_gender";
97 if ($data{'firstname'} eq '' && $categorycode ne "I"){
98 push @errors,"ERROR_firstname";
101 if ($data{'surname'} eq ''){
102 push @errors,"ERROR_surname";
105 if ($data{'streetaddress'} eq ''){
106 push @errors, "ERROR_address";
109 if ($data{'city'} eq ''){
110 push @errors, "ERROR_city";
114 foreach my $error (@errors) {
115 $template->param( $error => 1);
117 $template->param(nok => 1);
119 my $query="Select * from borrowers where borrowernumber=?";
120 my $sth=$dbh->prepare($query);
121 $sth->execute($data{'borrowernumber'});
122 if (my $data2=$sth->fetchrow_hashref){
125 $borrowernumber = &newmember(%data);
128 if($destination eq "circ"){
129 print $input->redirect("/cgi-bin/koha/circ/circulation.pl?findborrower=$data{'cardnumber'}");
131 print $input->redirect("/cgi-bin/koha/members/moremember.pl?bornum=$borrowernumber");
136 print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$borrowernumber");
137 } else { # this else goes down the whole script
138 if ($actionType eq 'Add'){
139 $template->param( addAction => 1);
141 $template->param( addAction =>0);
143 # retrieve previous values : either in DB or in CGI, in case of errors in values
146 my @names=$input->param;
147 foreach my $key (@names){
148 $data->{$key}=$input->param($key);
151 $data=borrdata('',$borrowernumber);
153 if ($actionType eq 'Add'){
154 $template->param( updtype => 'I');
156 $template->param( updtype => 'M');
158 my $cardnumber=C4::Members::fixup_cardnumber($data->{'cardnumber'});
159 if ($data->{'sex'} eq 'F'){
160 $template->param(female => 1);
162 my ($categories,$labels)=ethnicitycategories();
163 my $ethnicitycategoriescount=$#{$categories};
165 if ($ethnicitycategoriescount>=0) {
166 $ethcatpopup = CGI::popup_menu(-name=>'ethnicity',
168 -values=>$categories,
169 -default=>$data->{'ethnicity'},
171 $template->param(ethcatpopup => $ethcatpopup); # bad style, has to be fixed
174 ($categories,$labels)=borrowercategories();
175 my $catcodepopup = CGI::popup_menu(-name=>'categorycode',
176 -id => 'categorycode',
177 -values=>$categories,
178 -default=>$data->{'categorycode'},
181 my @relationships = ('','workplace', 'relative','friend', 'neighbour');
183 while (@relationships) {
184 my $relship = shift @relationships;
185 my %row = ('relationship' => $relship);
186 if ($data->{'altrelationship'} eq $relship) {
187 $row{'selected'}=' selected';
191 push(@relshipdata, \%row);
194 # %flags: keys=$data-keys, datas=[formname, HTML-explanation]
195 my %flags = ('gonenoaddress' => ['gna', 'Gone no address'],
196 'lost' => ['lost', 'Lost'],
197 'debarred' => ['debarred', 'Debarred']);
200 foreach (keys(%flags)) {
202 my %row = ('key' => $key,
203 'name' => $flags{$key}[0],
204 'html' => $flags{$key}[1]);
206 $row{'yes'}=' checked';
210 $row{'no'}=' checked';
212 push(@flagdata, \%row);
216 $template->param( modify => 1 );
219 #Convert dateofbirth to correct format
220 $data->{'dateofbirth'} = format_date($data->{'dateofbirth'});
225 my $branches=getbranches();
227 foreach my $branch (keys %$branches) {
228 if (C4::Context->preference("IndependantBranches")) {
229 my $userenv = C4::Context->userenv;
230 if ($userenv->{flags} == 1){
231 push @select_branch, $branch;
232 $select_branches{$branch} = $branches->{$branch}->{'branchname'};
233 $default = $data->{'branchcode'};
235 push @select_branch, $branch if ($branch eq $userenv->{branch});
236 $select_branches{$branch} = $branches->{$branch}->{'branchname'} if ($branch eq $userenv->{branch});
237 $default = $userenv->{branch};
240 push @select_branch, $branch;
241 $select_branches{$branch} = $branches->{$branch}->{'branchname'};
242 $default = $data->{'branchcode'};
246 my $CGIbranch=CGI::scrolling_list( -name => 'branchcode',
248 -values => \@select_branch,
249 -default => $data->{'branchcode'},
250 -labels => \%select_branches,
255 my $CGIsort1 = buildCGIsort("Bsort1","sort1",$data->{'sort1'});
257 $template->param(CGIsort1 => $CGIsort1);
259 $template->param( sort1 => $data->{'sort1'});
262 my $CGIsort2 = buildCGIsort("Bsort2","sort2",$data->{'sort2'});
264 $template->param(CGIsort2 =>$CGIsort2);
266 $template->param( sort2 => $data->{'sort2'});
269 $template->param( actionType => $actionType,
270 destination => $destination,
271 borrowernumber => $borrowernumber,
272 address => $data->{'streetaddress'},
273 firstname => $data->{'firstname'},
274 surname => $data->{'surname'},
275 othernames => $data->{'othernames'},
276 initials => $data->{'initials'},
277 ethcatpopup => $ethcatpopup,
278 catcodepopup => $catcodepopup,
279 streetaddress => $data->{'streetaddress'},
280 physstreet => $data->{'physstreet'},
281 zipcode => $data->{'zipcode'},
282 streetcity => $data->{'streetcity'},
283 homezipcode => $data->{'homezipcode'},
284 city => $data->{'city'},
285 phone => $data->{'phone'},
286 phoneday => $data->{'phoneday'},
287 faxnumber => $data->{'faxnumber'},
288 emailaddress => $data->{'emailaddress'},
289 textmessaging => $data->{'textmessaging'},
290 contactname => $data->{'contactname'},
291 altphone => $data->{'altphone'},
292 altnotes => $data->{'altnotes'},
293 borrowernotes => $data->{'borrowernotes'},
294 flagloop => \@flagdata,
295 relshiploop => \@relshipdata,
296 "title_".$data->{'title'} => " SELECTED ",
297 joining => format_date($data->{'dateenrolled'}),
298 expiry => format_date($data->{'expiry'}),
299 cardnumber => $cardnumber,
300 dateofbirth => $data->{'dateofbirth'},
301 dateformat => display_date_format(),
303 CGIbranch => $CGIbranch);
304 $template->param(Institution => 1) if ($categorycode eq "I");
305 output_html_with_http_headers $input, $cookie, $template->output;