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";
94 if ($data{'sex'} eq '' && $categorycode ne "I"){
95 push @errors, "ERROR_gender";
98 if ($data{'firstname'} eq '' && $categorycode ne "I"){
99 push @errors,"ERROR_firstname";
102 if ($data{'surname'} eq ''){
103 push @errors,"ERROR_surname";
106 if ($data{'streetaddress'} eq ''){
107 push @errors, "ERROR_address";
110 if ($data{'city'} eq ''){
111 push @errors, "ERROR_city";
114 if (C4::Context->preference("IndependantBranches")) {
115 my $userenv = C4::Context->userenv;
116 if ($userenv->{flags} == 1){
117 unless ($userenv->{branch} eq $data{'branchcode'}){
118 push @errors, "ERROR_branch";
124 foreach my $error (@errors) {
125 $template->param( $error => 1);
127 $template->param(nok => 1);
129 my $query="Select * from borrowers where borrowernumber=?";
130 my $sth=$dbh->prepare($query);
131 $sth->execute($data{'borrowernumber'});
132 if (my $data2=$sth->fetchrow_hashref){
135 $borrowernumber = &newmember(%data);
138 if($destination eq "circ"){
139 print $input->redirect("/cgi-bin/koha/circ/circulation.pl?findborrower=$data{'cardnumber'}");
141 print $input->redirect("/cgi-bin/koha/members/moremember.pl?bornum=$borrowernumber");
148 my $branch =$input->param('branchcode');
149 if (C4::Context->preference("IndependantBranches")) {
150 my $userenv = C4::Context->userenv;
151 if ($userenv->{flags} == 1){
152 if ($userenv->{branch} eq $branch){
153 print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$borrowernumber");
155 push @errors, "ERROR_branch";
157 print $input->redirect("/cgi-bin/koha/members/moremember.pl?bornum=$borrowernumber");
160 print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$borrowernumber");
163 print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$borrowernumber");
165 } else { # this else goes down the whole script
166 if ($actionType eq 'Add'){
167 $template->param( addAction => 1);
169 $template->param( addAction =>0);
171 # retrieve previous values : either in DB or in CGI, in case of errors in values
174 my @names=$input->param;
175 foreach my $key (@names){
176 $data->{$key}=$input->param($key);
179 $data=borrdata('',$borrowernumber);
181 if (C4::Context->preference("IndependantBranches")) {
182 my $userenv = C4::Context->userenv;
183 unless ($userenv->{flags} == 1){
184 warn "userenv=".$userenv->{'branch'}." member branch :".$data->{'branchcode'};
185 unless ($userenv->{'branch'} eq $data->{'branchcode'}){
186 print $input->redirect("/cgi-bin/koha/members/moremember.pl?bornum=$borrowernumber");
191 if ($actionType eq 'Add'){
192 $template->param( updtype => 'I');
194 $template->param( updtype => 'M');
196 my $cardnumber=C4::Members::fixup_cardnumber($data->{'cardnumber'});
197 if ($data->{'sex'} eq 'F'){
198 $template->param(female => 1);
200 my ($categories,$labels)=ethnicitycategories();
201 my $ethnicitycategoriescount=$#{$categories};
203 if ($ethnicitycategoriescount>=0) {
204 $ethcatpopup = CGI::popup_menu(-name=>'ethnicity',
206 -values=>$categories,
207 -default=>$data->{'ethnicity'},
209 $template->param(ethcatpopup => $ethcatpopup); # bad style, has to be fixed
212 ($categories,$labels)=borrowercategories();
213 my $catcodepopup = CGI::popup_menu(-name=>'categorycode',
214 -id => 'categorycode',
215 -values=>$categories,
216 -default=>$data->{'categorycode'},
219 my @relationships = ('','workplace', 'relative','friend', 'neighbour');
221 while (@relationships) {
222 my $relship = shift @relationships;
223 my %row = ('relationship' => $relship);
224 if ($data->{'altrelationship'} eq $relship) {
225 $row{'selected'}=' selected';
229 push(@relshipdata, \%row);
232 # %flags: keys=$data-keys, datas=[formname, HTML-explanation]
233 my %flags = ('gonenoaddress' => ['gna', 'Gone no address'],
234 'lost' => ['lost', 'Lost'],
235 'debarred' => ['debarred', 'Debarred']);
238 foreach (keys(%flags)) {
240 my %row = ('key' => $key,
241 'name' => $flags{$key}[0],
242 'html' => $flags{$key}[1]);
244 $row{'yes'}=' checked';
248 $row{'no'}=' checked';
250 push(@flagdata, \%row);
254 $template->param( modify => 1 );
257 #Convert dateofbirth to correct format
258 $data->{'dateofbirth'} = format_date($data->{'dateofbirth'});
263 my $branches=getbranches();
265 foreach my $branch (keys %$branches) {
266 if (C4::Context->preference("IndependantBranches")) {
267 my $userenv = C4::Context->userenv;
268 if ($userenv->{flags} == 1){
269 push @select_branch, $branch;
270 $select_branches{$branch} = $branches->{$branch}->{'branchname'};
271 $default = $data->{'branchcode'};
273 push @select_branch, $branch if ($branch eq $userenv->{branch});
274 $select_branches{$branch} = $branches->{$branch}->{'branchname'} if ($branch eq $userenv->{branch});
275 $default = $userenv->{branch};
278 push @select_branch, $branch;
279 $select_branches{$branch} = $branches->{$branch}->{'branchname'};
280 $default = $data->{'branchcode'};
284 my $CGIbranch=CGI::scrolling_list( -name => 'branchcode',
286 -values => \@select_branch,
287 -default => $data->{'branchcode'},
288 -labels => \%select_branches,
293 my $CGIsort1 = buildCGIsort("Bsort1","sort1",$data->{'sort1'});
295 $template->param(CGIsort1 => $CGIsort1);
297 $template->param( sort1 => $data->{'sort1'});
300 my $CGIsort2 = buildCGIsort("Bsort2","sort2",$data->{'sort2'});
302 $template->param(CGIsort2 =>$CGIsort2);
304 $template->param( sort2 => $data->{'sort2'});
307 $template->param( actionType => $actionType,
308 destination => $destination,
309 borrowernumber => $borrowernumber,
310 address => $data->{'streetaddress'},
311 firstname => $data->{'firstname'},
312 surname => $data->{'surname'},
313 othernames => $data->{'othernames'},
314 initials => $data->{'initials'},
315 ethcatpopup => $ethcatpopup,
316 catcodepopup => $catcodepopup,
317 streetaddress => $data->{'streetaddress'},
318 physstreet => $data->{'physstreet'},
319 zipcode => $data->{'zipcode'},
320 streetcity => $data->{'streetcity'},
321 homezipcode => $data->{'homezipcode'},
322 city => $data->{'city'},
323 phone => $data->{'phone'},
324 phoneday => $data->{'phoneday'},
325 faxnumber => $data->{'faxnumber'},
326 emailaddress => $data->{'emailaddress'},
327 textmessaging => $data->{'textmessaging'},
328 contactname => $data->{'contactname'},
329 altphone => $data->{'altphone'},
330 altnotes => $data->{'altnotes'},
331 borrowernotes => $data->{'borrowernotes'},
332 flagloop => \@flagdata,
333 relshiploop => \@relshipdata,
334 "title_".$data->{'title'} => " SELECTED ",
335 joining => format_date($data->{'dateenrolled'}),
336 expiry => format_date($data->{'expiry'}),
337 cardnumber => $cardnumber,
338 dateofbirth => $data->{'dateofbirth'},
339 dateformat => display_date_format(),
341 CGIbranch => $CGIbranch);
342 $template->param(Institution => 1) if ($categorycode eq "I");
343 output_html_with_http_headers $input, $cookie, $template->output;