|
Lines 331-336
sub generate_subfield_form {
Link Here
|
| 331 |
return \%subfield_data; |
331 |
return \%subfield_data; |
| 332 |
} |
332 |
} |
| 333 |
|
333 |
|
|
|
334 |
sub get_item_from_cookie { |
| 335 |
my ( $input ) = @_; |
| 336 |
|
| 337 |
my $item_from_cookie; |
| 338 |
my $lastitemcookie = $input->cookie('LastCreatedItem'); |
| 339 |
if ($lastitemcookie) { |
| 340 |
$lastitemcookie = decode_base64url($lastitemcookie); |
| 341 |
eval { |
| 342 |
if ( thaw($lastitemcookie) ) { |
| 343 |
$item_from_cookie = thaw($lastitemcookie); |
| 344 |
} |
| 345 |
}; |
| 346 |
if ($@) { |
| 347 |
$lastitemcookie ||= 'undef'; |
| 348 |
warn "Storable::thaw failed to thaw LastCreatedItem-cookie. Cookie value '".encode_base64url($lastitemcookie)."'. Caught error follows: '$@'"; |
| 349 |
} |
| 350 |
} |
| 351 |
return $item_from_cookie; |
| 352 |
} |
| 353 |
|
| 334 |
my $input = CGI->new; |
354 |
my $input = CGI->new; |
| 335 |
my $error = $input->param('error'); |
355 |
my $error = $input->param('error'); |
| 336 |
|
356 |
|
|
Lines 399-420
my @errors; # store errors found while checking data BEFORE saving item.
Link Here
|
| 399 |
|
419 |
|
| 400 |
# Getting last created item cookie |
420 |
# Getting last created item cookie |
| 401 |
my $prefillitem = C4::Context->preference('PrefillItem'); |
421 |
my $prefillitem = C4::Context->preference('PrefillItem'); |
| 402 |
my $item_from_cookie; |
|
|
| 403 |
if ($prefillitem) { |
| 404 |
my $lastitemcookie = $input->cookie('LastCreatedItem'); |
| 405 |
if ($lastitemcookie) { |
| 406 |
$lastitemcookie = decode_base64url($lastitemcookie); |
| 407 |
eval { |
| 408 |
if ( thaw($lastitemcookie) ) { |
| 409 |
$item_from_cookie = thaw($lastitemcookie); |
| 410 |
} |
| 411 |
}; |
| 412 |
if ($@) { |
| 413 |
$lastitemcookie = 'undef' unless $lastitemcookie; |
| 414 |
warn "Storable::thaw failed to thaw LastCreatedItem-cookie. Cookie value '".encode_base64url($lastitemcookie)."'. Caught error follows: '$@'"; |
| 415 |
} |
| 416 |
} |
| 417 |
} |
| 418 |
|
422 |
|
| 419 |
#------------------------------------------------------------------------------- |
423 |
#------------------------------------------------------------------------------- |
| 420 |
if ($op eq "additem") { |
424 |
if ($op eq "additem") { |
|
Lines 476-485
if ($op eq "additem") {
Link Here
|
| 476 |
# force the use of "add and duplicate" feature, so the form will be filled with |
480 |
# force the use of "add and duplicate" feature, so the form will be filled with |
| 477 |
# correct values. |
481 |
# correct values. |
| 478 |
|
482 |
|
| 479 |
# FIXME This need to be rewritten, we must store $item->unblessed instead |
|
|
| 480 |
# Pushing the last created item cookie back |
483 |
# Pushing the last created item cookie back |
| 481 |
if ( $prefillitem ) { |
484 |
if ( $prefillitem ) { |
| 482 |
$item_from_cookie = $input->cookie( |
485 |
my $last_created_item_cookie = $input->cookie( |
| 483 |
-name => 'LastCreatedItem', |
486 |
-name => 'LastCreatedItem', |
| 484 |
# We encode_base64url the whole freezed structure so we're sure we won't have any encoding problems |
487 |
# We encode_base64url the whole freezed structure so we're sure we won't have any encoding problems |
| 485 |
-value => encode_base64url( freeze( { %{$item->unblessed}, itemnumber => undef } ) ), |
488 |
-value => encode_base64url( freeze( { %{$item->unblessed}, itemnumber => undef } ) ), |
|
Lines 487-493
if ($op eq "additem") {
Link Here
|
| 487 |
-expires => '' |
490 |
-expires => '' |
| 488 |
); |
491 |
); |
| 489 |
|
492 |
|
| 490 |
$cookie = [ $cookie, $item_from_cookie ]; |
493 |
$cookie = [ $cookie, $last_created_item_cookie ]; |
| 491 |
} |
494 |
} |
| 492 |
|
495 |
|
| 493 |
} |
496 |
} |
|
Lines 497-502
if ($op eq "additem") {
Link Here
|
| 497 |
|
500 |
|
| 498 |
# If we have to add & duplicate |
501 |
# If we have to add & duplicate |
| 499 |
if ($prefillitem) { |
502 |
if ($prefillitem) { |
|
|
503 |
|
| 504 |
$current_item = $item->unblessed; |
| 505 |
|
| 500 |
if (C4::Context->preference('autoBarcode') eq 'incremental') { |
506 |
if (C4::Context->preference('autoBarcode') eq 'incremental') { |
| 501 |
my ( $barcode ) = C4::Barcodes::ValueBuilder::incremental::get_barcode; |
507 |
my ( $barcode ) = C4::Barcodes::ValueBuilder::incremental::get_barcode; |
| 502 |
$current_item->{barcode} = $barcode; |
508 |
$current_item->{barcode} = $barcode; |
|
Lines 794-804
for my $library ( @$libraries ) {
Link Here
|
| 794 |
|
800 |
|
| 795 |
|
801 |
|
| 796 |
# Using last created item if it exists |
802 |
# Using last created item if it exists |
| 797 |
$current_item = $item_from_cookie |
803 |
if ( $prefillitem |
| 798 |
if $item_from_cookie |
804 |
&& $op ne "additem" |
| 799 |
&& $prefillitem |
805 |
&& $op ne "edititem" ) |
| 800 |
&& $op ne "additem" |
806 |
{ |
| 801 |
&& $op ne "edititem"; |
807 |
my $item_from_cookie = get_item_from_cookie($input); |
|
|
808 |
$current_item = $item_from_cookie if $item_from_cookie; |
| 809 |
} |
| 802 |
|
810 |
|
| 803 |
my @subfields_to_prefill = split ' ', C4::Context->preference('SubfieldsToUseWhenPrefill'); |
811 |
my @subfields_to_prefill = split ' ', C4::Context->preference('SubfieldsToUseWhenPrefill'); |
| 804 |
|
812 |
|
| 805 |
- |
|
|