- my $pref_itemcallnumber = C4::Context->preference('itemcallnumber');
- if (!$value && $subfieldlib->{kohafield} eq 'items.itemcallnumber' && $pref_itemcallnumber) {
- foreach my $pref_itemcallnumber_part (split(/,/, $pref_itemcallnumber)){
- my $CNtag = substr( $pref_itemcallnumber_part, 0, 3 ); # 3-digit tag number
- my $CNsubfields = substr( $pref_itemcallnumber_part, 3 ); # Any and all subfields
- my $temp2 = $temp->field($CNtag);
-
- next unless $temp2;
- $value = $temp2->as_string( $CNsubfields, ' ' );
- last if $value;
- }
- }
-
- if ($frameworkcode eq 'FA' && $subfieldlib->{kohafield} eq 'items.barcode' && !$value){
- my $input = CGI->new;
- $value = $input->param('barcode');
- }
-
- if ( $subfieldlib->{authorised_value} ) {
- my @authorised_values;
- my %authorised_lib;
- # builds list, depending on authorised value...
- if ( $subfieldlib->{authorised_value} eq "LOST" ) {
- my $ClaimReturnedLostValue = C4::Context->preference('ClaimReturnedLostValue');
- my $item_is_return_claim = $ClaimReturnedLostValue && $item && $item->itemlost && $ClaimReturnedLostValue eq $item->itemlost;
- $subfield_data{IS_RETURN_CLAIM} = $item_is_return_claim;
-
- $subfield_data{IS_LOST_AV} = 1;
-
- push @authorised_values, qq{};
- my $av = GetAuthorisedValues( $subfieldlib->{authorised_value} );
- for my $r ( @$av ) {
- push @authorised_values, $r->{authorised_value};
- $authorised_lib{$r->{authorised_value}} = $r->{lib};
- }
- }
- elsif ( $subfieldlib->{authorised_value} eq "branches" ) {
- foreach my $thisbranch (@$branches) {
- push @authorised_values, $thisbranch->{branchcode};
- $authorised_lib{$thisbranch->{branchcode}} = $thisbranch->{branchname};
- $value = $thisbranch->{branchcode} if $thisbranch->{selected} && !$value;
- }
- }
- elsif ( $subfieldlib->{authorised_value} eq "itemtypes" ) {
- push @authorised_values, "";
- my $branch_limit = C4::Context->userenv && C4::Context->userenv->{"branch"};
- my $itemtypes;
- if($branch_limit) {
- $itemtypes = Koha::ItemTypes->search_with_localization({branchcode => $branch_limit});
- } else {
- $itemtypes = Koha::ItemTypes->search_with_localization;
- }
- while ( my $itemtype = $itemtypes->next ) {
- push @authorised_values, $itemtype->itemtype;
- $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description;
- }
-
- unless ( $value ) {
- my $itype_sth = $dbh->prepare("SELECT itemtype FROM biblioitems WHERE biblionumber = ?");
- $itype_sth->execute( $biblionumber );
- ( $value ) = $itype_sth->fetchrow_array;
- }
-
- #---- class_sources
- }
- elsif ( $subfieldlib->{authorised_value} eq "cn_source" ) {
- push @authorised_values, "";
-
- my $class_sources = GetClassSources();
- my $default_source = C4::Context->preference("DefaultClassificationSource");
-
- foreach my $class_source (sort keys %$class_sources) {
- next unless $class_sources->{$class_source}->{'used'} or
- ($value and $class_source eq $value) or
- ($class_source eq $default_source);
- push @authorised_values, $class_source;
- $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
- }
- $value = $default_source unless ($value);
-
- #---- "true" authorised value
- }
- else {
- push @authorised_values, qq{};
- my $av = GetAuthorisedValues( $subfieldlib->{authorised_value} );
- for my $r ( @$av ) {
- push @authorised_values, $r->{authorised_value};
- $authorised_lib{$r->{authorised_value}} = $r->{lib};
- }
- }
-
- if ( $subfieldlib->{hidden} > 4 or $subfieldlib->{hidden} <= -4 ) {
- $subfield_data{marc_value} = {
- type => 'hidden',
- id => $subfield_data{id},
- maxlength => $subfield_data{maxlength},
- value => $value,
- ( ( grep { $_ eq $subfieldlib->{authorised_value}} ( qw(branches itemtypes cn_source) ) ) ? () : ( category => $subfieldlib->{authorised_value}) ),
- };
- }
- else {
- $subfield_data{marc_value} = {
- type => 'select',
- id => "tag_".$tag."_subfield_".$subfieldtag."_".$index_subfield,
- values => \@authorised_values,
- labels => \%authorised_lib,
- default => $value,
- ( ( grep { $_ eq $subfieldlib->{authorised_value}} ( qw(branches itemtypes cn_source) ) ) ? () : ( category => $subfieldlib->{authorised_value}) ),
- };
- }
- }
- # it's a thesaurus / authority field
- elsif ( $subfieldlib->{authtypecode} ) {
- $subfield_data{marc_value} = {
- type => 'text_auth',
- id => $subfield_data{id},
- maxlength => $subfield_data{maxlength},
- value => $value,
- authtypecode => $subfieldlib->{authtypecode},
- };
- }
- # it's a plugin field
- elsif ( $subfieldlib->{value_builder} ) { # plugin
- require Koha::FrameworkPlugin;
- my $plugin = Koha::FrameworkPlugin->new({
- name => $subfieldlib->{'value_builder'},
- item_style => 1,
- });
- my $pars= { dbh => $dbh, record => $temp, tagslib =>$tagslib,
- id => $subfield_data{id}, tabloop => $loop_data };
- $plugin->build( $pars );
- if( !$plugin->errstr ) {
- my $class= 'buttonDot'. ( $plugin->noclick? ' disabled': '' );
- $subfield_data{marc_value} = {
- type => 'text_plugin',
- id => $subfield_data{id},
- maxlength => $subfield_data{maxlength},
- value => $value,
- class => $class,
- nopopup => $plugin->noclick,
- javascript => $plugin->javascript,
- };
- } else {
- warn $plugin->errstr;
- $subfield_data{marc_value} = {
- type => 'text',
- id => $subfield_data{id},
- maxlength => $subfield_data{maxlength},
- value => $value,
- }; # supply default input form
- }
- }
- elsif ( $tag eq '' ) { # it's an hidden field
- $subfield_data{marc_value} = {
- type => 'hidden',
- id => $subfield_data{id},
- maxlength => $subfield_data{maxlength},
- value => $value,
- };
- }
- elsif ( $subfieldlib->{'hidden'} ) { # FIXME: shouldn't input type be "hidden" ?
- $subfield_data{marc_value} = {
- type => 'text',
- id => $subfield_data{id},
- maxlength => $subfield_data{maxlength},
- value => $value,
- };
- }
- elsif (
- (
- $value and length($value) > 100
- )
- or (
- C4::Context->preference("marcflavour") eq "UNIMARC"
- and 300 <= $tag && $tag < 400 && $subfieldtag eq 'a'
- )
- or (
- C4::Context->preference("marcflavour") eq "MARC21"
- and 500 <= $tag && $tag < 600
- )
- ) {
- # oversize field (textarea)
- $subfield_data{marc_value} = {
- type => 'textarea',
- id => $subfield_data{id},
- value => $value,
- };
- } else {
- # it's a standard field
- $subfield_data{marc_value} = {
- type => 'text',
- id => $subfield_data{id},
- maxlength => $subfield_data{maxlength},
- value => $value,
- };