3 # Copyright 2006 SAN OUEST PROVENCE et Paul POULAIN
4 # Copyright 2010 BibLibre
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
27 use List
::MoreUtils qw
/uniq/;
28 use Digest
::MD5
qw(md5_base64);
35 use C4
::Members
::Attributes
;
36 use C4
::Members
::AttributeTypes
;
40 use C4
::Branch
; # GetBranches
41 use C4
::Form
::MessagingPreferences
;
42 use Koha
::Patron
::Debarments
;
48 if ( C4
::Context
->preference('NorwegianPatronDBEnable') && C4
::Context
->preference('NorwegianPatronDBEnable') == 1 ) {
49 load Koha
::NorwegianPatronDB
, qw( NLGetSyncDataFromBorrowernumber );
51 use Koha
::SMS
::Providers
;
56 $debug = $ENV{DEBUG} || 0;
60 ($debug) or $debug = $input->param('debug') || 0;
63 my $dbh = C4::Context->dbh;
65 my ($template, $loggedinuser, $cookie)
66 = get_template_and_user({template_name => "members/memberentrygen.tt",
70 flagsrequired => {borrowers => 1},
71 debug => ($debug) ? 1 : 0,
74 if ( C4::Context->preference('SMSSendDriver') eq 'Email' ) {
75 my @providers = Koha::SMS::Providers->search();
76 $template->param( sms_providers => \@providers );
79 my $guarantorid = $input->param('guarantorid');
80 my $borrowernumber = $input->param('borrowernumber');
81 my $actionType = $input->param('actionType') || '';
82 my $modify = $input->param('modify');
83 my $delete = $input->param('delete');
84 my $op = $input->param('op');
85 my $destination = $input->param('destination');
86 my $cardnumber = $input->param('cardnumber');
87 my $check_member = $input->param('check_member');
88 my $nodouble = $input->param('nodouble');
89 my $duplicate = $input->param('duplicate');
90 my $quickadd = $input->param('quickadd');
91 $nodouble = 1 if ($op eq 'modify' or $op eq 'duplicate'); # FIXME hack to represent fact that if we're
92 # modifying an existing patron, it ipso facto
93 # isn't a duplicate. Marking FIXME because this
94 # script needs to be refactored.
95 my $nok = $input->param('nok');
96 my $guarantorinfo = $input->param('guarantorinfo');
97 my $step = $input->param('step') || 0;
101 my $userenv = C4::Context->userenv;
104 ## Deal with debarments
106 debarments => GetDebarments( { borrowernumber => $borrowernumber } ) );
107 my @debarments_to_remove = $input->multi_param('remove_debarment');
108 foreach my $d ( @debarments_to_remove ) {
111 if ( $input->param('add_debarment') ) {
113 my $expiration = $input->param('debarred_expiration');
117 { 'dt' => dt_from_string($expiration), 'dateformat' => 'iso' } )
122 borrowernumber => $borrowernumber,
124 comment => scalar $input->param('debarred_comment'),
125 expiration => $expiration,
130 $template->param("uppercasesurnames" => C4::Context->preference('uppercasesurnames'));
132 my $minpw = C4::Context->preference('minPasswordLength');
133 $template->param("minPasswordLength" => $minpw);
135 # function to designate mandatory fields (visually with css)
136 my $check_BorrowerMandatoryField=C4::Context->preference("BorrowerMandatoryField");
137 my @field_check=split(/\|/,$check_BorrowerMandatoryField);
138 foreach (@field_check) {
139 $template->param( "mandatory$_" => 1);
141 # function to designate unwanted fields
142 my $check_BorrowerUnwantedField=C4::Context->preference("BorrowerUnwantedField");
143 @field_check=split(/\|/,$check_BorrowerUnwantedField);
144 foreach (@field_check) {
146 $template->param( "no$_" => 1);
148 $template->param( "add" => 1 ) if ( $op eq 'add' );
149 $template->param( "quickadd" => 1 ) if ( $quickadd );
150 $template->param( "duplicate" => 1 ) if ( $op eq 'duplicate' );
151 $template->param( "checked" => 1 ) if ( defined($nodouble) && $nodouble eq 1 );
152 ( $borrower_data = GetMember( 'borrowernumber' => $borrowernumber ) ) if ( $op eq 'modify' or $op eq 'save' or $op eq 'duplicate' );
153 my $categorycode = $input->param('categorycode') || $borrower_data->{'categorycode'};
154 my $category_type = $input->param('category_type') || '';
155 unless ($category_type or !($categorycode)){
156 my $borrowercategory = GetBorrowercategory($categorycode);
157 $category_type = $borrowercategory->{'category_type'};
158 my $category_name = $borrowercategory->{'description'};
159 $template->param("categoryname"=>$category_name);
161 $category_type="A" unless $category_type; # FIXME we should display a error message instead of a 500 error !
163 # if a add or modify is requested => check validity of data.
164 %data = %$borrower_data if ($borrower_data);
166 # initialize %newdata
167 my %newdata; # comes from $input->param()
168 if ( $op eq 'insert' || $op eq 'modify' || $op eq 'save' || $op eq 'duplicate' ) {
169 my @names = ( $borrower_data && $op ne 'save' ) ? keys %$borrower_data : $input->param();
170 foreach my $key (@names) {
171 if (defined $input->param($key)) {
172 $newdata{$key} = $input->param($key);
173 $newdata{$key} =~ s/\"/"/g unless $key eq 'borrowernotes' or $key eq 'opacnote';
177 foreach (qw(dateenrolled dateexpiry dateofbirth)) {
178 next unless exists $newdata{$_};
179 my $userdate = $newdata{$_} or next;
181 my $formatteddate = eval { output_pref
({ dt
=> dt_from_string
( $userdate ), dateformat
=> 'iso', dateonly
=> 1 } ); };
182 if ( $formatteddate ) {
183 $newdata{$_} = $formatteddate;
185 ($userdate eq '0000-00-00') and warn "Data error: $_ is '0000-00-00'";
186 $template->param( "ERROR_$_" => 1 );
187 push(@errors,"ERROR_$_");
190 # check permission to modify login info.
191 if (ref($borrower_data) && ($borrower_data->{'category_type'} eq 'S') && ! (C4
::Auth
::haspermission
($userenv->{'id'},{'staffaccess'=>1})) ) {
196 # remove keys from %newdata that ModMember() doesn't like
198 my @keys_to_delete = (
199 qr/^BorrowerMandatoryField$/,
208 qr/^setting_extended_patron_attributes$/,
209 qr/^setting_messaging_prefs$/,
217 for my $regexp (@keys_to_delete) {
218 for (keys %newdata) {
219 delete($newdata{$_}) if /$regexp/;
224 # Test uniqueness of surname, firstname and dateofbirth
225 if ( ( $op eq 'insert' ) and !$nodouble ) {
227 $conditions->{surname
} = $newdata{surname
} if $newdata{surname
};
228 if ( $category_type ne 'I' ) {
229 $conditions->{firstname
} = $newdata{firstname
} if $newdata{firstname
};
230 $conditions->{dateofbirth
} = $newdata{dateofbirth
} if $newdata{dateofbirth
};
233 my $patrons = Koha
::Patrons
->search($conditions);
234 if ( $patrons->count > 0) {
236 $check_member = $patrons->next->borrowernumber;
240 #recover all data from guarantor address phone ,fax...
241 if ( $guarantorid ) {
242 if (my $guarantordata=GetMember
(borrowernumber
=> $guarantorid)) {
243 $category_type = $guarantordata->{categorycode
} eq 'I' ?
'P' : 'C';
244 $guarantorinfo=$guarantordata->{'surname'}." , ".$guarantordata->{'firstname'};
245 $newdata{'contactfirstname'}= $guarantordata->{'firstname'};
246 $newdata{'contactname'} = $guarantordata->{'surname'};
247 $newdata{'contacttitle'} = $guarantordata->{'title'};
248 if ( $op eq 'add' ) {
249 foreach (qw(streetnumber address streettype address2
250 zipcode country city state phone phonepro mobile fax email emailpro branchcode
251 B_streetnumber B_streettype B_address B_address2
252 B_city B_state B_zipcode B_country B_email B_phone)) {
253 $newdata{$_} = $guarantordata->{$_};
259 ###############test to take the right zipcode, country and city name ##############
260 # set only if parameter was passed from the form
261 $newdata{'city'} = $input->param('city') if defined($input->param('city'));
262 $newdata{'zipcode'} = $input->param('zipcode') if defined($input->param('zipcode'));
263 $newdata{'country'} = $input->param('country') if defined($input->param('country'));
265 # builds default userid
266 # userid input text may be empty or missing because of syspref BorrowerUnwantedField
267 if ( ( defined $newdata{'userid'} && $newdata{'userid'} eq '' ) || $check_BorrowerUnwantedField =~ /userid/ ) {
268 if ( ( defined $newdata{'firstname'} ) && ( defined $newdata{'surname'} ) ) {
269 # Full page edit, firstname and surname input zones are present
270 $newdata{'userid'} = Generate_Userid
( $borrowernumber, $newdata{'firstname'}, $newdata{'surname'} );
272 elsif ( ( defined $data{'firstname'} ) && ( defined $data{'surname'} ) ) {
273 # Partial page edit (access through "Details"/"Library details" tab), firstname and surname input zones are not used
274 # Still, if the userid field is erased, we can create a new userid with available firstname and surname
275 $newdata{'userid'} = Generate_Userid
( $borrowernumber, $data{'firstname'}, $data{'surname'} );
278 $newdata{'userid'} = $data{'userid'};
282 $debug and warn join "\t", map {"$_: $newdata{$_}"} qw(dateofbirth dateenrolled dateexpiry);
283 my $extended_patron_attributes = ();
284 if ($op eq 'save' || $op eq 'insert'){
286 die "Wrong CSRF token"
287 unless Koha
::Token
->new->check_csrf({
288 id
=> C4
::Context
->userenv->{id
},
289 secret
=> md5_base64
( C4
::Context
->config('pass') ),
290 token
=> scalar $input->param('csrf_token'),
293 # If the cardnumber is blank, treat it as null.
294 $newdata{'cardnumber'} = undef if $newdata{'cardnumber'} =~ /^\s*$/;
296 if (my $error_code = checkcardnumber
($newdata{cardnumber
},$newdata{borrowernumber
})){
297 push @errors, $error_code == 1
298 ?
'ERROR_cardnumber_already_exists'
300 ?
'ERROR_cardnumber_length'
304 if ( $newdata{dateofbirth
} ) {
305 my $age = GetAge
($newdata{dateofbirth
});
306 my $borrowercategory=GetBorrowercategory
($newdata{'categorycode'});
307 my ($low,$high) = ($borrowercategory->{'dateofbirthrequired'}, $borrowercategory->{'upperagelimit'});
308 if (($high && ($age > $high)) or ($age < $low)) {
309 push @errors, 'ERROR_age_limitations';
310 $template->param( age_low
=> $low);
311 $template->param( age_high
=> $high);
315 if($newdata{surname
} && C4
::Context
->preference('uppercasesurnames')) {
316 $newdata{'surname'} = uc($newdata{'surname'});
319 if (C4
::Context
->preference("IndependentBranches")) {
320 unless ( C4
::Context
->IsSuperLibrarian() ){
321 $debug and print STDERR
" $newdata{'branchcode'} : ".$userenv->{flags
}.":".$userenv->{branch
};
322 unless (!$newdata{'branchcode'} || $userenv->{branch
} eq $newdata{'branchcode'}){
323 push @errors, "ERROR_branch";
327 # Check if the 'userid' is unique. 'userid' might not always be present in
328 # the edited values list when editing certain sub-forms. Get it straight
329 # from the DB if absent.
330 my $userid = $newdata{ userid
} // $borrower_data->{ userid
};
331 unless (Check_Userid
($userid,$borrowernumber)) {
332 push @errors, "ERROR_login_exist";
335 my $password = $input->param('password');
336 my $password2 = $input->param('password2');
337 push @errors, "ERROR_password_mismatch" if ( $password ne $password2 );
338 push @errors, "ERROR_short_password" if( $password && $minpw && $password ne '****' && (length($password) < $minpw) );
341 my $emailprimary = $input->param('email');
342 my $emailsecondary = $input->param('emailpro');
343 my $emailalt = $input->param('B_email');
346 push (@errors, "ERROR_bad_email") if (!Email
::Valid
->address($emailprimary));
348 if ($emailsecondary) {
349 push (@errors, "ERROR_bad_email_secondary") if (!Email
::Valid
->address($emailsecondary));
352 push (@errors, "ERROR_bad_email_alternative") if (!Email
::Valid
->address($emailalt));
355 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
356 $extended_patron_attributes = parse_extended_patron_attributes
($input);
357 foreach my $attr (@
$extended_patron_attributes) {
358 unless (C4
::Members
::Attributes
::CheckUniqueness
($attr->{code
}, $attr->{value
}, $borrowernumber)) {
359 my $attr_info = C4
::Members
::AttributeTypes
->fetch($attr->{code
});
360 push @errors, "ERROR_extended_unique_id_failed";
362 ERROR_extended_unique_id_failed_code
=> $attr->{code
},
363 ERROR_extended_unique_id_failed_value
=> $attr->{value
},
364 ERROR_extended_unique_id_failed_description
=> $attr_info->description()
371 if ( ($op eq 'modify' || $op eq 'insert' || $op eq 'save'|| $op eq 'duplicate') and ($step == 0 or $step == 3 )){
372 unless ($newdata{'dateexpiry'}){
373 my $arg2 = $newdata{'dateenrolled'} || output_pref
({ dt
=> dt_from_string
, dateformat
=> 'iso', dateonly
=> 1 });
374 $newdata{'dateexpiry'} = GetExpiryDate
($newdata{'categorycode'},$arg2);
378 # BZ 14683: Do not mixup mobile [read: other phone] with smsalertnumber
379 my $sms = $input->param('SMSnumber');
380 if ( defined $sms ) {
381 $newdata{smsalertnumber
} = $sms;
384 ### Error checks should happen before this line.
385 $nok = $nok || scalar(@errors);
386 if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){
387 $debug and warn "$op dates: " . join "\t", map {"$_: $newdata{$_}"} qw(dateofbirth dateenrolled dateexpiry);
388 if ($op eq 'insert'){
389 # we know it's not a duplicate borrowernumber or there would already be an error
390 $borrowernumber = &AddMember
(%newdata);
391 $newdata{'borrowernumber'} = $borrowernumber;
393 # If 'AutoEmailOpacUser' syspref is on, email user their account details from the 'notice' that matches the user's branchcode.
394 if ( C4
::Context
->preference("AutoEmailOpacUser") == 1 && $newdata{'userid'} && $newdata{'password'}) {
395 #look for defined primary email address, if blank - attempt to use borr.email and borr.emailpro instead
397 if (C4
::Context
->preference("AutoEmailPrimaryAddress") ne 'OFF' &&
398 $newdata{C4
::Context
->preference("AutoEmailPrimaryAddress")} =~ /\w\@\w/ ) {
399 $emailaddr = $newdata{C4
::Context
->preference("AutoEmailPrimaryAddress")}
401 elsif ($newdata{email
} =~ /\w\@\w/) {
402 $emailaddr = $newdata{email
}
404 elsif ($newdata{emailpro
} =~ /\w\@\w/) {
405 $emailaddr = $newdata{emailpro
}
407 elsif ($newdata{B_email
} =~ /\w\@\w/) {
408 $emailaddr = $newdata{B_email
}
410 # if we manage to find a valid email address, send notice
412 $newdata{emailaddr
} = $emailaddr;
415 $err = SendAlerts
( 'members', \
%newdata, "ACCTDETAILS" );
418 $template->param(error_alert
=> $@
);
419 } elsif ( ref($err) eq "HASH" && defined $err->{error
} and $err->{error
} eq "no_email" ) {
420 $template->{VARS
}->{'error_alert'} = "no_email";
422 $template->{VARS
}->{'info_alert'} = 1;
427 if (C4
::Context
->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) {
428 C4
::Members
::Attributes
::SetBorrowerAttributes
($borrowernumber, $extended_patron_attributes);
430 if (C4
::Context
->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) {
431 C4
::Form
::MessagingPreferences
::handle_form_action
($input, { borrowernumber
=> $borrowernumber }, $template, 1, $newdata{'categorycode'});
433 # Try to do the live sync with the Norwegian national patron database, if it is enabled
434 if ( exists $data{'borrowernumber'} && C4
::Context
->preference('NorwegianPatronDBEnable') && C4
::Context
->preference('NorwegianPatronDBEnable') == 1 ) {
435 NLSync
({ 'borrowernumber' => $borrowernumber });
437 } elsif ($op eq 'save'){
438 if ($NoUpdateLogin) {
439 delete $newdata{'password'};
440 delete $newdata{'userid'};
442 &ModMember
(%newdata) unless scalar(keys %newdata) <= 1; # bug 4508 - avoid crash if we're not
443 # updating any columns in the borrowers table,
444 # which can happen if we're only editing the
445 # patron attributes or messaging preferences sections
446 if (C4
::Context
->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) {
447 C4
::Members
::Attributes
::SetBorrowerAttributes
($borrowernumber, $extended_patron_attributes);
449 if (C4
::Context
->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) {
450 C4
::Form
::MessagingPreferences
::handle_form_action
($input, { borrowernumber
=> $borrowernumber }, $template);
453 print scalar ($destination eq "circ") ?
454 $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber") :
455 $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber") ;
456 exit; # You can only send 1 redirect! After that, content or other headers don't matter.
460 print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$borrowernumber");
461 exit; # same as above
464 if ($nok or !$nodouble){
465 $op="add" if ($op eq "insert");
466 $op="modify" if ($op eq "save");
468 $template->param( updtype
=> ($op eq 'add' ?
'I':'M')); # used to check for $op eq "insert"... but we just changed $op!
470 $template->param( step_1
=> 1,step_2
=> 1,step_3
=> 1, step_4
=> 1, step_5
=> 1, step_6
=> 1);
473 if (C4
::Context
->preference("IndependentBranches")) {
474 my $userenv = C4
::Context
->userenv;
475 if ( !C4
::Context
->IsSuperLibrarian() && $data{'branchcode'} ) {
476 unless ($userenv->{branch
} eq $data{'branchcode'}){
477 print $input->redirect("/cgi-bin/koha/members/members-home.pl");
483 $template->param( updtype
=> 'I', step_1
=>1, step_2
=>1, step_3
=>1, step_4
=>1, step_5
=> 1, step_6
=> 1);
485 if ($op eq "modify") {
486 $template->param( updtype
=> 'M',modify
=> 1 );
487 $template->param( step_1
=>1, step_2
=>1, step_3
=>1, step_4
=>1, step_5
=> 1, step_6
=> 1) unless $step;
489 $template->param( categorycode
=> $borrower_data->{'categorycode'} );
491 # Add sync data to the user data
492 if ( C4
::Context
->preference('NorwegianPatronDBEnable') && C4
::Context
->preference('NorwegianPatronDBEnable') == 1 ) {
493 my $sync = NLGetSyncDataFromBorrowernumber
( $borrowernumber );
501 if ( $op eq "duplicate" ) {
502 $template->param( updtype
=> 'I' );
503 $template->param( step_1
=> 1, step_2
=> 1, step_3
=> 1, step_4
=> 1, step_5
=> 1, step_6
=> 1 ) unless $step;
504 $data{'cardnumber'} = "";
507 $data{'cardnumber'}=fixup_cardnumber
($data{'cardnumber'}) if ( ( $op eq 'add' ) or ( $op eq 'duplicate' ) );
508 if(!defined($data{'sex'})){
509 $template->param( none
=> 1);
510 } elsif($data{'sex'} eq 'F'){
511 $template->param( female
=> 1);
512 } elsif ($data{'sex'} eq 'M'){
513 $template->param( male
=> 1);
515 $template->param( none
=> 1);
518 ##Now all the data to modify a member.
521 my $no_categories = 1;
523 foreach (qw(C A S P I X)) {
524 my $action="WHERE category_type=?";
525 my ($categories,$labels)=GetborCatFromCatType
($_,$action);
526 if(scalar(@
$categories) > 0){ $no_categories = 0; }
528 foreach my $cat (@
$categories){
529 push @categoryloop,{'categorycode' => $cat,
530 'categoryname' => $labels->{$cat},
531 'categorycodeselected' => ((defined($borrower_data->{'categorycode'}) &&
532 $cat eq $borrower_data->{'categorycode'})
533 || (defined($categorycode) && $cat eq $categorycode)),
537 $typehash{'typename'}=$_;
538 my $typedescription = "typename_".$typehash{'typename'};
539 $typehash{'categoryloop'}=\
@categoryloop;
540 push @typeloop,{'typename' => $_,
541 $typedescription => 1,
542 'categoryloop' => \
@categoryloop};
544 $template->param('typeloop' => \
@typeloop,
545 no_categories
=> $no_categories);
546 if($no_categories){ $no_add = 1; }
549 my $cities = Koha
::Cities
->search( {}, { order_by
=> 'city_name' } );
550 my $roadtypes = C4
::Koha
::GetAuthorisedValues
( 'ROADTYPE' );
552 roadtypes
=> $roadtypes,
556 my $default_borrowertitle = '';
557 unless ( $op eq 'duplicate' ) { $default_borrowertitle=$data{'title'} }
559 my @relationships = split /,|\|/, C4
::Context
->preference('borrowerRelationship');
561 while (@relationships) {
562 my $relship = shift @relationships || '';
563 my %row = ('relationship' => $relship);
564 if (defined($data{'relationship'}) and $data{'relationship'} eq $relship) {
565 $row{'selected'}=' selected';
569 push(@relshipdata, \
%row);
572 my %flags = ( 'gonenoaddress' => ['gonenoaddress' ],
577 foreach (keys(%flags)) {
579 my %row = ('key' => $key,
580 'name' => $flags{$key}[0]);
582 $row{'yes'}=' checked';
587 $row{'no'}=' checked';
589 push @flagdata,\
%row;
593 # in modify mod: userbranch value for GetBranchesLoop() comes from borrowers table
594 # in add mod: userbranch value come from branches table (ip correspondence)
597 if (C4
::Context
->userenv && C4
::Context
->userenv->{'branch'}) {
598 $userbranch = C4
::Context
->userenv->{'branch'};
601 if (defined ($data{'branchcode'}) and ( $op eq 'modify' || $op eq 'duplicate' || ( $op eq 'add' && $category_type eq 'C' ) )) {
602 $userbranch = $data{'branchcode'};
605 my $branchloop = GetBranchesLoop
( $userbranch );
609 $template->param(no_branches
=> 1);
613 $template->param(no_categories
=> 1);
615 $template->param(no_add
=> $no_add);
616 # --------------------------------------------------------------------------------------------------------
618 $template->param( sort1
=> $data{'sort1'});
619 $template->param( sort2
=> $data{'sort2'});
622 foreach my $error (@errors) {
623 $template->param($error) || $template->param( $error => 1);
625 $template->param(nok
=> 1);
628 #Formatting data for display
630 if (!defined($data{'dateenrolled'}) or $data{'dateenrolled'} eq ''){
631 $data{'dateenrolled'} = output_pref
({ dt
=> dt_from_string
, dateformat
=> 'iso', dateonly
=> 1 });
633 if ( $op eq 'duplicate' ) {
634 $data{'dateenrolled'} = output_pref
({ dt
=> dt_from_string
, dateformat
=> 'iso', dateonly
=> 1 });
635 $data{'dateexpiry'} = GetExpiryDate
( $data{'categorycode'}, $data{'dateenrolled'} );
637 if (C4
::Context
->preference('uppercasesurnames')) {
638 $data{'surname'} &&= uc( $data{'surname'} );
639 $data{'contactname'} &&= uc( $data{'contactname'} );
642 foreach (qw(dateenrolled dateexpiry dateofbirth)) {
644 $data{$_} = eval { output_pref
({ dt
=> dt_from_string
( $data{$_} ), dateonly
=> 1 } ); }; # back to syspref for display
646 $template->param( $_ => $data{$_});
649 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
650 $template->param(ExtendedPatronAttributes
=> 1);
651 patron_attributes_form
($template, $borrowernumber);
654 if (C4
::Context
->preference('EnhancedMessagingPreferences')) {
656 C4
::Form
::MessagingPreferences
::set_form_values
({ categorycode
=> $categorycode }, $template);
658 C4
::Form
::MessagingPreferences
::set_form_values
({ borrowernumber
=> $borrowernumber }, $template);
660 $template->param(SMSSendDriver
=> C4
::Context
->preference("SMSSendDriver"));
661 $template->param(SMSnumber
=> $data{'smsalertnumber'} );
662 $template->param(TalkingTechItivaPhone
=> C4
::Context
->preference("TalkingTechItivaPhoneNotification"));
665 $template->param( "showguarantor" => ($category_type=~/A|I|S|X/) ?
0 : 1); # associate with step to know where you are
666 $debug and warn "memberentry step: $step";
667 $template->param(%data);
668 $template->param( "step_$step" => 1) if $step; # associate with step to know where u are
669 $template->param( step
=> $step ) if $step; # associate with step to know where u are
672 BorrowerMandatoryField
=> C4
::Context
->preference("BorrowerMandatoryField"),#field to test with javascript
673 category_type
=> $category_type,#to know the category type of the borrower
674 "$category_type" => 1,# associate with step to know where u are
675 destination
=> $destination,#to know wher u come from and wher u must go in redirect
676 check_member
=> $check_member,#to know if the borrower already exist(=>1) or not (=>0)
679 $template->param( branchloop
=> $branchloop ) if ( $branchloop );
681 nodouble
=> $nodouble,
682 borrowernumber
=> $borrowernumber, #register number
683 guarantorid
=> ($borrower_data->{'guarantorid'} || $guarantorid),
684 relshiploop
=> \
@relshipdata,
685 btitle
=> $default_borrowertitle,
686 guarantorinfo
=> $guarantorinfo,
687 flagloop
=> \
@flagdata,
688 category_type
=>$category_type,
690 nok
=> $nok,#flag to know if an error
691 NoUpdateLogin
=> $NoUpdateLogin,
694 # Generate CSRF token
696 csrf_token
=> Koha
::Token
->new->generate_csrf(
697 { id
=> C4
::Context
->userenv->{id
},
698 secret
=> md5_base64
( C4
::Context
->config('pass') ),
703 if(defined($data{'flags'})){
704 $template->param(flags
=>$data{'flags'});
706 if(defined($data{'contacttitle'})){
707 $template->param("contacttitle_" . $data{'contacttitle'} => "SELECTED");
711 my ( $min, $max ) = C4
::Members
::get_cardnumber_length
();
712 if ( defined $min ) {
714 minlength_cardnumber
=> $min,
715 maxlength_cardnumber
=> $max
719 output_html_with_http_headers
$input, $cookie, $template->output;
721 sub parse_extended_patron_attributes
{
723 my @patron_attr = grep { /^patron_attr_\d+$/ } $input->multi_param();
727 foreach my $key (@patron_attr) {
728 my $value = $input->param($key);
729 next unless defined($value) and $value ne '';
730 my $code = $input->param("${key}_code");
731 next if exists $dups{$code}->{$value};
732 $dups{$code}->{$value} = 1;
733 push @attr, { code
=> $code, value
=> $value };
738 sub patron_attributes_form
{
739 my $template = shift;
740 my $borrowernumber = shift;
742 my @types = C4
::Members
::AttributeTypes
::GetAttributeTypes
();
743 if (scalar(@types) == 0) {
744 $template->param(no_patron_attribute_types
=> 1);
747 my $attributes = C4
::Members
::Attributes
::GetBorrowerAttributes
($borrowernumber);
748 my @classes = uniq
( map {$_->{class}} @
$attributes );
749 @classes = sort @classes;
751 # map patron's attributes into a more convenient structure
753 foreach my $attr (@
$attributes) {
754 push @
{ $attr_hash{$attr->{code
}} }, $attr;
757 my @attribute_loop = ();
760 foreach my $type_code (map { $_->{code
} } @types) {
761 my $attr_type = C4
::Members
::AttributeTypes
->fetch($type_code);
763 class => $attr_type->class(),
764 code
=> $attr_type->code(),
765 description
=> $attr_type->description(),
766 repeatable
=> $attr_type->repeatable(),
767 category
=> $attr_type->authorised_value_category(),
768 category_code
=> $attr_type->category_code(),
770 if (exists $attr_hash{$attr_type->code()}) {
771 foreach my $attr (@
{ $attr_hash{$attr_type->code()} }) {
772 my $newentry = { %$entry };
773 $newentry->{value
} = $attr->{value
};
774 $newentry->{use_dropdown
} = 0;
775 if ($attr_type->authorised_value_category()) {
776 $newentry->{use_dropdown
} = 1;
777 $newentry->{auth_val_loop
} = GetAuthorisedValues
($attr_type->authorised_value_category(), $attr->{value
});
780 $newentry->{form_id
} = "patron_attr_$i";
781 push @
{$items_by_class{$attr_type->class()}}, $newentry;
785 my $newentry = { %$entry };
786 if ($attr_type->authorised_value_category()) {
787 $newentry->{use_dropdown
} = 1;
788 $newentry->{auth_val_loop
} = GetAuthorisedValues
($attr_type->authorised_value_category());
790 $newentry->{form_id
} = "patron_attr_$i";
791 push @
{$items_by_class{$attr_type->class()}}, $newentry;
794 while ( my ($class, @items) = each %items_by_class ) {
795 my $lib = GetAuthorisedValueByCode
( 'PA_CLASS', $class ) || $class;
796 push @attribute_loop, {
803 $template->param(patron_attributes
=> \
@attribute_loop);