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