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 under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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/;
42 use C4
::Branch
; # GetBranches
43 use C4
::Form
::MessagingPreferences
;
44 use Koha
::Borrower
::Debarments
;
50 $debug = $ENV{DEBUG} || 0;
54 ($debug) or $debug = $input->param('debug') || 0;
57 my $dbh = C4::Context->dbh;
59 my ($template, $loggedinuser, $cookie)
60 = get_template_and_user({template_name => "members/memberentrygen.tmpl",
64 flagsrequired => {borrowers => 1},
65 debug => ($debug) ? 1 : 0,
68 my $guarantorid = $input->param('guarantorid');
69 my $borrowernumber = $input->param('borrowernumber');
70 my $actionType = $input->param('actionType') || '';
71 my $modify = $input->param('modify');
72 my $delete = $input->param('delete');
73 my $op = $input->param('op');
74 my $destination = $input->param('destination');
75 my $cardnumber = $input->param('cardnumber');
76 my $check_member = $input->param('check_member');
77 my $nodouble = $input->param('nodouble');
78 my $duplicate = $input->param('duplicate');
79 $nodouble = 1 if ($op eq 'modify' or $op eq 'duplicate'); # FIXME hack to represent fact that if we're
80 # modifying an existing patron, it ipso facto
81 # isn't a duplicate. Marking FIXME because this
82 # script needs to be refactored.
83 my $select_city = $input->param('select_city');
84 my $nok = $input->param('nok');
85 my $guarantorinfo = $input->param('guarantorinfo');
86 my $step = $input->param('step') || 0;
89 # $check_categorytype contains the value of duplicate borrowers category type to redirect in good template in step =2
90 my $check_categorytype=$input->param('check_categorytype');
91 # NOTE: Alert for ethnicity and ethnotes fields, they are invalid in all borrowers form
94 my $userenv = C4::Context->userenv;
97 ## Deal with debarments
99 debarments => GetDebarments( { borrowernumber => $borrowernumber } ) );
100 my @debarments_to_remove = $input->param('remove_debarment');
101 foreach my $d ( @debarments_to_remove ) {
104 if ( $input->param('add_debarment') ) {
106 my $expiration = $input->param('debarred_expiration');
110 { 'dt' => dt_from_string($expiration), 'dateformat' => 'iso' } )
115 borrowernumber => $borrowernumber,
117 comment => $input->param('debarred_comment'),
118 expiration => $expiration,
123 $template->param("uppercasesurnames" => C4::Context->preference('uppercasesurnames'));
125 my $minpw = C4::Context->preference('minPasswordLength');
126 $template->param("minPasswordLength" => $minpw);
128 # function to designate mandatory fields (visually with css)
129 my $check_BorrowerMandatoryField=C4::Context->preference("BorrowerMandatoryField");
130 my @field_check=split(/\|/,$check_BorrowerMandatoryField);
131 foreach (@field_check) {
132 $template->param( "mandatory$_" => 1);
134 # we'll need this, later.
135 my $dateofbirthmandatory = (scalar grep {$_ eq "dateofbirth"} @field_check) ? 1 : 0;
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') || '';
150 $template->{VARS}->{'type_only'} = 1;
152 my $new_c_type = $category_type; #if we have input param, then we've already chosen the cat_type.
153 unless ($category_type or !($categorycode)){
154 my $borrowercategory = GetBorrowercategory($categorycode);
155 $category_type = $borrowercategory->{'category_type'};
156 my $category_name = $borrowercategory->{'description'};
157 $template->param("categoryname"=>$category_name);
159 $category_type="A" unless $category_type; # FIXME we should display a error message instead of a 500 error !
161 # if a add or modify is requested => check validity of data.
162 %data = %$borrower_data if ($borrower_data);
164 # initialize %newdata
165 my %newdata; # comes from $input->param()
166 if ( $op eq 'insert' || $op eq 'modify' || $op eq 'save' || $op eq 'duplicate' ) {
167 my @names = ( $borrower_data && $op ne 'save' ) ? keys %$borrower_data : $input->param();
168 foreach my $key (@names) {
169 if (defined $input->param($key)) {
170 $newdata{$key} = $input->param($key);
171 $newdata{$key} =~ s/\"/"/g unless $key eq 'borrowernotes' or $key eq 'opacnote';
175 my $dateobject = C4::Dates->new();
176 my $syspref = $dateobject->regexp(); # same syspref format for all 3 dates
177 my $iso = $dateobject->regexp('iso'); #
178 foreach (qw(dateenrolled dateexpiry dateofbirth)) {
179 next unless exists $newdata{$_};
180 my $userdate = $newdata{$_} or next;
181 if ($userdate =~ /$syspref/) {
182 $newdata{$_} = format_date_in_iso
($userdate); # if they match syspref format, then convert to ISO
183 } elsif ($userdate =~ /$iso/) {
184 warn "Date $_ ($userdate) is already in ISO format";
186 ($userdate eq '0000-00-00') and warn "Data error: $_ is '0000-00-00'";
187 $template->param( "ERROR_$_" => 1 ); # else ERROR!
188 push(@errors,"ERROR_$_");
191 # check permission to modify login info.
192 if (ref($borrower_data) && ($borrower_data->{'category_type'} eq 'S') && ! (C4
::Auth
::haspermission
($userenv->{'id'},{'staffaccess'=>1})) ) {
197 # remove keys from %newdata that ModMember() doesn't like
199 my @keys_to_delete = (
200 qr/^BorrowerMandatoryField$/,
209 qr/^setting_extended_patron_attributes$/,
210 qr/^setting_messaging_prefs$/,
218 for my $regexp (@keys_to_delete) {
219 for (keys %newdata) {
220 delete($newdata{$_}) if /$regexp/;
225 #############test for member being unique #############
226 if ( ( $op eq 'insert' ) and !$nodouble ) {
227 my $category_type_send;
228 if ( $category_type eq 'I' ) {
229 $category_type_send = $category_type;
231 my $check_category; # recover the category code of the doublon suspect borrowers
232 # ($result,$categorycode) = checkuniquemember($collectivity,$surname,$firstname,$dateofbirth)
233 ( $check_member, $check_category ) = checkuniquemember
(
235 ( $newdata{surname
} ?
$newdata{surname
} : $data{surname
} ),
236 ( $newdata{firstname
} ?
$newdata{firstname
} : $data{firstname
} ),
237 ( $newdata{dateofbirth
} ?
$newdata{dateofbirth
} : $data{dateofbirth
} )
239 if ( !$check_member ) {
243 # recover the category type if the borrowers is a doublon
244 if ($check_category) {
245 my $tmpborrowercategory = GetBorrowercategory
($check_category);
246 $check_categorytype = $tmpborrowercategory->{'category_type'};
250 #recover all data from guarantor address phone ,fax...
251 if ( $guarantorid and ( $category_type eq 'C' || $category_type eq 'P' )) {
252 if (my $guarantordata=GetMember
(borrowernumber
=> $guarantorid)) {
253 $guarantorinfo=$guarantordata->{'surname'}." , ".$guarantordata->{'firstname'};
254 $newdata{'contactfirstname'}= $guarantordata->{'firstname'};
255 $newdata{'contactname'} = $guarantordata->{'surname'};
256 $newdata{'contacttitle'} = $guarantordata->{'title'};
257 if ( $op eq 'add' ) {
258 foreach (qw(streetnumber address streettype address2
259 zipcode country city state phone phonepro mobile fax email emailpro branchcode
260 B_streetnumber B_streettype B_address B_address2
261 B_city B_state B_zipcode B_country B_email B_phone)) {
262 $newdata{$_} = $guarantordata->{$_};
268 ###############test to take the right zipcode, country and city name ##############
269 # set only if parameter was passed from the form
270 $newdata{'city'} = $input->param('city') if defined($input->param('city'));
271 $newdata{'zipcode'} = $input->param('zipcode') if defined($input->param('zipcode'));
272 $newdata{'country'} = $input->param('country') if defined($input->param('country'));
274 #builds default userid
275 if ( (defined $newdata{'userid'}) && ($newdata{'userid'} eq '')){
276 if ( ( defined $newdata{'firstname'} ) && ( defined $newdata{'surname'} ) ) {
277 # Full page edit, firstname and surname input zones are present
278 $newdata{'userid'} = Generate_Userid
( $borrowernumber, $newdata{'firstname'}, $newdata{'surname'} );
280 elsif ( ( defined $data{'firstname'} ) && ( defined $data{'surname'} ) ) {
281 # Partial page edit (access through "Details"/"Library details" tab), firstname and surname input zones are not used
282 # Still, if the userid field is erased, we can create a new userid with available firstname and surname
283 $newdata{'userid'} = Generate_Userid
( $borrowernumber, $data{'firstname'}, $data{'surname'} );
286 $newdata{'userid'} = $data{'userid'};
290 $debug and warn join "\t", map {"$_: $newdata{$_}"} qw(dateofbirth dateenrolled dateexpiry);
291 my $extended_patron_attributes = ();
292 if ($op eq 'save' || $op eq 'insert'){
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
} && $dateofbirthmandatory) {
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
328 unless (Check_Userid
($newdata{'userid'},$borrowernumber)) {
329 push @errors, "ERROR_login_exist";
332 my $password = $input->param('password');
333 my $password2 = $input->param('password2');
334 push @errors, "ERROR_password_mismatch" if ( $password ne $password2 );
335 push @errors, "ERROR_short_password" if( $password && $minpw && $password ne '****' && (length($password) < $minpw) );
337 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
338 $extended_patron_attributes = parse_extended_patron_attributes
($input);
339 foreach my $attr (@
$extended_patron_attributes) {
340 unless (C4
::Members
::Attributes
::CheckUniqueness
($attr->{code
}, $attr->{value
}, $borrowernumber)) {
341 push @errors, "ERROR_extended_unique_id_failed";
342 $template->param(ERROR_extended_unique_id_failed_value
=> "$attr->{code}/$attr->{value}");
348 if ( ($op eq 'modify' || $op eq 'insert' || $op eq 'save'|| $op eq 'duplicate') and ($step == 0 or $step == 3 )){
349 unless ($newdata{'dateexpiry'}){
350 my $arg2 = $newdata{'dateenrolled'} || C4
::Dates
->today('iso');
351 $newdata{'dateexpiry'} = GetExpiryDate
($newdata{'categorycode'},$arg2);
356 defined $input->param('SMSnumber')
358 $input->param('SMSnumber') eq ""
359 or $input->param('SMSnumber') ne $newdata{'mobile'}
362 $newdata{smsalertnumber
} = $input->param('SMSnumber');
365 ### Error checks should happen before this line.
366 $nok = $nok || scalar(@errors);
367 if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){
368 $debug and warn "$op dates: " . join "\t", map {"$_: $newdata{$_}"} qw(dateofbirth dateenrolled dateexpiry);
369 if ($op eq 'insert'){
370 # we know it's not a duplicate borrowernumber or there would already be an error
371 $borrowernumber = &AddMember
(%newdata);
372 $newdata{'borrowernumber'} = $borrowernumber;
374 # If 'AutoEmailOpacUser' syspref is on, email user their account details from the 'notice' that matches the user's branchcode.
375 if ( C4
::Context
->preference("AutoEmailOpacUser") == 1 && $newdata{'userid'} && $newdata{'password'}) {
376 #look for defined primary email address, if blank - attempt to use borr.email and borr.emailpro instead
378 if (C4
::Context
->preference("AutoEmailPrimaryAddress") ne 'OFF' &&
379 $newdata{C4
::Context
->preference("AutoEmailPrimaryAddress")} =~ /\w\@\w/ ) {
380 $emailaddr = $newdata{C4
::Context
->preference("AutoEmailPrimaryAddress")}
382 elsif ($newdata{email
} =~ /\w\@\w/) {
383 $emailaddr = $newdata{email
}
385 elsif ($newdata{emailpro
} =~ /\w\@\w/) {
386 $emailaddr = $newdata{emailpro
}
388 elsif ($newdata{B_email
} =~ /\w\@\w/) {
389 $emailaddr = $newdata{B_email
}
391 # if we manage to find a valid email address, send notice
393 $newdata{emailaddr
} = $emailaddr;
396 $err = SendAlerts
( 'members', \
%newdata, "ACCTDETAILS" );
399 $template->param(error_alert
=> $@
);
400 } elsif ( ref($err) eq "HASH" && defined $err->{error
} and $err->{error
} eq "no_email" ) {
401 $template->{VARS
}->{'error_alert'} = "no_email";
403 $template->{VARS
}->{'info_alert'} = 1;
408 if (C4
::Context
->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) {
409 C4
::Members
::Attributes
::SetBorrowerAttributes
($borrowernumber, $extended_patron_attributes);
411 if (C4
::Context
->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) {
412 C4
::Form
::MessagingPreferences
::handle_form_action
($input, { borrowernumber
=> $borrowernumber }, $template, 1, $newdata{'categorycode'});
414 } elsif ($op eq 'save'){
415 if ($NoUpdateLogin) {
416 delete $newdata{'password'};
417 delete $newdata{'userid'};
419 &ModMember
(%newdata) unless scalar(keys %newdata) <= 1; # bug 4508 - avoid crash if we're not
420 # updating any columns in the borrowers table,
421 # which can happen if we're only editing the
422 # patron attributes or messaging preferences sections
423 if (C4
::Context
->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) {
424 C4
::Members
::Attributes
::SetBorrowerAttributes
($borrowernumber, $extended_patron_attributes);
426 if (C4
::Context
->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) {
427 C4
::Form
::MessagingPreferences
::handle_form_action
($input, { borrowernumber
=> $borrowernumber }, $template);
430 print scalar ($destination eq "circ") ?
431 $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber") :
432 $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber") ;
433 exit; # You can only send 1 redirect! After that, content or other headers don't matter.
437 print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$borrowernumber");
438 exit; # same as above
441 if ($nok or !$nodouble){
442 $op="add" if ($op eq "insert");
443 $op="modify" if ($op eq "save");
445 $template->param( updtype
=> ($op eq 'add' ?
'I':'M')); # used to check for $op eq "insert"... but we just changed $op!
447 $template->param( step_1
=> 1,step_2
=> 1,step_3
=> 1, step_4
=> 1, step_5
=> 1, step_6
=> 1);
450 if (C4
::Context
->preference("IndependentBranches")) {
451 my $userenv = C4
::Context
->userenv;
452 if ( !C4
::Context
->IsSuperLibrarian() && $data{'branchcode'} ) {
453 unless ($userenv->{branch
} eq $data{'branchcode'}){
454 print $input->redirect("/cgi-bin/koha/members/members-home.pl");
460 $template->param( updtype
=> 'I', step_1
=>1, step_2
=>1, step_3
=>1, step_4
=>1, step_5
=> 1, step_6
=> 1);
462 if ($op eq "modify") {
463 $template->param( updtype
=> 'M',modify
=> 1 );
464 $template->param( step_1
=>1, step_2
=>1, step_3
=>1, step_4
=>1, step_5
=> 1, step_6
=> 1) unless $step;
466 $template->param( categorycode
=> $borrower_data->{'categorycode'} );
469 if ( $op eq "duplicate" ) {
470 $template->param( updtype
=> 'I' );
471 $template->param( step_1
=> 1, step_2
=> 1, step_3
=> 1, step_4
=> 1, step_5
=> 1, step_6
=> 1 ) unless $step;
472 $data{'cardnumber'} = "";
475 $data{'cardnumber'}=fixup_cardnumber
($data{'cardnumber'}) if ( ( $op eq 'add' ) or ( $op eq 'duplicate' ) );
476 if(!defined($data{'sex'})){
477 $template->param( none
=> 1);
478 } elsif($data{'sex'} eq 'F'){
479 $template->param( female
=> 1);
480 } elsif ($data{'sex'} eq 'M'){
481 $template->param( male
=> 1);
483 $template->param( none
=> 1);
486 ##Now all the data to modify a member.
487 my ($categories,$labels)=ethnicitycategories
();
489 my $ethnicitycategoriescount=$#{$categories};
491 if ($ethnicitycategoriescount>=0) {
492 $ethcatpopup = CGI
::popup_menu
(-name
=>'ethnicity',
495 -values=>$categories,
496 -default=>$data{'ethnicity'},
498 $template->param(ethcatpopup
=> $ethcatpopup); # bad style, has to be fixed
502 my $no_categories = 1;
504 foreach (qw(C A S P I X)) {
505 my $action="WHERE category_type=?";
506 ($categories,$labels)=GetborCatFromCatType
($_,$action);
507 if(scalar(@
$categories) > 0){ $no_categories = 0; }
509 foreach my $cat (@
$categories){
510 push @categoryloop,{'categorycode' => $cat,
511 'categoryname' => $labels->{$cat},
512 'categorycodeselected' => ((defined($borrower_data->{'categorycode'}) &&
513 $cat eq $borrower_data->{'categorycode'})
514 || (defined($categorycode) && $cat eq $categorycode)),
518 $typehash{'typename'}=$_;
519 my $typedescription = "typename_".$typehash{'typename'};
520 $typehash{'categoryloop'}=\
@categoryloop;
521 push @typeloop,{'typename' => $_,
522 $typedescription => 1,
523 'categoryloop' => \
@categoryloop};
525 $template->param('typeloop' => \
@typeloop,
526 no_categories
=> $no_categories);
527 if($no_categories){ $no_add = 1; }
529 if ( $guarantorid ) {
530 $select_city = getidcity
($data{city
});
532 ($default_city=$select_city) if ($step eq 0);
533 if (!defined($select_city) or $select_city eq '' ){
534 $default_city = &getidcity
($data{'city'});
537 my $city_arrayref = GetCities
();
538 if (@
{$city_arrayref} ) {
539 $template->param( city_cgipopup
=> 1);
541 if ($default_city) { # flag the current or default val
542 for my $city ( @
{$city_arrayref} ) {
543 if ($default_city == $city->{cityid
}) {
544 $city->{selected
} = 1;
551 my $roadtypes = C4
::Koha
::GetAuthorisedValues
( 'ROADTYPE', $data{streettype
} );
552 $template->param( roadtypes
=> $roadtypes);
554 my $default_borrowertitle = '';
555 unless ( $op eq 'duplicate' ) { $default_borrowertitle=$data{'title'} }
556 my($borrowertitle)=GetTitles
();
557 $template->param( title_cgipopup
=> 1) if ($borrowertitle);
558 my $borrotitlepopup = CGI
::popup_menu
(-name
=>'title',
560 -values=>$borrowertitle,
562 -default=>$default_borrowertitle
565 my @relationships = split /,|\|/, C4
::Context
->preference('borrowerRelationship');
567 while (@relationships) {
568 my $relship = shift @relationships || '';
569 my %row = ('relationship' => $relship);
570 if (defined($data{'relationship'}) and $data{'relationship'} eq $relship) {
571 $row{'selected'}=' selected';
575 push(@relshipdata, \
%row);
578 my %flags = ( 'gonenoaddress' => ['gonenoaddress' ],
583 foreach (keys(%flags)) {
585 my %row = ('key' => $key,
586 'name' => $flags{$key}[0]);
588 $row{'yes'}=' checked';
593 $row{'no'}=' checked';
595 push @flagdata,\
%row;
599 # in modify mod: userbranch value for GetBranchesLoop() comes from borrowers table
600 # in add mod: userbranch value come from branches table (ip correspondence)
603 if (C4
::Context
->userenv && C4
::Context
->userenv->{'branch'}) {
604 $userbranch = C4
::Context
->userenv->{'branch'};
607 if (defined ($data{'branchcode'}) and ( $op eq 'modify' || ( $op eq 'add' && $category_type eq 'C' ) )) {
608 $userbranch = $data{'branchcode'};
611 my $branchloop = GetBranchesLoop
( $userbranch );
615 $template->param(no_branches
=> 1);
619 $template->param(no_categories
=> 1);
621 $template->param(no_add
=> $no_add);
622 # --------------------------------------------------------------------------------------------------------
624 $template->param( sort1
=> $data{'sort1'});
625 $template->param( sort2
=> $data{'sort2'});
628 foreach my $error (@errors) {
629 $template->param($error) || $template->param( $error => 1);
631 $template->param(nok
=> 1);
634 #Formatting data for display
636 if (!defined($data{'dateenrolled'}) or $data{'dateenrolled'} eq ''){
637 $data{'dateenrolled'}=C4
::Dates
->today('iso');
639 if ( $op eq 'duplicate' ) {
640 $data{'dateenrolled'} = C4
::Dates
->today('iso');
641 $data{'dateexpiry'} = GetExpiryDate
( $data{'categorycode'}, $data{'dateenrolled'} );
643 if (C4
::Context
->preference('uppercasesurnames')) {
644 $data{'surname'} &&= uc( $data{'surname'} );
645 $data{'contactname'} &&= uc( $data{'contactname'} );
648 foreach (qw(dateenrolled dateexpiry dateofbirth)) {
649 $data{$_} = format_date
($data{$_}); # back to syspref for display
650 $template->param( $_ => $data{$_});
653 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
654 $template->param(ExtendedPatronAttributes
=> 1);
655 patron_attributes_form
($template, $borrowernumber);
658 if (C4
::Context
->preference('EnhancedMessagingPreferences')) {
660 C4
::Form
::MessagingPreferences
::set_form_values
({ categorycode
=> $categorycode }, $template);
662 C4
::Form
::MessagingPreferences
::set_form_values
({ borrowernumber
=> $borrowernumber }, $template);
664 $template->param(SMSSendDriver
=> C4
::Context
->preference("SMSSendDriver"));
665 $template->param(SMSnumber
=> defined $data{'smsalertnumber'} ?
$data{'smsalertnumber'} : $data{'mobile'});
666 $template->param(TalkingTechItivaPhone
=> C4
::Context
->preference("TalkingTechItivaPhoneNotification"));
669 $template->param( "showguarantor" => ($category_type=~/A|I|S|X/) ?
0 : 1); # associate with step to know where you are
670 $debug and warn "memberentry step: $step";
671 $template->param(%data);
672 $template->param( "step_$step" => 1) if $step; # associate with step to know where u are
673 $template->param( step
=> $step ) if $step; # associate with step to know where u are
676 BorrowerMandatoryField
=> C4
::Context
->preference("BorrowerMandatoryField"),#field to test with javascript
677 category_type
=> $category_type,#to know the category type of the borrower
678 select_city
=> $select_city,
679 "$category_type" => 1,# associate with step to know where u are
680 destination
=> $destination,#to know wher u come from and wher u must go in redirect
681 check_member
=> $check_member,#to know if the borrower already exist(=>1) or not (=>0)
684 $template->param( branchloop
=> $branchloop ) if ( $branchloop );
686 nodouble
=> $nodouble,
687 borrowernumber
=> $borrowernumber, #register number
688 guarantorid
=> ($borrower_data->{'guarantorid'} || $guarantorid),
689 ethcatpopup
=> $ethcatpopup,
690 relshiploop
=> \
@relshipdata,
691 city_loop
=> $city_arrayref,
692 borrotitlepopup
=> $borrotitlepopup,
693 guarantorinfo
=> $guarantorinfo,
694 flagloop
=> \
@flagdata,
695 check_categorytype
=>$check_categorytype,#to recover the category type with checkcategorytype function
696 category_type
=>$category_type,
698 nok
=> $nok,#flag to konw if an error
699 NoUpdateLogin
=> $NoUpdateLogin
702 if(defined($data{'flags'})){
703 $template->param(flags
=>$data{'flags'});
705 if(defined($data{'contacttitle'})){
706 $template->param("contacttitle_" . $data{'contacttitle'} => "SELECTED");
710 my ( $min, $max ) = C4
::Members
::get_cardnumber_length
();
711 if ( defined $min ) {
713 minlength_cardnumber
=> $min,
714 maxlength_cardnumber
=> $max
718 output_html_with_http_headers
$input, $cookie, $template->output;
720 sub parse_extended_patron_attributes
{
722 my @patron_attr = grep { /^patron_attr_\d+$/ } $input->param();
726 foreach my $key (@patron_attr) {
727 my $value = $input->param($key);
728 next unless defined($value) and $value ne '';
729 my $password = $input->param("${key}_password");
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, password
=> $password };
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 password_allowed
=> $attr_type->password_allowed(),
768 category
=> $attr_type->authorised_value_category(),
769 category_code
=> $attr_type->category_code(),
772 if (exists $attr_hash{$attr_type->code()}) {
773 foreach my $attr (@
{ $attr_hash{$attr_type->code()} }) {
774 my $newentry = { %$entry };
775 $newentry->{value
} = $attr->{value
};
776 $newentry->{password
} = $attr->{password
};
777 $newentry->{use_dropdown
} = 0;
778 if ($attr_type->authorised_value_category()) {
779 $newentry->{use_dropdown
} = 1;
780 $newentry->{auth_val_loop
} = GetAuthorisedValues
($attr_type->authorised_value_category(), $attr->{value
});
783 $newentry->{form_id
} = "patron_attr_$i";
784 push @
{$items_by_class{$attr_type->class()}}, $newentry;
788 my $newentry = { %$entry };
789 if ($attr_type->authorised_value_category()) {
790 $newentry->{use_dropdown
} = 1;
791 $newentry->{auth_val_loop
} = GetAuthorisedValues
($attr_type->authorised_value_category());
793 $newentry->{form_id
} = "patron_attr_$i";
794 push @
{$items_by_class{$attr_type->class()}}, $newentry;
797 while ( my ($class, @items) = each %items_by_class ) {
798 my $lib = GetAuthorisedValueByCode
( 'PA_CLASS', $class ) || $class;
799 push @attribute_loop, {
806 $template->param(patron_attributes
=> \
@attribute_loop);