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

(-)a/Koha/Biblio.pm (+23 lines)
Lines 417-422 sub items { Link Here
417
    return Koha::Items->_new_from_dbic( $items_rs );
417
    return Koha::Items->_new_from_dbic( $items_rs );
418
}
418
}
419
419
420
sub host_items {
421
    my ($self) = @_;
422
423
    return Koha::Items->new->empty
424
      unless C4::Context->preference('EasyAnalyticalRecords');
425
426
    my $marcflavour = C4::Context->preference("marcflavour");
427
    my $analyticfield = '773';
428
    if ( $marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC' ) {
429
        $analyticfield = '773';
430
    }
431
    elsif ( $marcflavour eq 'UNIMARC' ) {
432
        $analyticfield = '461';
433
    }
434
    my $marc_record = $self->metadata->record;
435
    my @itemnumbers;
436
    foreach my $field ( $marc_record->field($analyticfield) ) {
437
        push @itemnumbers, $field->subfield('9');
438
    }
439
440
    return Koha::Items->search( { itemnumber => { -in => \@itemnumbers } } );
441
}
442
420
=head3 itemtype
443
=head3 itemtype
421
444
422
my $itemtype = $biblio->itemtype();
445
my $itemtype = $biblio->itemtype();
(-)a/Koha/Item.pm (-1 / +72 lines)
Lines 25-31 use Data::Dumper; Link Here
25
use Try::Tiny;
25
use Try::Tiny;
26
26
27
use Koha::Database;
27
use Koha::Database;
28
use Koha::DateUtils qw( dt_from_string );
28
use Koha::DateUtils qw( dt_from_string output_pref );
29
29
30
use C4::Context;
30
use C4::Context;
31
use C4::Circulation;
31
use C4::Circulation;
Lines 828-833 sub cover_images { Link Here
828
    return Koha::CoverImages->_new_from_dbic($cover_image_rs);
828
    return Koha::CoverImages->_new_from_dbic($cover_image_rs);
829
}
829
}
830
830
831
sub columns_to_str {
832
    my ( $self ) = @_;
833
834
    my $frameworkcode = $self->biblio->frameworkcode;
835
    my $tagslib = C4::Biblio::GetMarcStructure(1, $frameworkcode);
836
    my ( $itemtagfield, $itemtagsubfield) = C4::Biblio::GetMarcFromKohaField( "items.itemnumber" );
837
838
    my $columns_info = $self->_result->result_source->columns_info;
839
840
    my $mss = C4::Biblio::GetMarcSubfieldStructure( $frameworkcode, { unsafe => 1 } );
841
    my $values = {};
842
    for my $column ( keys %$columns_info ) {
843
844
        next if $column eq 'more_subfields_xml';
845
846
        my $value;
847
        if ( Koha::Object::_datetime_column_type( $columns_info->{$column}->{data_type} ) ) {
848
            $value = output_pref({ dateformat => 'rfc3339', dt => dt_from_string($value, 'sql')});
849
        } else {
850
            $value = $self->$column;
851
        }
852
853
        if ( not defined $value or $value eq "" ) {
854
            $values->{$column} = $value;
855
            next;
856
        }
857
858
        my $subfield =
859
          exists $mss->{"items.$column"}
860
          ? @{ $mss->{"items.$column"} }[0] # Should we deal with several subfields??
861
          : undef;
862
863
        $values->{$column} =
864
            $subfield
865
          ? $subfield->{authorised_value}
866
              ? C4::Biblio::GetAuthorisedValueDesc( $itemtagfield,
867
                  $subfield->{tagsubfield}, $value, '', $tagslib )
868
              : $value
869
          : $value;
870
    }
871
872
    my $marc_more=
873
      $self->more_subfields_xml
874
      ? MARC::Record->new_from_xml( $self->more_subfields_xml, 'UTF-8' )
875
      : undef;
876
877
    my $more_values;
878
    if ( $marc_more ) {
879
        my ( $field ) = $marc_more->fields;
880
        for my $sf ( $field->subfields ) {
881
            my $subfield_code = $sf->[0];
882
            my $value = $sf->[1];
883
            my $subfield = $tagslib->{$itemtagfield}->{$subfield_code};
884
            next unless $subfield; # We have the value but it's not mapped, data lose! No regression however.
885
            $value =
886
              $subfield->{authorised_value}
887
              ? C4::Biblio::GetAuthorisedValueDesc( $itemtagfield,
888
                $subfield->{tagsubfield}, $value, '', $tagslib )
889
              : $value;
890
891
            push @{$more_values->{$subfield_code}}, $value;
892
        }
893
894
        while ( my ( $k, $v ) = each %$more_values ) {
895
            $values->{$k} = join ' | ', @$v;
896
        }
897
    }
898
899
    return $values;
900
}
901
831
=head3 _set_found_trigger
902
=head3 _set_found_trigger
832
903
833
    $self->_set_found_trigger
904
    $self->_set_found_trigger
(-)a/cataloguing/additem.pl (-322 / +153 lines)
Lines 38-44 use Koha::ItemTypes; Link Here
38
use Koha::Libraries;
38
use Koha::Libraries;
39
use Koha::Patrons;
39
use Koha::Patrons;
40
use Koha::SearchEngine::Indexer;
40
use Koha::SearchEngine::Indexer;
41
use List::MoreUtils qw/any/;
42
use C4::Search;
41
use C4::Search;
43
use Storable qw(thaw freeze);
42
use Storable qw(thaw freeze);
44
use URI::Escape;
43
use URI::Escape;
Lines 47-106 use C4::Members; Link Here
47
use MARC::File::XML;
46
use MARC::File::XML;
48
use URI::Escape;
47
use URI::Escape;
49
use MIME::Base64 qw(decode_base64url encode_base64url);
48
use MIME::Base64 qw(decode_base64url encode_base64url);
49
use List::Util qw( first );
50
use List::MoreUtils qw( any uniq );
50
51
51
our $dbh = C4::Context->dbh;
52
our $dbh = C4::Context->dbh;
52
53
53
sub find_value {
54
    my ($tagfield,$insubfield,$record) = @_;
55
    my $result;
56
    my $indicator;
57
    foreach my $field ($record->field($tagfield)) {
58
        my @subfields = $field->subfields();
59
        foreach my $subfield (@subfields) {
60
            if (@$subfield[0] eq $insubfield) {
61
                $result .= @$subfield[1];
62
                $indicator = $field->indicator(1).$field->indicator(2);
63
            }
64
        }
65
    }
66
    return($indicator,$result);
67
}
68
69
sub get_item_from_barcode {
70
    my ($barcode)=@_;
71
    my $dbh=C4::Context->dbh;
72
    my $result;
73
    my $rq=$dbh->prepare("SELECT itemnumber from items where items.barcode=?");
74
    $rq->execute($barcode);
75
    ($result)=$rq->fetchrow;
76
    return($result);
77
}
78
79
# NOTE: This code is subject to change in the future with the implemenation of ajax based autobarcode code
80
# NOTE: 'incremental' is the ONLY autoBarcode option available to those not using javascript
81
sub _increment_barcode {
82
    my ($record, $frameworkcode) = @_;
83
    my ($tagfield,$tagsubfield) = &GetMarcFromKohaField( "items.barcode" );
84
    unless ($record->field($tagfield)->subfield($tagsubfield)) {
85
        my $sth_barcode = $dbh->prepare("select max(abs(barcode)) from items");
86
        $sth_barcode->execute;
87
        my ($newbarcode) = $sth_barcode->fetchrow;
88
        $newbarcode++;
89
        # OK, we have the new barcode, now create the entry in MARC record
90
        my $fieldItem = $record->field($tagfield);
91
        $record->delete_field($fieldItem);
92
        $fieldItem->add_subfields($tagsubfield => $newbarcode);
93
        $record->insert_fields_ordered($fieldItem);
94
    }
95
    return $record;
96
}
97
98
99
sub generate_subfield_form {
54
sub generate_subfield_form {
100
        my ($tag, $subfieldtag, $value, $tagslib,$subfieldlib, $branches, $biblionumber, $temp, $loop_data, $i, $restrictededition, $item) = @_;
55
        my ($tag, $subfieldtag, $value, $tagslib,$subfieldlib, $branches, $biblionumber, $temp, $subfields, $i, $restrictededition, $item) = @_;
101
  
56
  
102
        my $frameworkcode = &GetFrameworkCode($biblionumber);
57
        my $frameworkcode = &GetFrameworkCode($biblionumber);
103
58
59
        $item //= {};
60
104
        my %subfield_data;
61
        my %subfield_data;
105
        my $dbh = C4::Context->dbh;
62
        my $dbh = C4::Context->dbh;
106
        
63
        
Lines 171-177 sub generate_subfield_form { Link Here
171
            # builds list, depending on authorised value...
128
            # builds list, depending on authorised value...
172
            if ( $subfieldlib->{authorised_value} eq "LOST" ) {
129
            if ( $subfieldlib->{authorised_value} eq "LOST" ) {
173
                my $ClaimReturnedLostValue = C4::Context->preference('ClaimReturnedLostValue');
130
                my $ClaimReturnedLostValue = C4::Context->preference('ClaimReturnedLostValue');
174
                my $item_is_return_claim = $ClaimReturnedLostValue && $item && $item->itemlost && $ClaimReturnedLostValue eq $item->itemlost;
131
                my $item_is_return_claim = $ClaimReturnedLostValue && exists $item->{itemlost} && $ClaimReturnedLostValue eq $item->{itemlost};
175
                $subfield_data{IS_RETURN_CLAIM} = $item_is_return_claim;
132
                $subfield_data{IS_RETURN_CLAIM} = $item_is_return_claim;
176
133
177
                $subfield_data{IS_LOST_AV} = 1;
134
                $subfield_data{IS_LOST_AV} = 1;
Lines 276-282 sub generate_subfield_form { Link Here
276
                item_style => 1,
233
                item_style => 1,
277
            });
234
            });
278
            my $pars=  { dbh => $dbh, record => $temp, tagslib =>$tagslib,
235
            my $pars=  { dbh => $dbh, record => $temp, tagslib =>$tagslib,
279
                id => $subfield_data{id}, tabloop => $loop_data };
236
                id => $subfield_data{id}, tabloop => $subfields };
280
            $plugin->build( $pars );
237
            $plugin->build( $pars );
281
            if( !$plugin->errstr ) {
238
            if( !$plugin->errstr ) {
282
                my $class= 'buttonDot'. ( $plugin->noclick? ' disabled': '' );
239
                my $class= 'buttonDot'. ( $plugin->noclick? ' disabled': '' );
Lines 363-396 sub generate_subfield_form { Link Here
363
        return \%subfield_data;
320
        return \%subfield_data;
364
}
321
}
365
322
366
# Removes some subfields when prefilling items
367
# This function will remove any subfield that is not in the SubfieldsToUseWhenPrefill syspref
368
sub removeFieldsForPrefill {
369
370
    my $item = shift;
371
372
    # Getting item tag
373
    my ($tag, $subtag) = GetMarcFromKohaField( "items.barcode" );
374
375
    # Getting list of subfields to keep
376
    my $subfieldsToUseWhenPrefill = C4::Context->preference('SubfieldsToUseWhenPrefill');
377
378
    # Removing subfields that are not in the syspref
379
    if ($tag && $subfieldsToUseWhenPrefill) {
380
        my $field = $item->field($tag);
381
        my @subfieldsToUse= split(/ /,$subfieldsToUseWhenPrefill);
382
        foreach my $subfield ($field->subfields()) {
383
            if (!grep { $subfield->[0] eq $_ } @subfieldsToUse) {
384
                $field->delete_subfield(code => $subfield->[0]);
385
            }
386
387
        }
388
    }
389
390
    return $item;
391
392
}
393
394
my $input        = CGI->new;
323
my $input        = CGI->new;
395
my $error        = $input->param('error');
324
my $error        = $input->param('error');
396
325
Lines 405-410 if( $input->param('itemnumber') && !$input->param('biblionumber') ){ Link Here
405
    $itemnumber = $input->param('itemnumber');
334
    $itemnumber = $input->param('itemnumber');
406
}
335
}
407
336
337
my $biblio = Koha::Biblios->find($biblionumber);
338
408
my $op           = $input->param('op') || q{};
339
my $op           = $input->param('op') || q{};
409
my $hostitemnumber = $input->param('hostitemnumber');
340
my $hostitemnumber = $input->param('hostitemnumber');
410
my $marcflavour  = C4::Context->preference("marcflavour");
341
my $marcflavour  = C4::Context->preference("marcflavour");
Lines 416-422 my $fa_branch = $input->param('branch'); Link Here
416
my $fa_stickyduedate      = $input->param('stickyduedate');
347
my $fa_stickyduedate      = $input->param('stickyduedate');
417
my $fa_duedatespec        = $input->param('duedatespec');
348
my $fa_duedatespec        = $input->param('duedatespec');
418
349
419
my $frameworkcode = &GetFrameworkCode($biblionumber);
350
our $frameworkcode = &GetFrameworkCode($biblionumber);
420
351
421
# Defining which userflag is needing according to the framework currently used
352
# Defining which userflag is needing according to the framework currently used
422
my $userflags;
353
my $userflags;
Lines 445-473 $restrictededition = 0 if ($restrictededition != 0 && C4::Context->IsSuperLibra Link Here
445
# In case user has fast cataloging permission (and we're in fast cataloging), editing is not restricted
376
# In case user has fast cataloging permission (and we're in fast cataloging), editing is not restricted
446
$restrictededition = 0 if ($restrictededition != 0 && $frameworkcode eq 'FA' && haspermission($uid, {'editcatalogue' => 'fast_cataloging'}));
377
$restrictededition = 0 if ($restrictededition != 0 && $frameworkcode eq 'FA' && haspermission($uid, {'editcatalogue' => 'fast_cataloging'}));
447
378
448
my $tagslib = &GetMarcStructure(1,$frameworkcode);
379
our $tagslib = &GetMarcStructure(1,$frameworkcode);
449
my $record = GetMarcBiblio({ biblionumber => $biblionumber });
380
my $record = GetMarcBiblio({ biblionumber => $biblionumber });
450
381
451
output_and_exit_if_error( $input, $cookie, $template,
382
output_and_exit_if_error( $input, $cookie, $template,
452
    { module => 'cataloguing', record => $record } );
383
    { module => 'cataloguing', record => $record } );
453
384
454
my $oldrecord = TransformMarcToKoha($record);
385
my $oldrecord = TransformMarcToKoha($record);
455
my $itemrecord;
386
my $current_item;
456
my $nextop="additem";
387
my $nextop="additem";
457
my @errors; # store errors found while checking data BEFORE saving item.
388
my @errors; # store errors found while checking data BEFORE saving item.
458
389
459
# Getting last created item cookie
390
# Getting last created item cookie
460
my $prefillitem = C4::Context->preference('PrefillItem');
391
my $prefillitem = C4::Context->preference('PrefillItem');
461
my $justaddeditem;
392
my $item_from_cookie;
462
my $cookieitemrecord;
463
if ($prefillitem) {
393
if ($prefillitem) {
464
    my $lastitemcookie = $input->cookie('LastCreatedItem');
394
    my $lastitemcookie = $input->cookie('LastCreatedItem');
465
    if ($lastitemcookie) {
395
    if ($lastitemcookie) {
466
        $lastitemcookie = decode_base64url($lastitemcookie);
396
        $lastitemcookie = decode_base64url($lastitemcookie);
467
        eval {
397
        eval {
468
            if ( thaw($lastitemcookie) ) {
398
            if ( thaw($lastitemcookie) ) {
469
                $cookieitemrecord = thaw($lastitemcookie);
399
                $item_from_cookie = thaw($lastitemcookie);
470
                $cookieitemrecord = removeFieldsForPrefill($cookieitemrecord);
471
            }
400
            }
472
        };
401
        };
473
        if ($@) {
402
        if ($@) {
Lines 478-501 if ($prefillitem) { Link Here
478
}
407
}
479
408
480
#-------------------------------------------------------------------------------
409
#-------------------------------------------------------------------------------
481
my $current_item;
482
if ($op eq "additem") {
410
if ($op eq "additem") {
483
411
484
    my $add_submit                 = $input->param('add_submit');
412
    my $add_submit                 = $input->param('add_submit');
485
    my $add_duplicate_submit       = $input->param('add_duplicate_submit');
486
    my $add_multiple_copies_submit = $input->param('add_multiple_copies_submit');
413
    my $add_multiple_copies_submit = $input->param('add_multiple_copies_submit');
487
    my $number_of_copies           = $input->param('number_of_copies');
414
    my $number_of_copies           = $input->param('number_of_copies');
488
415
489
    # This is a bit tricky : if there is a cookie for the last created item and
490
    # we just added an item, the cookie value is not correct yet (it will be updated
491
    # next page). To prevent the form from being filled with outdated values, we
492
    # force the use of "add and duplicate" feature, so the form will be filled with
493
    # correct values.
494
    $add_duplicate_submit = 1 if ($prefillitem);
495
    $justaddeditem = 1;
496
497
    my @columns = Koha::Items->columns;
416
    my @columns = Koha::Items->columns;
498
    my $biblio = Koha::Biblios->find($biblionumber);
499
    my $item = Koha::Item->new;
417
    my $item = Koha::Item->new;
500
    $item->biblionumber($biblio->biblionumber);
418
    $item->biblionumber($biblio->biblionumber);
501
    for my $c ( @columns ) {
419
    for my $c ( @columns ) {
Lines 517-525 if ($op eq "additem") { Link Here
517
            }
435
            }
518
            $item->more_subfields_xml(undef);
436
            $item->more_subfields_xml(undef);
519
        } else {
437
        } else {
520
            my $v = $input->param("items.".$c);
438
            my @v = $input->multi_param("items.".$c);
521
            next unless defined $v;
439
            next unless @v;
522
            $item->$c($v);
440
            $item->$c(join ' | ', uniq @v);
523
        }
441
        }
524
    }
442
    }
525
443
Lines 530-573 if ($op eq "additem") { Link Here
530
    }
448
    }
531
449
532
    # If we have to add or add & duplicate, we add the item
450
    # If we have to add or add & duplicate, we add the item
533
    if ( $add_submit || $add_duplicate_submit ) {
451
    if ( $add_submit || $prefillitem) {
534
452
535
        # check for item barcode # being unique
453
        # check for item barcode # being unique
536
        if ( Koha::Items->search({ barcode => $item->barcode })->count ) {
454
        if ( Koha::Items->search({ barcode => $item->barcode })->count ) {
537
            # if barcode exists, don't create, but report The problem.
455
            # if barcode exists, don't create, but report The problem.
538
            push @errors, "barcode_not_unique";
456
            push @errors, "barcode_not_unique";
457
458
            $current_item = $item->unblessed; # Restore edit form for the same item
539
        }
459
        }
540
        else {
460
        else {
541
            $item->store->discard_changes;
461
            $item->store->discard_changes;
542
462
463
            # This is a bit tricky : if there is a cookie for the last created item and
464
            # we just added an item, the cookie value is not correct yet (it will be updated
465
            # next page). To prevent the form from being filled with outdated values, we
466
            # force the use of "add and duplicate" feature, so the form will be filled with
467
            # correct values.
468
543
            # FIXME This need to be rewritten, we must store $item->unblessed instead
469
            # FIXME This need to be rewritten, we must store $item->unblessed instead
544
            ## Pushing the last created item cookie back
470
            # Pushing the last created item cookie back
545
            #if ($prefillitem && defined $record) {
471
            if ( $prefillitem ) {
546
            #    my $itemcookie = $input->cookie(
472
                $item_from_cookie = $input->cookie(
547
            #        -name => 'LastCreatedItem',
473
                    -name => 'LastCreatedItem',
548
            #        # We encode_base64url the whole freezed structure so we're sure we won't have any encoding problems
474
                    # We encode_base64url the whole freezed structure so we're sure we won't have any encoding problems
549
            #        -value   => encode_base64url( freeze( $record ) ),
475
                    -value   => encode_base64url( freeze( { %{$item->unblessed}, itemnumber => undef } ) ),
550
            #        -HttpOnly => 1,
476
                    -HttpOnly => 1,
551
            #        -expires => ''
477
                    -expires => ''
552
            #    );
478
                );
553
479
554
            #    $cookie = [ $cookie, $itemcookie ];
480
                $cookie = [ $cookie, $item_from_cookie ];
555
            #}
481
            }
556
482
557
        }
483
        }
558
        $nextop = "additem";
484
        $nextop = "additem";
559
485
560
561
        # FIXME reset item to the item we were editing
562
        #if ($exist_itemnumber) {
563
564
        #    $itemrecord = $record;
565
        #}
566
        $current_item = $item->unblessed;
567
    }
486
    }
568
487
569
    # If we have to add & duplicate
488
    # If we have to add & duplicate
570
    if ($add_duplicate_submit) {
489
    if ($prefillitem) {
571
        if (C4::Context->preference('autoBarcode') eq 'incremental') {
490
        if (C4::Context->preference('autoBarcode') eq 'incremental') {
572
            my ( $barcode ) = C4::Barcodes::ValueBuilder::incremental::get_barcode;
491
            my ( $barcode ) = C4::Barcodes::ValueBuilder::incremental::get_barcode;
573
            $current_item->{barcode} = $barcode;
492
            $current_item->{barcode} = $barcode;
Lines 576-589 if ($op eq "additem") { Link Here
576
            # we have to clear the barcode field in the duplicate item record to make way for the new one generated by the javascript plugin
495
            # we have to clear the barcode field in the duplicate item record to make way for the new one generated by the javascript plugin
577
            $current_item->{barcode} = undef; # FIXME or delete?
496
            $current_item->{barcode} = undef; # FIXME or delete?
578
        }
497
        }
579
        # FIXME This subroutine needs to be adjusted
580
        # We want to pass $item
581
        # $itemrecord = removeFieldsForPrefill($itemrecord) if ($prefillitem);
582
    }
498
    }
583
499
584
    # If we have to add multiple copies
500
    # If we have to add multiple copies
585
    if ($add_multiple_copies_submit) {
501
    if ($add_multiple_copies_submit) {
586
502
503
        $current_item = $item->unblessed;
504
587
        my $copynumber = $current_item->{copynumber};
505
        my $copynumber = $current_item->{copynumber};
588
        my $oldbarcode = $current_item->{barcode};
506
        my $oldbarcode = $current_item->{barcode};
589
507
Lines 594-600 if ($op eq "additem") { Link Here
594
        if ( $oldbarcode && !$testbarcode ) {
512
        if ( $oldbarcode && !$testbarcode ) {
595
513
596
            push @errors, "no_next_barcode";
514
            push @errors, "no_next_barcode";
597
            $itemrecord = $record;
598
515
599
        }
516
        }
600
        else {
517
        else {
Lines 642-648 if ($op eq "additem") { Link Here
642
                if ( !$exist_itemnumber ) {
559
                if ( !$exist_itemnumber ) {
643
                    delete $current_item->{itemnumber};
560
                    delete $current_item->{itemnumber};
644
                    $current_item = Koha::Item->new($current_item)->store(
561
                    $current_item = Koha::Item->new($current_item)->store(
645
                        { skip_record_index => 1 } )->discard_changes->unblessed;
562
                        { skip_record_index => 1 } );
563
                    $current_item->discard_changes; # Cannot chain discard_changes
564
                    $current_item = $current_item->unblessed;
646
                    set_item_default_location($current_item->{itemnumber});
565
                    set_item_default_location($current_item->{itemnumber});
647
566
648
# We count the item only if it was really added
567
# We count the item only if it was really added
Lines 682-722 if ($op eq "additem") { Link Here
682
} elsif ($op eq "edititem") {
601
} elsif ($op eq "edititem") {
683
#-------------------------------------------------------------------------------
602
#-------------------------------------------------------------------------------
684
# retrieve item if exist => then, it's a modif
603
# retrieve item if exist => then, it's a modif
685
    $itemrecord = C4::Items::GetMarcItem($biblionumber,$itemnumber);
604
    $current_item = Koha::Items->find($itemnumber)->unblessed;
605
    # FIXME Handle non existent item
686
    $nextop = "saveitem";
606
    $nextop = "saveitem";
687
#-------------------------------------------------------------------------------
607
#-------------------------------------------------------------------------------
688
} elsif ($op eq "dupeitem") {
608
} elsif ($op eq "dupeitem") {
689
#-------------------------------------------------------------------------------
609
#-------------------------------------------------------------------------------
690
# retrieve item if exist => then, it's a modif
610
# retrieve item if exist => then, it's a modif
691
    $itemrecord = C4::Items::GetMarcItem($biblionumber,$itemnumber);
611
    my $item = Koha::Items->find($itemnumber);
612
    # FIXME Handle non existent item
692
    if (C4::Context->preference('autoBarcode') eq 'incremental') {
613
    if (C4::Context->preference('autoBarcode') eq 'incremental') {
693
        $itemrecord = _increment_barcode($itemrecord, $frameworkcode);
614
        my ( $barcode ) = C4::Barcodes::ValueBuilder::incremental::get_barcode;
615
        $item->barcode($barcode);
694
    }
616
    }
695
    else {
617
    else {
696
        # we have to clear the barcode field in the duplicate item record to make way for the new one generated by the javascript plugin
618
        $item->barcode(undef); # Don't save it!
697
        my ($tagfield,$tagsubfield) = &GetMarcFromKohaField( "items.barcode" );
698
        my $fieldItem = $itemrecord->field($tagfield);
699
        $itemrecord->delete_field($fieldItem);
700
        $fieldItem->delete_subfields($tagsubfield);
701
        $itemrecord->insert_fields_ordered($fieldItem);
702
    }
619
    }
703
620
704
    #check for hidden subfield and remove them for the duplicated item
705
    foreach my $field ($itemrecord->fields()){
706
        my $tag = $field->{_tag};
707
        foreach my $subfield ($field->subfields()){
708
            my $subfieldtag = $subfield->[0];
709
            if ($tagslib->{$tag}->{$subfieldtag}->{'tab'} ne "10"
710
            ||  abs($tagslib->{$tag}->{$subfieldtag}->{hidden})>4 ){
711
                my $fieldItem = $itemrecord->field($tag);
712
                $itemrecord->delete_field($fieldItem);
713
                $fieldItem->delete_subfields($subfieldtag);
714
                $itemrecord->insert_fields_ordered($fieldItem);
715
            }
716
        }
717
    }
718
719
    $itemrecord = removeFieldsForPrefill($itemrecord) if ($prefillitem);
720
    $nextop = "additem";
621
    $nextop = "additem";
721
#-------------------------------------------------------------------------------
622
#-------------------------------------------------------------------------------
722
} elsif ($op eq "delitem") {
623
} elsif ($op eq "delitem") {
Lines 785-793 if ($op eq "additem") { Link Here
785
            }
686
            }
786
            $item->more_subfields_xml(undef);
687
            $item->more_subfields_xml(undef);
787
        } else {
688
        } else {
788
            my $v = $input->param("items.".$c);
689
            my @v = $input->multi_param("items.".$c);
789
            next unless defined $v;
690
            next unless @v;
790
            $item->$c($v);
691
            $item->$c(join ' | ', uniq @v);
791
        }
692
        }
792
    }
693
    }
793
694
Lines 795-800 if ($op eq "additem") { Link Here
795
    if ( Koha::Items->search({ barcode => $item->barcode, itemnumber => { '!=' => $item->itemnumber } })->count ) {
696
    if ( Koha::Items->search({ barcode => $item->barcode, itemnumber => { '!=' => $item->itemnumber } })->count ) {
796
        # FIXME We shouldn't need that, ->store would explode as there is a unique constraint on items.barcode
697
        # FIXME We shouldn't need that, ->store would explode as there is a unique constraint on items.barcode
797
        push @errors,"barcode_not_unique";
698
        push @errors,"barcode_not_unique";
699
        $current_item = $item->unblessed; # Restore edit form for the same item
798
    } else {
700
    } else {
799
        my $newitemlost = $item->itemlost;
701
        my $newitemlost = $item->itemlost;
800
        if ( $newitemlost && $newitemlost ge '1' && !$olditemlost ) {
702
        if ( $newitemlost && $newitemlost ge '1' && !$olditemlost ) {
Lines 834-1046 if ($op) { Link Here
834
#-------------------------------------------------------------------------------
736
#-------------------------------------------------------------------------------
835
737
836
# now, build existiing item list
738
# now, build existiing item list
837
my $temp = GetMarcBiblio({ biblionumber => $biblionumber });
838
#my @fields = $record->fields();
839
840
739
841
my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code
740
my @items;
842
my @big_array;
741
for my $item ( $biblio->items->as_list, $biblio->host_items->as_list ) {
843
#---- finds where items.itemnumber is stored
742
    push @items, $item->columns_to_str;
844
my (  $itemtagfield,   $itemtagsubfield) = &GetMarcFromKohaField( "items.itemnumber" );
845
my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField( "items.homebranch" );
846
C4::Biblio::EmbedItemsInMarcBiblio({
847
    marc_record  => $temp,
848
    biblionumber => $biblionumber });
849
my @fields = $temp->fields();
850
851
852
my @hostitemnumbers;
853
if ( C4::Context->preference('EasyAnalyticalRecords') ) {
854
    my $analyticfield = '773';
855
    if ($marcflavour  eq 'MARC21' || $marcflavour eq 'NORMARC') {
856
        $analyticfield = '773';
857
    } elsif ($marcflavour eq 'UNIMARC') {
858
        $analyticfield = '461';
859
    }
860
    foreach my $hostfield ($temp->field($analyticfield)){
861
        my $hostbiblionumber = $hostfield->subfield('0');
862
        if ($hostbiblionumber){
863
            my $hostrecord = GetMarcBiblio({
864
                biblionumber => $hostbiblionumber,
865
                embed_items  => 1 });
866
            if ($hostrecord) {
867
                my ($itemfield, undef) = GetMarcFromKohaField( 'items.itemnumber' );
868
                foreach my $hostitem ($hostrecord->field($itemfield)){
869
                    if ($hostitem->subfield('9') eq $hostfield->subfield('9')){
870
                        push (@fields, $hostitem);
871
                        push (@hostitemnumbers, $hostfield->subfield('9'));
872
                    }
873
                }
874
            }
875
        }
876
    }
877
}
743
}
878
744
879
foreach my $field (@fields) {
745
my @witness_attributes = uniq map {
880
    next if ( $field->tag() < 10 );
746
    my $item = $_;
881
747
    map { defined $item->{$_} && $item->{$_} ne "" ? $_ : () } keys %$item
882
    my @subf = $field->subfields or ();    # don't use ||, as that forces $field->subfelds to be interpreted in scalar context
748
} @items;
883
    my %this_row;
884
    # loop through each subfield
885
    my $i = 0;
886
    foreach my $subfield (@subf){
887
        my $subfieldcode = $subfield->[0];
888
        my $subfieldvalue= $subfield->[1];
889
890
        next if ($tagslib->{$field->tag()}->{$subfieldcode}->{tab} ne 10 
891
                && ($field->tag() ne $itemtagfield 
892
                && $subfieldcode   ne $itemtagsubfield));
893
        $witness{$subfieldcode} = $tagslib->{$field->tag()}->{$subfieldcode}->{lib} if ($tagslib->{$field->tag()}->{$subfieldcode}->{tab}  eq 10);
894
		if ($tagslib->{$field->tag()}->{$subfieldcode}->{tab}  eq 10) {
895
		    $this_row{$subfieldcode} .= " | " if($this_row{$subfieldcode});
896
        	$this_row{$subfieldcode} .= GetAuthorisedValueDesc( $field->tag(),
897
                        $subfieldcode, $subfieldvalue, '', $tagslib) 
898
						|| $subfieldvalue;
899
        }
900
749
901
        if (($field->tag eq $branchtagfield) && ($subfieldcode eq $branchtagsubfield) && C4::Context->preference("IndependentBranches")) {
750
our ( $itemtagfield, $itemtagsubfield ) = &GetMarcFromKohaField("items.itemnumber");
902
            #verifying rights
903
            my $userenv = C4::Context->userenv();
904
            unless (C4::Context->IsSuperLibrarian() or (($userenv->{'branch'} eq $subfieldvalue))){
905
                $this_row{'nomod'} = 1;
906
            }
907
        }
908
        $this_row{itemnumber} = $subfieldvalue if ($field->tag() eq $itemtagfield && $subfieldcode eq $itemtagsubfield);
909
910
        if ( C4::Context->preference('EasyAnalyticalRecords') ) {
911
            foreach my $hostitemnumber (@hostitemnumbers) {
912
                my $item = Koha::Items->find( $hostitemnumber );
913
                if ($this_row{itemnumber} eq $hostitemnumber) {
914
                    $this_row{hostitemflag} = 1;
915
                    $this_row{hostbiblionumber}= $item->biblio->biblionumber;
916
                    last;
917
                }
918
            }
919
        }
920
    }
921
    if (%this_row) {
922
        push(@big_array, \%this_row);
923
    }
924
}
925
751
926
my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField( "items.holdingbranch" );
752
my $subfieldcode_attribute_mappings;
927
@big_array = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @big_array;
753
for my $subfield_code ( keys %{ $tagslib->{$itemtagfield} } ) {
928
929
# now, construct template !
930
# First, the existing items for display
931
my @item_value_loop;
932
my @header_value_loop;
933
for my $row ( @big_array ) {
934
    my %row_data;
935
    my @item_fields;
936
    foreach my $key (sort keys %witness){
937
        my $item_field;
938
        if ( $row->{$key} ){
939
            $item_field->{field} = $row->{$key};
940
        } else {
941
            $item_field->{field} = '';
942
        }
943
754
944
        for my $kohafield (
755
    my $subfield = $tagslib->{$itemtagfield}->{$subfield_code};
945
            qw( items.dateaccessioned items.onloan items.datelastseen items.datelastborrowed items.replacementpricedate )
946
          )
947
        {
948
            my ( undef, $subfield ) = GetMarcFromKohaField($kohafield);
949
            next unless $key eq $subfield;
950
            $item_field->{datatype} = 'date';
951
        }
952
756
953
        push @item_fields, $item_field;
757
    next if IsMarcStructureInternal( $subfield );
758
    next unless $subfield->{tab} eq 10; # Is this really needed?
759
760
    my $attribute;
761
    if ( $subfield->{kohafield} ) {
762
        ( $attribute = $subfield->{kohafield} ) =~ s|^items\.||;
763
    } else {
764
        $attribute = $subfield_code; # It's in more_subfields_xml
954
    }
765
    }
955
    $row_data{item_value} = [ @item_fields ];
766
    next unless grep { $attribute eq $_ } @witness_attributes;
956
    $row_data{itemnumber} = $row->{itemnumber};
767
    $subfieldcode_attribute_mappings->{$subfield_code} = $attribute;
957
    #reporting this_row values
958
    $row_data{'nomod'} = $row->{'nomod'};
959
    $row_data{'hostitemflag'} = $row->{'hostitemflag'};
960
    $row_data{'hostbiblionumber'} = $row->{'hostbiblionumber'};
961
#	$row_data{'countanalytics'} = $row->{'countanalytics'};
962
    push(@item_value_loop,\%row_data);
963
}
768
}
964
foreach my $subfield_code (sort keys(%witness)) {
965
    my %header_value;
966
    $header_value{header_value} = $witness{$subfield_code};
967
968
    my $subfieldlib = $tagslib->{$itemtagfield}->{$subfield_code};
969
    my $kohafield = $subfieldlib->{kohafield};
970
    if ( $kohafield && $kohafield =~ /items.(.+)/ ) {
971
        $header_value{column_name} = $1;
972
    }
973
769
974
    push(@header_value_loop, \%header_value);
770
my @header_value_loop = map {
975
}
771
    {
772
        header_value  => $tagslib->{$itemtagfield}->{$_}->{lib},
773
        attribute     => $subfieldcode_attribute_mappings->{$_},
774
        subfield_code => $_,
775
    }
776
} sort keys %$subfieldcode_attribute_mappings;
976
777
977
# now, build the item form for entering a new item
778
# now, build the item form for entering a new item
978
my @loop_data =();
979
my $i=0;
980
981
my $branch = $input->param('branch') || C4::Context->userenv->{branch};
779
my $branch = $input->param('branch') || C4::Context->userenv->{branch};
982
my $libraries = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed;# build once ahead of time, instead of multiple times later.
780
my $libraries = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed;# build once ahead of time, instead of multiple times later.
983
for my $library ( @$libraries ) {
781
for my $library ( @$libraries ) {
984
    $library->{selected} = 1 if $library->{branchcode} eq $branch
782
    $library->{selected} = 1 if $library->{branchcode} eq $branch
985
}
783
}
986
784
987
my $item = Koha::Items->find($itemnumber);
988
785
989
# We generate form, from actuel record
786
# Using last created item if it exists
990
@fields = ();
787
$current_item = $item_from_cookie
991
if($itemrecord){
788
  if $item_from_cookie
992
    foreach my $field ($itemrecord->fields()){
789
  && $prefillitem
993
        my $tag = $field->{_tag};
790
  && $op ne "additem"
994
        foreach my $subfield ( $field->subfields() ){
791
  && $op ne "edititem";
995
792
996
            my $subfieldtag = $subfield->[0];
793
my @subfields_to_prefill = split ' ', C4::Context->preference('SubfieldsToUseWhenPrefill');
997
            my $value       = $subfield->[1];
998
            my $subfieldlib = $tagslib->{$tag}->{$subfieldtag};
999
794
1000
            next if ($tagslib->{$tag}->{$subfieldtag}->{'tab'} ne "10");
795
if ( $current_item->{more_subfields_xml} ) {
796
    $current_item->{marc_more_subfields_xml} = MARC::Record->new_from_xml($current_item->{more_subfields_xml}, 'UTF-8');
797
}
1001
798
1002
            my $subfield_data = generate_subfield_form($tag, $subfieldtag, $value, $tagslib, $subfieldlib, $libraries, $biblionumber, $temp, \@loop_data, $i, $restrictededition, $item);
799
# We generate form, and fill with values if defined
1003
            push @fields, "$tag$subfieldtag";
800
my $temp = GetMarcBiblio({ biblionumber => $biblionumber });
1004
            push (@loop_data, $subfield_data);
801
my $i = 0;
1005
            $i++;
802
my @subfields;
803
foreach my $tag ( keys %{$tagslib} ) {
804
    foreach my $subtag ( keys %{ $tagslib->{$tag} } ) {
805
806
        my $subfield = $tagslib->{$tag}{$subtag};
807
808
        next if IsMarcStructureInternal( $subfield );
809
        next if ( $subfield->{tab} ne "10" );
810
811
        my @values = ();
812
813
        my $subfield_data;
814
815
        # If we are not adding a new item
816
        # OR
817
        # If the subfield must be prefilled with last catalogued item
818
        if (
819
            $nextop ne 'additem'
820
            || (
821
                !$prefillitem
822
                || ( $prefillitem && grep { $_ eq $subtag }
823
                    @subfields_to_prefill )
824
            )
825
          )
826
        {
827
            my $kohafield = $subfield->{kohafield};
828
            if ($kohafield) {
829
830
                # This is a mapped field
831
                ( my $attribute = $kohafield ) =~ s|^items\.||;
832
                push @values, $subfield->{repeatable}
833
                    ? split '\s\|\s', $current_item->{$attribute}
834
                    : $current_item->{$attribute}
835
                  if defined $current_item->{$attribute};
836
            } else {
837
                # Not mapped, picked the values from more_subfields_xml's MARC
838
                my $marc_more = $current_item->{marc_more_subfields_xml};
839
                if ( $marc_more ) {
840
                    for my $f ( $marc_more->fields($tag) ) {
841
                        push @values, $f->subfield($subtag);
1006
                    }
842
                    }
1007
1008
                }
843
                }
1009
            }
844
            }
1010
    # and now we add fields that are empty
845
        }
1011
1012
# Using last created item if it exists
1013
846
1014
$itemrecord = $cookieitemrecord if ($prefillitem and not $justaddeditem and $op ne "edititem");
847
        @values = ('') unless @values;
1015
848
1016
# We generate form, and fill with values if defined
849
        for my $value (@values) {
1017
foreach my $tag ( keys %{$tagslib}){
850
            my $subfield_data = generate_subfield_form(
1018
    foreach my $subtag (keys %{$tagslib->{$tag}}){
851
                $tag,                        $subtag,
1019
        next if IsMarcStructureInternal($tagslib->{$tag}{$subtag});
852
                $value,                      $tagslib,
1020
        next if ($tagslib->{$tag}->{$subtag}->{'tab'} ne "10");
853
                $subfield,                   $libraries,
1021
        next if any { /^$tag$subtag$/ }  @fields;
854
                $biblionumber,               $temp,
1022
855
                \@subfields,                 $i,
1023
        my @values = (undef);
856
                $restrictededition,          $current_item,
1024
        @values = $itemrecord->field($tag)->subfield($subtag) if ($itemrecord && defined($itemrecord->field($tag)) && defined($itemrecord->field($tag)->subfield($subtag)));
857
            );
1025
        for my $value (@values){
858
            push @subfields, $subfield_data;
1026
            my $subfield_data = generate_subfield_form($tag, $subtag, $value, $tagslib, $tagslib->{$tag}->{$subtag}, $libraries, $biblionumber, $temp, \@loop_data, $i, $restrictededition, $item);
1027
            push (@loop_data, $subfield_data);
1028
            $i++;
859
            $i++;
1029
        }
860
        }
1030
  }
861
    }
1031
}
862
}
1032
@loop_data = sort { $a->{display_order} <=> $b->{display_order} || $a->{subfield} cmp $b->{subfield} } @loop_data;
863
@subfields = sort { $a->{display_order} <=> $b->{display_order} || $a->{subfield} cmp $b->{subfield} } @subfields;
1033
864
1034
# what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit.
865
# what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit.
1035
$template->param(
866
$template->param(
1036
    biblionumber => $biblionumber,
867
    biblionumber => $biblionumber,
1037
    title        => $oldrecord->{title},
868
    title        => $oldrecord->{title},
1038
    author       => $oldrecord->{author},
869
    author       => $oldrecord->{author},
1039
    item_loop        => \@item_value_loop,
870
    items        => \@items,
1040
    item_header_loop => \@header_value_loop,
871
    item_header_loop => \@header_value_loop,
1041
    item             => \@loop_data,
872
    subfields    => \@subfields,
1042
    itemnumber       => $itemnumber,
873
    itemnumber       => $itemnumber,
1043
    barcode          => $item ? $item->barcode : undef,
874
    barcode          => $current_item->{barcode},
1044
    itemtagfield     => $itemtagfield,
875
    itemtagfield     => $itemtagfield,
1045
    itemtagsubfield  => $itemtagsubfield,
876
    itemtagsubfield  => $itemtagsubfield,
1046
    op      => $nextop,
877
    op      => $nextop,
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt (-52 / +50 lines)
Lines 1-6 Link Here
1
[% USE raw %]
1
[% USE raw %]
2
[% USE Asset %]
2
[% USE Asset %]
3
[% USE Koha %]
3
[% USE Koha %]
4
[% USE Branches %]
4
[% USE KohaDates %]
5
[% USE KohaDates %]
5
[% USE TablesSettings %]
6
[% USE TablesSettings %]
6
[% INCLUDE 'doc-head-open.inc' %]
7
[% INCLUDE 'doc-head-open.inc' %]
Lines 47-53 Link Here
47
[% IF last_item_for_hold %]<div class="dialog alert"><strong>Cannot delete</strong>: Last item for bibliographic record with biblio-level hold on it.</div>[% END %]
48
[% IF last_item_for_hold %]<div class="dialog alert"><strong>Cannot delete</strong>: Last item for bibliographic record with biblio-level hold on it.</div>[% END %]
48
49
49
<div id="cataloguing_additem_itemlist">
50
<div id="cataloguing_additem_itemlist">
50
    [% IF ( item_loop ) %]
51
    [% IF items %]
51
        [% SET date_fields = [ 'dateaccessioned', 'onloan', 'datelastseen', 'datelastborrowed', 'replacementpricedate' ] %]
52
        [% SET date_fields = [ 'dateaccessioned', 'onloan', 'datelastseen', 'datelastborrowed', 'replacementpricedate' ] %]
52
        <div>
53
        <div>
53
        <table id="itemst">
54
        <table id="itemst">
Lines 55-65 Link Here
55
            <tr>
56
            <tr>
56
                <th class="NoSort">&nbsp;</th>
57
                <th class="NoSort">&nbsp;</th>
57
                [% FOREACH item_header IN item_header_loop %]
58
                [% FOREACH item_header IN item_header_loop %]
58
                    [% IF item_header.column_name %]
59
                    [% IF item_header.attribute %]
59
                        [% IF date_fields.grep(item_header.column_name).size %]
60
                        [% IF date_fields.grep(item_header.attribute).size %]
60
                            <th class="title-string" data-colname="[% item_header.column_name | html %]">
61
                            <th class="title-string" data-colname="[% item_header.attribute | html %]">
61
                        [% ELSE %]
62
                        [% ELSE %]
62
                            <th data-colname="[% item_header.column_name | html %]">
63
                            <th data-colname="[% item_header.attribute | html %]">
63
                        [% END %]
64
                        [% END %]
64
                    [% ELSE %]
65
                    [% ELSE %]
65
                        <th>
66
                        <th>
Lines 70-123 Link Here
70
            </tr>
71
            </tr>
71
          </thead>
72
          </thead>
72
          <tbody>
73
          <tbody>
73
                [% FOREACH item_loo IN item_loop %]
74
                [% FOREACH item IN items %]
74
                    [% IF ( item_loo.itemnumber == itemnumber) %]
75
                    [% SET can_be_edited = ! ( Koha.Preference('IndependentBranches') && ! logged_in_user && item.homebranch != Branches.GetLoggedInBranchcode() ) %]
75
                        [% IF item_loo.nomod %]
76
                    [% IF item.itemnumber == itemnumber%]
76
                           <tr id="row[% item_loo.itemnumber | html %]" class="active">
77
                        [% UNLESS can_be_edited %]
78
                           <tr id="row[% item.itemnumber | html %]" class="active">
77
                        [% ELSE %]
79
                        [% ELSE %]
78
                            <tr id="row[% item_loo.itemnumber | html %]" class="active editable">
80
                            <tr id="row[% item.itemnumber | html %]" class="active editable">
79
                        [% END %]
81
                        [% END %]
80
                    [% ELSE %]
82
                    [% ELSE %]
81
                        [% IF item_loo.nomod %]
83
                        [% UNLESS can_be_edited %]
82
                           <tr id="row[% item_loo.itemnumber | html %]">
84
                           <tr id="row[% item.itemnumber | html %]">
83
                        [% ELSE %]
85
                        [% ELSE %]
84
                            <tr id="row[% item_loo.itemnumber | html %]" class="editable">
86
                            <tr id="row[% item.itemnumber | html %]" class="editable">
85
                        [% END %]
87
                        [% END %]
86
                    [% END %]
88
                    [% END %]
87
                    [% IF ( item_loo.nomod ) %]
89
                    [% UNLESS can_be_edited %]
88
                      <td>&nbsp;</td>
90
                      <td>&nbsp;</td>
89
                    [% ELSE %]
91
                    [% ELSE %]
90
                      <td>
92
                      <td>
91
                          <div class="btn-group dropup">
93
                          <div class="btn-group dropup">
92
                          <a class="btn btn-default btn-xs dropdown-toggle" id="itemactions[% item_loo.itemnumber | html %]" role="button" data-toggle="dropdown" href="#">
94
                          <a class="btn btn-default btn-xs dropdown-toggle" id="itemactions[% item.itemnumber | html %]" role="button" data-toggle="dropdown" href="#">
93
                              Actions <b class="caret"></b>
95
                              Actions <b class="caret"></b>
94
                          </a>
96
                          </a>
95
                          <ul class="dropdown-menu" role="menu" aria-labelledby="itemactions[% item_loo.itemnumber | html %]">
97
                          <ul class="dropdown-menu" role="menu" aria-labelledby="itemactions[% item.itemnumber | html %]">
96
98
97
                        [% IF ( item_loo.hostitemflag ) %]
99
                        [% IF item.biblionumber != biblionumber %] [%# Host item %]
98
                              <li><a href="additem.pl?op=edititem&amp;biblionumber=[% item_loo.hostbiblionumber | uri %]&amp;itemnumber=[% item_loo.itemnumber | uri %]#edititem">Edit in host</a> &nbsp; <a class="delete" href="/cgi-bin/koha/cataloguing/additem.pl?op=delinkitem&amp;biblionumber=[% biblionumber | html %]&amp;hostitemnumber=[% item_loo.itemnumber | html %]&amp;searchid=[% searchid | html %]">Delink</a></li>
100
                              <li><a href="additem.pl?op=edititem&amp;biblionumber=[% item.biblionumber | uri %]&amp;itemnumber=[% item.itemnumber | uri %]#edititem">Edit in host</a> &nbsp; <a class="delete" href="/cgi-bin/koha/cataloguing/additem.pl?op=delinkitem&amp;biblionumber=[% biblionumber | html %]&amp;hostitemnumber=[% item.itemnumber | html %]&amp;searchid=[% searchid | html %]">Delink</a></li>
99
                        [% ELSE %]
101
                        [% ELSE %]
100
                              <li><a href="additem.pl?op=edititem&amp;biblionumber=[% biblionumber | uri %]&amp;itemnumber=[% item_loo.itemnumber | uri %]&amp;searchid=[% searchid | uri %]#edititem">Edit</a></li>
102
                              <li><a href="additem.pl?op=edititem&amp;biblionumber=[% biblionumber | uri %]&amp;itemnumber=[% item.itemnumber | uri %]&amp;searchid=[% searchid | uri %]#edititem">Edit</a></li>
101
                              <li><a href="additem.pl?op=dupeitem&amp;biblionumber=[% biblionumber | uri %]&amp;itemnumber=[% item_loo.itemnumber | uri %]&amp;searchid=[% searchid | uri %]#additema">Duplicate</a></li>
103
                              <li><a href="additem.pl?op=dupeitem&amp;biblionumber=[% biblionumber | uri %]&amp;itemnumber=[% item.itemnumber | uri %]&amp;searchid=[% searchid | uri %]#additema">Duplicate</a></li>
102
                              <li class="print_label"><a href="/cgi-bin/koha/labels/label-edit-batch.pl?op=add&amp;number_type=itemnumber&amp;number_list=[% item_loo.itemnumber | uri %]" target="_blank" >Print label</a></li>
104
                              <li class="print_label"><a href="/cgi-bin/koha/labels/label-edit-batch.pl?op=add&amp;number_type=itemnumber&amp;number_list=[% item.itemnumber | uri %]" target="_blank" >Print label</a></li>
103
                          [% IF ( item_loo.countanalytics ) %]
105
                              <li><a class="delete" href="/cgi-bin/koha/cataloguing/additem.pl?op=delitem&amp;biblionumber=[% item.biblionumber | html %]&amp;itemnumber=[% item.itemnumber | html %]&amp;searchid=[% searchid | html %]" onclick="return confirm_deletion();">Delete</a></li>
104
                              <li><a href="/cgi-bin/koha/catalogue/search.pl?idx=hi&amp;q=% item_loo.itemnumber %]">View analytics</a></li>
105
                          [% ELSE %]
106
                              <li><a class="delete" href="/cgi-bin/koha/cataloguing/additem.pl?op=delitem&amp;biblionumber=[% biblionumber | html %]&amp;itemnumber=[% item_loo.itemnumber | html %]&amp;searchid=[% searchid | html %]" onclick="return confirm_deletion();">Delete</a></li>
107
                          [% END %]
108
                        [% END %]
106
                        [% END %]
109
                            [% IF ( OPACBaseURL ) %]
107
                            [% IF ( OPACBaseURL ) %]
110
                                <li class="view-in-opac"><a target="_blank" href="[% Koha.Preference('OPACBaseURL') | url %]/cgi-bin/koha/opac-detail.pl?biblionumber=[% biblionumber | uri %]">OPAC view</a></li>
108
                                <li class="view-in-opac"><a target="_blank" href="[% Koha.Preference('OPACBaseURL') | url %]/cgi-bin/koha/opac-detail.pl?biblionumber=[% item.biblionumber | uri %]">OPAC view</a></li>
111
                            [% END %]
109
                            [% END %]
112
                          </ul>
110
                          </ul>
113
                          </div>
111
                          </div>
114
                      </td>
112
                      </td>
115
                    [% END %]
113
                    [% END %]
116
                [% FOREACH item_valu IN item_loo.item_value %]
114
                [% FOREACH header IN item_header_loop %]
117
                    [% IF item_valu.datatype == 'date' %]
115
                    [% SET attribute = header.attribute %]
118
                        <td><span title="[% item_valu.field | html %]">[% item_valu.field | $KohaDates %]</span></td>
116
                    [% IF header.attribute AND date_fields.grep(attribute).size %]
117
                        <td><span title="[% item.$attribute | html %]">[% item.$attribute | $KohaDates %]</span></td>
119
                    [% ELSE %]
118
                    [% ELSE %]
120
                        <td>[% item_valu.field | html %]</td>
119
                        <td>[% item.$attribute | html %]</td>
121
                    [% END %]
120
                    [% END %]
122
                [% END %]
121
                [% END %]
123
                </tr>
122
                </tr>
Lines 147-172 Link Here
147
    [% END %]
146
    [% END %]
148
	<fieldset class="rows">
147
	<fieldset class="rows">
149
	<ol>
148
	<ol>
150
        [% FOREACH ite IN item %]
149
        [% FOREACH subfield IN subfields %]
151
150
152
                [% IF ite.kohafield == 'items.more_subfields_xml' %]
151
                [% IF subfield.kohafield == 'items.more_subfields_xml' %]
153
                    [% SET kohafield = 'items.more_subfields_xml_' _ ite.subfield %]
152
                    [% SET kohafield = 'items.more_subfields_xml_' _ subfield.subfield %]
154
                [% ELSE %]
153
                [% ELSE %]
155
                    [% SET kohafield = ite.kohafield %]
154
                    [% SET kohafield = subfield.kohafield %]
156
                [% END %]
155
                [% END %]
157
156
158
               <li><div class="subfield_line" style="[% ite.visibility | html %]" id="subfield[% ite.tag | html %][% ite.subfield | html %][% ite.random | html %]">
157
               <li><div class="subfield_line" style="[% subfield.visibility | html %]" id="subfield[% subfield.tag | html %][% subfield.subfield | html %][% subfield.random | html %]">
159
                [% IF ( ite.mandatory ) %]
158
                [% IF ( subfield.mandatory ) %]
160
               <label class="required">[% ite.subfield | html %] - [% ite.marc_lib | $raw %]</label>
159
               <label class="required">[% subfield.subfield | html %] - [% subfield.marc_lib | $raw %]</label>
161
               [% ELSE %]
160
               [% ELSE %]
162
               <label>[% ite.subfield | html %] - [% ite.marc_lib | $raw %]</label>
161
               <label>[% subfield.subfield | html %] - [% subfield.marc_lib | $raw %]</label>
163
               [% END %]
162
               [% END %]
164
163
165
                [% SET mv = ite.marc_value %]
164
                [% SET mv = subfield.marc_value %]
166
                [% IF ( mv.type == 'hidden' ) %]
165
                [% IF ( mv.type == 'hidden' ) %]
167
                    <input type="hidden" id="[%- mv.id | html -%]" name="[% kohafield %]" class="input_marceditor" size="50" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]">
166
                    <input type="hidden" id="[%- mv.id | html -%]" name="[% kohafield %]" class="input_marceditor" size="50" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]">
168
                [% ELSIF ( mv.type == 'select' ) %]
167
                [% ELSIF ( mv.type == 'select' ) %]
169
                    [% IF ( mv.readonly || ite.IS_RETURN_CLAIM ) %]
168
                    [% IF ( mv.readonly || subfield.IS_RETURN_CLAIM ) %]
170
                        <select name="[% kohafield %]" id="[%- mv.id | html -%]" size="1" class="input_marceditor" readonly="readonly" disabled="disabled">
169
                        <select name="[% kohafield %]" id="[%- mv.id | html -%]" size="1" class="input_marceditor" readonly="readonly" disabled="disabled">
171
                    [% ELSE %]
170
                    [% ELSE %]
172
                        <select name="[% kohafield %]" id="[%- mv.id | html -%]" size="1" class="input_marceditor" data-category="[% mv.category | html %]">
171
                        <select name="[% kohafield %]" id="[%- mv.id | html -%]" size="1" class="input_marceditor" data-category="[% mv.category | html %]">
Lines 175-181 Link Here
175
                        [% IF aval == mv.default %]
174
                        [% IF aval == mv.default %]
176
                        <option value="[%- aval | html -%]" selected="selected">[%- mv.labels.$aval | html -%]</option>
175
                        <option value="[%- aval | html -%]" selected="selected">[%- mv.labels.$aval | html -%]</option>
177
                        [% ELSE %]
176
                        [% ELSE %]
178
                            [% IF ite.IS_LOST_AV && Koha.Preference("ClaimReturnedLostValue") && aval == Koha.Preference("ClaimReturnedLostValue") %]
177
                            [% IF subfield.IS_LOST_AV && Koha.Preference("ClaimReturnedLostValue") && aval == Koha.Preference("ClaimReturnedLostValue") %]
179
                                <option disabled="disabled" value="[%- aval | html -%]" title="Return claims must be processed from the patron details page">[%- mv.labels.$aval | html -%]</option>
178
                                <option disabled="disabled" value="[%- aval | html -%]" title="Return claims must be processed from the patron details page">[%- mv.labels.$aval | html -%]</option>
180
                            [%  ELSE %]
179
                            [%  ELSE %]
181
                                <option value="[%- aval | html -%]">[%- mv.labels.$aval | html -%]</option>
180
                                <option value="[%- aval | html -%]">[%- mv.labels.$aval | html -%]</option>
Lines 217-236 Link Here
217
                    [% END %]
216
                    [% END %]
218
                [% END %]
217
                [% END %]
219
218
220
                [% IF ite.kohafield == 'items.more_subfields_xml' %]
219
                [% IF subfield.kohafield == 'items.more_subfields_xml' %]
221
                    <input type="hidden" name="items.more_subfields_xml" value="[% ite.subfield %]" />
220
                    <input type="hidden" name="items.more_subfields_xml" value="[% subfield.subfield %]" />
222
                [% END %]
221
                [% END %]
223
                <input type="hidden" name="tag"       value="[% ite.tag | html %]" />
222
                <input type="hidden" name="tag"       value="[% subfield.tag | html %]" />
224
                <input type="hidden" name="subfield"  value="[% ite.subfield | html %]" />
223
                <input type="hidden" name="subfield"  value="[% subfield.subfield | html %]" />
225
                <input type="hidden" name="mandatory" value="[% ite.mandatory | html %]" />
224
                <input type="hidden" name="mandatory" value="[% subfield.mandatory | html %]" />
226
                <input type="hidden" name="important" value="[% ite.important | html %]" />
225
                <input type="hidden" name="important" value="[% subfield.important | html %]" />
227
                [% IF ( ite.repeatable ) %]
226
                [% IF ( subfield.repeatable ) %]
228
                    <a href="#" class="buttonPlus" onclick="CloneItemSubfield(this.parentNode.parentNode); return false;">
227
                    <a href="#" class="buttonPlus" onclick="CloneItemSubfield(this.parentNode.parentNode); return false;">
229
                        <img src="[% interface | html %]/[% theme | html %]/img/clone-subfield.png" alt="Clone" title="Clone this subfield" />
228
                        <img src="[% interface | html %]/[% theme | html %]/img/clone-subfield.png" alt="Clone" title="Clone this subfield" />
230
                    </a>
229
                    </a>
231
                [% END %]
230
                [% END %]
232
                [% IF ( ite.mandatory ) %] <span class="required">Required</span>
231
                [% IF ( subfield.mandatory ) %] <span class="required">Required</span>
233
                [% ELSIF ( ite.important ) %] <span class="important">Important</span>
232
                [% ELSIF ( subfield.important ) %] <span class="important">Important</span>
234
                [% END %]
233
                [% END %]
235
            </div></li>
234
            </div></li>
236
        [% END %]
235
        [% END %]
237
- 

Return to bug 27526