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