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);
34 use C4::Members::Attributes;
35 use C4::Members::AttributeTypes;
37 use C4::Dates qw/format_date format_date_in_iso/;
41 use C4::Branch; # GetBranches
42 use C4::Form::MessagingPreferences;
47 $debug = $ENV{DEBUG} || 0;
51 ($debug) or $debug = $input->param('debug') || 0;
54 my $dbh = C4::Context->dbh;
56 my ($template, $loggedinuser, $cookie)
57 = get_template_and_user({template_name => "members/memberentrygen.tmpl",
61 flagsrequired => {borrowers => 1},
62 debug => ($debug) ? 1 : 0,
64 my $guarantorid = $input->param('guarantorid');
65 my $borrowernumber = $input->param('borrowernumber');
66 my $actionType = $input->param('actionType') || '';
67 my $modify = $input->param('modify');
68 my $delete = $input->param('delete');
69 my $op = $input->param('op');
70 my $destination = $input->param('destination');
71 my $cardnumber = $input->param('cardnumber');
72 my $check_member = $input->param('check_member');
73 my $nodouble = $input->param('nodouble');
74 my $duplicate = $input->param('duplicate');
75 $nodouble = 1 if ($op eq 'modify' or $op eq 'duplicate'); # FIXME hack to represent fact that if we're
76 # modifying an existing patron, it ipso facto
77 # isn't a duplicate. Marking FIXME because this
78 # script needs to be refactored.
79 my $select_city = $input->param('select_city');
80 my $nok = $input->param('nok');
81 my $guarantorinfo = $input->param('guarantorinfo');
82 my $step = $input->param('step') || 0;
85 # $check_categorytype contains the value of duplicate borrowers category type to redirect in good template in step =2
86 my $check_categorytype=$input->param('check_categorytype');
87 # NOTE: Alert for ethnicity and ethnotes fields, they are invalid in all borrowers form
90 my $userenv = C4::Context->userenv;
92 $template->param("uppercasesurnames" => C4::Context->preference('uppercasesurnames'));
94 my $minpw = C4::Context->preference('minPasswordLength');
95 $template->param("minPasswordLength" => $minpw);
97 # function to designate mandatory fields (visually with css)
98 my $check_BorrowerMandatoryField=C4::Context->preference("BorrowerMandatoryField");
99 my @field_check=split(/\|/,$check_BorrowerMandatoryField);
100 foreach (@field_check) {
101 $template->param( "mandatory$_" => 1);
103 $template->param( "add" => 1 ) if ( $op eq 'add' );
104 $template->param( "duplicate" => 1 ) if ( $op eq 'duplicate' );
105 $template->param( "checked" => 1 ) if ( defined($nodouble) && $nodouble eq 1 );
106 ( $borrower_data = GetMember( 'borrowernumber' => $borrowernumber ) ) if ( $op eq 'modify' or $op eq 'save' or $op eq 'duplicate' );
107 my $categorycode = $input->param('categorycode') || $borrower_data->{'categorycode'};
108 my $category_type = $input->param('category_type') || '';
110 $template->{VARS}->{'type_only'} = 1;
112 my $new_c_type = $category_type; #if we have input param, then we've already chosen the cat_type.
113 unless ($category_type or !($categorycode)){
114 my $borrowercategory = GetBorrowercategory($categorycode);
115 $category_type = $borrowercategory->{'category_type'};
116 my $category_name = $borrowercategory->{'description'};
117 $template->param("categoryname"=>$category_name);
119 $category_type="A" unless $category_type; # FIXME we should display a error message instead of a 500 error !
121 # if a add or modify is requested => check validity of data.
122 %data = %$borrower_data if ($borrower_data);
124 # initialize %newdata
125 my %newdata; # comes from $input->param()
126 if ( $op eq 'insert' || $op eq 'modify' || $op eq 'save' || $op eq 'duplicate' ) {
127 my @names = ( $borrower_data && $op ne 'save' ) ? keys %$borrower_data : $input->param();
128 foreach my $key (@names) {
129 if (defined $input->param($key)) {
130 $newdata{$key} = $input->param($key);
131 $newdata{$key} =~ s/\"/"/g unless $key eq 'borrowernotes' or $key eq 'opacnote';
134 my $dateobject = C4::Dates->new();
135 my $syspref = $dateobject->regexp(); # same syspref format for all 3 dates
136 my $iso = $dateobject->regexp('iso'); #
137 foreach (qw(dateenrolled dateexpiry dateofbirth)) {
138 next unless exists $newdata{$_};
139 my $userdate = $newdata{$_} or next;
140 if ($userdate =~ /$syspref/) {
141 $newdata{$_} = format_date_in_iso($userdate); # if they match syspref format, then convert to ISO
142 } elsif ($userdate =~ /$iso/) {
143 warn "Date $_ ($userdate) is already in ISO format";
145 ($userdate eq '0000-00-00') and warn "Data error: $_ is '0000-00-00'";
146 $template->param( "ERROR_$_" => 1 ); # else ERROR!
147 push(@errors,"ERROR_$_");
150 # check permission to modify login info.
151 if (ref($borrower_data) && ($borrower_data->{'category_type'} eq 'S') && ! (C4::Auth::haspermission($userenv->{'id'},{'staffaccess'=>1})) ) {
156 # remove keys from %newdata that ModMember() doesn't like
158 my @keys_to_delete = (
159 qr/^BorrowerMandatoryField$/,
166 qr/^select_roadtype$/,
169 qr/^setting_extended_patron_attributes$/,
170 qr/^setting_messaging_prefs$/,
178 for my $regexp (@keys_to_delete) {
179 for (keys %newdata) {
180 delete($newdata{$_}) if /$regexp/;
185 #############test for member being unique #############
186 if (($op eq 'insert') and !$nodouble){
187 my $category_type_send=$category_type if ($category_type eq 'I');
188 my $check_category; # recover the category code of the doublon suspect borrowers
189 # ($result,$categorycode) = checkuniquemember($collectivity,$surname,$firstname,$dateofbirth)
190 ($check_member,$check_category) = checkuniquemember(
192 ($newdata{surname} ? $newdata{surname} : $data{surname} ),
193 ($newdata{firstname} ? $newdata{firstname} : $data{firstname} ),
194 ($newdata{dateofbirth} ? $newdata{dateofbirth} : $data{dateofbirth})
199 # recover the category type if the borrowers is a doublon
200 if ($check_category) {
201 my $tmpborrowercategory=GetBorrowercategory($check_category);
202 $check_categorytype=$tmpborrowercategory->{'category_type'};
206 #recover all data from guarantor address phone ,fax...
207 if ( $guarantorid and ( $category_type eq 'C' || $category_type eq 'P' )) {
208 if (my $guarantordata=GetMember(borrowernumber => $guarantorid)) {
209 $guarantorinfo=$guarantordata->{'surname'}." , ".$guarantordata->{'firstname'};
210 $newdata{'contactfirstname'}= $guarantordata->{'firstname'};
211 $newdata{'contactname'} = $guarantordata->{'surname'};
212 $newdata{'contacttitle'} = $guarantordata->{'title'};
213 if ( $op eq 'add' ) {
214 foreach (qw(streetnumber address streettype address2
215 zipcode country city state phone phonepro mobile fax email emailpro branchcode
216 B_streetnumber B_streettype B_address B_address2
217 B_city B_state B_zipcode B_country B_email B_phone)) {
218 $newdata{$_} = $guarantordata->{$_};
224 ###############test to take the right zipcode, country and city name ##############
225 # set only if parameter was passed from the form
226 $newdata{'city'} = $input->param('city') if defined($input->param('city'));
227 $newdata{'zipcode'} = $input->param('zipcode') if defined($input->param('zipcode'));
228 $newdata{'country'} = $input->param('country') if defined($input->param('country'));
230 #builds default userid
231 if ( (defined $newdata{'userid'}) && ($newdata{'userid'} eq '')){
232 $newdata{'userid'} = Generate_Userid($borrowernumber, $newdata{'firstname'}, $newdata{'surname'});
235 $debug and warn join "\t", map {"$_: $newdata{$_}"} qw(dateofbirth dateenrolled dateexpiry);
236 my $extended_patron_attributes = ();
237 if ($op eq 'save' || $op eq 'insert'){
238 # If the cardnumber is blank, treat it as null.
239 $newdata{'cardnumber'} = undef if $newdata{'cardnumber'} =~ /^\s*$/;
241 if (checkcardnumber($newdata{cardnumber},$newdata{borrowernumber})){
242 push @errors, 'ERROR_cardnumber';
244 my $dateofbirthmandatory = (scalar grep {$_ eq "dateofbirth"} @field_check) ? 1 : 0;
245 if ($newdata{dateofbirth} && $dateofbirthmandatory) {
246 my $age = GetAge($newdata{dateofbirth});
247 my $borrowercategory=GetBorrowercategory($newdata{'categorycode'});
248 my ($low,$high) = ($borrowercategory->{'dateofbirthrequired'}, $borrowercategory->{'upperagelimit'});
249 if (($high && ($age > $high)) or ($age < $low)) {
250 push @errors, 'ERROR_age_limitations';
251 $template->param('ERROR_age_limitations' => "$low to $high");
255 if($newdata{surname} && C4::Context->preference('uppercasesurnames')) {
256 $newdata{'surname'} = uc($newdata{'surname'});
259 if (C4::Context->preference("IndependantBranches")) {
260 if ($userenv && $userenv->{flags} % 2 != 1){
261 $debug and print STDERR " $newdata{'branchcode'} : ".$userenv->{flags}.":".$userenv->{branch};
262 unless (!$newdata{'branchcode'} || $userenv->{branch} eq $newdata{'branchcode'}){
263 push @errors, "ERROR_branch";
267 # Check if the userid is unique
268 unless (Check_Userid($newdata{'userid'},$borrowernumber)) {
269 push @errors, "ERROR_login_exist";
272 my $password = $input->param('password');
273 push @errors, "ERROR_short_password" if( $password && $minpw && $password ne '****' && (length($password) < $minpw) );
275 if (C4::Context->preference('ExtendedPatronAttributes')) {
276 $extended_patron_attributes = parse_extended_patron_attributes($input);
277 foreach my $attr (@$extended_patron_attributes) {
278 unless (C4::Members::Attributes::CheckUniqueness($attr->{code}, $attr->{value}, $borrowernumber)) {
279 push @errors, "ERROR_extended_unique_id_failed";
280 $template->param(ERROR_extended_unique_id_failed => "$attr->{code}/$attr->{value}");
286 if ( ($op eq 'modify' || $op eq 'insert' || $op eq 'save'|| $op eq 'duplicate') and ($step == 0 or $step == 3 )){
287 unless ($newdata{'dateexpiry'}){
288 my $arg2 = $newdata{'dateenrolled'} || C4::Dates->today('iso');
289 $newdata{'dateexpiry'} = GetExpiryDate($newdata{'categorycode'},$arg2);
293 if ( ( defined $input->param('SMSnumber') ) && ( $input->param('SMSnumber') ne $newdata{'mobile'} ) ) {
294 $newdata{smsalertnumber} = $input->param('SMSnumber');
297 ### Error checks should happen before this line.
298 $nok = $nok || scalar(@errors);
299 if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){
300 $debug and warn "$op dates: " . join "\t", map {"$_: $newdata{$_}"} qw(dateofbirth dateenrolled dateexpiry);
301 if ($op eq 'insert'){
302 # we know it's not a duplicate borrowernumber or there would already be an error
303 $borrowernumber = &AddMember(%newdata);
304 $newdata{'borrowernumber'} = $borrowernumber;
306 # If 'AutoEmailOpacUser' syspref is on, email user their account details from the 'notice' that matches the user's branchcode.
307 if ( C4::Context->preference("AutoEmailOpacUser") == 1 && $newdata{'userid'} && $newdata{'password'}) {
308 #look for defined primary email address, if blank - attempt to use borr.email and borr.emailpro instead
310 if (C4::Context->preference("AutoEmailPrimaryAddress") ne 'OFF' &&
311 $newdata{C4::Context->preference("AutoEmailPrimaryAddress")} =~ /\w\@\w/ ) {
312 $emailaddr = $newdata{C4::Context->preference("AutoEmailPrimaryAddress")}
314 elsif ($newdata{email} =~ /\w\@\w/) {
315 $emailaddr = $newdata{email}
317 elsif ($newdata{emailpro} =~ /\w\@\w/) {
318 $emailaddr = $newdata{emailpro}
320 elsif ($newdata{B_email} =~ /\w\@\w/) {
321 $emailaddr = $newdata{B_email}
323 # if we manage to find a valid email address, send notice
325 $newdata{emailaddr} = $emailaddr;
326 my $letter = getletter ('members', "ACCTDETAILS:$newdata{'branchcode'}") ;
327 # if $branch notice fails, then email a default notice instead.
328 $letter = getletter ('members', "ACCTDETAILS") if !$letter;
329 SendAlerts ( 'members' , \%newdata , $letter ) if $letter
333 if ($data{'organisations'}){
334 # need to add the members organisations
335 my @orgs=split(/\|/,$data{'organisations'});
336 add_member_orgs($borrowernumber,\@orgs);
338 if (C4::Context->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) {
339 C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $extended_patron_attributes);
341 if (C4::Context->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) {
342 C4::Form::MessagingPreferences::handle_form_action($input, { borrowernumber => $borrowernumber }, $template, 1, $newdata{'categorycode'});
344 } elsif ($op eq 'save'){
345 if ($NoUpdateLogin) {
346 delete $newdata{'password'};
347 delete $newdata{'userid'};
349 &ModMember(%newdata) unless scalar(keys %newdata) <= 1; # bug 4508 - avoid crash if we're not
350 # updating any columns in the borrowers table,
351 # which can happen if we're only editing the
352 # patron attributes or messaging preferences sections
353 if (C4::Context->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) {
354 C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $extended_patron_attributes);
356 if (C4::Context->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) {
357 C4::Form::MessagingPreferences::handle_form_action($input, { borrowernumber => $borrowernumber }, $template);
360 print scalar ($destination eq "circ") ?
361 $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber") :
362 $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber") ;
363 exit; # You can only send 1 redirect! After that, content or other headers don't matter.
367 print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$borrowernumber");
368 exit; # same as above
371 if ($nok or !$nodouble){
372 $op="add" if ($op eq "insert");
373 $op="modify" if ($op eq "save");
375 $template->param( updtype => ($op eq 'add' ?'I':'M')); # used to check for $op eq "insert"... but we just changed $op!
377 $template->param( step_1 => 1,step_2 => 1,step_3 => 1, step_4 => 1, step_5 => 1, step_6 => 1);
380 if (C4::Context->preference("IndependantBranches")) {
381 my $userenv = C4::Context->userenv;
382 if ($userenv->{flags} % 2 != 1 && $data{'branchcode'}){
383 unless ($userenv->{branch} eq $data{'branchcode'}){
384 print $input->redirect("/cgi-bin/koha/members/members-home.pl");
390 $template->param( updtype => 'I', step_1=>1, step_2=>1, step_3=>1, step_4=>1, step_5 => 1, step_6 => 1);
392 if ($op eq "modify") {
393 $template->param( updtype => 'M',modify => 1 );
394 $template->param( step_1=>1, step_2=>1, step_3=>1, step_4=>1, step_5 => 1, step_6 => 1) unless $step;
396 if ( $op eq "duplicate" ) {
397 $template->param( updtype => 'I' );
398 $template->param( step_1 => 1, step_2 => 1, step_3 => 1, step_4 => 1, step_5 => 1, step_6 => 1 ) unless $step;
401 $data{'cardnumber'}=fixup_cardnumber($data{'cardnumber'}) if $op eq 'add';
402 if(!defined($data{'sex'})){
403 $template->param( none => 1);
404 } elsif($data{'sex'} eq 'F'){
405 $template->param( female => 1);
406 } elsif ($data{'sex'} eq 'M'){
407 $template->param( male => 1);
409 $template->param( none => 1);
412 ##Now all the data to modify a member.
413 my ($categories,$labels)=ethnicitycategories();
415 my $ethnicitycategoriescount=$#{$categories};
417 if ($ethnicitycategoriescount>=0) {
418 $ethcatpopup = CGI::popup_menu(-name=>'ethnicity',
421 -values=>$categories,
422 -default=>$data{'ethnicity'},
424 $template->param(ethcatpopup => $ethcatpopup); # bad style, has to be fixed
428 my $no_categories = 1;
430 foreach (qw(C A S P I X)) {
431 my $action="WHERE category_type=?";
432 ($categories,$labels)=GetborCatFromCatType($_,$action);
433 if(scalar(@$categories) > 0){ $no_categories = 0; }
435 foreach my $cat (@$categories){
436 push @categoryloop,{'categorycode' => $cat,
437 'categoryname' => $labels->{$cat},
438 'categorycodeselected' => ((defined($borrower_data->{'categorycode'}) &&
439 $cat eq $borrower_data->{'categorycode'})
440 || (defined($categorycode) && $cat eq $categorycode)),
444 $typehash{'typename'}=$_;
445 my $typedescription = "typename_".$typehash{'typename'};
446 $typehash{'categoryloop'}=\@categoryloop;
447 push @typeloop,{'typename' => $_,
448 $typedescription => 1,
449 'categoryloop' => \@categoryloop};
451 $template->param('typeloop' => \@typeloop,
452 no_categories => $no_categories);
453 if($no_categories){ $no_add = 1; }
455 if ( $guarantorid ) {
456 $select_city = getidcity($data{city});
458 ($default_city=$select_city) if ($step eq 0);
459 if (!defined($select_city) or $select_city eq '' ){
460 $default_city = &getidcity($data{'city'});
463 my $city_arrayref = GetCities();
464 if (@{$city_arrayref} ) {
465 $template->param( city_cgipopup => 1);
467 if ($default_city) { # flag the current or default val
468 for my $city ( @{$city_arrayref} ) {
469 if ($default_city == $city->{cityid}) {
470 $city->{selected} = 1;
477 my $default_roadtype;
478 $default_roadtype=$data{'streettype'} ;
479 my($roadtypeid,$road_type)=GetRoadTypes();
480 $template->param( road_cgipopup => 1) if ($roadtypeid );
481 my $roadpopup = CGI::popup_menu(-name=>'streettype',
483 -values=>$roadtypeid,
486 -default=>$default_roadtype
489 my $default_borrowertitle;
490 $default_borrowertitle=$data{'title'} ;
491 my($borrowertitle)=GetTitles();
492 $template->param( title_cgipopup => 1) if ($borrowertitle);
493 my $borrotitlepopup = CGI::popup_menu(-name=>'title',
495 -values=>$borrowertitle,
497 -default=>$default_borrowertitle
500 my @relationships = split /,|\|/, C4::Context->preference('borrowerRelationship');
502 while (@relationships) {
503 my $relship = shift @relationships || '';
504 my %row = ('relationship' => $relship);
505 if (defined($data{'relationship'}) and $data{'relationship'} eq $relship) {
506 $row{'selected'}=' selected';
510 push(@relshipdata, \%row);
513 my %flags = ( 'gonenoaddress' => ['gonenoaddress' ],
515 'debarred' => ['debarred']);
519 foreach (keys(%flags)) {
521 my %row = ('key' => $key,
522 'name' => $flags{$key}[0]);
524 $row{'yes'}=' checked';
529 $row{'no'}=' checked';
531 push @flagdata,\%row;
539 my $onlymine=(C4::Context->preference('IndependantBranches') &&
540 C4::Context->userenv &&
541 C4::Context->userenv->{flags} % 2 !=1 &&
542 C4::Context->userenv->{branch}?1:0);
544 my $branches=GetBranches($onlymine);
547 for my $branch (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) {
548 push @select_branch,$branch;
549 $select_branches{$branch} = $branches->{$branch}->{'branchname'};
550 $default = C4::Context->userenv->{'branch'} if (C4::Context->userenv && C4::Context->userenv->{'branch'});
552 if(scalar(@select_branch) > 0){
553 # --------------------------------------------------------------------------------------------------------
554 #in modify mod :default value from $CGIbranch comes from borrowers table
555 #in add mod: default value come from branches table (ip correspendence)
556 if (defined ($data{'branchcode'}) and ( $op eq 'modify' || ( $op eq 'add' && $category_type eq 'C' ) )) {
557 $default = $data{'branchcode'};
559 $CGIbranch = CGI::scrolling_list(-id => 'branchcode',
560 -name => 'branchcode',
561 -values => \@select_branch,
562 -labels => \%select_branches,
566 -default => $default,
572 $template->param(no_branches => 1);
576 $template->param(no_categories => 1);
578 $template->param(no_add => $no_add);
579 my $CGIorganisations;
580 my $member_of_institution;
581 if (C4::Context->preference("memberofinstitution")){
582 my $organisations=get_institutions();
585 foreach my $organisation (keys %$organisations) {
586 push @orgs,$organisation;
587 $org_labels{$organisation}=$organisations->{$organisation}->{'surname'};
589 $member_of_institution=1;
591 $CGIorganisations = CGI::scrolling_list( -id => 'organisations',
592 -name => 'organisations',
593 -labels => \%org_labels,
601 # --------------------------------------------------------------------------------------------------------
603 my $CGIsort = buildCGIsort("Bsort1","sort1",$data{'sort1'});
605 $template->param(CGIsort1 => $CGIsort);
607 $template->param( sort1 => $data{'sort1'}); # shouldn't this be in an "else" statement like the 2nd one?
609 $CGIsort = buildCGIsort("Bsort2","sort2",$data{'sort2'});
611 $template->param(CGIsort2 => $CGIsort);
613 $template->param( sort2 => $data{'sort2'});
617 foreach my $error (@errors) {
618 $template->param($error) || $template->param( $error => 1);
620 $template->param(nok => 1);
623 #Formatting data for display
625 if (!defined($data{'dateenrolled'}) or $data{'dateenrolled'} eq ''){
626 $data{'dateenrolled'}=C4::Dates->today('iso');
628 if ( $op eq 'duplicate' ) {
629 $data{'dateenrolled'} = C4::Dates->today('iso');
630 $data{'dateexpiry'} = GetExpiryDate( $data{'categorycode'}, $data{'dateenrolled'} );
632 if (C4::Context->preference('uppercasesurnames')) {
633 $data{'surname'} =uc($data{'surname'} );
634 $data{'contactname'}=uc($data{'contactname'});
636 foreach (qw(dateenrolled dateexpiry dateofbirth)) {
637 $data{$_} = format_date($data{$_}); # back to syspref for display
638 $template->param( $_ => $data{$_});
641 if (C4::Context->preference('ExtendedPatronAttributes')) {
642 $template->param(ExtendedPatronAttributes => 1);
643 patron_attributes_form($template, $borrowernumber);
646 if (C4::Context->preference('EnhancedMessagingPreferences')) {
648 C4::Form::MessagingPreferences::set_form_values({ categorycode => $categorycode }, $template);
650 C4::Form::MessagingPreferences::set_form_values({ borrowernumber => $borrowernumber }, $template);
652 $template->param(SMSSendDriver => C4::Context->preference("SMSSendDriver"));
653 $template->param(SMSnumber => defined $data{'smsalertnumber'} ? $data{'smsalertnumber'} : $data{'mobile'});
656 $template->param( "showguarantor" => ($category_type=~/A|I|S|X/) ? 0 : 1); # associate with step to know where you are
657 $debug and warn "memberentry step: $step";
658 $template->param(%data);
659 $template->param( "step_$step" => 1) if $step; # associate with step to know where u are
660 $template->param( step => $step ) if $step; # associate with step to know where u are
661 $template->param( debug => $debug ) if $debug;
664 BorrowerMandatoryField => C4::Context->preference("BorrowerMandatoryField"),#field to test with javascript
665 category_type => $category_type,#to know the category type of the borrower
666 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
667 select_city => $select_city,
668 "$category_type" => 1,# associate with step to know where u are
669 destination => $destination,#to know wher u come from and wher u must go in redirect
670 check_member => $check_member,#to know if the borrower already exist(=>1) or not (=>0)
673 $template->param(CGIbranch=>$CGIbranch) if ($CGIbranch);
675 nodouble => $nodouble,
676 borrowernumber => $borrowernumber, #register number
677 guarantorid => ($borrower_data->{'guarantorid'} || $guarantorid),
678 ethcatpopup => $ethcatpopup,
679 relshiploop => \@relshipdata,
680 city_loop => $city_arrayref,
681 roadpopup => $roadpopup,
682 borrotitlepopup => $borrotitlepopup,
683 guarantorinfo => $guarantorinfo,
684 flagloop => \@flagdata,
685 dateformat => C4::Dates->new()->visual(),
686 C4::Context->preference('dateformat') => 1,
687 check_categorytype =>$check_categorytype,#to recover the category type with checkcategorytype function
688 category_type =>$category_type,
690 nok => $nok,#flag to konw if an error
691 memberofinstution => $member_of_institution,
692 CGIorganisations => $CGIorganisations,
693 NoUpdateLogin => $NoUpdateLogin
696 if(defined($data{'flags'})){
697 $template->param(flags=>$data{'flags'});
699 if(defined($data{'contacttitle'})){
700 $template->param("contacttitle_" . $data{'contacttitle'} => "SELECTED");
704 output_html_with_http_headers $input, $cookie, $template->output;
706 sub parse_extended_patron_attributes {
708 my @patron_attr = grep { /^patron_attr_\d+$/ } $input->param();
712 foreach my $key (@patron_attr) {
713 my $value = $input->param($key);
714 next unless defined($value) and $value ne '';
715 my $password = $input->param("${key}_password");
716 my $code = $input->param("${key}_code");
717 next if exists $dups{$code}->{$value};
718 $dups{$code}->{$value} = 1;
719 push @attr, { code => $code, value => $value, password => $password };
724 sub patron_attributes_form {
725 my $template = shift;
726 my $borrowernumber = shift;
728 my @types = C4::Members::AttributeTypes::GetAttributeTypes();
729 if (scalar(@types) == 0) {
730 $template->param(no_patron_attribute_types => 1);
733 my $attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
735 # map patron's attributes into a more convenient structure
737 foreach my $attr (@$attributes) {
738 push @{ $attr_hash{$attr->{code}} }, $attr;
741 my @attribute_loop = ();
743 foreach my $type_code (map { $_->{code} } @types) {
744 my $attr_type = C4::Members::AttributeTypes->fetch($type_code);
746 code => $attr_type->code(),
747 description => $attr_type->description(),
748 repeatable => $attr_type->repeatable(),
749 password_allowed => $attr_type->password_allowed(),
750 category => $attr_type->authorised_value_category(),
753 if (exists $attr_hash{$attr_type->code()}) {
754 foreach my $attr (@{ $attr_hash{$attr_type->code()} }) {
755 my $newentry = { map { $_ => $entry->{$_} } %$entry };
756 $newentry->{value} = $attr->{value};
757 $newentry->{password} = $attr->{password};
758 $newentry->{use_dropdown} = 0;
759 if ($attr_type->authorised_value_category()) {
760 $newentry->{use_dropdown} = 1;
761 $newentry->{auth_val_loop} = GetAuthorisedValues($attr_type->authorised_value_category(), $attr->{value});
764 $newentry->{form_id} = "patron_attr_$i";
765 #use Data::Dumper; die Dumper($entry) if $entry->{use_dropdown};
766 push @attribute_loop, $newentry;
770 my $newentry = { map { $_ => $entry->{$_} } %$entry };
771 if ($attr_type->authorised_value_category()) {
772 $newentry->{use_dropdown} = 1;
773 $newentry->{auth_val_loop} = GetAuthorisedValues($attr_type->authorised_value_category());
775 $newentry->{form_id} = "patron_attr_$i";
776 push @attribute_loop, $newentry;
779 $template->param(patron_attributes => \@attribute_loop);