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 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 (-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" size="50" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]">
174
                    <input type="hidden" id="[%- mv.id | html -%]" name="[% kohafield | html %]" class="input_marceditor" size="50" 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">
177
                        <select name="[% kohafield | html %]" id="[%- mv.id | html -%]" class="input_marceditor" readonly="readonly" disabled="disabled">
179
                    [% ELSE %]
178
                    [% ELSE %]
180
                        <select name="[% kohafield %]" id="[%- mv.id | html -%]" class="input_marceditor" data-category="[% mv.category | html %]">
179
                        <select name="[% kohafield | html %]" id="[%- mv.id | html -%]" class="input_marceditor" data-category="[% mv.category | html %]">
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" size="50" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" readonly="readonly" />
195
                        <input type="text" id="[%- mv.id | html -%]" name="[% kohafield | html %]" class="input_marceditor" size="50" 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" size="50" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" />
197
                        <input type="text" id="[%- mv.id | html -%]" name="[% kohafield | html %]" class="input_marceditor" size="50" 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" size="50" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" readonly="readonly" />
203
                        <input type="text" id="[%- mv.id | html -%]" name="[% kohafield | html %]" class="input_marceditor" size="50" 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" size="50" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" />
205
                        <input type="text" id="[%- mv.id | html -%]" name="[% kohafield | html %]" class="input_marceditor" size="50" 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" size="50" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" readonly="readonly" />
215
                        <input type="text" id="[%- mv.id | html -%]" name="[% kohafield | html %]" class="input_marceditor" size="50" 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" size="50" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" />
217
                        <input type="text" id="[%- mv.id | html -%]" name="[% kohafield | html %]" class="input_marceditor" size="50" 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