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');
107 $expiration = $expiration ? output_pref( dt_from_string($expiration), 'iso' ) : undef;
111 borrowernumber => $borrowernumber,
113 comment => $input->param('debarred_comment'),
114 expiration => $expiration,
119 $template->param("uppercasesurnames" => C4::Context->preference('uppercasesurnames'));
121 my $minpw = C4::Context->preference('minPasswordLength');
122 $template->param("minPasswordLength" => $minpw);
124 # function to designate mandatory fields (visually with css)
125 my $check_BorrowerMandatoryField=C4::Context->preference("BorrowerMandatoryField");
126 my @field_check=split(/\|/,$check_BorrowerMandatoryField);
127 foreach (@field_check) {
128 $template->param( "mandatory$_" => 1);
130 # we'll need this, later.
131 my $dateofbirthmandatory = (scalar grep {$_ eq "dateofbirth"} @field_check) ? 1 : 0;
132 # function to designate unwanted fields
133 my $check_BorrowerUnwantedField=C4::Context->preference("BorrowerUnwantedField");
134 @field_check=split(/\|/,$check_BorrowerUnwantedField);
135 foreach (@field_check) {
137 $template->param( "no$_" => 1);
139 $template->param( "add" => 1 ) if ( $op eq 'add' );
140 $template->param( "duplicate" => 1 ) if ( $op eq 'duplicate' );
141 $template->param( "checked" => 1 ) if ( defined($nodouble) && $nodouble eq 1 );
142 ( $borrower_data = GetMember( 'borrowernumber' => $borrowernumber ) ) if ( $op eq 'modify' or $op eq 'save' or $op eq 'duplicate' );
143 my $categorycode = $input->param('categorycode') || $borrower_data->{'categorycode'};
144 my $category_type = $input->param('category_type') || '';
146 $template->{VARS}->{'type_only'} = 1;
148 my $new_c_type = $category_type; #if we have input param, then we've already chosen the cat_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$/,
203 qr/^select_roadtype$/,
206 qr/^setting_extended_patron_attributes$/,
207 qr/^setting_messaging_prefs$/,
215 for my $regexp (@keys_to_delete) {
216 for (keys %newdata) {
217 delete($newdata{$_}) if /$regexp/;
222 #############test for member being unique #############
223 if ( ( $op eq 'insert' ) and !$nodouble ) {
224 my $category_type_send;
225 if ( $category_type eq 'I' ) {
226 $category_type_send = $category_type;
228 my $check_category; # recover the category code of the doublon suspect borrowers
229 # ($result,$categorycode) = checkuniquemember($collectivity,$surname,$firstname,$dateofbirth)
230 ( $check_member, $check_category ) = checkuniquemember
(
232 ( $newdata{surname
} ?
$newdata{surname
} : $data{surname
} ),
233 ( $newdata{firstname
} ?
$newdata{firstname
} : $data{firstname
} ),
234 ( $newdata{dateofbirth
} ?
$newdata{dateofbirth
} : $data{dateofbirth
} )
236 if ( !$check_member ) {
240 # recover the category type if the borrowers is a doublon
241 if ($check_category) {
242 my $tmpborrowercategory = GetBorrowercategory
($check_category);
243 $check_categorytype = $tmpborrowercategory->{'category_type'};
247 #recover all data from guarantor address phone ,fax...
248 if ( $guarantorid and ( $category_type eq 'C' || $category_type eq 'P' )) {
249 if (my $guarantordata=GetMember
(borrowernumber
=> $guarantorid)) {
250 $guarantorinfo=$guarantordata->{'surname'}." , ".$guarantordata->{'firstname'};
251 $newdata{'contactfirstname'}= $guarantordata->{'firstname'};
252 $newdata{'contactname'} = $guarantordata->{'surname'};
253 $newdata{'contacttitle'} = $guarantordata->{'title'};
254 if ( $op eq 'add' ) {
255 foreach (qw(streetnumber address streettype address2
256 zipcode country city state phone phonepro mobile fax email emailpro branchcode
257 B_streetnumber B_streettype B_address B_address2
258 B_city B_state B_zipcode B_country B_email B_phone)) {
259 $newdata{$_} = $guarantordata->{$_};
265 ###############test to take the right zipcode, country and city name ##############
266 # set only if parameter was passed from the form
267 $newdata{'city'} = $input->param('city') if defined($input->param('city'));
268 $newdata{'zipcode'} = $input->param('zipcode') if defined($input->param('zipcode'));
269 $newdata{'country'} = $input->param('country') if defined($input->param('country'));
271 #builds default userid
272 if ( (defined $newdata{'userid'}) && ($newdata{'userid'} eq '')){
273 if ( ( defined $newdata{'firstname'} ) && ( defined $newdata{'surname'} ) ) {
274 # Full page edit, firstname and surname input zones are present
275 $newdata{'userid'} = Generate_Userid
( $borrowernumber, $newdata{'firstname'}, $newdata{'surname'} );
277 elsif ( ( defined $data{'firstname'} ) && ( defined $data{'surname'} ) ) {
278 # Partial page edit (access through "Details"/"Library details" tab), firstname and surname input zones are not used
279 # Still, if the userid field is erased, we can create a new userid with available firstname and surname
280 $newdata{'userid'} = Generate_Userid
( $borrowernumber, $data{'firstname'}, $data{'surname'} );
283 $newdata{'userid'} = $data{'userid'};
287 $debug and warn join "\t", map {"$_: $newdata{$_}"} qw(dateofbirth dateenrolled dateexpiry);
288 my $extended_patron_attributes = ();
289 if ($op eq 'save' || $op eq 'insert'){
290 # If the cardnumber is blank, treat it as null.
291 $newdata{'cardnumber'} = undef if $newdata{'cardnumber'} =~ /^\s*$/;
293 if (checkcardnumber
($newdata{cardnumber
},$newdata{borrowernumber
})){
294 push @errors, 'ERROR_cardnumber';
296 if ($newdata{dateofbirth
} && $dateofbirthmandatory) {
297 my $age = GetAge
($newdata{dateofbirth
});
298 my $borrowercategory=GetBorrowercategory
($newdata{'categorycode'});
299 my ($low,$high) = ($borrowercategory->{'dateofbirthrequired'}, $borrowercategory->{'upperagelimit'});
300 if (($high && ($age > $high)) or ($age < $low)) {
301 push @errors, 'ERROR_age_limitations';
302 $template->param( age_low
=> $low);
303 $template->param( age_high
=> $high);
307 if($newdata{surname
} && C4
::Context
->preference('uppercasesurnames')) {
308 $newdata{'surname'} = uc($newdata{'surname'});
311 if (C4
::Context
->preference("IndependentBranches")) {
312 if ($userenv && $userenv->{flags
} % 2 != 1){
313 $debug and print STDERR
" $newdata{'branchcode'} : ".$userenv->{flags
}.":".$userenv->{branch
};
314 unless (!$newdata{'branchcode'} || $userenv->{branch
} eq $newdata{'branchcode'}){
315 push @errors, "ERROR_branch";
319 # Check if the userid is unique
320 unless (Check_Userid
($newdata{'userid'},$borrowernumber)) {
321 push @errors, "ERROR_login_exist";
324 my $password = $input->param('password');
325 my $password2 = $input->param('password2');
326 push @errors, "ERROR_password_mismatch" if ( $password ne $password2 );
327 push @errors, "ERROR_short_password" if( $password && $minpw && $password ne '****' && (length($password) < $minpw) );
329 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
330 $extended_patron_attributes = parse_extended_patron_attributes
($input);
331 foreach my $attr (@
$extended_patron_attributes) {
332 unless (C4
::Members
::Attributes
::CheckUniqueness
($attr->{code
}, $attr->{value
}, $borrowernumber)) {
333 push @errors, "ERROR_extended_unique_id_failed";
334 $template->param(ERROR_extended_unique_id_failed_value
=> "$attr->{code}/$attr->{value}");
340 if ( ($op eq 'modify' || $op eq 'insert' || $op eq 'save'|| $op eq 'duplicate') and ($step == 0 or $step == 3 )){
341 unless ($newdata{'dateexpiry'}){
342 my $arg2 = $newdata{'dateenrolled'} || C4
::Dates
->today('iso');
343 $newdata{'dateexpiry'} = GetExpiryDate
($newdata{'categorycode'},$arg2);
347 if ( ( defined $input->param('SMSnumber') ) && ( $input->param('SMSnumber') ne $newdata{'mobile'} ) ) {
348 $newdata{smsalertnumber
} = $input->param('SMSnumber');
351 ### Error checks should happen before this line.
352 $nok = $nok || scalar(@errors);
353 if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){
354 $debug and warn "$op dates: " . join "\t", map {"$_: $newdata{$_}"} qw(dateofbirth dateenrolled dateexpiry);
355 if ($op eq 'insert'){
356 # we know it's not a duplicate borrowernumber or there would already be an error
357 $borrowernumber = &AddMember
(%newdata);
358 $newdata{'borrowernumber'} = $borrowernumber;
360 # If 'AutoEmailOpacUser' syspref is on, email user their account details from the 'notice' that matches the user's branchcode.
361 if ( C4
::Context
->preference("AutoEmailOpacUser") == 1 && $newdata{'userid'} && $newdata{'password'}) {
362 #look for defined primary email address, if blank - attempt to use borr.email and borr.emailpro instead
364 if (C4
::Context
->preference("AutoEmailPrimaryAddress") ne 'OFF' &&
365 $newdata{C4
::Context
->preference("AutoEmailPrimaryAddress")} =~ /\w\@\w/ ) {
366 $emailaddr = $newdata{C4
::Context
->preference("AutoEmailPrimaryAddress")}
368 elsif ($newdata{email
} =~ /\w\@\w/) {
369 $emailaddr = $newdata{email
}
371 elsif ($newdata{emailpro
} =~ /\w\@\w/) {
372 $emailaddr = $newdata{emailpro
}
374 elsif ($newdata{B_email
} =~ /\w\@\w/) {
375 $emailaddr = $newdata{B_email
}
377 # if we manage to find a valid email address, send notice
379 $newdata{emailaddr
} = $emailaddr;
382 $err = SendAlerts
( 'members', \
%newdata, "ACCTDETAILS" );
385 $template->param(error_alert
=> $@
);
386 } elsif ( ref($err) eq "HASH" && defined $err->{error
} and $err->{error
} eq "no_email" ) {
387 $template->{VARS
}->{'error_alert'} = "no_email";
389 $template->{VARS
}->{'info_alert'} = 1;
394 if ($data{'organisations'}){
395 # need to add the members organisations
396 my @orgs=split(/\|/,$data{'organisations'});
397 add_member_orgs
($borrowernumber,\
@orgs);
399 if (C4
::Context
->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) {
400 C4
::Members
::Attributes
::SetBorrowerAttributes
($borrowernumber, $extended_patron_attributes);
402 if (C4
::Context
->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) {
403 C4
::Form
::MessagingPreferences
::handle_form_action
($input, { borrowernumber
=> $borrowernumber }, $template, 1, $newdata{'categorycode'});
405 } elsif ($op eq 'save'){
406 if ($NoUpdateLogin) {
407 delete $newdata{'password'};
408 delete $newdata{'userid'};
410 &ModMember
(%newdata) unless scalar(keys %newdata) <= 1; # bug 4508 - avoid crash if we're not
411 # updating any columns in the borrowers table,
412 # which can happen if we're only editing the
413 # patron attributes or messaging preferences sections
414 if (C4
::Context
->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) {
415 C4
::Members
::Attributes
::SetBorrowerAttributes
($borrowernumber, $extended_patron_attributes);
417 if (C4
::Context
->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) {
418 C4
::Form
::MessagingPreferences
::handle_form_action
($input, { borrowernumber
=> $borrowernumber }, $template);
421 print scalar ($destination eq "circ") ?
422 $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber") :
423 $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber") ;
424 exit; # You can only send 1 redirect! After that, content or other headers don't matter.
428 print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$borrowernumber");
429 exit; # same as above
432 if ($nok or !$nodouble){
433 $op="add" if ($op eq "insert");
434 $op="modify" if ($op eq "save");
436 $template->param( updtype
=> ($op eq 'add' ?
'I':'M')); # used to check for $op eq "insert"... but we just changed $op!
438 $template->param( step_1
=> 1,step_2
=> 1,step_3
=> 1, step_4
=> 1, step_5
=> 1, step_6
=> 1);
441 if (C4
::Context
->preference("IndependentBranches")) {
442 my $userenv = C4
::Context
->userenv;
443 if ($userenv->{flags
} % 2 != 1 && $data{'branchcode'}){
444 unless ($userenv->{branch
} eq $data{'branchcode'}){
445 print $input->redirect("/cgi-bin/koha/members/members-home.pl");
451 $template->param( updtype
=> 'I', step_1
=>1, step_2
=>1, step_3
=>1, step_4
=>1, step_5
=> 1, step_6
=> 1);
453 if ($op eq "modify") {
454 $template->param( updtype
=> 'M',modify
=> 1 );
455 $template->param( step_1
=>1, step_2
=>1, step_3
=>1, step_4
=>1, step_5
=> 1, step_6
=> 1) unless $step;
457 $template->param( categorycode
=> $borrower_data->{'categorycode'} );
460 if ( $op eq "duplicate" ) {
461 $template->param( updtype
=> 'I' );
462 $template->param( step_1
=> 1, step_2
=> 1, step_3
=> 1, step_4
=> 1, step_5
=> 1, step_6
=> 1 ) unless $step;
463 $data{'cardnumber'} = "";
466 $data{'cardnumber'}=fixup_cardnumber
($data{'cardnumber'}) if ( ( $op eq 'add' ) or ( $op eq 'duplicate' ) );
467 if(!defined($data{'sex'})){
468 $template->param( none
=> 1);
469 } elsif($data{'sex'} eq 'F'){
470 $template->param( female
=> 1);
471 } elsif ($data{'sex'} eq 'M'){
472 $template->param( male
=> 1);
474 $template->param( none
=> 1);
477 ##Now all the data to modify a member.
478 my ($categories,$labels)=ethnicitycategories
();
480 my $ethnicitycategoriescount=$#{$categories};
482 if ($ethnicitycategoriescount>=0) {
483 $ethcatpopup = CGI
::popup_menu
(-name
=>'ethnicity',
486 -values=>$categories,
487 -default=>$data{'ethnicity'},
489 $template->param(ethcatpopup
=> $ethcatpopup); # bad style, has to be fixed
493 my $no_categories = 1;
495 foreach (qw(C A S P I X)) {
496 my $action="WHERE category_type=?";
497 ($categories,$labels)=GetborCatFromCatType
($_,$action);
498 if(scalar(@
$categories) > 0){ $no_categories = 0; }
500 foreach my $cat (@
$categories){
501 push @categoryloop,{'categorycode' => $cat,
502 'categoryname' => $labels->{$cat},
503 'categorycodeselected' => ((defined($borrower_data->{'categorycode'}) &&
504 $cat eq $borrower_data->{'categorycode'})
505 || (defined($categorycode) && $cat eq $categorycode)),
509 $typehash{'typename'}=$_;
510 my $typedescription = "typename_".$typehash{'typename'};
511 $typehash{'categoryloop'}=\
@categoryloop;
512 push @typeloop,{'typename' => $_,
513 $typedescription => 1,
514 'categoryloop' => \
@categoryloop};
516 $template->param('typeloop' => \
@typeloop,
517 no_categories
=> $no_categories);
518 if($no_categories){ $no_add = 1; }
520 if ( $guarantorid ) {
521 $select_city = getidcity
($data{city
});
523 ($default_city=$select_city) if ($step eq 0);
524 if (!defined($select_city) or $select_city eq '' ){
525 $default_city = &getidcity
($data{'city'});
528 my $city_arrayref = GetCities
();
529 if (@
{$city_arrayref} ) {
530 $template->param( city_cgipopup
=> 1);
532 if ($default_city) { # flag the current or default val
533 for my $city ( @
{$city_arrayref} ) {
534 if ($default_city == $city->{cityid
}) {
535 $city->{selected
} = 1;
542 my $default_roadtype;
543 $default_roadtype=$data{'streettype'} ;
544 my($roadtypeid,$road_type)=GetRoadTypes
();
545 $template->param( road_cgipopup
=> 1) if ($roadtypeid );
546 my $roadpopup = CGI
::popup_menu
(-name
=>'streettype',
548 -values=>$roadtypeid,
551 -default=>$default_roadtype
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 my $CGIorganisations;
623 my $member_of_institution;
624 if (C4
::Context
->preference("memberofinstitution")){
625 my $organisations=get_institutions
();
628 foreach my $organisation (keys %$organisations) {
629 push @orgs,$organisation;
630 $org_labels{$organisation}=$organisations->{$organisation}->{'surname'};
632 $member_of_institution=1;
634 $CGIorganisations = CGI
::scrolling_list
( -id
=> 'organisations',
635 -name
=> 'organisations',
636 -labels
=> \
%org_labels,
644 # --------------------------------------------------------------------------------------------------------
646 my $CGIsort = buildCGIsort
("Bsort1","sort1",$data{'sort1'});
648 $template->param(CGIsort1
=> $CGIsort);
650 $template->param( sort1
=> $data{'sort1'}); # shouldn't this be in an "else" statement like the 2nd one?
652 $CGIsort = buildCGIsort
("Bsort2","sort2",$data{'sort2'});
654 $template->param(CGIsort2
=> $CGIsort);
656 $template->param( sort2
=> $data{'sort2'});
660 foreach my $error (@errors) {
661 $template->param($error) || $template->param( $error => 1);
663 $template->param(nok
=> 1);
666 #Formatting data for display
668 if (!defined($data{'dateenrolled'}) or $data{'dateenrolled'} eq ''){
669 $data{'dateenrolled'}=C4
::Dates
->today('iso');
671 if ( $op eq 'duplicate' ) {
672 $data{'dateenrolled'} = C4
::Dates
->today('iso');
673 $data{'dateexpiry'} = GetExpiryDate
( $data{'categorycode'}, $data{'dateenrolled'} );
675 if (C4
::Context
->preference('uppercasesurnames')) {
676 $data{'surname'} &&= uc( $data{'surname'} );
677 $data{'contactname'} &&= uc( $data{'contactname'} );
680 foreach (qw(dateenrolled dateexpiry dateofbirth)) {
681 $data{$_} = format_date
($data{$_}); # back to syspref for display
682 $template->param( $_ => $data{$_});
685 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
686 $template->param(ExtendedPatronAttributes
=> 1);
687 patron_attributes_form
($template, $borrowernumber);
690 if (C4
::Context
->preference('EnhancedMessagingPreferences')) {
692 C4
::Form
::MessagingPreferences
::set_form_values
({ categorycode
=> $categorycode }, $template);
694 C4
::Form
::MessagingPreferences
::set_form_values
({ borrowernumber
=> $borrowernumber }, $template);
696 $template->param(SMSSendDriver
=> C4
::Context
->preference("SMSSendDriver"));
697 $template->param(SMSnumber
=> defined $data{'smsalertnumber'} ?
$data{'smsalertnumber'} : $data{'mobile'});
698 $template->param(TalkingTechItivaPhone
=> C4
::Context
->preference("TalkingTechItivaPhoneNotification"));
701 $template->param( "showguarantor" => ($category_type=~/A|I|S|X/) ?
0 : 1); # associate with step to know where you are
702 $debug and warn "memberentry step: $step";
703 $template->param(%data);
704 $template->param( "step_$step" => 1) if $step; # associate with step to know where u are
705 $template->param( step
=> $step ) if $step; # associate with step to know where u are
708 BorrowerMandatoryField
=> C4
::Context
->preference("BorrowerMandatoryField"),#field to test with javascript
709 category_type
=> $category_type,#to know the category type of the borrower
710 select_city
=> $select_city,
711 "$category_type" => 1,# associate with step to know where u are
712 destination
=> $destination,#to know wher u come from and wher u must go in redirect
713 check_member
=> $check_member,#to know if the borrower already exist(=>1) or not (=>0)
716 $template->param( branchloop
=> $branchloop ) if ( $branchloop );
718 nodouble
=> $nodouble,
719 borrowernumber
=> $borrowernumber, #register number
720 guarantorid
=> ($borrower_data->{'guarantorid'} || $guarantorid),
721 ethcatpopup
=> $ethcatpopup,
722 relshiploop
=> \
@relshipdata,
723 city_loop
=> $city_arrayref,
724 roadpopup
=> $roadpopup,
725 borrotitlepopup
=> $borrotitlepopup,
726 guarantorinfo
=> $guarantorinfo,
727 flagloop
=> \
@flagdata,
728 check_categorytype
=>$check_categorytype,#to recover the category type with checkcategorytype function
729 category_type
=>$category_type,
731 nok
=> $nok,#flag to konw if an error
732 memberofinstution
=> $member_of_institution,
733 CGIorganisations
=> $CGIorganisations,
734 NoUpdateLogin
=> $NoUpdateLogin
737 if(defined($data{'flags'})){
738 $template->param(flags
=>$data{'flags'});
740 if(defined($data{'contacttitle'})){
741 $template->param("contacttitle_" . $data{'contacttitle'} => "SELECTED");
745 output_html_with_http_headers
$input, $cookie, $template->output;
747 sub parse_extended_patron_attributes
{
749 my @patron_attr = grep { /^patron_attr_\d+$/ } $input->param();
753 foreach my $key (@patron_attr) {
754 my $value = $input->param($key);
755 next unless defined($value) and $value ne '';
756 my $password = $input->param("${key}_password");
757 my $code = $input->param("${key}_code");
758 next if exists $dups{$code}->{$value};
759 $dups{$code}->{$value} = 1;
760 push @attr, { code
=> $code, value
=> $value, password
=> $password };
765 sub patron_attributes_form
{
766 my $template = shift;
767 my $borrowernumber = shift;
769 my @types = C4
::Members
::AttributeTypes
::GetAttributeTypes
();
770 if (scalar(@types) == 0) {
771 $template->param(no_patron_attribute_types
=> 1);
774 my $attributes = C4
::Members
::Attributes
::GetBorrowerAttributes
($borrowernumber);
775 my @classes = uniq
( map {$_->{class}} @
$attributes );
776 @classes = sort @classes;
778 # map patron's attributes into a more convenient structure
780 foreach my $attr (@
$attributes) {
781 push @
{ $attr_hash{$attr->{code
}} }, $attr;
784 my @attribute_loop = ();
787 foreach my $type_code (map { $_->{code
} } @types) {
788 my $attr_type = C4
::Members
::AttributeTypes
->fetch($type_code);
790 class => $attr_type->class(),
791 code
=> $attr_type->code(),
792 description
=> $attr_type->description(),
793 repeatable
=> $attr_type->repeatable(),
794 password_allowed
=> $attr_type->password_allowed(),
795 category
=> $attr_type->authorised_value_category(),
796 category_code
=> $attr_type->category_code(),
799 if (exists $attr_hash{$attr_type->code()}) {
800 foreach my $attr (@
{ $attr_hash{$attr_type->code()} }) {
801 my $newentry = { map { $_ => $entry->{$_} } %$entry };
802 $newentry->{value
} = $attr->{value
};
803 $newentry->{password
} = $attr->{password
};
804 $newentry->{use_dropdown
} = 0;
805 if ($attr_type->authorised_value_category()) {
806 $newentry->{use_dropdown
} = 1;
807 $newentry->{auth_val_loop
} = GetAuthorisedValues
($attr_type->authorised_value_category(), $attr->{value
});
810 $newentry->{form_id
} = "patron_attr_$i";
811 push @
{$items_by_class{$attr_type->class()}}, $newentry;
815 my $newentry = { map { $_ => $entry->{$_} } %$entry };
816 if ($attr_type->authorised_value_category()) {
817 $newentry->{use_dropdown
} = 1;
818 $newentry->{auth_val_loop
} = GetAuthorisedValues
($attr_type->authorised_value_category());
820 $newentry->{form_id
} = "patron_attr_$i";
821 push @
{$items_by_class{$attr_type->class()}}, $newentry;
824 while ( my ($class, @items) = each %items_by_class ) {
825 my $lib = GetAuthorisedValueByCode
( 'PA_CLASS', $class ) || $class;
826 push @attribute_loop, {
833 $template->param(patron_attributes
=> \
@attribute_loop);