Lines 27-33
Link Here
|
27 |
|
27 |
|
28 |
use Modern::Perl; |
28 |
use Modern::Perl; |
29 |
use CGI qw ( -utf8 ); |
29 |
use CGI qw ( -utf8 ); |
30 |
use C4::Auth; |
30 |
use C4::Auth qw ( get_template_and_user ); |
31 |
use C4::Branch; |
31 |
use C4::Branch; |
32 |
use C4::Koha; |
32 |
use C4::Koha; |
33 |
use C4::Members; |
33 |
use C4::Members; |
Lines 261-269
if ( $op eq 'do' ) {
Link Here
|
261 |
$infos->{$field} = "" if grep { /^$field$/ } @disabled; |
261 |
$infos->{$field} = "" if grep { /^$field$/ } @disabled; |
262 |
} |
262 |
} |
263 |
|
263 |
|
264 |
my @attributes = $input->param('patron_attributes'); |
264 |
my $successes = 0; |
265 |
my @attr_values = $input->param('patron_attributes_value'); |
|
|
266 |
|
267 |
my @errors; |
265 |
my @errors; |
268 |
my @borrowernumbers = $input->param('borrowernumber'); |
266 |
my @borrowernumbers = $input->param('borrowernumber'); |
269 |
# For each borrower selected |
267 |
# For each borrower selected |
Lines 277-343
if ( $op eq 'do' ) {
Link Here
|
277 |
$infos->{cardnumber} = $borrowerinfo->{cardnumber} || ''; |
275 |
$infos->{cardnumber} = $borrowerinfo->{cardnumber} || ''; |
278 |
push @errors, { error => "can_not_update", borrowernumber => $infos->{borrowernumber}, cardnumber => $infos->{cardnumber} }; |
276 |
push @errors, { error => "can_not_update", borrowernumber => $infos->{borrowernumber}, cardnumber => $infos->{cardnumber} }; |
279 |
} |
277 |
} |
|
|
278 |
else { |
279 |
$successes++; |
280 |
} |
280 |
} |
281 |
} |
281 |
|
282 |
|
282 |
# |
283 |
# |
283 |
my $borrower_categorycode = GetBorrowerCategorycode $borrowernumber; |
284 |
if (@disabled) { |
284 |
my $i=0; |
285 |
my @attributes = $input->param('patron_attributes'); |
285 |
for ( @attributes ) { |
286 |
my @attr_values = $input->param('patron_attributes_value'); |
286 |
my $attribute; |
287 |
my $borrower_categorycode = GetBorrowerCategorycode $borrowernumber; |
287 |
$attribute->{code} = $_; |
288 |
my $i=0; |
288 |
$attribute->{attribute} = $attr_values[$i]; |
289 |
for ( @attributes ) { |
289 |
my $attr_type = C4::Members::AttributeTypes->fetch( $_ ); |
290 |
my $attribute; |
290 |
# If this borrower is not in the category of this attribute, we don't want to modify this attribute |
291 |
$attribute->{code} = $_; |
291 |
++$i and next if $attr_type->{category_code} and $attr_type->{category_code} ne $borrower_categorycode; |
292 |
$attribute->{attribute} = $attr_values[$i]; |
292 |
my $valuename = "attr" . $i . "_value"; |
293 |
my $attr_type = C4::Members::AttributeTypes->fetch( $_ ); |
293 |
if ( grep { /^$valuename$/ } @disabled ) { |
294 |
# If this borrower is not in the category of this attribute, we don't want to modify this attribute |
294 |
# The attribute is disabled, we remove it for this borrower ! |
295 |
++$i and next if $attr_type->{category_code} and $attr_type->{category_code} ne $borrower_categorycode; |
295 |
eval { |
296 |
my $valuename = "attr" . $i . "_value"; |
296 |
C4::Members::Attributes::DeleteBorrowerAttribute( $borrowernumber, $attribute ); |
297 |
if ( grep { /^$valuename$/ } @disabled ) { |
297 |
}; |
298 |
# The attribute is disabled, we remove it for this borrower ! |
298 |
push @errors, { error => $@ } if $@; |
299 |
eval { |
299 |
} else { |
300 |
C4::Members::Attributes::DeleteBorrowerAttribute( $borrowernumber, $attribute ); |
300 |
# Attribute's value is empty, we don't want to modify it |
301 |
}; |
301 |
++$i and next if not $attribute->{attribute}; |
302 |
push @errors, { error => $@ } if $@; |
302 |
|
303 |
} else { |
303 |
eval { |
304 |
# Attribute's value is empty, we don't want to modify it |
304 |
C4::Members::Attributes::UpdateBorrowerAttribute( $borrowernumber, $attribute ); |
305 |
++$i and next if not $attribute->{attribute}; |
305 |
}; |
306 |
|
306 |
push @errors, { error => $@ } if $@; |
307 |
eval { |
|
|
308 |
C4::Members::Attributes::UpdateBorrowerAttribute( $borrowernumber, $attribute ); |
309 |
}; |
310 |
push @errors, { error => $@ } if $@; |
311 |
} |
312 |
$i++; |
307 |
} |
313 |
} |
308 |
$i++; |
|
|
309 |
} |
314 |
} |
310 |
} |
315 |
} |
311 |
$op = "show_results"; # We have process modifications, the user want to view its |
316 |
$op = "show_results"; # We have process modifications, the user want to view its |
312 |
|
317 |
|
313 |
# Construct the results list |
318 |
# Construct a detailed list if there are fewer than 20 patrons |
314 |
my @borrowers; |
319 |
if (scalar @borrowernumbers < 20) { |
315 |
my $max_nb_attr = 0; |
320 |
my @borrowers; |
316 |
for my $borrowernumber ( @borrowernumbers ) { |
321 |
my $max_nb_attr = 0; |
317 |
my $borrower = GetBorrowerInfos( borrowernumber => $borrowernumber ); |
322 |
for my $borrowernumber ( @borrowernumbers ) { |
318 |
if ( $borrower ) { |
323 |
my $borrower = GetBorrowerInfos( borrowernumber => $borrowernumber ); |
319 |
$max_nb_attr = scalar( @{ $borrower->{patron_attributes} } ) |
324 |
if ( $borrower ) { |
320 |
if scalar( @{ $borrower->{patron_attributes} } ) > $max_nb_attr; |
325 |
$max_nb_attr = scalar( @{ $borrower->{patron_attributes} } ) |
321 |
push @borrowers, $borrower; |
326 |
if scalar( @{ $borrower->{patron_attributes} } ) > $max_nb_attr; |
|
|
327 |
push @borrowers, $borrower; |
328 |
} |
329 |
} |
330 |
my @patron_attributes_option; |
331 |
for my $borrower ( @borrowers ) { |
332 |
push @patron_attributes_option, { value => "$_->{code}", lib => $_->{code} } for @{ $borrower->{patron_attributes} }; |
333 |
my $length = scalar( @{ $borrower->{patron_attributes} } ); |
334 |
push @{ $borrower->{patron_attributes} }, {} for ( $length .. $max_nb_attr - 1); |
322 |
} |
335 |
} |
323 |
} |
|
|
324 |
my @patron_attributes_option; |
325 |
for my $borrower ( @borrowers ) { |
326 |
push @patron_attributes_option, { value => "$_->{code}", lib => $_->{code} } for @{ $borrower->{patron_attributes} }; |
327 |
my $length = scalar( @{ $borrower->{patron_attributes} } ); |
328 |
push @{ $borrower->{patron_attributes} }, {} for ( $length .. $max_nb_attr - 1); |
329 |
} |
330 |
|
336 |
|
331 |
my @attributes_header = (); |
337 |
my @attributes_header = (); |
332 |
for ( 1 .. scalar( $max_nb_attr ) ) { |
338 |
for ( 1 .. scalar( $max_nb_attr ) ) { |
333 |
push @attributes_header, { attribute => "Attributes $_" }; |
339 |
push @attributes_header, { attribute => "Attributes $_" }; |
334 |
} |
340 |
} |
335 |
|
341 |
|
336 |
$template->param( borrowers => \@borrowers ); |
342 |
$template->param( borrowers => \@borrowers ); |
337 |
$template->param( attributes_header => \@attributes_header ); |
343 |
$template->param( attributes_header => \@attributes_header ); |
|
|
344 |
} |
338 |
|
345 |
|
339 |
$template->param( borrowers => \@borrowers ); |
346 |
$template->param( successes => $successes ); |
340 |
$template->param( errors => \@errors ); |
347 |
$template->param( errors => \@errors ); |
|
|
348 |
|
341 |
} else { |
349 |
} else { |
342 |
|
350 |
|
343 |
$template->param( patron_lists => [ GetPatronLists() ] ); |
351 |
$template->param( patron_lists => [ GetPatronLists() ] ); |
344 |
- |
|
|