3 # Copyright 2006 SAN OUEST PROVENCE et Paul POULAIN
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 # use Digest::MD5 qw(md5_base64);
33 use C4
::Members
::Attributes
;
34 use C4
::Members
::AttributeTypes
;
36 use C4
::Dates qw
/format_date format_date_in_iso/;
40 use C4
::Branch
; # GetBranches
41 use C4
::Form
::MessagingPreferences
;
46 $debug = $ENV{DEBUG} || 0;
50 ($debug) or $debug = $input->param('debug') || 0;
53 my $dbh = C4::Context->dbh;
55 my ($template, $loggedinuser, $cookie)
56 = get_template_and_user({template_name => "members/memberentrygen.tmpl",
60 flagsrequired => {borrowers => 1},
61 debug => ($debug) ? 1 : 0,
63 my $guarantorid = $input->param('guarantorid');
64 my $borrowernumber = $input->param('borrowernumber');
65 my $actionType = $input->param('actionType') || '';
66 my $modify = $input->param('modify');
67 my $delete = $input->param('delete');
68 my $op = $input->param('op');
69 my $destination = $input->param('destination');
70 my $cardnumber = $input->param('cardnumber');
71 my $check_member = $input->param('check_member');
72 my $nodouble = $input->param('nodouble');
73 $nodouble = 1 if $op eq 'modify'; # FIXME hack to represent fact that if we're
74 # modifying an existing patron, it ipso facto
75 # isn't a duplicate. Marking FIXME because this
76 # script needs to be refactored.
77 my $select_city = $input->param('select_city');
78 my $nok = $input->param('nok');
79 my $guarantorinfo = $input->param('guarantorinfo');
80 my $step = $input->param('step') || 0;
83 # $check_categorytype contains the value of duplicate borrowers category type to redirect in good template in step =2
84 my $check_categorytype=$input->param('check_categorytype');
85 # NOTE: Alert for ethnicity and ethnotes fields, they are invalid in all borrowers form
88 my $userenv = C4::Context->userenv;
90 $template->param("uppercasesurnames" => C4::Context->preference('uppercasesurnames'));
92 my $minpw = C4::Context->preference('minPasswordLength');
93 $template->param("minPasswordLength" => $minpw);
95 # function to designate mandatory fields (visually with css)
96 my $check_BorrowerMandatoryField=C4::Context->preference("BorrowerMandatoryField");
97 my @field_check=split(/\|/,$check_BorrowerMandatoryField);
98 foreach (@field_check) {
99 $template->param( "mandatory$_" => 1);
101 $template->param("add"=>1) if ($op eq 'add');
102 $template->param("checked" => 1) if (defined($nodouble) && $nodouble eq 1);
103 ($borrower_data = GetMember( 'borrowernumber'=>$borrowernumber )) if ($op eq 'modify' or $op eq 'save');
104 my $categorycode = $input->param('categorycode') || $borrower_data->{'categorycode'};
105 my $category_type = $input->param('category_type');
106 my $new_c_type = $category_type; #if we have input param, then we've already chosen the cat_type.
107 unless ($category_type or !($categorycode)){
108 my $borrowercategory = GetBorrowercategory($categorycode);
109 $category_type = $borrowercategory->{'category_type'};
110 my $category_name = $borrowercategory->{'description'};
111 $template->param("categoryname"=>$category_name);
113 $category_type="A" unless $category_type; # FIXME we should display a error message instead of a 500 error !
115 # if a add or modify is requested => check validity of data.
116 %data = %$borrower_data if ($borrower_data);
118 # initialize %newdata
119 my %newdata; # comes from $input->param()
120 if ($op eq 'insert' || $op eq 'modify' || $op eq 'save') {
121 my @names= ($borrower_data && $op ne 'save') ? keys %$borrower_data : $input->param();
122 foreach my $key (@names) {
123 if (defined $input->param($key)) {
124 $newdata{$key} = $input->param($key);
125 $newdata{$key} =~ s/\"/"/g unless $key eq 'borrowernotes' or $key eq 'opacnote';
128 my $dateobject = C4::Dates->new();
129 my $syspref = $dateobject->regexp(); # same syspref format for all 3 dates
130 my $iso = $dateobject->regexp('iso'); #
131 foreach (qw(dateenrolled dateexpiry dateofbirth)) {
132 next unless exists $newdata{$_};
133 my $userdate = $newdata{$_} or next;
134 if ($userdate =~ /$syspref/) {
135 $newdata{$_} = format_date_in_iso
($userdate); # if they match syspref format, then convert to ISO
136 } elsif ($userdate =~ /$iso/) {
137 warn "Date $_ ($userdate) is already in ISO format";
139 ($userdate eq '0000-00-00') and warn "Data error: $_ is '0000-00-00'";
140 $template->param( "ERROR_$_" => 1 ); # else ERROR!
141 push(@errors,"ERROR_$_");
144 # check permission to modify login info.
145 if (ref($borrower_data) && ($borrower_data->{'category_type'} eq 'S') && ! (C4
::Auth
::haspermission
($userenv->{'id'},{'staffaccess'=>1})) ) {
150 # remove keys from %newdata that ModMember() doesn't like
152 my @keys_to_delete = (
153 qr/^BorrowerMandatoryField$/,
160 qr/^select_roadtype$/,
163 qr/^setting_extended_patron_attributes$/,
164 qr/^setting_messaging_prefs$/,
172 for my $regexp (@keys_to_delete) {
173 for (keys %newdata) {
174 delete($newdata{$_}) if /$regexp/;
179 #############test for member being unique #############
180 if (($op eq 'insert') and !$nodouble){
181 my $category_type_send=$category_type if ($category_type eq 'I');
182 my $check_category; # recover the category code of the doublon suspect borrowers
183 # ($result,$categorycode) = checkuniquemember($collectivity,$surname,$firstname,$dateofbirth)
184 ($check_member,$check_category) = checkuniquemember
(
186 ($newdata{surname
} ?
$newdata{surname
} : $data{surname
} ),
187 ($newdata{firstname
} ?
$newdata{firstname
} : $data{firstname
} ),
188 ($newdata{dateofbirth
} ?
$newdata{dateofbirth
} : $data{dateofbirth
})
193 # recover the category type if the borrowers is a doublon
194 if ($check_category) {
195 my $tmpborrowercategory=GetBorrowercategory
($check_category);
196 $check_categorytype=$tmpborrowercategory->{'category_type'};
200 #recover all data from guarantor address phone ,fax...
201 if ( defined($guarantorid) and
202 ( $category_type eq 'C' || $category_type eq 'P' ) and
203 $guarantorid ne '' and
204 $guarantorid ne '0' ) {
205 if (my $guarantordata=GetMember
(borrowernumber
=> $guarantorid)) {
206 $guarantorinfo=$guarantordata->{'surname'}." , ".$guarantordata->{'firstname'};
207 if ( !defined($data{'contactname'}) or $data{'contactname'} eq '' or
208 $data{'contactname'} ne $guarantordata->{'surname'} ) {
209 $newdata{'contactfirstname'}= $guarantordata->{'firstname'};
210 $newdata{'contactname'} = $guarantordata->{'surname'};
211 $newdata{'contacttitle'} = $guarantordata->{'title'};
212 foreach (qw(streetnumber address streettype address2
213 zipcode country city phone phonepro mobile fax email emailpro branchcode)) {
214 $newdata{$_} = $guarantordata->{$_};
220 ###############test to take the right zipcode, country and city name ##############
221 if (!defined($guarantorid) or $guarantorid eq '' or $guarantorid eq '0') {
222 # set only if parameter was passed from the form
223 $newdata{'city'} = $input->param('city') if defined($input->param('city'));
224 $newdata{'zipcode'} = $input->param('zipcode') if defined($input->param('zipcode'));
225 $newdata{'country'} = $input->param('country') if defined($input->param('country'));
228 #builds default userid
229 if ( (defined $newdata{'userid'}) && ($newdata{'userid'} eq '')){
230 $newdata{'userid'} = Generate_Userid
($borrowernumber, $newdata{'firstname'}, $newdata{'surname'});
233 $debug and warn join "\t", map {"$_: $newdata{$_}"} qw(dateofbirth dateenrolled dateexpiry);
234 my $extended_patron_attributes = ();
235 if ($op eq 'save' || $op eq 'insert'){
236 if (checkcardnumber
($newdata{cardnumber
},$newdata{borrowernumber
})){
237 push @errors, 'ERROR_cardnumber';
239 my $dateofbirthmandatory = (scalar grep {$_ eq "dateofbirth"} @field_check) ?
1 : 0;
240 if ($newdata{dateofbirth
} && $dateofbirthmandatory) {
241 my $age = GetAge
($newdata{dateofbirth
});
242 my $borrowercategory=GetBorrowercategory
($newdata{'categorycode'});
243 my ($low,$high) = ($borrowercategory->{'dateofbirthrequired'}, $borrowercategory->{'upperagelimit'});
244 if (($high && ($age > $high)) or ($age < $low)) {
245 push @errors, 'ERROR_age_limitations';
246 $template->param('ERROR_age_limitations' => "$low to $high");
250 if($newdata{surname
} && C4
::Context
->preference('uppercasesurnames')) {
251 $newdata{'surname'} = uc($newdata{'surname'});
254 if (C4
::Context
->preference("IndependantBranches")) {
255 if ($userenv && $userenv->{flags
} % 2 != 1){
256 $debug and print STDERR
" $newdata{'branchcode'} : ".$userenv->{flags
}.":".$userenv->{branch
};
257 unless (!$newdata{'branchcode'} || $userenv->{branch
} eq $newdata{'branchcode'}){
258 push @errors, "ERROR_branch";
262 # Check if the userid is unique
263 unless (Check_Userid
($newdata{'userid'},$borrowernumber)) {
264 push @errors, "ERROR_login_exist";
267 my $password = $input->param('password');
268 push @errors, "ERROR_short_password" if( $password && $minpw && $password ne '****' && (length($password) < $minpw) );
270 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
271 $extended_patron_attributes = parse_extended_patron_attributes
($input);
272 foreach my $attr (@
$extended_patron_attributes) {
273 unless (C4
::Members
::Attributes
::CheckUniqueness
($attr->{code
}, $attr->{value
}, $borrowernumber)) {
274 push @errors, "ERROR_extended_unique_id_failed";
275 $template->param(ERROR_extended_unique_id_failed
=> "$attr->{code}/$attr->{value}");
281 if ( ($op eq 'modify' || $op eq 'insert' || $op eq 'save') and ($step == 0 or $step == 3 )){
282 if (exists ($newdata{'dateexpiry'}) && !($newdata{'dateexpiry'})){
283 my $arg2 = $newdata{'dateenrolled'} || C4
::Dates
->today('iso');
284 $newdata{'dateexpiry'} = GetExpiryDate
($newdata{'categorycode'},$arg2);
288 if ( ( defined $input->param('SMSnumber') ) && ( $input->param('SMSnumber') ne $newdata{'mobile'} ) ) {
289 $newdata{smsalertnumber
} = $input->param('SMSnumber');
292 ### Error checks should happen before this line.
293 $nok = $nok || scalar(@errors);
294 if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){
295 $debug and warn "$op dates: " . join "\t", map {"$_: $newdata{$_}"} qw(dateofbirth dateenrolled dateexpiry);
296 if ($op eq 'insert'){
297 # we know it's not a duplicate borrowernumber or there would already be an error
298 $borrowernumber = &AddMember
(%newdata);
300 # If 'AutoEmailOpacUser' syspref is on, email user their account details from the 'notice' that matches the user's branchcode.
301 if ( C4
::Context
->preference("AutoEmailOpacUser") == 1 && $newdata{'userid'} && $newdata{'password'}) {
302 #look for defined primary email address, if blank - attempt to use borr.email and borr.emailpro instead
304 if (C4
::Context
->preference("AutoEmailPrimaryAddress") ne 'OFF' &&
305 $newdata{C4
::Context
->preference("AutoEmailPrimaryAddress")} =~ /\w\@\w/ ) {
306 $emailaddr = $newdata{C4
::Context
->preference("AutoEmailPrimaryAddress")}
308 elsif ($newdata{email
} =~ /\w\@\w/) {
309 $emailaddr = $newdata{email
}
311 elsif ($newdata{emailpro
} =~ /\w\@\w/) {
312 $emailaddr = $newdata{emailpro
}
314 elsif ($newdata{B_email
} =~ /\w\@\w/) {
315 $emailaddr = $newdata{B_email
}
317 # if we manage to find a valid email address, send notice
319 $newdata{emailaddr
} = $emailaddr;
320 my $letter = getletter
('members', "ACCTDETAILS:$newdata{'branchcode'}") ;
321 # if $branch notice fails, then email a default notice instead.
322 $letter = getletter
('members', "ACCTDETAILS") if !$letter;
323 SendAlerts
( 'members' , \
%newdata , $letter ) if $letter
327 if ($data{'organisations'}){
328 # need to add the members organisations
329 my @orgs=split(/\|/,$data{'organisations'});
330 add_member_orgs
($borrowernumber,\
@orgs);
332 if (C4
::Context
->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) {
333 C4
::Members
::Attributes
::SetBorrowerAttributes
($borrowernumber, $extended_patron_attributes);
335 if (C4
::Context
->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) {
336 C4
::Form
::MessagingPreferences
::handle_form_action
($input, { borrowernumber
=> $borrowernumber }, $template);
338 } elsif ($op eq 'save'){
339 if ($NoUpdateLogin) {
340 delete $newdata{'password'};
341 delete $newdata{'userid'};
343 &ModMember
(%newdata) unless scalar(keys %newdata) <= 1; # bug 4508 - avoid crash if we're not
344 # updating any columns in the borrowers table,
345 # which can happen if we're only editing the
346 # patron attributes or messaging preferences sections
347 if (C4
::Context
->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) {
348 C4
::Members
::Attributes
::SetBorrowerAttributes
($borrowernumber, $extended_patron_attributes);
350 if (C4
::Context
->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) {
351 C4
::Form
::MessagingPreferences
::handle_form_action
($input, { borrowernumber
=> $borrowernumber }, $template);
354 print scalar ($destination eq "circ") ?
355 $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber") :
356 $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber") ;
357 exit; # You can only send 1 redirect! After that, content or other headers don't matter.
361 print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$borrowernumber");
362 exit; # same as above
365 if ($nok or !$nodouble){
366 $op="add" if ($op eq "insert");
367 $op="modify" if ($op eq "save");
369 $template->param( updtype
=> ($op eq 'add' ?
'I':'M')); # used to check for $op eq "insert"... but we just changed $op!
371 $template->param( step_1
=> 1,step_2
=> 1,step_3
=> 1, step_4
=> 1, step_5
=> 1, step_6
=> 1);
374 if (C4
::Context
->preference("IndependantBranches")) {
375 my $userenv = C4
::Context
->userenv;
376 if ($userenv->{flags
} % 2 != 1 && $data{branchcode
}){
377 unless ($userenv->{branch
} eq $data{'branchcode'}){
378 print $input->redirect("/cgi-bin/koha/members/members-home.pl");
384 $template->param( updtype
=> 'I', step_1
=>1, step_2
=>1, step_3
=>1, step_4
=>1, step_5
=> 1, step_6
=> 1);
386 if ($op eq "modify") {
387 $template->param( updtype
=> 'M',modify
=> 1 );
388 $template->param( step_1
=>1, step_2
=>1, step_3
=>1, step_4
=>1, step_5
=> 1, step_6
=> 1) unless $step;
390 # my $cardnumber=$data{'cardnumber'};
391 $data{'cardnumber'}=fixup_cardnumber
($data{'cardnumber'}) if $op eq 'add';
392 if(!defined($data{'sex'})){
393 $template->param( none
=> 1);
394 } elsif($data{'sex'} eq 'F'){
395 $template->param( female
=> 1);
396 } elsif ($data{'sex'} eq 'M'){
397 $template->param( male
=> 1);
399 $template->param( none
=> 1);
402 ##Now all the data to modify a member.
403 my ($categories,$labels)=ethnicitycategories
();
405 my $ethnicitycategoriescount=$#{$categories};
407 if ($ethnicitycategoriescount>=0) {
408 $ethcatpopup = CGI
::popup_menu
(-name
=>'ethnicity',
411 -values=>$categories,
412 -default=>$data{'ethnicity'},
414 $template->param(ethcatpopup
=> $ethcatpopup); # bad style, has to be fixed
418 foreach (qw(C A S P I X)) {
419 my $action="WHERE category_type=?";
420 ($categories,$labels)=GetborCatFromCatType
($_,$action);
422 foreach my $cat (@
$categories){
423 push @categoryloop,{'categorycode' => $cat,
424 'categoryname' => $labels->{$cat},
425 'categorycodeselected' => ((defined($borrower_data->{'categorycode'}) &&
426 $cat eq $borrower_data->{'categorycode'})
427 || (defined($categorycode) && $cat eq $categorycode)),
431 $typehash{'typename'}=$_;
432 $typehash{'categoryloop'}=\
@categoryloop;
433 push @typeloop,{'typename' => $_,
434 'categoryloop' => \
@categoryloop};
436 $template->param('typeloop' => \
@typeloop);
439 $select_city=getidcity
($data{'city'}) if defined $guarantorid and ($guarantorid ne '0');
440 ($default_city=$select_city) if ($step eq 0);
441 if (!defined($select_city) or $select_city eq '' ){
442 $default_city = &getidcity
($data{'city'});
445 my $city_arrayref = GetCities
();
446 if (@
{$city_arrayref} ) {
447 $template->param( city_cgipopup
=> 1);
449 if ($default_city) { # flag the current or default val
450 for my $city ( @
{$city_arrayref} ) {
451 if ($default_city == $city->{cityid
}) {
452 $city->{selected
} = 1;
459 my $default_roadtype;
460 $default_roadtype=$data{'streettype'} ;
461 my($roadtypeid,$road_type)=GetRoadTypes
();
462 $template->param( road_cgipopup
=> 1) if ($roadtypeid );
463 my $roadpopup = CGI
::popup_menu
(-name
=>'streettype',
465 -values=>$roadtypeid,
468 -default=>$default_roadtype
471 my $default_borrowertitle;
472 $default_borrowertitle=$data{'title'} ;
473 my($borrowertitle)=GetTitles
();
474 $template->param( title_cgipopup
=> 1) if ($borrowertitle);
475 my $borrotitlepopup = CGI
::popup_menu
(-name
=>'title',
477 -values=>$borrowertitle,
479 -default=>$default_borrowertitle
482 my @relationships = split /,|\|/, C4
::Context
->preference('BorrowerRelationship');
484 while (@relationships) {
485 my $relship = shift @relationships || '';
486 my %row = ('relationship' => $relship);
487 if (defined($data{'relationship'}) and $data{'relationship'} eq $relship) {
488 $row{'selected'}=' selected';
492 push(@relshipdata, \
%row);
495 my %flags = ( 'gonenoaddress' => ['gonenoaddress' ],
497 'debarred' => ['debarred']);
501 foreach (keys(%flags)) {
503 my %row = ('key' => $key,
504 'name' => $flags{$key}[0]);
506 $row{'yes'}=' checked';
511 $row{'no'}=' checked';
513 push @flagdata,\
%row;
521 my $onlymine=(C4
::Context
->preference('IndependantBranches') &&
522 C4
::Context
->userenv &&
523 C4
::Context
->userenv->{flags
} % 2 !=1 &&
524 C4
::Context
->userenv->{branch
}?
1:0);
526 my $branches=GetBranches
($onlymine);
529 for my $branch (sort { $branches->{$a}->{branchname
} cmp $branches->{$b}->{branchname
} } keys %$branches) {
530 push @select_branch,$branch;
531 $select_branches{$branch} = $branches->{$branch}->{'branchname'};
532 $default = C4
::Context
->userenv->{'branch'} if (C4
::Context
->userenv && C4
::Context
->userenv->{'branch'});
534 # --------------------------------------------------------------------------------------------------------
535 #in modify mod :default value from $CGIbranch comes from borrowers table
536 #in add mod: default value come from branches table (ip correspendence)
537 $default=$data{'branchcode'} if ($op eq 'modify' || ($op eq 'add' && $category_type eq 'C'));
538 my $CGIbranch = CGI
::scrolling_list
(-id
=> 'branchcode',
539 -name
=> 'branchcode',
540 -values => \
@select_branch,
541 -labels
=> \
%select_branches,
545 -default => $default,
547 my $CGIorganisations;
548 my $member_of_institution;
549 if (C4
::Context
->preference("memberofinstitution")){
550 my $organisations=get_institutions
();
553 foreach my $organisation (keys %$organisations) {
554 push @orgs,$organisation;
555 $org_labels{$organisation}=$organisations->{$organisation}->{'surname'};
557 $member_of_institution=1;
559 $CGIorganisations = CGI
::scrolling_list
( -id
=> 'organisations',
560 -name
=> 'organisations',
561 -labels
=> \
%org_labels,
569 # --------------------------------------------------------------------------------------------------------
571 my $CGIsort = buildCGIsort
("Bsort1","sort1",$data{'sort1'});
573 $template->param(CGIsort1
=> $CGIsort);
575 $template->param( sort1
=> $data{'sort1'}); # shouldn't this be in an "else" statement like the 2nd one?
577 $CGIsort = buildCGIsort
("Bsort2","sort2",$data{'sort2'});
579 $template->param(CGIsort2
=> $CGIsort);
581 $template->param( sort2
=> $data{'sort2'});
585 foreach my $error (@errors) {
586 $template->param($error) || $template->param( $error => 1);
588 $template->param(nok
=> 1);
591 #Formatting data for display
593 if (!defined($data{'dateenrolled'}) or $data{'dateenrolled'} eq ''){
594 $data{'dateenrolled'}=C4
::Dates
->today('iso');
596 if (C4
::Context
->preference('uppercasesurnames')) {
597 $data{'surname'} =uc($data{'surname'} );
598 $data{'contactname'}=uc($data{'contactname'});
600 foreach (qw(dateenrolled dateexpiry dateofbirth)) {
601 $data{$_} = format_date
($data{$_}); # back to syspref for display
602 $template->param( $_ => $data{$_});
605 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
606 $template->param(ExtendedPatronAttributes
=> 1);
607 patron_attributes_form
($template, $borrowernumber);
610 if (C4
::Context
->preference('EnhancedMessagingPreferences')) {
612 C4
::Form
::MessagingPreferences
::set_form_values
({ categorycode
=> $categorycode }, $template);
614 C4
::Form
::MessagingPreferences
::set_form_values
({ borrowernumber
=> $borrowernumber }, $template);
616 $template->param(SMSSendDriver
=> C4
::Context
->preference("SMSSendDriver"));
617 $template->param(SMSnumber
=> defined $data{'smsalertnumber'} ?
$data{'smsalertnumber'} : $data{'mobile'});
620 $template->param( "showguarantor" => ($category_type=~/A|I|S|X/) ?
0 : 1); # associate with step to know where you are
621 $debug and warn "memberentry step: $step";
622 $template->param(%data);
623 $template->param( "step_$step" => 1) if $step; # associate with step to know where u are
624 $template->param( step
=> $step ) if $step; # associate with step to know where u are
625 $template->param( debug
=> $debug ) if $debug;
628 BorrowerMandatoryField
=> C4
::Context
->preference("BorrowerMandatoryField"),#field to test with javascript
629 category_type
=> $category_type,#to know the category type of the borrower
630 DHTMLcalendar_dateformat
=> C4
::Dates
->DHTMLcalendar(),
631 select_city
=> $select_city,
632 "$category_type" => 1,# associate with step to know where u are
633 destination
=> $destination,#to know wher u come from and wher u must go in redirect
634 check_member
=> $check_member,#to know if the borrower already exist(=>1) or not (=>0)
638 nodouble
=> $nodouble,
639 borrowernumber
=> $borrowernumber, #register number
640 guarantorid
=> (defined($borrower_data->{'guarantorid'})) ?
$borrower_data->{'guarantorid'} : $guarantorid,
641 ethcatpopup
=> $ethcatpopup,
642 relshiploop
=> \
@relshipdata,
643 city_loop
=> $city_arrayref,
644 roadpopup
=> $roadpopup,
645 borrotitlepopup
=> $borrotitlepopup,
646 guarantorinfo
=> $guarantorinfo,
647 flagloop
=> \
@flagdata,
648 dateformat
=> C4
::Dates
->new()->visual(),
649 C4
::Context
->preference('dateformat') => 1,
650 check_categorytype
=>$check_categorytype,#to recover the category type with checkcategorytype function
652 nok
=> $nok,#flag to konw if an error
653 CGIbranch
=> $CGIbranch,
654 memberofinstution
=> $member_of_institution,
655 CGIorganisations
=> $CGIorganisations,
656 NoUpdateLogin
=> $NoUpdateLogin
659 if(defined($data{'flags'})){
660 $template->param(flags
=>$data{'flags'});
662 if(defined($data{'contacttitle'})){
663 $template->param("contacttitle_" . $data{'contacttitle'} => "SELECTED");
667 output_html_with_http_headers
$input, $cookie, $template->output;
669 sub parse_extended_patron_attributes
{
671 my @patron_attr = grep { /^patron_attr_\d+$/ } $input->param();
675 foreach my $key (@patron_attr) {
676 my $value = $input->param($key);
677 next unless defined($value) and $value ne '';
678 my $password = $input->param("${key}_password");
679 my $code = $input->param("${key}_code");
680 next if exists $dups{$code}->{$value};
681 $dups{$code}->{$value} = 1;
682 push @attr, { code
=> $code, value
=> $value, password
=> $password };
687 sub patron_attributes_form
{
688 my $template = shift;
689 my $borrowernumber = shift;
691 my @types = C4
::Members
::AttributeTypes
::GetAttributeTypes
();
692 if (scalar(@types) == 0) {
693 $template->param(no_patron_attribute_types
=> 1);
696 my $attributes = C4
::Members
::Attributes
::GetBorrowerAttributes
($borrowernumber);
698 # map patron's attributes into a more convenient structure
700 foreach my $attr (@
$attributes) {
701 push @
{ $attr_hash{$attr->{code
}} }, $attr;
704 my @attribute_loop = ();
706 foreach my $type_code (map { $_->{code
} } @types) {
707 my $attr_type = C4
::Members
::AttributeTypes
->fetch($type_code);
709 code
=> $attr_type->code(),
710 description
=> $attr_type->description(),
711 repeatable
=> $attr_type->repeatable(),
712 password_allowed
=> $attr_type->password_allowed(),
713 category
=> $attr_type->authorised_value_category(),
716 if (exists $attr_hash{$attr_type->code()}) {
717 foreach my $attr (@
{ $attr_hash{$attr_type->code()} }) {
718 my $newentry = { map { $_ => $entry->{$_} } %$entry };
719 $newentry->{value
} = $attr->{value
};
720 $newentry->{password
} = $attr->{password
};
721 $newentry->{use_dropdown
} = 0;
722 if ($attr_type->authorised_value_category()) {
723 $newentry->{use_dropdown
} = 1;
724 $newentry->{auth_val_loop
} = GetAuthorisedValues
($attr_type->authorised_value_category(), $attr->{value
});
727 $newentry->{form_id
} = "patron_attr_$i";
728 #use Data::Dumper; die Dumper($entry) if $entry->{use_dropdown};
729 push @attribute_loop, $newentry;
733 my $newentry = { map { $_ => $entry->{$_} } %$entry };
734 if ($attr_type->authorised_value_category()) {
735 $newentry->{use_dropdown
} = 1;
736 $newentry->{auth_val_loop
} = GetAuthorisedValues
($attr_type->authorised_value_category());
738 $newentry->{form_id
} = "patron_attr_$i";
739 push @attribute_loop, $newentry;
742 $template->param(patron_attributes
=> \
@attribute_loop);