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

(-)a/Koha/Biblio.pm (+23 lines)
Lines 419-424 sub items { Link Here
419
    return Koha::Items->_new_from_dbic( $items_rs );
419
    return Koha::Items->_new_from_dbic( $items_rs );
420
}
420
}
421
421
422
sub host_items {
423
    my ($self) = @_;
424
425
    return Koha::Items->new->empty
426
      unless C4::Context->preference('EasyAnalyticalRecords');
427
428
    my $marcflavour = C4::Context->preference("marcflavour");
429
    my $analyticfield = '773';
430
    if ( $marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC' ) {
431
        $analyticfield = '773';
432
    }
433
    elsif ( $marcflavour eq 'UNIMARC' ) {
434
        $analyticfield = '461';
435
    }
436
    my $marc_record = $self->metadata->record;
437
    my @itemnumbers;
438
    foreach my $field ( $marc_record->field($analyticfield) ) {
439
        push @itemnumbers, $field->subfield('9');
440
    }
441
442
    return Koha::Items->search( { itemnumber => { -in => \@itemnumbers } } );
443
}
444
422
=head3 itemtype
445
=head3 itemtype
423
446
424
my $itemtype = $biblio->itemtype();
447
my $itemtype = $biblio->itemtype();
(-)a/Koha/Item.pm (-1 / +72 lines)
Lines 23-29 use List::MoreUtils qw( any ); Link Here
23
use Data::Dumper qw( Dumper );
23
use Data::Dumper qw( Dumper );
24
24
25
use Koha::Database;
25
use Koha::Database;
26
use Koha::DateUtils qw( dt_from_string );
26
use Koha::DateUtils qw( dt_from_string output_pref );
27
27
28
use C4::Context;
28
use C4::Context;
29
use C4::Circulation qw( GetBranchItemRule );
29
use C4::Circulation qw( GetBranchItemRule );
Lines 940-945 sub cover_images { Link Here
940
    return Koha::CoverImages->_new_from_dbic($cover_image_rs);
940
    return Koha::CoverImages->_new_from_dbic($cover_image_rs);
941
}
941
}
942
942
943
sub columns_to_str {
944
    my ( $self ) = @_;
945
946
    my $frameworkcode = $self->biblio->frameworkcode;
947
    my $tagslib = C4::Biblio::GetMarcStructure(1, $frameworkcode);
948
    my ( $itemtagfield, $itemtagsubfield) = C4::Biblio::GetMarcFromKohaField( "items.itemnumber" );
949
950
    my $columns_info = $self->_result->result_source->columns_info;
951
952
    my $mss = C4::Biblio::GetMarcSubfieldStructure( $frameworkcode, { unsafe => 1 } );
953
    my $values = {};
954
    for my $column ( keys %$columns_info ) {
955
956
        next if $column eq 'more_subfields_xml';
957
958
        my $value;
959
        if ( Koha::Object::_datetime_column_type( $columns_info->{$column}->{data_type} ) ) {
960
            $value = output_pref({ dateformat => 'rfc3339', dt => dt_from_string($value, 'sql')});
961
        } else {
962
            $value = $self->$column;
963
        }
964
965
        if ( not defined $value or $value eq "" ) {
966
            $values->{$column} = $value;
967
            next;
968
        }
969
970
        my $subfield =
971
          exists $mss->{"items.$column"}
972
          ? @{ $mss->{"items.$column"} }[0] # Should we deal with several subfields??
973
          : undef;
974
975
        $values->{$column} =
976
            $subfield
977
          ? $subfield->{authorised_value}
978
              ? C4::Biblio::GetAuthorisedValueDesc( $itemtagfield,
979
                  $subfield->{tagsubfield}, $value, '', $tagslib )
980
              : $value
981
          : $value;
982
    }
983
984
    my $marc_more=
985
      $self->more_subfields_xml
986
      ? MARC::Record->new_from_xml( $self->more_subfields_xml, 'UTF-8' )
987
      : undef;
988
989
    my $more_values;
990
    if ( $marc_more ) {
991
        my ( $field ) = $marc_more->fields;
992
        for my $sf ( $field->subfields ) {
993
            my $subfield_code = $sf->[0];
994
            my $value = $sf->[1];
995
            my $subfield = $tagslib->{$itemtagfield}->{$subfield_code};
996
            next unless $subfield; # We have the value but it's not mapped, data lose! No regression however.
997
            $value =
998
              $subfield->{authorised_value}
999
              ? C4::Biblio::GetAuthorisedValueDesc( $itemtagfield,
1000
                $subfield->{tagsubfield}, $value, '', $tagslib )
1001
              : $value;
1002
1003
            push @{$more_values->{$subfield_code}}, $value;
1004
        }
1005
1006
        while ( my ( $k, $v ) = each %$more_values ) {
1007
            $values->{$k} = join ' | ', @$v;
1008
        }
1009
    }
1010
1011
    return $values;
1012
}
1013
943
=head3 _set_found_trigger
1014
=head3 _set_found_trigger
944
1015
945
    $self->_set_found_trigger
1016
    $self->_set_found_trigger
(-)a/cataloguing/additem.pl (-322 / +153 lines)
Lines 48-54 use Koha::ItemTypes; Link Here
48
use Koha::Libraries;
48
use Koha::Libraries;
49
use Koha::Patrons;
49
use Koha::Patrons;
50
use Koha::SearchEngine::Indexer;
50
use Koha::SearchEngine::Indexer;
51
use List::MoreUtils qw( any );
52
use C4::Search qw( enabled_staff_search_views );
51
use C4::Search qw( enabled_staff_search_views );
53
use Storable qw( freeze thaw );
52
use Storable qw( freeze thaw );
54
use URI::Escape qw( uri_escape_utf8 );
53
use URI::Escape qw( uri_escape_utf8 );
Lines 57-116 use C4::Members; Link Here
57
use MARC::File::XML;
56
use MARC::File::XML;
58
use URI::Escape qw( uri_escape_utf8 );
57
use URI::Escape qw( uri_escape_utf8 );
59
use MIME::Base64 qw( decode_base64url encode_base64url );
58
use MIME::Base64 qw( decode_base64url encode_base64url );
59
use List::Util qw( first );
60
use List::MoreUtils qw( any uniq );
60
61
61
our $dbh = C4::Context->dbh;
62
our $dbh = C4::Context->dbh;
62
63
63
sub find_value {
64
    my ($tagfield,$insubfield,$record) = @_;
65
    my $result;
66
    my $indicator;
67
    foreach my $field ($record->field($tagfield)) {
68
        my @subfields = $field->subfields();
69
        foreach my $subfield (@subfields) {
70
            if (@$subfield[0] eq $insubfield) {
71
                $result .= @$subfield[1];
72
                $indicator = $field->indicator(1).$field->indicator(2);
73
            }
74
        }
75
    }
76
    return($indicator,$result);
77
}
78
79
sub get_item_from_barcode {
80
    my ($barcode)=@_;
81
    my $dbh=C4::Context->dbh;
82
    my $result;
83
    my $rq=$dbh->prepare("SELECT itemnumber from items where items.barcode=?");
84
    $rq->execute($barcode);
85
    ($result)=$rq->fetchrow;
86
    return($result);
87
}
88
89
# NOTE: This code is subject to change in the future with the implemenation of ajax based autobarcode code
90
# NOTE: 'incremental' is the ONLY autoBarcode option available to those not using javascript
91
sub _increment_barcode {
92
    my ($record, $frameworkcode) = @_;
93
    my ($tagfield,$tagsubfield) = &GetMarcFromKohaField( "items.barcode" );
94
    unless ($record->field($tagfield)->subfield($tagsubfield)) {
95
        my $sth_barcode = $dbh->prepare("select max(abs(barcode)) from items");
96
        $sth_barcode->execute;
97
        my ($newbarcode) = $sth_barcode->fetchrow;
98
        $newbarcode++;
99
        # OK, we have the new barcode, now create the entry in MARC record
100
        my $fieldItem = $record->field($tagfield);
101
        $record->delete_field($fieldItem);
102
        $fieldItem->add_subfields($tagsubfield => $newbarcode);
103
        $record->insert_fields_ordered($fieldItem);
104
    }
105
    return $record;
106
}
107
108
109
sub generate_subfield_form {
64
sub generate_subfield_form {
110
        my ($tag, $subfieldtag, $value, $tagslib,$subfieldlib, $branches, $biblionumber, $temp, $loop_data, $i, $restrictededition, $item) = @_;
65
        my ($tag, $subfieldtag, $value, $tagslib,$subfieldlib, $branches, $biblionumber, $temp, $subfields, $i, $restrictededition, $item) = @_;
111
  
66
  
112
        my $frameworkcode = &GetFrameworkCode($biblionumber);
67
        my $frameworkcode = &GetFrameworkCode($biblionumber);
113
68
69
        $item //= {};
70
114
        my %subfield_data;
71
        my %subfield_data;
115
        my $dbh = C4::Context->dbh;
72
        my $dbh = C4::Context->dbh;
116
        
73
        
Lines 182-188 sub generate_subfield_form { Link Here
182
            # builds list, depending on authorised value...
139
            # builds list, depending on authorised value...
183
            if ( $subfieldlib->{authorised_value} eq "LOST" ) {
140
            if ( $subfieldlib->{authorised_value} eq "LOST" ) {
184
                my $ClaimReturnedLostValue = C4::Context->preference('ClaimReturnedLostValue');
141
                my $ClaimReturnedLostValue = C4::Context->preference('ClaimReturnedLostValue');
185
                my $item_is_return_claim = $ClaimReturnedLostValue && $item && $item->itemlost && $ClaimReturnedLostValue eq $item->itemlost;
142
                my $item_is_return_claim = $ClaimReturnedLostValue && exists $item->{itemlost} && $ClaimReturnedLostValue eq $item->{itemlost};
186
                $subfield_data{IS_RETURN_CLAIM} = $item_is_return_claim;
143
                $subfield_data{IS_RETURN_CLAIM} = $item_is_return_claim;
187
144
188
                $subfield_data{IS_LOST_AV} = 1;
145
                $subfield_data{IS_LOST_AV} = 1;
Lines 287-293 sub generate_subfield_form { Link Here
287
                item_style => 1,
244
                item_style => 1,
288
            });
245
            });
289
            my $pars=  { dbh => $dbh, record => $temp, tagslib =>$tagslib,
246
            my $pars=  { dbh => $dbh, record => $temp, tagslib =>$tagslib,
290
                id => $subfield_data{id}, tabloop => $loop_data };
247
                id => $subfield_data{id}, tabloop => $subfields };
291
            $plugin->build( $pars );
248
            $plugin->build( $pars );
292
            if( !$plugin->errstr ) {
249
            if( !$plugin->errstr ) {
293
                my $class= 'buttonDot'. ( $plugin->noclick? ' disabled': '' );
250
                my $class= 'buttonDot'. ( $plugin->noclick? ' disabled': '' );
Lines 374-407 sub generate_subfield_form { Link Here
374
        return \%subfield_data;
331
        return \%subfield_data;
375
}
332
}
376
333
377
# Removes some subfields when prefilling items
378
# This function will remove any subfield that is not in the SubfieldsToUseWhenPrefill syspref
379
sub removeFieldsForPrefill {
380
381
    my $item = shift;
382
383
    # Getting item tag
384
    my ($tag, $subtag) = GetMarcFromKohaField( "items.barcode" );
385
386
    # Getting list of subfields to keep
387
    my $subfieldsToUseWhenPrefill = C4::Context->preference('SubfieldsToUseWhenPrefill');
388
389
    # Removing subfields that are not in the syspref
390
    if ($tag && $subfieldsToUseWhenPrefill) {
391
        my $field = $item->field($tag);
392
        my @subfieldsToUse= split(/ /,$subfieldsToUseWhenPrefill);
393
        foreach my $subfield ($field->subfields()) {
394
            if (!grep { $subfield->[0] eq $_ } @subfieldsToUse) {
395
                $field->delete_subfield(code => $subfield->[0]);
396
            }
397
398
        }
399
    }
400
401
    return $item;
402
403
}
404
405
my $input        = CGI->new;
334
my $input        = CGI->new;
406
my $error        = $input->param('error');
335
my $error        = $input->param('error');
407
336
Lines 416-421 if( $input->param('itemnumber') && !$input->param('biblionumber') ){ Link Here
416
    $itemnumber = $input->param('itemnumber');
345
    $itemnumber = $input->param('itemnumber');
417
}
346
}
418
347
348
my $biblio = Koha::Biblios->find($biblionumber);
349
419
my $op           = $input->param('op') || q{};
350
my $op           = $input->param('op') || q{};
420
my $hostitemnumber = $input->param('hostitemnumber');
351
my $hostitemnumber = $input->param('hostitemnumber');
421
my $marcflavour  = C4::Context->preference("marcflavour");
352
my $marcflavour  = C4::Context->preference("marcflavour");
Lines 427-433 my $fa_branch = $input->param('branch'); Link Here
427
my $fa_stickyduedate      = $input->param('stickyduedate');
358
my $fa_stickyduedate      = $input->param('stickyduedate');
428
my $fa_duedatespec        = $input->param('duedatespec');
359
my $fa_duedatespec        = $input->param('duedatespec');
429
360
430
my $frameworkcode = &GetFrameworkCode($biblionumber);
361
our $frameworkcode = &GetFrameworkCode($biblionumber);
431
362
432
# Defining which userflag is needing according to the framework currently used
363
# Defining which userflag is needing according to the framework currently used
433
my $userflags;
364
my $userflags;
Lines 455-483 $restrictededition = 0 if ($restrictededition != 0 && C4::Context->IsSuperLibra Link Here
455
# In case user has fast cataloging permission (and we're in fast cataloging), editing is not restricted
386
# In case user has fast cataloging permission (and we're in fast cataloging), editing is not restricted
456
$restrictededition = 0 if ($restrictededition != 0 && $frameworkcode eq 'FA' && haspermission($uid, {'editcatalogue' => 'fast_cataloging'}));
387
$restrictededition = 0 if ($restrictededition != 0 && $frameworkcode eq 'FA' && haspermission($uid, {'editcatalogue' => 'fast_cataloging'}));
457
388
458
my $tagslib = &GetMarcStructure(1,$frameworkcode);
389
our $tagslib = &GetMarcStructure(1,$frameworkcode);
459
my $record = GetMarcBiblio({ biblionumber => $biblionumber });
390
my $record = GetMarcBiblio({ biblionumber => $biblionumber });
460
391
461
output_and_exit_if_error( $input, $cookie, $template,
392
output_and_exit_if_error( $input, $cookie, $template,
462
    { module => 'cataloguing', record => $record } );
393
    { module => 'cataloguing', record => $record } );
463
394
464
my $oldrecord = TransformMarcToKoha($record);
395
my $oldrecord = TransformMarcToKoha($record);
465
my $itemrecord;
396
my $current_item;
466
my $nextop="additem";
397
my $nextop="additem";
467
my @errors; # store errors found while checking data BEFORE saving item.
398
my @errors; # store errors found while checking data BEFORE saving item.
468
399
469
# Getting last created item cookie
400
# Getting last created item cookie
470
my $prefillitem = C4::Context->preference('PrefillItem');
401
my $prefillitem = C4::Context->preference('PrefillItem');
471
my $justaddeditem;
402
my $item_from_cookie;
472
my $cookieitemrecord;
473
if ($prefillitem) {
403
if ($prefillitem) {
474
    my $lastitemcookie = $input->cookie('LastCreatedItem');
404
    my $lastitemcookie = $input->cookie('LastCreatedItem');
475
    if ($lastitemcookie) {
405
    if ($lastitemcookie) {
476
        $lastitemcookie = decode_base64url($lastitemcookie);
406
        $lastitemcookie = decode_base64url($lastitemcookie);
477
        eval {
407
        eval {
478
            if ( thaw($lastitemcookie) ) {
408
            if ( thaw($lastitemcookie) ) {
479
                $cookieitemrecord = thaw($lastitemcookie);
409
                $item_from_cookie = thaw($lastitemcookie);
480
                $cookieitemrecord = removeFieldsForPrefill($cookieitemrecord);
481
            }
410
            }
482
        };
411
        };
483
        if ($@) {
412
        if ($@) {
Lines 488-511 if ($prefillitem) { Link Here
488
}
417
}
489
418
490
#-------------------------------------------------------------------------------
419
#-------------------------------------------------------------------------------
491
my $current_item;
492
if ($op eq "additem") {
420
if ($op eq "additem") {
493
421
494
    my $add_submit                 = $input->param('add_submit');
422
    my $add_submit                 = $input->param('add_submit');
495
    my $add_duplicate_submit       = $input->param('add_duplicate_submit');
496
    my $add_multiple_copies_submit = $input->param('add_multiple_copies_submit');
423
    my $add_multiple_copies_submit = $input->param('add_multiple_copies_submit');
497
    my $number_of_copies           = $input->param('number_of_copies');
424
    my $number_of_copies           = $input->param('number_of_copies');
498
425
499
    # This is a bit tricky : if there is a cookie for the last created item and
500
    # we just added an item, the cookie value is not correct yet (it will be updated
501
    # next page). To prevent the form from being filled with outdated values, we
502
    # force the use of "add and duplicate" feature, so the form will be filled with
503
    # correct values.
504
    $add_duplicate_submit = 1 if ($prefillitem);
505
    $justaddeditem = 1;
506
507
    my @columns = Koha::Items->columns;
426
    my @columns = Koha::Items->columns;
508
    my $biblio = Koha::Biblios->find($biblionumber);
509
    my $item = Koha::Item->new;
427
    my $item = Koha::Item->new;
510
    $item->biblionumber($biblio->biblionumber);
428
    $item->biblionumber($biblio->biblionumber);
511
    for my $c ( @columns ) {
429
    for my $c ( @columns ) {
Lines 527-535 if ($op eq "additem") { Link Here
527
            }
445
            }
528
            $item->more_subfields_xml(undef);
446
            $item->more_subfields_xml(undef);
529
        } else {
447
        } else {
530
            my $v = $input->param("items.".$c);
448
            my @v = $input->multi_param("items.".$c);
531
            next unless defined $v;
449
            next unless @v;
532
            $item->$c($v);
450
            $item->$c(join ' | ', uniq @v);
533
        }
451
        }
534
    }
452
    }
535
453
Lines 540-583 if ($op eq "additem") { Link Here
540
    }
458
    }
541
459
542
    # If we have to add or add & duplicate, we add the item
460
    # If we have to add or add & duplicate, we add the item
543
    if ( $add_submit || $add_duplicate_submit ) {
461
    if ( $add_submit || $prefillitem) {
544
462
545
        # check for item barcode # being unique
463
        # check for item barcode # being unique
546
        if ( Koha::Items->search({ barcode => $item->barcode })->count ) {
464
        if ( Koha::Items->search({ barcode => $item->barcode })->count ) {
547
            # if barcode exists, don't create, but report The problem.
465
            # if barcode exists, don't create, but report The problem.
548
            push @errors, "barcode_not_unique";
466
            push @errors, "barcode_not_unique";
467
468
            $current_item = $item->unblessed; # Restore edit form for the same item
549
        }
469
        }
550
        else {
470
        else {
551
            $item->store->discard_changes;
471
            $item->store->discard_changes;
552
472
473
            # This is a bit tricky : if there is a cookie for the last created item and
474
            # we just added an item, the cookie value is not correct yet (it will be updated
475
            # next page). To prevent the form from being filled with outdated values, we
476
            # force the use of "add and duplicate" feature, so the form will be filled with
477
            # correct values.
478
553
            # FIXME This need to be rewritten, we must store $item->unblessed instead
479
            # FIXME This need to be rewritten, we must store $item->unblessed instead
554
            ## Pushing the last created item cookie back
480
            # Pushing the last created item cookie back
555
            #if ($prefillitem && defined $record) {
481
            if ( $prefillitem ) {
556
            #    my $itemcookie = $input->cookie(
482
                $item_from_cookie = $input->cookie(
557
            #        -name => 'LastCreatedItem',
483
                    -name => 'LastCreatedItem',
558
            #        # We encode_base64url the whole freezed structure so we're sure we won't have any encoding problems
484
                    # We encode_base64url the whole freezed structure so we're sure we won't have any encoding problems
559
            #        -value   => encode_base64url( freeze( $record ) ),
485
                    -value   => encode_base64url( freeze( { %{$item->unblessed}, itemnumber => undef } ) ),
560
            #        -HttpOnly => 1,
486
                    -HttpOnly => 1,
561
            #        -expires => ''
487
                    -expires => ''
562
            #    );
488
                );
563
489
564
            #    $cookie = [ $cookie, $itemcookie ];
490
                $cookie = [ $cookie, $item_from_cookie ];
565
            #}
491
            }
566
492
567
        }
493
        }
568
        $nextop = "additem";
494
        $nextop = "additem";
569
495
570
571
        # FIXME reset item to the item we were editing
572
        #if ($exist_itemnumber) {
573
574
        #    $itemrecord = $record;
575
        #}
576
        $current_item = $item->unblessed;
577
    }
496
    }
578
497
579
    # If we have to add & duplicate
498
    # If we have to add & duplicate
580
    if ($add_duplicate_submit) {
499
    if ($prefillitem) {
581
        if (C4::Context->preference('autoBarcode') eq 'incremental') {
500
        if (C4::Context->preference('autoBarcode') eq 'incremental') {
582
            my ( $barcode ) = C4::Barcodes::ValueBuilder::incremental::get_barcode;
501
            my ( $barcode ) = C4::Barcodes::ValueBuilder::incremental::get_barcode;
583
            $current_item->{barcode} = $barcode;
502
            $current_item->{barcode} = $barcode;
Lines 586-599 if ($op eq "additem") { Link Here
586
            # we have to clear the barcode field in the duplicate item record to make way for the new one generated by the javascript plugin
505
            # we have to clear the barcode field in the duplicate item record to make way for the new one generated by the javascript plugin
587
            $current_item->{barcode} = undef; # FIXME or delete?
506
            $current_item->{barcode} = undef; # FIXME or delete?
588
        }
507
        }
589
        # FIXME This subroutine needs to be adjusted
590
        # We want to pass $item
591
        # $itemrecord = removeFieldsForPrefill($itemrecord) if ($prefillitem);
592
    }
508
    }
593
509
594
    # If we have to add multiple copies
510
    # If we have to add multiple copies
595
    if ($add_multiple_copies_submit) {
511
    if ($add_multiple_copies_submit) {
596
512
513
        $current_item = $item->unblessed;
514
597
        my $copynumber = $current_item->{copynumber};
515
        my $copynumber = $current_item->{copynumber};
598
        my $oldbarcode = $current_item->{barcode};
516
        my $oldbarcode = $current_item->{barcode};
599
517
Lines 604-610 if ($op eq "additem") { Link Here
604
        if ( $oldbarcode && !$testbarcode ) {
522
        if ( $oldbarcode && !$testbarcode ) {
605
523
606
            push @errors, "no_next_barcode";
524
            push @errors, "no_next_barcode";
607
            $itemrecord = $record;
608
525
609
        }
526
        }
610
        else {
527
        else {
Lines 652-658 if ($op eq "additem") { Link Here
652
                if ( !$exist_itemnumber ) {
569
                if ( !$exist_itemnumber ) {
653
                    delete $current_item->{itemnumber};
570
                    delete $current_item->{itemnumber};
654
                    $current_item = Koha::Item->new($current_item)->store(
571
                    $current_item = Koha::Item->new($current_item)->store(
655
                        { skip_record_index => 1 } )->discard_changes->unblessed;
572
                        { skip_record_index => 1 } );
573
                    $current_item->discard_changes; # Cannot chain discard_changes
574
                    $current_item = $current_item->unblessed;
656
                    set_item_default_location($current_item->{itemnumber});
575
                    set_item_default_location($current_item->{itemnumber});
657
576
658
# We count the item only if it was really added
577
# We count the item only if it was really added
Lines 692-732 if ($op eq "additem") { Link Here
692
} elsif ($op eq "edititem") {
611
} elsif ($op eq "edititem") {
693
#-------------------------------------------------------------------------------
612
#-------------------------------------------------------------------------------
694
# retrieve item if exist => then, it's a modif
613
# retrieve item if exist => then, it's a modif
695
    $itemrecord = C4::Items::GetMarcItem($biblionumber,$itemnumber);
614
    $current_item = Koha::Items->find($itemnumber)->unblessed;
615
    # FIXME Handle non existent item
696
    $nextop = "saveitem";
616
    $nextop = "saveitem";
697
#-------------------------------------------------------------------------------
617
#-------------------------------------------------------------------------------
698
} elsif ($op eq "dupeitem") {
618
} elsif ($op eq "dupeitem") {
699
#-------------------------------------------------------------------------------
619
#-------------------------------------------------------------------------------
700
# retrieve item if exist => then, it's a modif
620
# retrieve item if exist => then, it's a modif
701
    $itemrecord = C4::Items::GetMarcItem($biblionumber,$itemnumber);
621
    my $item = Koha::Items->find($itemnumber);
622
    # FIXME Handle non existent item
702
    if (C4::Context->preference('autoBarcode') eq 'incremental') {
623
    if (C4::Context->preference('autoBarcode') eq 'incremental') {
703
        $itemrecord = _increment_barcode($itemrecord, $frameworkcode);
624
        my ( $barcode ) = C4::Barcodes::ValueBuilder::incremental::get_barcode;
625
        $item->barcode($barcode);
704
    }
626
    }
705
    else {
627
    else {
706
        # we have to clear the barcode field in the duplicate item record to make way for the new one generated by the javascript plugin
628
        $item->barcode(undef); # Don't save it!
707
        my ($tagfield,$tagsubfield) = &GetMarcFromKohaField( "items.barcode" );
708
        my $fieldItem = $itemrecord->field($tagfield);
709
        $itemrecord->delete_field($fieldItem);
710
        $fieldItem->delete_subfields($tagsubfield);
711
        $itemrecord->insert_fields_ordered($fieldItem);
712
    }
629
    }
713
630
714
    #check for hidden subfield and remove them for the duplicated item
715
    foreach my $field ($itemrecord->fields()){
716
        my $tag = $field->{_tag};
717
        foreach my $subfield ($field->subfields()){
718
            my $subfieldtag = $subfield->[0];
719
            if ($tagslib->{$tag}->{$subfieldtag}->{'tab'} ne "10"
720
            ||  abs($tagslib->{$tag}->{$subfieldtag}->{hidden})>4 ){
721
                my $fieldItem = $itemrecord->field($tag);
722
                $itemrecord->delete_field($fieldItem);
723
                $fieldItem->delete_subfields($subfieldtag);
724
                $itemrecord->insert_fields_ordered($fieldItem);
725
            }
726
        }
727
    }
728
729
    $itemrecord = removeFieldsForPrefill($itemrecord) if ($prefillitem);
730
    $nextop = "additem";
631
    $nextop = "additem";
731
#-------------------------------------------------------------------------------
632
#-------------------------------------------------------------------------------
732
} elsif ($op eq "delitem") {
633
} elsif ($op eq "delitem") {
Lines 795-803 if ($op eq "additem") { Link Here
795
            }
696
            }
796
            $item->more_subfields_xml(undef);
697
            $item->more_subfields_xml(undef);
797
        } else {
698
        } else {
798
            my $v = $input->param("items.".$c);
699
            my @v = $input->multi_param("items.".$c);
799
            next unless defined $v;
700
            next unless @v;
800
            $item->$c($v);
701
            $item->$c(join ' | ', uniq @v);
801
        }
702
        }
802
    }
703
    }
803
704
Lines 805-810 if ($op eq "additem") { Link Here
805
    if ( Koha::Items->search({ barcode => $item->barcode, itemnumber => { '!=' => $item->itemnumber } })->count ) {
706
    if ( Koha::Items->search({ barcode => $item->barcode, itemnumber => { '!=' => $item->itemnumber } })->count ) {
806
        # FIXME We shouldn't need that, ->store would explode as there is a unique constraint on items.barcode
707
        # FIXME We shouldn't need that, ->store would explode as there is a unique constraint on items.barcode
807
        push @errors,"barcode_not_unique";
708
        push @errors,"barcode_not_unique";
709
        $current_item = $item->unblessed; # Restore edit form for the same item
808
    } else {
710
    } else {
809
        my $newitemlost = $item->itemlost;
711
        my $newitemlost = $item->itemlost;
810
        if ( $newitemlost && $newitemlost ge '1' && !$olditemlost ) {
712
        if ( $newitemlost && $newitemlost ge '1' && !$olditemlost ) {
Lines 844-1056 if ($op) { Link Here
844
#-------------------------------------------------------------------------------
746
#-------------------------------------------------------------------------------
845
747
846
# now, build existiing item list
748
# now, build existiing item list
847
my $temp = GetMarcBiblio({ biblionumber => $biblionumber });
848
#my @fields = $record->fields();
849
850
749
851
my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code
750
my @items;
852
my @big_array;
751
for my $item ( $biblio->items->as_list, $biblio->host_items->as_list ) {
853
#---- finds where items.itemnumber is stored
752
    push @items, $item->columns_to_str;
854
my (  $itemtagfield,   $itemtagsubfield) = &GetMarcFromKohaField( "items.itemnumber" );
855
my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField( "items.homebranch" );
856
C4::Biblio::EmbedItemsInMarcBiblio({
857
    marc_record  => $temp,
858
    biblionumber => $biblionumber });
859
my @fields = $temp->fields();
860
861
862
my @hostitemnumbers;
863
if ( C4::Context->preference('EasyAnalyticalRecords') ) {
864
    my $analyticfield = '773';
865
    if ($marcflavour  eq 'MARC21' || $marcflavour eq 'NORMARC') {
866
        $analyticfield = '773';
867
    } elsif ($marcflavour eq 'UNIMARC') {
868
        $analyticfield = '461';
869
    }
870
    foreach my $hostfield ($temp->field($analyticfield)){
871
        my $hostbiblionumber = $hostfield->subfield('0');
872
        if ($hostbiblionumber){
873
            my $hostrecord = GetMarcBiblio({
874
                biblionumber => $hostbiblionumber,
875
                embed_items  => 1 });
876
            if ($hostrecord) {
877
                my ($itemfield, undef) = GetMarcFromKohaField( 'items.itemnumber' );
878
                foreach my $hostitem ($hostrecord->field($itemfield)){
879
                    if ($hostitem->subfield('9') eq $hostfield->subfield('9')){
880
                        push (@fields, $hostitem);
881
                        push (@hostitemnumbers, $hostfield->subfield('9'));
882
                    }
883
                }
884
            }
885
        }
886
    }
887
}
753
}
888
754
889
foreach my $field (@fields) {
755
my @witness_attributes = uniq map {
890
    next if ( $field->tag() < 10 );
756
    my $item = $_;
891
757
    map { defined $item->{$_} && $item->{$_} ne "" ? $_ : () } keys %$item
892
    my @subf = $field->subfields or ();    # don't use ||, as that forces $field->subfelds to be interpreted in scalar context
758
} @items;
893
    my %this_row;
894
    # loop through each subfield
895
    my $i = 0;
896
    foreach my $subfield (@subf){
897
        my $subfieldcode = $subfield->[0];
898
        my $subfieldvalue= $subfield->[1];
899
900
        next if ($tagslib->{$field->tag()}->{$subfieldcode}->{tab} ne 10 
901
                && ($field->tag() ne $itemtagfield 
902
                && $subfieldcode   ne $itemtagsubfield));
903
        $witness{$subfieldcode} = $tagslib->{$field->tag()}->{$subfieldcode}->{lib} if ($tagslib->{$field->tag()}->{$subfieldcode}->{tab}  eq 10);
904
		if ($tagslib->{$field->tag()}->{$subfieldcode}->{tab}  eq 10) {
905
		    $this_row{$subfieldcode} .= " | " if($this_row{$subfieldcode});
906
        	$this_row{$subfieldcode} .= GetAuthorisedValueDesc( $field->tag(),
907
                        $subfieldcode, $subfieldvalue, '', $tagslib) 
908
						|| $subfieldvalue;
909
        }
910
759
911
        if (($field->tag eq $branchtagfield) && ($subfieldcode eq $branchtagsubfield) && C4::Context->preference("IndependentBranches")) {
760
our ( $itemtagfield, $itemtagsubfield ) = &GetMarcFromKohaField("items.itemnumber");
912
            #verifying rights
913
            my $userenv = C4::Context->userenv();
914
            unless (C4::Context->IsSuperLibrarian() or (($userenv->{'branch'} eq $subfieldvalue))){
915
                $this_row{'nomod'} = 1;
916
            }
917
        }
918
        $this_row{itemnumber} = $subfieldvalue if ($field->tag() eq $itemtagfield && $subfieldcode eq $itemtagsubfield);
919
920
        if ( C4::Context->preference('EasyAnalyticalRecords') ) {
921
            foreach my $hostitemnumber (@hostitemnumbers) {
922
                my $item = Koha::Items->find( $hostitemnumber );
923
                if ($this_row{itemnumber} eq $hostitemnumber) {
924
                    $this_row{hostitemflag} = 1;
925
                    $this_row{hostbiblionumber}= $item->biblio->biblionumber;
926
                    last;
927
                }
928
            }
929
        }
930
    }
931
    if (%this_row) {
932
        push(@big_array, \%this_row);
933
    }
934
}
935
761
936
my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField( "items.holdingbranch" );
762
my $subfieldcode_attribute_mappings;
937
@big_array = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @big_array;
763
for my $subfield_code ( keys %{ $tagslib->{$itemtagfield} } ) {
938
939
# now, construct template !
940
# First, the existing items for display
941
my @item_value_loop;
942
my @header_value_loop;
943
for my $row ( @big_array ) {
944
    my %row_data;
945
    my @item_fields;
946
    foreach my $key (sort keys %witness){
947
        my $item_field;
948
        if ( $row->{$key} ){
949
            $item_field->{field} = $row->{$key};
950
        } else {
951
            $item_field->{field} = '';
952
        }
953
764
954
        for my $kohafield (
765
    my $subfield = $tagslib->{$itemtagfield}->{$subfield_code};
955
            qw( items.dateaccessioned items.onloan items.datelastseen items.datelastborrowed items.replacementpricedate )
956
          )
957
        {
958
            my ( undef, $subfield ) = GetMarcFromKohaField($kohafield);
959
            next unless $key eq $subfield;
960
            $item_field->{datatype} = 'date';
961
        }
962
766
963
        push @item_fields, $item_field;
767
    next if IsMarcStructureInternal( $subfield );
768
    next unless $subfield->{tab} eq 10; # Is this really needed?
769
770
    my $attribute;
771
    if ( $subfield->{kohafield} ) {
772
        ( $attribute = $subfield->{kohafield} ) =~ s|^items\.||;
773
    } else {
774
        $attribute = $subfield_code; # It's in more_subfields_xml
964
    }
775
    }
965
    $row_data{item_value} = [ @item_fields ];
776
    next unless grep { $attribute eq $_ } @witness_attributes;
966
    $row_data{itemnumber} = $row->{itemnumber};
777
    $subfieldcode_attribute_mappings->{$subfield_code} = $attribute;
967
    #reporting this_row values
968
    $row_data{'nomod'} = $row->{'nomod'};
969
    $row_data{'hostitemflag'} = $row->{'hostitemflag'};
970
    $row_data{'hostbiblionumber'} = $row->{'hostbiblionumber'};
971
#	$row_data{'countanalytics'} = $row->{'countanalytics'};
972
    push(@item_value_loop,\%row_data);
973
}
778
}
974
foreach my $subfield_code (sort keys(%witness)) {
975
    my %header_value;
976
    $header_value{header_value} = $witness{$subfield_code};
977
978
    my $subfieldlib = $tagslib->{$itemtagfield}->{$subfield_code};
979
    my $kohafield = $subfieldlib->{kohafield};
980
    if ( $kohafield && $kohafield =~ /items.(.+)/ ) {
981
        $header_value{column_name} = $1;
982
    }
983
779
984
    push(@header_value_loop, \%header_value);
780
my @header_value_loop = map {
985
}
781
    {
782
        header_value  => $tagslib->{$itemtagfield}->{$_}->{lib},
783
        attribute     => $subfieldcode_attribute_mappings->{$_},
784
        subfield_code => $_,
785
    }
786
} sort keys %$subfieldcode_attribute_mappings;
986
787
987
# now, build the item form for entering a new item
788
# now, build the item form for entering a new item
988
my @loop_data =();
989
my $i=0;
990
991
my $branch = $input->param('branch') || C4::Context->userenv->{branch};
789
my $branch = $input->param('branch') || C4::Context->userenv->{branch};
992
my $libraries = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed;# build once ahead of time, instead of multiple times later.
790
my $libraries = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed;# build once ahead of time, instead of multiple times later.
993
for my $library ( @$libraries ) {
791
for my $library ( @$libraries ) {
994
    $library->{selected} = 1 if $library->{branchcode} eq $branch
792
    $library->{selected} = 1 if $library->{branchcode} eq $branch
995
}
793
}
996
794
997
my $item = Koha::Items->find($itemnumber);
998
795
999
# We generate form, from actuel record
796
# Using last created item if it exists
1000
@fields = ();
797
$current_item = $item_from_cookie
1001
if($itemrecord){
798
  if $item_from_cookie
1002
    foreach my $field ($itemrecord->fields()){
799
  && $prefillitem
1003
        my $tag = $field->{_tag};
800
  && $op ne "additem"
1004
        foreach my $subfield ( $field->subfields() ){
801
  && $op ne "edititem";
1005
802
1006
            my $subfieldtag = $subfield->[0];
803
my @subfields_to_prefill = split ' ', C4::Context->preference('SubfieldsToUseWhenPrefill');
1007
            my $value       = $subfield->[1];
1008
            my $subfieldlib = $tagslib->{$tag}->{$subfieldtag};
1009
804
1010
            next if ($tagslib->{$tag}->{$subfieldtag}->{'tab'} ne "10");
805
if ( $current_item->{more_subfields_xml} ) {
806
    $current_item->{marc_more_subfields_xml} = MARC::Record->new_from_xml($current_item->{more_subfields_xml}, 'UTF-8');
807
}
1011
808
1012
            my $subfield_data = generate_subfield_form($tag, $subfieldtag, $value, $tagslib, $subfieldlib, $libraries, $biblionumber, $temp, \@loop_data, $i, $restrictededition, $item);
809
# We generate form, and fill with values if defined
1013
            push @fields, "$tag$subfieldtag";
810
my $temp = GetMarcBiblio({ biblionumber => $biblionumber });
1014
            push (@loop_data, $subfield_data);
811
my $i = 0;
1015
            $i++;
812
my @subfields;
813
foreach my $tag ( keys %{$tagslib} ) {
814
    foreach my $subtag ( keys %{ $tagslib->{$tag} } ) {
815
816
        my $subfield = $tagslib->{$tag}{$subtag};
817
818
        next if IsMarcStructureInternal( $subfield );
819
        next if ( $subfield->{tab} ne "10" );
820
821
        my @values = ();
822
823
        my $subfield_data;
824
825
        # If we are not adding a new item
826
        # OR
827
        # If the subfield must be prefilled with last catalogued item
828
        if (
829
            $nextop ne 'additem'
830
            || (
831
                !$prefillitem
832
                || ( $prefillitem && grep { $_ eq $subtag }
833
                    @subfields_to_prefill )
834
            )
835
          )
836
        {
837
            my $kohafield = $subfield->{kohafield};
838
            if ($kohafield) {
839
840
                # This is a mapped field
841
                ( my $attribute = $kohafield ) =~ s|^items\.||;
842
                push @values, $subfield->{repeatable}
843
                    ? split '\s\|\s', $current_item->{$attribute}
844
                    : $current_item->{$attribute}
845
                  if defined $current_item->{$attribute};
846
            } else {
847
                # Not mapped, picked the values from more_subfields_xml's MARC
848
                my $marc_more = $current_item->{marc_more_subfields_xml};
849
                if ( $marc_more ) {
850
                    for my $f ( $marc_more->fields($tag) ) {
851
                        push @values, $f->subfield($subtag);
1016
                    }
852
                    }
1017
1018
                }
853
                }
1019
            }
854
            }
1020
    # and now we add fields that are empty
855
        }
1021
1022
# Using last created item if it exists
1023
856
1024
$itemrecord = $cookieitemrecord if ($prefillitem and not $justaddeditem and $op ne "edititem");
857
        @values = ('') unless @values;
1025
858
1026
# We generate form, and fill with values if defined
859
        for my $value (@values) {
1027
foreach my $tag ( keys %{$tagslib}){
860
            my $subfield_data = generate_subfield_form(
1028
    foreach my $subtag (keys %{$tagslib->{$tag}}){
861
                $tag,                        $subtag,
1029
        next if IsMarcStructureInternal($tagslib->{$tag}{$subtag});
862
                $value,                      $tagslib,
1030
        next if ($tagslib->{$tag}->{$subtag}->{'tab'} ne "10");
863
                $subfield,                   $libraries,
1031
        next if any { /^$tag$subtag$/ }  @fields;
864
                $biblionumber,               $temp,
1032
865
                \@subfields,                 $i,
1033
        my @values = (undef);
866
                $restrictededition,          $current_item,
1034
        @values = $itemrecord->field($tag)->subfield($subtag) if ($itemrecord && defined($itemrecord->field($tag)) && defined($itemrecord->field($tag)->subfield($subtag)));
867
            );
1035
        for my $value (@values){
868
            push @subfields, $subfield_data;
1036
            my $subfield_data = generate_subfield_form($tag, $subtag, $value, $tagslib, $tagslib->{$tag}->{$subtag}, $libraries, $biblionumber, $temp, \@loop_data, $i, $restrictededition, $item);
1037
            push (@loop_data, $subfield_data);
1038
            $i++;
869
            $i++;
1039
        }
870
        }
1040
  }
871
    }
1041
}
872
}
1042
@loop_data = sort { $a->{display_order} <=> $b->{display_order} || $a->{subfield} cmp $b->{subfield} } @loop_data;
873
@subfields = sort { $a->{display_order} <=> $b->{display_order} || $a->{subfield} cmp $b->{subfield} } @subfields;
1043
874
1044
# what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit.
875
# what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit.
1045
$template->param(
876
$template->param(
1046
    biblionumber => $biblionumber,
877
    biblionumber => $biblionumber,
1047
    title        => $oldrecord->{title},
878
    title        => $oldrecord->{title},
1048
    author       => $oldrecord->{author},
879
    author       => $oldrecord->{author},
1049
    item_loop        => \@item_value_loop,
880
    items        => \@items,
1050
    item_header_loop => \@header_value_loop,
881
    item_header_loop => \@header_value_loop,
1051
    item             => \@loop_data,
882
    subfields    => \@subfields,
1052
    itemnumber       => $itemnumber,
883
    itemnumber       => $itemnumber,
1053
    barcode          => $item ? $item->barcode : undef,
884
    barcode          => $current_item->{barcode},
1054
    itemtagfield     => $itemtagfield,
885
    itemtagfield     => $itemtagfield,
1055
    itemtagsubfield  => $itemtagsubfield,
886
    itemtagsubfield  => $itemtagsubfield,
1056
    op      => $nextop,
887
    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