Lines 239-336
if ( $op eq 'show' ) {
Link Here
|
239 |
|
239 |
|
240 |
# Process modifications |
240 |
# Process modifications |
241 |
if ( $op eq 'do' ) { |
241 |
if ( $op eq 'do' ) { |
|
|
242 |
my @borrowernumbers = $input->param('borrowernumber'); |
243 |
my @errors; |
242 |
|
244 |
|
243 |
my @disabled = $input->param('disable_input'); |
245 |
if ( $input->param("delete") ) { |
244 |
my $infos; |
246 |
my @deleted_borrowers; |
245 |
for my $field ( qw/surname firstname branchcode categorycode sort1 sort2 dateenrolled dateexpiry debarred debarredcomment borrowernotes/ ) { |
|
|
246 |
my $value = $input->param($field); |
247 |
$infos->{$field} = $value if $value; |
248 |
$infos->{$field} = "" if grep { /^$field$/ } @disabled; |
249 |
} |
250 |
|
251 |
my @attributes = $input->param('patron_attributes'); |
252 |
my @attr_values = $input->param('patron_attributes_value'); |
253 |
|
247 |
|
254 |
my @errors; |
248 |
for my $borrowernumber (@borrowernumbers) { |
255 |
my @borrowernumbers = $input->param('borrowernumber'); |
249 |
my $borrower = GetMember( borrowernumber => $borrowernumber ); |
256 |
# For each borrower selected |
250 |
my ( $overdue_count, $issue_count, $total_fines ) = |
257 |
for my $borrowernumber ( @borrowernumbers ) { |
251 |
GetMemberIssuesAndFines($borrowernumber); |
258 |
# If at least one field are filled, we want to modify the borrower |
|
|
259 |
if ( defined $infos ) { |
260 |
$infos->{borrowernumber} = $borrowernumber; |
261 |
my $success = ModMember(%$infos); |
262 |
push @errors, { error => "can_not_update", borrowernumber => $infos->{borrowernumber} } if not $success; |
263 |
} |
264 |
|
252 |
|
265 |
# |
253 |
if ($issue_count) { |
266 |
my $borrower_categorycode = GetBorrowerCategorycode $borrowernumber; |
254 |
push( @errors, |
267 |
my $i=0; |
255 |
{ error => "current_issues", borrower => $borrower } ); |
268 |
for ( @attributes ) { |
256 |
} |
269 |
my $attribute; |
257 |
elsif ($total_fines) { |
270 |
$attribute->{code} = $_; |
258 |
push( @errors, |
271 |
$attribute->{attribute} = $attr_values[$i]; |
259 |
{ error => "fees_owed", borrower => $borrower } ); |
272 |
my $attr_type = C4::Members::AttributeTypes->fetch( $_ ); |
260 |
} |
273 |
# If this borrower is not in the category of this attribute, we don't want to modify this attribute |
261 |
else { |
274 |
++$i and next if $attr_type->{category_code} and $attr_type->{category_code} ne $borrower_categorycode; |
262 |
MoveMemberToDeleted($borrowernumber); |
275 |
my $valuename = "attr" . $i . "_value"; |
263 |
DelMember($borrowernumber); |
276 |
if ( grep { /^$valuename$/ } @disabled ) { |
264 |
push( @deleted_borrowers, $borrower ); |
277 |
# The attribute is disabled, we remove it for this borrower ! |
|
|
278 |
eval { |
279 |
C4::Members::Attributes::DeleteBorrowerAttribute( $borrowernumber, $attribute ); |
280 |
}; |
281 |
push @errors, { error => $@ } if $@; |
282 |
} else { |
283 |
# Attribute's value is empty, we don't want to modify it |
284 |
++$i and next if not $attribute->{attribute}; |
285 |
|
286 |
eval { |
287 |
C4::Members::Attributes::UpdateBorrowerAttribute( $borrowernumber, $attribute ); |
288 |
}; |
289 |
push @errors, { error => $@ } if $@; |
290 |
} |
265 |
} |
291 |
$i++; |
|
|
292 |
} |
266 |
} |
|
|
267 |
|
268 |
$template->param( |
269 |
borrowers => \@deleted_borrowers, |
270 |
action => 'delete_patrons', |
271 |
); |
293 |
} |
272 |
} |
294 |
$op = "show_results"; # We have process modifications, the user want to view its |
273 |
else { |
|
|
274 |
my @disabled = $input->param('disable_input'); |
275 |
my $infos; |
295 |
|
276 |
|
296 |
# Construct the results list |
277 |
for my $field ( |
297 |
my @borrowers; |
278 |
qw/surname firstname branchcode categorycode sort1 sort2 dateenrolled dateexpiry debarred debarredcomment borrowernotes/ |
298 |
my $max_nb_attr = 0; |
279 |
) |
299 |
for my $borrowernumber ( @borrowernumbers ) { |
280 |
{ |
300 |
my $borrower = GetBorrowerInfos( borrowernumber => $borrowernumber ); |
281 |
my $value = $input->param($field); |
301 |
if ( $borrower ) { |
282 |
$infos->{$field} = $value if $value; |
302 |
$max_nb_attr = scalar( @{ $borrower->{patron_attributes} } ) |
283 |
$infos->{$field} = "" if grep { /^$field$/ } @disabled; |
303 |
if scalar( @{ $borrower->{patron_attributes} } ) > $max_nb_attr; |
|
|
304 |
push @borrowers, $borrower; |
305 |
} |
284 |
} |
306 |
} |
|
|
307 |
my @patron_attributes_option; |
308 |
for my $borrower ( @borrowers ) { |
309 |
push @patron_attributes_option, { value => "$_->{code}", lib => $_->{code} } for @{ $borrower->{patron_attributes} }; |
310 |
my $length = scalar( @{ $borrower->{patron_attributes} } ); |
311 |
push @{ $borrower->{patron_attributes} }, {} for ( $length .. $max_nb_attr - 1); |
312 |
} |
313 |
|
285 |
|
314 |
my @attributes_header = (); |
286 |
my @attributes = $input->param('patron_attributes'); |
315 |
for ( 1 .. scalar( $max_nb_attr ) ) { |
287 |
my @attr_values = $input->param('patron_attributes_value'); |
316 |
push @attributes_header, { attribute => "Attributes $_" }; |
288 |
|
317 |
} |
289 |
# For each borrower selected |
|
|
290 |
for my $borrowernumber (@borrowernumbers) { |
291 |
|
292 |
# If at least one field are filled, we want to modify the borrower |
293 |
if ( defined $infos ) { |
294 |
$infos->{borrowernumber} = $borrowernumber; |
295 |
my $success = ModMember(%$infos); |
296 |
push @errors, |
297 |
{ |
298 |
error => "can_not_update", |
299 |
borrowernumber => $infos->{borrowernumber} |
300 |
} |
301 |
if not $success; |
302 |
} |
318 |
|
303 |
|
319 |
$template->param( borrowers => \@borrowers ); |
304 |
my $borrower_categorycode = GetBorrowerCategorycode $borrowernumber; |
320 |
$template->param( attributes_header => \@attributes_header ); |
305 |
my $i = 0; |
|
|
306 |
for (@attributes) { |
307 |
my $attribute; |
308 |
$attribute->{code} = $_; |
309 |
$attribute->{attribute} = $attr_values[$i]; |
310 |
my $attr_type = C4::Members::AttributeTypes->fetch($_); |
311 |
|
312 |
# If this borrower is not in the category of this attribute, we don't want to modify this attribute |
313 |
++$i and next |
314 |
if $attr_type->{category_code} |
315 |
and $attr_type->{category_code} ne $borrower_categorycode; |
316 |
|
317 |
my $valuename = "attr" . $i . "_value"; |
318 |
if ( grep { /^$valuename$/ } @disabled ) { |
319 |
|
320 |
# The attribute is disabled, we remove it for this borrower ! |
321 |
eval { |
322 |
C4::Members::Attributes::DeleteBorrowerAttribute( |
323 |
$borrowernumber, $attribute ); |
324 |
}; |
325 |
push @errors, { error => $@ } if $@; |
326 |
} |
327 |
else { |
328 |
|
329 |
# Attribute's value is empty, we don't want to modify it |
330 |
++$i and next if not $attribute->{attribute}; |
331 |
|
332 |
eval { |
333 |
C4::Members::Attributes::UpdateBorrowerAttribute( |
334 |
$borrowernumber, $attribute ); |
335 |
}; |
336 |
push @errors, { error => $@ } if $@; |
337 |
} |
338 |
$i++; |
339 |
} |
340 |
|
341 |
# Construct the results list |
342 |
my @borrowers; |
343 |
my $max_nb_attr = 0; |
344 |
for my $borrowernumber (@borrowernumbers) { |
345 |
my $borrower = |
346 |
GetBorrowerInfos( borrowernumber => $borrowernumber ); |
347 |
if ($borrower) { |
348 |
$max_nb_attr = scalar( @{ $borrower->{patron_attributes} } ) |
349 |
if scalar( @{ $borrower->{patron_attributes} } ) > |
350 |
$max_nb_attr; |
351 |
push @borrowers, $borrower; |
352 |
} |
353 |
} |
354 |
my @patron_attributes_option; |
355 |
for my $borrower (@borrowers) { |
356 |
push @patron_attributes_option, |
357 |
{ value => "$_->{code}", lib => $_->{code} } |
358 |
for @{ $borrower->{patron_attributes} }; |
359 |
|
360 |
my $length = scalar( @{ $borrower->{patron_attributes} } ); |
361 |
|
362 |
push @{ $borrower->{patron_attributes} }, {} |
363 |
for ( $length .. $max_nb_attr - 1 ); |
364 |
} |
365 |
|
366 |
my @attributes_header = (); |
367 |
for ( 1 .. scalar($max_nb_attr) ) { |
368 |
push @attributes_header, { attribute => "Attributes $_" }; |
369 |
} |
370 |
|
371 |
$template->param( |
372 |
borrowers => \@borrowers, |
373 |
attributes_header => \@attributes_header |
374 |
); |
375 |
} |
376 |
|
377 |
} |
321 |
|
378 |
|
322 |
$template->param( borrowers => \@borrowers ); |
|
|
323 |
$template->param( errors => \@errors ); |
379 |
$template->param( errors => \@errors ); |
|
|
380 |
|
381 |
$op = "show_results"; |
382 |
|
324 |
} else { |
383 |
} else { |
325 |
|
384 |
|
326 |
$template->param( patron_lists => [ GetPatronLists() ] ); |
385 |
$template->param( patron_lists => [ GetPatronLists() ] ); |
327 |
} |
386 |
} |
328 |
|
387 |
|
329 |
$template->param( |
388 |
$template->param( op => $op ); |
330 |
op => $op, |
389 |
|
331 |
); |
|
|
332 |
output_html_with_http_headers $input, $cookie, $template->output; |
390 |
output_html_with_http_headers $input, $cookie, $template->output; |
333 |
exit; |
|
|
334 |
|
391 |
|
335 |
sub GetBorrowerInfos { |
392 |
sub GetBorrowerInfos { |
336 |
my ( %info ) = @_; |
393 |
my ( %info ) = @_; |
337 |
- |
|
|