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;
40 use C4::Branch; # GetBranches
41 use C4::Form::MessagingPreferences;
42 use Koha::Patron::Debarments;
47 if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
48 load Koha::NorwegianPatronDB, qw( NLGetSyncDataFromBorrowernumber );
50 use Koha::SMS::Providers;
55 $debug = $ENV{DEBUG} || 0;
59 ($debug) or $debug = $input->param('debug') || 0;
62 my $dbh = C4::Context->dbh;
64 my ($template, $loggedinuser, $cookie)
65 = get_template_and_user({template_name => "members/memberentrygen.tt",
69 flagsrequired => {borrowers => 1},
70 debug => ($debug) ? 1 : 0,
73 if ( C4::Context->preference('SMSSendDriver') eq 'Email' ) {
74 my @providers = Koha::SMS::Providers->search();
75 $template->param( sms_providers => \@providers );
78 my $guarantorid = $input->param('guarantorid');
79 my $borrowernumber = $input->param('borrowernumber');
80 my $actionType = $input->param('actionType') || '';
81 my $modify = $input->param('modify');
82 my $delete = $input->param('delete');
83 my $op = $input->param('op');
84 my $destination = $input->param('destination');
85 my $cardnumber = $input->param('cardnumber');
86 my $check_member = $input->param('check_member');
87 my $nodouble = $input->param('nodouble');
88 my $duplicate = $input->param('duplicate');
89 my $quickadd = $input->param('quickadd');
90 $nodouble = 1 if ($op eq 'modify' or $op eq 'duplicate'); # FIXME hack to represent fact that if we're
91 # modifying an existing patron, it ipso facto
92 # isn't a duplicate. Marking FIXME because this
93 # script needs to be refactored.
94 my $nok = $input->param('nok');
95 my $guarantorinfo = $input->param('guarantorinfo');
96 my $step = $input->param('step') || 0;
100 my $userenv = C4::Context->userenv;
103 ## Deal with debarments
105 debarments => GetDebarments( { borrowernumber => $borrowernumber } ) );
106 my @debarments_to_remove = $input->multi_param('remove_debarment');
107 foreach my $d ( @debarments_to_remove ) {
110 if ( $input->param('add_debarment') ) {
112 my $expiration = $input->param('debarred_expiration');
116 { 'dt' => dt_from_string($expiration), 'dateformat' => 'iso' } )
121 borrowernumber => $borrowernumber,
123 comment => scalar $input->param('debarred_comment'),
124 expiration => $expiration,
129 $template->param("uppercasesurnames" => C4::Context->preference('uppercasesurnames'));
131 my $minpw = C4::Context->preference('minPasswordLength');
132 $template->param("minPasswordLength" => $minpw);
134 # function to designate mandatory fields (visually with css)
135 my $check_BorrowerMandatoryField=C4::Context->preference("BorrowerMandatoryField");
136 my @field_check=split(/\|/,$check_BorrowerMandatoryField);
137 foreach (@field_check) {
138 $template->param( "mandatory$_" => 1);
140 # function to designate unwanted fields
141 my $check_BorrowerUnwantedField=C4::Context->preference("BorrowerUnwantedField");
142 @field_check=split(/\|/,$check_BorrowerUnwantedField);
143 foreach (@field_check) {
145 $template->param( "no$_" => 1);
147 $template->param( "add" => 1 ) if ( $op eq 'add' );
148 $template->param( "quickadd" => 1 ) if ( $quickadd );
149 $template->param( "duplicate" => 1 ) if ( $op eq 'duplicate' );
150 $template->param( "checked" => 1 ) if ( defined($nodouble) && $nodouble eq 1 );
151 ( $borrower_data = GetMember( 'borrowernumber' => $borrowernumber ) ) if ( $op eq 'modify' or $op eq 'save' or $op eq 'duplicate' );
152 my $categorycode = $input->param('categorycode') || $borrower_data->{'categorycode'};
153 my $category_type = $input->param('category_type') || '';
154 unless ($category_type or !($categorycode)){
155 my $borrowercategory = GetBorrowercategory($categorycode);
156 $category_type = $borrowercategory->{'category_type'};
157 my $category_name = $borrowercategory->{'description'};
158 $template->param("categoryname"=>$category_name);
160 $category_type="A" unless $category_type; # FIXME we should display a error message instead of a 500 error !
162 # if a add or modify is requested => check validity of data.
163 %data = %$borrower_data if ($borrower_data);
165 # initialize %newdata
166 my %newdata; # comes from $input->param()
167 if ( $op eq 'insert' || $op eq 'modify' || $op eq 'save' || $op eq 'duplicate' ) {
168 my @names = ( $borrower_data && $op ne 'save' ) ? keys %$borrower_data : $input->param();
169 foreach my $key (@names) {
170 if (defined $input->param($key)) {
171 $newdata{$key} = $input->param($key);
172 $newdata{$key} =~ s/\"/"/g unless $key eq 'borrowernotes' or $key eq 'opacnote';
176 foreach (qw(dateenrolled dateexpiry dateofbirth)) {
177 next unless exists $newdata{$_};
178 my $userdate = $newdata{$_} or next;
180 my $formatteddate = eval { output_pref({ dt => dt_from_string( $userdate ), dateformat => 'iso', dateonly => 1 } ); };
181 if ( $formatteddate ) {
182 $newdata{$_} = $formatteddate;
184 ($userdate eq '0000-00-00') and warn "Data error: $_ is '0000-00-00'";
185 $template->param( "ERROR_$_" => 1 );
186 push(@errors,"ERROR_$_");
189 # check permission to modify login info.
190 if (ref($borrower_data) && ($borrower_data->{'category_type'} eq 'S') && ! (C4::Auth::haspermission($userenv->{'id'},{'staffaccess'=>1})) ) {
195 # remove keys from %newdata that ModMember() doesn't like
197 my @keys_to_delete = (
198 qr/^BorrowerMandatoryField$/,
207 qr/^setting_extended_patron_attributes$/,
208 qr/^setting_messaging_prefs$/,
216 for my $regexp (@keys_to_delete) {
217 for (keys %newdata) {
218 delete($newdata{$_}) if /$regexp/;
223 # Test uniqueness of surname, firstname and dateofbirth
224 if ( ( $op eq 'insert' ) and !$nodouble ) {
226 $conditions->{surname} = $newdata{surname} if $newdata{surname};
227 if ( $category_type ne 'I' ) {
228 $conditions->{firstname} = $newdata{firstname} if $newdata{firstname};
229 $conditions->{dateofbirth} = $newdata{dateofbirth} if $newdata{dateofbirth};
231 my $patrons = Koha::Patrons->search($conditions);
232 if ( $patrons->count > 0) {
234 $check_member = $patrons->next->borrowernumber;
238 #recover all data from guarantor address phone ,fax...
239 if ( $guarantorid ) {
240 if (my $guarantordata=GetMember(borrowernumber => $guarantorid)) {
241 $category_type = $guarantordata->{categorycode} eq 'I' ? 'P' : 'C';
242 $guarantorinfo=$guarantordata->{'surname'}." , ".$guarantordata->{'firstname'};
243 $newdata{'contactfirstname'}= $guarantordata->{'firstname'};
244 $newdata{'contactname'} = $guarantordata->{'surname'};
245 $newdata{'contacttitle'} = $guarantordata->{'title'};
246 if ( $op eq 'add' ) {
247 foreach (qw(streetnumber address streettype address2
248 zipcode country city state phone phonepro mobile fax email emailpro branchcode
249 B_streetnumber B_streettype B_address B_address2
250 B_city B_state B_zipcode B_country B_email B_phone)) {
251 $newdata{$_} = $guarantordata->{$_};
257 ###############test to take the right zipcode, country and city name ##############
258 # set only if parameter was passed from the form
259 $newdata{'city'} = $input->param('city') if defined($input->param('city'));
260 $newdata{'zipcode'} = $input->param('zipcode') if defined($input->param('zipcode'));
261 $newdata{'country'} = $input->param('country') if defined($input->param('country'));
263 # builds default userid
264 # userid input text may be empty or missing because of syspref BorrowerUnwantedField
265 if ( ( defined $newdata{'userid'} && $newdata{'userid'} eq '' ) || $check_BorrowerUnwantedField =~ /userid/ ) {
266 if ( ( defined $newdata{'firstname'} ) && ( defined $newdata{'surname'} ) ) {
267 # Full page edit, firstname and surname input zones are present
268 $newdata{'userid'} = Generate_Userid( $borrowernumber, $newdata{'firstname'}, $newdata{'surname'} );
270 elsif ( ( defined $data{'firstname'} ) && ( defined $data{'surname'} ) ) {
271 # Partial page edit (access through "Details"/"Library details" tab), firstname and surname input zones are not used
272 # Still, if the userid field is erased, we can create a new userid with available firstname and surname
273 $newdata{'userid'} = Generate_Userid( $borrowernumber, $data{'firstname'}, $data{'surname'} );
276 $newdata{'userid'} = $data{'userid'};
280 $debug and warn join "\t", map {"$_: $newdata{$_}"} qw(dateofbirth dateenrolled dateexpiry);
281 my $extended_patron_attributes = ();
282 if ($op eq 'save' || $op eq 'insert'){
283 # If the cardnumber is blank, treat it as null.
284 $newdata{'cardnumber'} = undef if $newdata{'cardnumber'} =~ /^\s*$/;
286 if (my $error_code = checkcardnumber($newdata{cardnumber},$newdata{borrowernumber})){
287 push @errors, $error_code == 1
288 ? 'ERROR_cardnumber_already_exists'
290 ? 'ERROR_cardnumber_length'
294 if ( $newdata{dateofbirth} ) {
295 my $age = GetAge($newdata{dateofbirth});
296 my $borrowercategory=GetBorrowercategory($newdata{'categorycode'});
297 my ($low,$high) = ($borrowercategory->{'dateofbirthrequired'}, $borrowercategory->{'upperagelimit'});
298 if (($high && ($age > $high)) or ($age < $low)) {
299 push @errors, 'ERROR_age_limitations';
300 $template->param( age_low => $low);
301 $template->param( age_high => $high);
305 if($newdata{surname} && C4::Context->preference('uppercasesurnames')) {
306 $newdata{'surname'} = uc($newdata{'surname'});
309 if (C4::Context->preference("IndependentBranches")) {
310 unless ( C4::Context->IsSuperLibrarian() ){
311 $debug and print STDERR " $newdata{'branchcode'} : ".$userenv->{flags}.":".$userenv->{branch};
312 unless (!$newdata{'branchcode'} || $userenv->{branch} eq $newdata{'branchcode'}){
313 push @errors, "ERROR_branch";
317 # Check if the 'userid' is unique. 'userid' might not always be present in
318 # the edited values list when editing certain sub-forms. Get it straight
319 # from the DB if absent.
320 my $userid = $newdata{ userid } // $borrower_data->{ userid };
321 unless (Check_Userid($userid,$borrowernumber)) {
322 push @errors, "ERROR_login_exist";
325 my $password = $input->param('password');
326 my $password2 = $input->param('password2');
327 push @errors, "ERROR_password_mismatch" if ( $password ne $password2 );
328 push @errors, "ERROR_short_password" if( $password && $minpw && $password ne '****' && (length($password) < $minpw) );
331 my $emailprimary = $input->param('email');
332 my $emailsecondary = $input->param('emailpro');
333 my $emailalt = $input->param('B_email');
336 push (@errors, "ERROR_bad_email") if (!Email::Valid->address($emailprimary));
338 if ($emailsecondary) {
339 push (@errors, "ERROR_bad_email_secondary") if (!Email::Valid->address($emailsecondary));
342 push (@errors, "ERROR_bad_email_alternative") if (!Email::Valid->address($emailalt));
345 if (C4::Context->preference('ExtendedPatronAttributes')) {
346 $extended_patron_attributes = parse_extended_patron_attributes($input);
347 foreach my $attr (@$extended_patron_attributes) {
348 unless (C4::Members::Attributes::CheckUniqueness($attr->{code}, $attr->{value}, $borrowernumber)) {
349 my $attr_info = C4::Members::AttributeTypes->fetch($attr->{code});
350 push @errors, "ERROR_extended_unique_id_failed";
352 ERROR_extended_unique_id_failed_code => $attr->{code},
353 ERROR_extended_unique_id_failed_value => $attr->{value},
354 ERROR_extended_unique_id_failed_description => $attr_info->description()
361 if ( ($op eq 'modify' || $op eq 'insert' || $op eq 'save'|| $op eq 'duplicate') and ($step == 0 or $step == 3 )){
362 unless ($newdata{'dateexpiry'}){
363 my $arg2 = $newdata{'dateenrolled'} || output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
364 $newdata{'dateexpiry'} = GetExpiryDate($newdata{'categorycode'},$arg2);
368 # BZ 14683: Do not mixup mobile [read: other phone] with smsalertnumber
369 my $sms = $input->param('SMSnumber');
370 if ( defined $sms ) {
371 $newdata{smsalertnumber} = $sms;
374 ### Error checks should happen before this line.
375 $nok = $nok || scalar(@errors);
376 if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){
377 $debug and warn "$op dates: " . join "\t", map {"$_: $newdata{$_}"} qw(dateofbirth dateenrolled dateexpiry);
378 if ($op eq 'insert'){
379 # we know it's not a duplicate borrowernumber or there would already be an error
380 $borrowernumber = &AddMember(%newdata);
381 $newdata{'borrowernumber'} = $borrowernumber;
383 # If 'AutoEmailOpacUser' syspref is on, email user their account details from the 'notice' that matches the user's branchcode.
384 if ( C4::Context->preference("AutoEmailOpacUser") == 1 && $newdata{'userid'} && $newdata{'password'}) {
385 #look for defined primary email address, if blank - attempt to use borr.email and borr.emailpro instead
387 if (C4::Context->preference("AutoEmailPrimaryAddress") ne 'OFF' &&
388 $newdata{C4::Context->preference("AutoEmailPrimaryAddress")} =~ /\w\@\w/ ) {
389 $emailaddr = $newdata{C4::Context->preference("AutoEmailPrimaryAddress")}
391 elsif ($newdata{email} =~ /\w\@\w/) {
392 $emailaddr = $newdata{email}
394 elsif ($newdata{emailpro} =~ /\w\@\w/) {
395 $emailaddr = $newdata{emailpro}
397 elsif ($newdata{B_email} =~ /\w\@\w/) {
398 $emailaddr = $newdata{B_email}
400 # if we manage to find a valid email address, send notice
402 $newdata{emailaddr} = $emailaddr;
405 $err = SendAlerts ( 'members', \%newdata, "ACCTDETAILS" );
408 $template->param(error_alert => $@);
409 } elsif ( ref($err) eq "HASH" && defined $err->{error} and $err->{error} eq "no_email" ) {
410 $template->{VARS}->{'error_alert'} = "no_email";
412 $template->{VARS}->{'info_alert'} = 1;
417 if (C4::Context->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) {
418 C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $extended_patron_attributes);
420 if (C4::Context->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) {
421 C4::Form::MessagingPreferences::handle_form_action($input, { borrowernumber => $borrowernumber }, $template, 1, $newdata{'categorycode'});
423 # Try to do the live sync with the Norwegian national patron database, if it is enabled
424 if ( exists $data{'borrowernumber'} && C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
425 NLSync({ 'borrowernumber' => $borrowernumber });
427 } elsif ($op eq 'save'){
428 if ($NoUpdateLogin) {
429 delete $newdata{'password'};
430 delete $newdata{'userid'};
432 &ModMember(%newdata) unless scalar(keys %newdata) <= 1; # bug 4508 - avoid crash if we're not
433 # updating any columns in the borrowers table,
434 # which can happen if we're only editing the
435 # patron attributes or messaging preferences sections
436 if (C4::Context->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) {
437 C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $extended_patron_attributes);
439 if (C4::Context->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) {
440 C4::Form::MessagingPreferences::handle_form_action($input, { borrowernumber => $borrowernumber }, $template);
443 print scalar ($destination eq "circ") ?
444 $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber") :
445 $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber") ;
446 exit; # You can only send 1 redirect! After that, content or other headers don't matter.
450 print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$borrowernumber");
451 exit; # same as above
454 if ($nok or !$nodouble){
455 $op="add" if ($op eq "insert");
456 $op="modify" if ($op eq "save");
458 $template->param( updtype => ($op eq 'add' ?'I':'M')); # used to check for $op eq "insert"... but we just changed $op!
460 $template->param( step_1 => 1,step_2 => 1,step_3 => 1, step_4 => 1, step_5 => 1, step_6 => 1);
463 if (C4::Context->preference("IndependentBranches")) {
464 my $userenv = C4::Context->userenv;
465 if ( !C4::Context->IsSuperLibrarian() && $data{'branchcode'} ) {
466 unless ($userenv->{branch} eq $data{'branchcode'}){
467 print $input->redirect("/cgi-bin/koha/members/members-home.pl");
473 $template->param( updtype => 'I', step_1=>1, step_2=>1, step_3=>1, step_4=>1, step_5 => 1, step_6 => 1);
475 if ($op eq "modify") {
476 $template->param( updtype => 'M',modify => 1 );
477 $template->param( step_1=>1, step_2=>1, step_3=>1, step_4=>1, step_5 => 1, step_6 => 1) unless $step;
479 $template->param( categorycode => $borrower_data->{'categorycode'} );
481 # Add sync data to the user data
482 if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
483 my $sync = NLGetSyncDataFromBorrowernumber( $borrowernumber );
491 if ( $op eq "duplicate" ) {
492 $template->param( updtype => 'I' );
493 $template->param( step_1 => 1, step_2 => 1, step_3 => 1, step_4 => 1, step_5 => 1, step_6 => 1 ) unless $step;
494 $data{'cardnumber'} = "";
497 $data{'cardnumber'}=fixup_cardnumber($data{'cardnumber'}) if ( ( $op eq 'add' ) or ( $op eq 'duplicate' ) );
498 if(!defined($data{'sex'})){
499 $template->param( none => 1);
500 } elsif($data{'sex'} eq 'F'){
501 $template->param( female => 1);
502 } elsif ($data{'sex'} eq 'M'){
503 $template->param( male => 1);
505 $template->param( none => 1);
508 ##Now all the data to modify a member.
511 my $no_categories = 1;
513 foreach (qw(C A S P I X)) {
514 my $action="WHERE category_type=?";
515 my ($categories,$labels)=GetborCatFromCatType($_,$action);
516 if(scalar(@$categories) > 0){ $no_categories = 0; }
518 foreach my $cat (@$categories){
519 push @categoryloop,{'categorycode' => $cat,
520 'categoryname' => $labels->{$cat},
521 'categorycodeselected' => ((defined($borrower_data->{'categorycode'}) &&
522 $cat eq $borrower_data->{'categorycode'})
523 || (defined($categorycode) && $cat eq $categorycode)),
527 $typehash{'typename'}=$_;
528 my $typedescription = "typename_".$typehash{'typename'};
529 $typehash{'categoryloop'}=\@categoryloop;
530 push @typeloop,{'typename' => $_,
531 $typedescription => 1,
532 'categoryloop' => \@categoryloop};
534 $template->param('typeloop' => \@typeloop,
535 no_categories => $no_categories);
536 if($no_categories){ $no_add = 1; }
539 my $cities = Koha::Cities->search( {}, { order_by => 'city_name' } );
540 my $roadtypes = C4::Koha::GetAuthorisedValues( 'ROADTYPE' );
542 roadtypes => $roadtypes,
546 my $default_borrowertitle = '';
547 unless ( $op eq 'duplicate' ) { $default_borrowertitle=$data{'title'} }
548 my($borrowertitle)=GetTitles();
549 $template->param( title_cgipopup => 1) if ($borrowertitle);
550 my $borrotitlepopup = CGI::popup_menu(-name=>'title',
552 -values=>$borrowertitle,
554 -default=>$default_borrowertitle
557 my @relationships = split /,|\|/, C4::Context->preference('borrowerRelationship');
559 while (@relationships) {
560 my $relship = shift @relationships || '';
561 my %row = ('relationship' => $relship);
562 if (defined($data{'relationship'}) and $data{'relationship'} eq $relship) {
563 $row{'selected'}=' selected';
567 push(@relshipdata, \%row);
570 my %flags = ( 'gonenoaddress' => ['gonenoaddress' ],
575 foreach (keys(%flags)) {
577 my %row = ('key' => $key,
578 'name' => $flags{$key}[0]);
580 $row{'yes'}=' checked';
585 $row{'no'}=' checked';
587 push @flagdata,\%row;
591 # in modify mod: userbranch value for GetBranchesLoop() comes from borrowers table
592 # in add mod: userbranch value come from branches table (ip correspondence)
595 if (C4::Context->userenv && C4::Context->userenv->{'branch'}) {
596 $userbranch = C4::Context->userenv->{'branch'};
599 if (defined ($data{'branchcode'}) and ( $op eq 'modify' || $op eq 'duplicate' || ( $op eq 'add' && $category_type eq 'C' ) )) {
600 $userbranch = $data{'branchcode'};
603 my $branchloop = GetBranchesLoop( $userbranch );
607 $template->param(no_branches => 1);
611 $template->param(no_categories => 1);
613 $template->param(no_add => $no_add);
614 # --------------------------------------------------------------------------------------------------------
616 $template->param( sort1 => $data{'sort1'});
617 $template->param( sort2 => $data{'sort2'});
620 foreach my $error (@errors) {
621 $template->param($error) || $template->param( $error => 1);
623 $template->param(nok => 1);
626 #Formatting data for display
628 if (!defined($data{'dateenrolled'}) or $data{'dateenrolled'} eq ''){
629 $data{'dateenrolled'} = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
631 if ( $op eq 'duplicate' ) {
632 $data{'dateenrolled'} = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
633 $data{'dateexpiry'} = GetExpiryDate( $data{'categorycode'}, $data{'dateenrolled'} );
635 if (C4::Context->preference('uppercasesurnames')) {
636 $data{'surname'} &&= uc( $data{'surname'} );
637 $data{'contactname'} &&= uc( $data{'contactname'} );
640 foreach (qw(dateenrolled dateexpiry dateofbirth)) {
642 $data{$_} = eval { output_pref({ dt => dt_from_string( $data{$_} ), dateonly => 1 } ); }; # back to syspref for display
644 $template->param( $_ => $data{$_});
647 if (C4::Context->preference('ExtendedPatronAttributes')) {
648 $template->param(ExtendedPatronAttributes => 1);
649 patron_attributes_form($template, $borrowernumber);
652 if (C4::Context->preference('EnhancedMessagingPreferences')) {
654 C4::Form::MessagingPreferences::set_form_values({ categorycode => $categorycode }, $template);
656 C4::Form::MessagingPreferences::set_form_values({ borrowernumber => $borrowernumber }, $template);
658 $template->param(SMSSendDriver => C4::Context->preference("SMSSendDriver"));
659 $template->param(SMSnumber => $data{'smsalertnumber'} );
660 $template->param(TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification"));
663 $template->param( "showguarantor" => ($category_type=~/A|I|S|X/) ? 0 : 1); # associate with step to know where you are
664 $debug and warn "memberentry step: $step";
665 $template->param(%data);
666 $template->param( "step_$step" => 1) if $step; # associate with step to know where u are
667 $template->param( step => $step ) if $step; # associate with step to know where u are
670 BorrowerMandatoryField => C4::Context->preference("BorrowerMandatoryField"),#field to test with javascript
671 category_type => $category_type,#to know the category type of the borrower
672 "$category_type" => 1,# associate with step to know where u are
673 destination => $destination,#to know wher u come from and wher u must go in redirect
674 check_member => $check_member,#to know if the borrower already exist(=>1) or not (=>0)
677 $template->param( branchloop => $branchloop ) if ( $branchloop );
679 nodouble => $nodouble,
680 borrowernumber => $borrowernumber, #register number
681 guarantorid => ($borrower_data->{'guarantorid'} || $guarantorid),
682 relshiploop => \@relshipdata,
683 borrotitlepopup => $borrotitlepopup,
684 guarantorinfo => $guarantorinfo,
685 flagloop => \@flagdata,
686 category_type =>$category_type,
688 nok => $nok,#flag to know if an error
689 NoUpdateLogin => $NoUpdateLogin
692 if(defined($data{'flags'})){
693 $template->param(flags=>$data{'flags'});
695 if(defined($data{'contacttitle'})){
696 $template->param("contacttitle_" . $data{'contacttitle'} => "SELECTED");
700 my ( $min, $max ) = C4::Members::get_cardnumber_length();
701 if ( defined $min ) {
703 minlength_cardnumber => $min,
704 maxlength_cardnumber => $max
708 output_html_with_http_headers $input, $cookie, $template->output;
710 sub parse_extended_patron_attributes {
712 my @patron_attr = grep { /^patron_attr_\d+$/ } $input->multi_param();
716 foreach my $key (@patron_attr) {
717 my $value = $input->param($key);
718 next unless defined($value) and $value ne '';
719 my $code = $input->param("${key}_code");
720 next if exists $dups{$code}->{$value};
721 $dups{$code}->{$value} = 1;
722 push @attr, { code => $code, value => $value };
727 sub patron_attributes_form {
728 my $template = shift;
729 my $borrowernumber = shift;
731 my @types = C4::Members::AttributeTypes::GetAttributeTypes();
732 if (scalar(@types) == 0) {
733 $template->param(no_patron_attribute_types => 1);
736 my $attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
737 my @classes = uniq( map {$_->{class}} @$attributes );
738 @classes = sort @classes;
740 # map patron's attributes into a more convenient structure
742 foreach my $attr (@$attributes) {
743 push @{ $attr_hash{$attr->{code}} }, $attr;
746 my @attribute_loop = ();
749 foreach my $type_code (map { $_->{code} } @types) {
750 my $attr_type = C4::Members::AttributeTypes->fetch($type_code);
752 class => $attr_type->class(),
753 code => $attr_type->code(),
754 description => $attr_type->description(),
755 repeatable => $attr_type->repeatable(),
756 category => $attr_type->authorised_value_category(),
757 category_code => $attr_type->category_code(),
759 if (exists $attr_hash{$attr_type->code()}) {
760 foreach my $attr (@{ $attr_hash{$attr_type->code()} }) {
761 my $newentry = { %$entry };
762 $newentry->{value} = $attr->{value};
763 $newentry->{use_dropdown} = 0;
764 if ($attr_type->authorised_value_category()) {
765 $newentry->{use_dropdown} = 1;
766 $newentry->{auth_val_loop} = GetAuthorisedValues($attr_type->authorised_value_category(), $attr->{value});
769 $newentry->{form_id} = "patron_attr_$i";
770 push @{$items_by_class{$attr_type->class()}}, $newentry;
774 my $newentry = { %$entry };
775 if ($attr_type->authorised_value_category()) {
776 $newentry->{use_dropdown} = 1;
777 $newentry->{auth_val_loop} = GetAuthorisedValues($attr_type->authorised_value_category());
779 $newentry->{form_id} = "patron_attr_$i";
780 push @{$items_by_class{$attr_type->class()}}, $newentry;
783 while ( my ($class, @items) = each %items_by_class ) {
784 my $lib = GetAuthorisedValueByCode( 'PA_CLASS', $class ) || $class;
785 push @attribute_loop, {
792 $template->param(patron_attributes => \@attribute_loop);