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 Digest::MD5 qw(md5_base64);
28 use List
::MoreUtils qw
/uniq/;
35 use C4
::Members
::Attributes
;
36 use C4
::Members
::AttributeTypes
;
38 use C4
::Dates qw
/format_date format_date_in_iso/;
41 use C4
::Branch
; # GetBranches
42 use C4
::Form
::MessagingPreferences
;
43 use Koha
::Borrower
::Debarments
;
47 if ( C4
::Context
->preference('NorwegianPatronDBEnable') && C4
::Context
->preference('NorwegianPatronDBEnable') == 1 ) {
48 load Koha
::NorwegianPatronDB
, qw( NLGetSyncDataFromBorrowernumber );
54 $debug = $ENV{DEBUG} || 0;
58 ($debug) or $debug = $input->param('debug') || 0;
61 my $dbh = C4::Context->dbh;
63 my ($template, $loggedinuser, $cookie)
64 = get_template_and_user({template_name => "members/memberentrygen.tt",
68 flagsrequired => {borrowers => 1},
69 debug => ($debug) ? 1 : 0,
72 my $guarantorid = $input->param('guarantorid');
73 my $borrowernumber = $input->param('borrowernumber');
74 my $actionType = $input->param('actionType') || '';
75 my $modify = $input->param('modify');
76 my $delete = $input->param('delete');
77 my $op = $input->param('op');
78 my $destination = $input->param('destination');
79 my $cardnumber = $input->param('cardnumber');
80 my $check_member = $input->param('check_member');
81 my $nodouble = $input->param('nodouble');
82 my $duplicate = $input->param('duplicate');
83 $nodouble = 1 if ($op eq 'modify' or $op eq 'duplicate'); # FIXME hack to represent fact that if we're
84 # modifying an existing patron, it ipso facto
85 # isn't a duplicate. Marking FIXME because this
86 # script needs to be refactored.
87 my $select_city = $input->param('select_city');
88 my $nok = $input->param('nok');
89 my $guarantorinfo = $input->param('guarantorinfo');
90 my $step = $input->param('step') || 0;
93 # NOTE: Alert for ethnicity and ethnotes fields, they are invalid in all borrowers form
96 my $userenv = C4::Context->userenv;
99 ## Deal with debarments
101 debarments => GetDebarments( { borrowernumber => $borrowernumber } ) );
102 my @debarments_to_remove = $input->param('remove_debarment');
103 foreach my $d ( @debarments_to_remove ) {
106 if ( $input->param('add_debarment') ) {
108 my $expiration = $input->param('debarred_expiration');
112 { 'dt' => dt_from_string($expiration), 'dateformat' => 'iso' } )
117 borrowernumber => $borrowernumber,
119 comment => $input->param('debarred_comment'),
120 expiration => $expiration,
125 $template->param("uppercasesurnames" => C4::Context->preference('uppercasesurnames'));
127 my $minpw = C4::Context->preference('minPasswordLength');
128 $template->param("minPasswordLength" => $minpw);
130 # function to designate mandatory fields (visually with css)
131 my $check_BorrowerMandatoryField=C4::Context->preference("BorrowerMandatoryField");
132 my @field_check=split(/\|/,$check_BorrowerMandatoryField);
133 foreach (@field_check) {
134 $template->param( "mandatory$_" => 1);
136 # function to designate unwanted fields
137 my $check_BorrowerUnwantedField=C4::Context->preference("BorrowerUnwantedField");
138 @field_check=split(/\|/,$check_BorrowerUnwantedField);
139 foreach (@field_check) {
141 $template->param( "no$_" => 1);
143 $template->param( "add" => 1 ) if ( $op eq 'add' );
144 $template->param( "duplicate" => 1 ) if ( $op eq 'duplicate' );
145 $template->param( "checked" => 1 ) if ( defined($nodouble) && $nodouble eq 1 );
146 ( $borrower_data = GetMember( 'borrowernumber' => $borrowernumber ) ) if ( $op eq 'modify' or $op eq 'save' or $op eq 'duplicate' );
147 my $categorycode = $input->param('categorycode') || $borrower_data->{'categorycode'};
148 my $category_type = $input->param('category_type') || '';
149 unless ($category_type or !($categorycode)){
150 my $borrowercategory = GetBorrowercategory($categorycode);
151 $category_type = $borrowercategory->{'category_type'};
152 my $category_name = $borrowercategory->{'description'};
153 $template->param("categoryname"=>$category_name);
155 $category_type="A" unless $category_type; # FIXME we should display a error message instead of a 500 error !
157 # if a add or modify is requested => check validity of data.
158 %data = %$borrower_data if ($borrower_data);
160 # initialize %newdata
161 my %newdata; # comes from $input->param()
162 if ( $op eq 'insert' || $op eq 'modify' || $op eq 'save' || $op eq 'duplicate' ) {
163 my @names = ( $borrower_data && $op ne 'save' ) ? keys %$borrower_data : $input->param();
164 foreach my $key (@names) {
165 if (defined $input->param($key)) {
166 $newdata{$key} = $input->param($key);
167 $newdata{$key} =~ s/\"/"/g unless $key eq 'borrowernotes' or $key eq 'opacnote';
171 my $dateobject = C4::Dates->new();
172 my $syspref = $dateobject->regexp(); # same syspref format for all 3 dates
173 my $iso = $dateobject->regexp('iso'); #
174 foreach (qw(dateenrolled dateexpiry dateofbirth)) {
175 next unless exists $newdata{$_};
176 my $userdate = $newdata{$_} or next;
177 if ($userdate =~ /$syspref/) {
178 $newdata{$_} = format_date_in_iso
($userdate); # if they match syspref format, then convert to ISO
179 } elsif ($userdate =~ /$iso/) {
180 warn "Date $_ ($userdate) is already in ISO format";
182 ($userdate eq '0000-00-00') and warn "Data error: $_ is '0000-00-00'";
183 $template->param( "ERROR_$_" => 1 ); # else ERROR!
184 push(@errors,"ERROR_$_");
187 # check permission to modify login info.
188 if (ref($borrower_data) && ($borrower_data->{'category_type'} eq 'S') && ! (C4
::Auth
::haspermission
($userenv->{'id'},{'staffaccess'=>1})) ) {
193 # remove keys from %newdata that ModMember() doesn't like
195 my @keys_to_delete = (
196 qr/^BorrowerMandatoryField$/,
205 qr/^setting_extended_patron_attributes$/,
206 qr/^setting_messaging_prefs$/,
214 for my $regexp (@keys_to_delete) {
215 for (keys %newdata) {
216 delete($newdata{$_}) if /$regexp/;
221 #############test for member being unique #############
222 if ( ( $op eq 'insert' ) and !$nodouble ) {
223 my $category_type_send;
224 if ( $category_type eq 'I' ) {
225 $category_type_send = $category_type;
227 my $check_category; # recover the category code of the doublon suspect borrowers
228 # ($result,$categorycode) = checkuniquemember($collectivity,$surname,$firstname,$dateofbirth)
229 ( $check_member, $check_category ) = checkuniquemember
(
231 ( $newdata{surname
} ?
$newdata{surname
} : $data{surname
} ),
232 ( $newdata{firstname
} ?
$newdata{firstname
} : $data{firstname
} ),
233 ( $newdata{dateofbirth
} ?
$newdata{dateofbirth
} : $data{dateofbirth
} )
235 if ( !$check_member ) {
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 if ( (defined $newdata{'userid'}) && ($newdata{'userid'} eq '')){
267 if ( ( defined $newdata{'firstname'} ) && ( defined $newdata{'surname'} ) ) {
268 # Full page edit, firstname and surname input zones are present
269 $newdata{'userid'} = Generate_Userid
( $borrowernumber, $newdata{'firstname'}, $newdata{'surname'} );
271 elsif ( ( defined $data{'firstname'} ) && ( defined $data{'surname'} ) ) {
272 # Partial page edit (access through "Details"/"Library details" tab), firstname and surname input zones are not used
273 # Still, if the userid field is erased, we can create a new userid with available firstname and surname
274 $newdata{'userid'} = Generate_Userid
( $borrowernumber, $data{'firstname'}, $data{'surname'} );
277 $newdata{'userid'} = $data{'userid'};
281 $debug and warn join "\t", map {"$_: $newdata{$_}"} qw(dateofbirth dateenrolled dateexpiry);
282 my $extended_patron_attributes = ();
283 if ($op eq 'save' || $op eq 'insert'){
284 # If the cardnumber is blank, treat it as null.
285 $newdata{'cardnumber'} = undef if $newdata{'cardnumber'} =~ /^\s*$/;
287 if (my $error_code = checkcardnumber
($newdata{cardnumber
},$newdata{borrowernumber
})){
288 push @errors, $error_code == 1
289 ?
'ERROR_cardnumber_already_exists'
291 ?
'ERROR_cardnumber_length'
295 if ( $newdata{dateofbirth
} ) {
296 my $age = GetAge
($newdata{dateofbirth
});
297 my $borrowercategory=GetBorrowercategory
($newdata{'categorycode'});
298 my ($low,$high) = ($borrowercategory->{'dateofbirthrequired'}, $borrowercategory->{'upperagelimit'});
299 if (($high && ($age > $high)) or ($age < $low)) {
300 push @errors, 'ERROR_age_limitations';
301 $template->param( age_low
=> $low);
302 $template->param( age_high
=> $high);
306 if($newdata{surname
} && C4
::Context
->preference('uppercasesurnames')) {
307 $newdata{'surname'} = uc($newdata{'surname'});
310 if (C4
::Context
->preference("IndependentBranches")) {
311 unless ( C4
::Context
->IsSuperLibrarian() ){
312 $debug and print STDERR
" $newdata{'branchcode'} : ".$userenv->{flags
}.":".$userenv->{branch
};
313 unless (!$newdata{'branchcode'} || $userenv->{branch
} eq $newdata{'branchcode'}){
314 push @errors, "ERROR_branch";
318 # Check if the 'userid' is unique. 'userid' might not always be present in
319 # the edited values list when editing certain sub-forms. Get it straight
320 # from the DB if absent.
321 my $userid = $newdata{ userid
} // $borrower_data->{ userid
};
322 unless (Check_Userid
($userid,$borrowernumber)) {
323 push @errors, "ERROR_login_exist";
326 my $password = $input->param('password');
327 my $password2 = $input->param('password2');
328 push @errors, "ERROR_password_mismatch" if ( $password ne $password2 );
329 push @errors, "ERROR_short_password" if( $password && $minpw && $password ne '****' && (length($password) < $minpw) );
332 my $emailprimary = $input->param('email');
333 my $emailsecondary = $input->param('emailpro');
334 my $emailalt = $input->param('B_email');
337 push (@errors, "ERROR_bad_email") if (!Email
::Valid
->address($emailprimary));
339 if ($emailsecondary) {
340 push (@errors, "ERROR_bad_email_secondary") if (!Email
::Valid
->address($emailsecondary));
343 push (@errors, "ERROR_bad_email_alternative") if (!Email
::Valid
->address($emailalt));
346 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
347 $extended_patron_attributes = parse_extended_patron_attributes
($input);
348 foreach my $attr (@
$extended_patron_attributes) {
349 unless (C4
::Members
::Attributes
::CheckUniqueness
($attr->{code
}, $attr->{value
}, $borrowernumber)) {
350 my $attr_info = C4
::Members
::AttributeTypes
->fetch($attr->{code
});
351 push @errors, "ERROR_extended_unique_id_failed";
353 ERROR_extended_unique_id_failed_code
=> $attr->{code
},
354 ERROR_extended_unique_id_failed_value
=> $attr->{value
},
355 ERROR_extended_unique_id_failed_description
=> $attr_info->description()
362 if ( ($op eq 'modify' || $op eq 'insert' || $op eq 'save'|| $op eq 'duplicate') and ($step == 0 or $step == 3 )){
363 unless ($newdata{'dateexpiry'}){
364 my $arg2 = $newdata{'dateenrolled'} || C4
::Dates
->today('iso');
365 $newdata{'dateexpiry'} = GetExpiryDate
($newdata{'categorycode'},$arg2);
370 defined $input->param('SMSnumber')
372 $input->param('SMSnumber') eq ""
373 or $input->param('SMSnumber') ne $newdata{'mobile'}
376 $newdata{smsalertnumber
} = $input->param('SMSnumber');
379 ### Error checks should happen before this line.
380 $nok = $nok || scalar(@errors);
381 if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){
382 $debug and warn "$op dates: " . join "\t", map {"$_: $newdata{$_}"} qw(dateofbirth dateenrolled dateexpiry);
383 if ($op eq 'insert'){
384 # we know it's not a duplicate borrowernumber or there would already be an error
385 $borrowernumber = &AddMember
(%newdata);
386 $newdata{'borrowernumber'} = $borrowernumber;
388 # If 'AutoEmailOpacUser' syspref is on, email user their account details from the 'notice' that matches the user's branchcode.
389 if ( C4
::Context
->preference("AutoEmailOpacUser") == 1 && $newdata{'userid'} && $newdata{'password'}) {
390 #look for defined primary email address, if blank - attempt to use borr.email and borr.emailpro instead
392 if (C4
::Context
->preference("AutoEmailPrimaryAddress") ne 'OFF' &&
393 $newdata{C4
::Context
->preference("AutoEmailPrimaryAddress")} =~ /\w\@\w/ ) {
394 $emailaddr = $newdata{C4
::Context
->preference("AutoEmailPrimaryAddress")}
396 elsif ($newdata{email
} =~ /\w\@\w/) {
397 $emailaddr = $newdata{email
}
399 elsif ($newdata{emailpro
} =~ /\w\@\w/) {
400 $emailaddr = $newdata{emailpro
}
402 elsif ($newdata{B_email
} =~ /\w\@\w/) {
403 $emailaddr = $newdata{B_email
}
405 # if we manage to find a valid email address, send notice
407 $newdata{emailaddr
} = $emailaddr;
410 $err = SendAlerts
( 'members', \
%newdata, "ACCTDETAILS" );
413 $template->param(error_alert
=> $@
);
414 } elsif ( ref($err) eq "HASH" && defined $err->{error
} and $err->{error
} eq "no_email" ) {
415 $template->{VARS
}->{'error_alert'} = "no_email";
417 $template->{VARS
}->{'info_alert'} = 1;
422 if (C4
::Context
->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) {
423 C4
::Members
::Attributes
::SetBorrowerAttributes
($borrowernumber, $extended_patron_attributes);
425 if (C4
::Context
->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) {
426 C4
::Form
::MessagingPreferences
::handle_form_action
($input, { borrowernumber
=> $borrowernumber }, $template, 1, $newdata{'categorycode'});
428 # Try to do the live sync with the Norwegian national patron database, if it is enabled
429 if ( exists $data{'borrowernumber'} && C4
::Context
->preference('NorwegianPatronDBEnable') && C4
::Context
->preference('NorwegianPatronDBEnable') == 1 ) {
430 NLSync
({ 'borrowernumber' => $borrowernumber });
432 } elsif ($op eq 'save'){
433 if ($NoUpdateLogin) {
434 delete $newdata{'password'};
435 delete $newdata{'userid'};
437 &ModMember
(%newdata) unless scalar(keys %newdata) <= 1; # bug 4508 - avoid crash if we're not
438 # updating any columns in the borrowers table,
439 # which can happen if we're only editing the
440 # patron attributes or messaging preferences sections
441 if (C4
::Context
->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) {
442 C4
::Members
::Attributes
::SetBorrowerAttributes
($borrowernumber, $extended_patron_attributes);
444 if (C4
::Context
->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) {
445 C4
::Form
::MessagingPreferences
::handle_form_action
($input, { borrowernumber
=> $borrowernumber }, $template);
448 print scalar ($destination eq "circ") ?
449 $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber") :
450 $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber") ;
451 exit; # You can only send 1 redirect! After that, content or other headers don't matter.
455 print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$borrowernumber");
456 exit; # same as above
459 if ($nok or !$nodouble){
460 $op="add" if ($op eq "insert");
461 $op="modify" if ($op eq "save");
463 $template->param( updtype
=> ($op eq 'add' ?
'I':'M')); # used to check for $op eq "insert"... but we just changed $op!
465 $template->param( step_1
=> 1,step_2
=> 1,step_3
=> 1, step_4
=> 1, step_5
=> 1, step_6
=> 1);
468 if (C4
::Context
->preference("IndependentBranches")) {
469 my $userenv = C4
::Context
->userenv;
470 if ( !C4
::Context
->IsSuperLibrarian() && $data{'branchcode'} ) {
471 unless ($userenv->{branch
} eq $data{'branchcode'}){
472 print $input->redirect("/cgi-bin/koha/members/members-home.pl");
478 $template->param( updtype
=> 'I', step_1
=>1, step_2
=>1, step_3
=>1, step_4
=>1, step_5
=> 1, step_6
=> 1);
480 if ($op eq "modify") {
481 $template->param( updtype
=> 'M',modify
=> 1 );
482 $template->param( step_1
=>1, step_2
=>1, step_3
=>1, step_4
=>1, step_5
=> 1, step_6
=> 1) unless $step;
484 $template->param( categorycode
=> $borrower_data->{'categorycode'} );
486 # Add sync data to the user data
487 if ( C4
::Context
->preference('NorwegianPatronDBEnable') && C4
::Context
->preference('NorwegianPatronDBEnable') == 1 ) {
488 my $sync = NLGetSyncDataFromBorrowernumber
( $borrowernumber );
496 if ( $op eq "duplicate" ) {
497 $template->param( updtype
=> 'I' );
498 $template->param( step_1
=> 1, step_2
=> 1, step_3
=> 1, step_4
=> 1, step_5
=> 1, step_6
=> 1 ) unless $step;
499 $data{'cardnumber'} = "";
502 $data{'cardnumber'}=fixup_cardnumber
($data{'cardnumber'}) if ( ( $op eq 'add' ) or ( $op eq 'duplicate' ) );
503 if(!defined($data{'sex'})){
504 $template->param( none
=> 1);
505 } elsif($data{'sex'} eq 'F'){
506 $template->param( female
=> 1);
507 } elsif ($data{'sex'} eq 'M'){
508 $template->param( male
=> 1);
510 $template->param( none
=> 1);
513 ##Now all the data to modify a member.
514 my ($categories,$labels)=ethnicitycategories
();
516 my $ethnicitycategoriescount=$#{$categories};
518 if ($ethnicitycategoriescount>=0) {
519 $ethcatpopup = CGI
::popup_menu
(-name
=>'ethnicity',
522 -values=>$categories,
523 -default=>$data{'ethnicity'},
525 $template->param(ethcatpopup
=> $ethcatpopup); # bad style, has to be fixed
529 my $no_categories = 1;
531 foreach (qw(C A S P I X)) {
532 my $action="WHERE category_type=?";
533 ($categories,$labels)=GetborCatFromCatType
($_,$action);
534 if(scalar(@
$categories) > 0){ $no_categories = 0; }
536 foreach my $cat (@
$categories){
537 push @categoryloop,{'categorycode' => $cat,
538 'categoryname' => $labels->{$cat},
539 'categorycodeselected' => ((defined($borrower_data->{'categorycode'}) &&
540 $cat eq $borrower_data->{'categorycode'})
541 || (defined($categorycode) && $cat eq $categorycode)),
545 $typehash{'typename'}=$_;
546 my $typedescription = "typename_".$typehash{'typename'};
547 $typehash{'categoryloop'}=\
@categoryloop;
548 push @typeloop,{'typename' => $_,
549 $typedescription => 1,
550 'categoryloop' => \
@categoryloop};
552 $template->param('typeloop' => \
@typeloop,
553 no_categories
=> $no_categories);
554 if($no_categories){ $no_add = 1; }
556 if ( $guarantorid ) {
557 $select_city = getidcity
($data{city
});
559 ($default_city=$select_city) if ($step eq 0);
560 if (!defined($select_city) or $select_city eq '' ){
561 $default_city = &getidcity
($data{'city'});
564 my $city_arrayref = GetCities
();
565 if (@
{$city_arrayref} ) {
566 $template->param( city_cgipopup
=> 1);
568 if ($default_city) { # flag the current or default val
569 for my $city ( @
{$city_arrayref} ) {
570 if ($default_city == $city->{cityid
}) {
571 $city->{selected
} = 1;
578 my $roadtypes = C4
::Koha
::GetAuthorisedValues
( 'ROADTYPE', $data{streettype
} );
579 $template->param( roadtypes
=> $roadtypes);
581 my $default_borrowertitle = '';
582 unless ( $op eq 'duplicate' ) { $default_borrowertitle=$data{'title'} }
583 my($borrowertitle)=GetTitles
();
584 $template->param( title_cgipopup
=> 1) if ($borrowertitle);
585 my $borrotitlepopup = CGI
::popup_menu
(-name
=>'title',
587 -values=>$borrowertitle,
589 -default=>$default_borrowertitle
592 my @relationships = split /,|\|/, C4
::Context
->preference('borrowerRelationship');
594 while (@relationships) {
595 my $relship = shift @relationships || '';
596 my %row = ('relationship' => $relship);
597 if (defined($data{'relationship'}) and $data{'relationship'} eq $relship) {
598 $row{'selected'}=' selected';
602 push(@relshipdata, \
%row);
605 my %flags = ( 'gonenoaddress' => ['gonenoaddress' ],
610 foreach (keys(%flags)) {
612 my %row = ('key' => $key,
613 'name' => $flags{$key}[0]);
615 $row{'yes'}=' checked';
620 $row{'no'}=' checked';
622 push @flagdata,\
%row;
626 # in modify mod: userbranch value for GetBranchesLoop() comes from borrowers table
627 # in add mod: userbranch value come from branches table (ip correspondence)
630 if (C4
::Context
->userenv && C4
::Context
->userenv->{'branch'}) {
631 $userbranch = C4
::Context
->userenv->{'branch'};
634 if (defined ($data{'branchcode'}) and ( $op eq 'modify' || $op eq 'duplicate' || ( $op eq 'add' && $category_type eq 'C' ) )) {
635 $userbranch = $data{'branchcode'};
638 my $branchloop = GetBranchesLoop
( $userbranch );
642 $template->param(no_branches
=> 1);
646 $template->param(no_categories
=> 1);
648 $template->param(no_add
=> $no_add);
649 # --------------------------------------------------------------------------------------------------------
651 $template->param( sort1
=> $data{'sort1'});
652 $template->param( sort2
=> $data{'sort2'});
655 foreach my $error (@errors) {
656 $template->param($error) || $template->param( $error => 1);
658 $template->param(nok
=> 1);
661 #Formatting data for display
663 if (!defined($data{'dateenrolled'}) or $data{'dateenrolled'} eq ''){
664 $data{'dateenrolled'}=C4
::Dates
->today('iso');
666 if ( $op eq 'duplicate' ) {
667 $data{'dateenrolled'} = C4
::Dates
->today('iso');
668 $data{'dateexpiry'} = GetExpiryDate
( $data{'categorycode'}, $data{'dateenrolled'} );
670 if (C4
::Context
->preference('uppercasesurnames')) {
671 $data{'surname'} &&= uc( $data{'surname'} );
672 $data{'contactname'} &&= uc( $data{'contactname'} );
675 foreach (qw(dateenrolled dateexpiry dateofbirth)) {
676 $data{$_} = format_date
($data{$_}); # back to syspref for display
677 $template->param( $_ => $data{$_});
680 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
681 $template->param(ExtendedPatronAttributes
=> 1);
682 patron_attributes_form
($template, $borrowernumber);
685 if (C4
::Context
->preference('EnhancedMessagingPreferences')) {
687 C4
::Form
::MessagingPreferences
::set_form_values
({ categorycode
=> $categorycode }, $template);
689 C4
::Form
::MessagingPreferences
::set_form_values
({ borrowernumber
=> $borrowernumber }, $template);
691 $template->param(SMSSendDriver
=> C4
::Context
->preference("SMSSendDriver"));
692 $template->param(SMSnumber
=> defined $data{'smsalertnumber'} ?
$data{'smsalertnumber'} : $data{'mobile'});
693 $template->param(TalkingTechItivaPhone
=> C4
::Context
->preference("TalkingTechItivaPhoneNotification"));
696 $template->param( "showguarantor" => ($category_type=~/A|I|S|X/) ?
0 : 1); # associate with step to know where you are
697 $debug and warn "memberentry step: $step";
698 $template->param(%data);
699 $template->param( "step_$step" => 1) if $step; # associate with step to know where u are
700 $template->param( step
=> $step ) if $step; # associate with step to know where u are
703 BorrowerMandatoryField
=> C4
::Context
->preference("BorrowerMandatoryField"),#field to test with javascript
704 category_type
=> $category_type,#to know the category type of the borrower
705 select_city
=> $select_city,
706 "$category_type" => 1,# associate with step to know where u are
707 destination
=> $destination,#to know wher u come from and wher u must go in redirect
708 check_member
=> $check_member,#to know if the borrower already exist(=>1) or not (=>0)
711 $template->param( branchloop
=> $branchloop ) if ( $branchloop );
713 nodouble
=> $nodouble,
714 borrowernumber
=> $borrowernumber, #register number
715 guarantorid
=> ($borrower_data->{'guarantorid'} || $guarantorid),
716 ethcatpopup
=> $ethcatpopup,
717 relshiploop
=> \
@relshipdata,
718 city_loop
=> $city_arrayref,
719 borrotitlepopup
=> $borrotitlepopup,
720 guarantorinfo
=> $guarantorinfo,
721 flagloop
=> \
@flagdata,
722 category_type
=>$category_type,
724 nok
=> $nok,#flag to konw if an error
725 NoUpdateLogin
=> $NoUpdateLogin
728 if(defined($data{'flags'})){
729 $template->param(flags
=>$data{'flags'});
731 if(defined($data{'contacttitle'})){
732 $template->param("contacttitle_" . $data{'contacttitle'} => "SELECTED");
736 my ( $min, $max ) = C4
::Members
::get_cardnumber_length
();
737 if ( defined $min ) {
739 minlength_cardnumber
=> $min,
740 maxlength_cardnumber
=> $max
744 output_html_with_http_headers
$input, $cookie, $template->output;
746 sub parse_extended_patron_attributes
{
748 my @patron_attr = grep { /^patron_attr_\d+$/ } $input->param();
752 foreach my $key (@patron_attr) {
753 my $value = $input->param($key);
754 next unless defined($value) and $value ne '';
755 my $password = $input->param("${key}_password");
756 my $code = $input->param("${key}_code");
757 next if exists $dups{$code}->{$value};
758 $dups{$code}->{$value} = 1;
759 push @attr, { code
=> $code, value
=> $value, password
=> $password };
764 sub patron_attributes_form
{
765 my $template = shift;
766 my $borrowernumber = shift;
768 my @types = C4
::Members
::AttributeTypes
::GetAttributeTypes
();
769 if (scalar(@types) == 0) {
770 $template->param(no_patron_attribute_types
=> 1);
773 my $attributes = C4
::Members
::Attributes
::GetBorrowerAttributes
($borrowernumber);
774 my @classes = uniq
( map {$_->{class}} @
$attributes );
775 @classes = sort @classes;
777 # map patron's attributes into a more convenient structure
779 foreach my $attr (@
$attributes) {
780 push @
{ $attr_hash{$attr->{code
}} }, $attr;
783 my @attribute_loop = ();
786 foreach my $type_code (map { $_->{code
} } @types) {
787 my $attr_type = C4
::Members
::AttributeTypes
->fetch($type_code);
789 class => $attr_type->class(),
790 code
=> $attr_type->code(),
791 description
=> $attr_type->description(),
792 repeatable
=> $attr_type->repeatable(),
793 password_allowed
=> $attr_type->password_allowed(),
794 category
=> $attr_type->authorised_value_category(),
795 category_code
=> $attr_type->category_code(),
798 if (exists $attr_hash{$attr_type->code()}) {
799 foreach my $attr (@
{ $attr_hash{$attr_type->code()} }) {
800 my $newentry = { %$entry };
801 $newentry->{value
} = $attr->{value
};
802 $newentry->{password
} = $attr->{password
};
803 $newentry->{use_dropdown
} = 0;
804 if ($attr_type->authorised_value_category()) {
805 $newentry->{use_dropdown
} = 1;
806 $newentry->{auth_val_loop
} = GetAuthorisedValues
($attr_type->authorised_value_category(), $attr->{value
});
809 $newentry->{form_id
} = "patron_attr_$i";
810 push @
{$items_by_class{$attr_type->class()}}, $newentry;
814 my $newentry = { %$entry };
815 if ($attr_type->authorised_value_category()) {
816 $newentry->{use_dropdown
} = 1;
817 $newentry->{auth_val_loop
} = GetAuthorisedValues
($attr_type->authorised_value_category());
819 $newentry->{form_id
} = "patron_attr_$i";
820 push @
{$items_by_class{$attr_type->class()}}, $newentry;
823 while ( my ($class, @items) = each %items_by_class ) {
824 my $lib = GetAuthorisedValueByCode
( 'PA_CLASS', $class ) || $class;
825 push @attribute_loop, {
832 $template->param(patron_attributes
=> \
@attribute_loop);