View | Details | Raw Unified | Return to bug 27526
Collapse All | Expand All

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

Return to bug 27526