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

(-)a/cataloguing/additem.pl (-25 / +32 lines)
Lines 320-325 sub generate_subfield_form { Link Here
320
        return \%subfield_data;
320
        return \%subfield_data;
321
}
321
}
322
322
323
sub get_item_from_cookie {
324
    my ( $input ) = @_;
325
326
    my $item_from_cookie;
327
    my $lastitemcookie = $input->cookie('LastCreatedItem');
328
    if ($lastitemcookie) {
329
        $lastitemcookie = decode_base64url($lastitemcookie);
330
        eval {
331
            if ( thaw($lastitemcookie) ) {
332
                $item_from_cookie = thaw($lastitemcookie);
333
            }
334
        };
335
        if ($@) {
336
            $lastitemcookie ||= 'undef';
337
            warn "Storable::thaw failed to thaw LastCreatedItem-cookie. Cookie value '".encode_base64url($lastitemcookie)."'. Caught error follows: '$@'";
338
        }
339
    }
340
    return $item_from_cookie;
341
}
342
323
my $input        = CGI->new;
343
my $input        = CGI->new;
324
my $error        = $input->param('error');
344
my $error        = $input->param('error');
325
345
Lines 388-409 my @errors; # store errors found while checking data BEFORE saving item. Link Here
388
408
389
# Getting last created item cookie
409
# Getting last created item cookie
390
my $prefillitem = C4::Context->preference('PrefillItem');
410
my $prefillitem = C4::Context->preference('PrefillItem');
391
my $item_from_cookie;
392
if ($prefillitem) {
393
    my $lastitemcookie = $input->cookie('LastCreatedItem');
394
    if ($lastitemcookie) {
395
        $lastitemcookie = decode_base64url($lastitemcookie);
396
        eval {
397
            if ( thaw($lastitemcookie) ) {
398
                $item_from_cookie = thaw($lastitemcookie);
399
            }
400
        };
401
        if ($@) {
402
            $lastitemcookie = 'undef' unless $lastitemcookie;
403
            warn "Storable::thaw failed to thaw LastCreatedItem-cookie. Cookie value '".encode_base64url($lastitemcookie)."'. Caught error follows: '$@'";
404
        }
405
    }
406
}
407
411
408
#-------------------------------------------------------------------------------
412
#-------------------------------------------------------------------------------
409
if ($op eq "additem") {
413
if ($op eq "additem") {
Lines 465-474 if ($op eq "additem") { Link Here
465
            # force the use of "add and duplicate" feature, so the form will be filled with
469
            # force the use of "add and duplicate" feature, so the form will be filled with
466
            # correct values.
470
            # correct values.
467
471
468
            # FIXME This need to be rewritten, we must store $item->unblessed instead
469
            # Pushing the last created item cookie back
472
            # Pushing the last created item cookie back
470
            if ( $prefillitem ) {
473
            if ( $prefillitem ) {
471
                $item_from_cookie = $input->cookie(
474
                my $last_created_item_cookie = $input->cookie(
472
                    -name => 'LastCreatedItem',
475
                    -name => 'LastCreatedItem',
473
                    # We encode_base64url the whole freezed structure so we're sure we won't have any encoding problems
476
                    # We encode_base64url the whole freezed structure so we're sure we won't have any encoding problems
474
                    -value   => encode_base64url( freeze( { %{$item->unblessed}, itemnumber => undef } ) ),
477
                    -value   => encode_base64url( freeze( { %{$item->unblessed}, itemnumber => undef } ) ),
Lines 476-482 if ($op eq "additem") { Link Here
476
                    -expires => ''
479
                    -expires => ''
477
                );
480
                );
478
481
479
                $cookie = [ $cookie, $item_from_cookie ];
482
                $cookie = [ $cookie, $last_created_item_cookie ];
480
            }
483
            }
481
484
482
        }
485
        }
Lines 486-491 if ($op eq "additem") { Link Here
486
489
487
    # If we have to add & duplicate
490
    # If we have to add & duplicate
488
    if ($prefillitem) {
491
    if ($prefillitem) {
492
493
        $current_item = $item->unblessed;
494
489
        if (C4::Context->preference('autoBarcode') eq 'incremental') {
495
        if (C4::Context->preference('autoBarcode') eq 'incremental') {
490
            my ( $barcode ) = C4::Barcodes::ValueBuilder::incremental::get_barcode;
496
            my ( $barcode ) = C4::Barcodes::ValueBuilder::incremental::get_barcode;
491
            $current_item->{barcode} = $barcode;
497
            $current_item->{barcode} = $barcode;
Lines 783-793 for my $library ( @$libraries ) { Link Here
783
789
784
790
785
# Using last created item if it exists
791
# Using last created item if it exists
786
$current_item = $item_from_cookie
792
if (   $prefillitem
787
  if $item_from_cookie
793
    && $op ne "additem"
788
  && $prefillitem
794
    && $op ne "edititem" )
789
  && $op ne "additem"
795
{
790
  && $op ne "edititem";
796
    my $item_from_cookie = get_item_from_cookie($input);
797
    $current_item = $item_from_cookie if $item_from_cookie;
798
}
791
799
792
my @subfields_to_prefill = split ' ', C4::Context->preference('SubfieldsToUseWhenPrefill');
800
my @subfields_to_prefill = split ' ', C4::Context->preference('SubfieldsToUseWhenPrefill');
793
801
794
- 

Return to bug 27526