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

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

Return to bug 27526