-
- $subfield_data{visibility} = "display:none;" if (($subfieldlib->{hidden} > 4) || ($subfieldlib->{hidden} <= -4));
-
- my $pref_itemcallnumber = C4::Context->preference('itemcallnumber');
- if (!$value && $subfieldlib->{kohafield} eq 'items.itemcallnumber' && $pref_itemcallnumber) {
- my $CNtag = substr($pref_itemcallnumber, 0, 3);
- my $CNsubfield = substr($pref_itemcallnumber, 3, 1);
- my $CNsubfield2 = substr($pref_itemcallnumber, 4, 1);
- my $temp2 = $temp->field($CNtag);
- if ($temp2) {
- $value = join ' ', $temp2->subfield($CNsubfield) || q{}, $temp2->subfield($CNsubfield2) || q{};
- #remove any trailing space incase one subfield is used
- $value =~ s/^\s+|\s+$//g;
- }
- }
-
- if ($frameworkcode eq 'FA' && $subfieldlib->{kohafield} eq 'items.barcode' && !$value){
- my $input = new CGI;
- $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 "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 $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,
- };
- }
- else {
- $subfield_data{marc_value} = {
- type => 'select',
- id => "tag_".$tag."_subfield_".$subfieldtag."_".$index_subfield,
- values => \@authorised_values,
- labels => \%authorised_lib,
- default => $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,
- };
- }
-
- # Getting list of subfields to keep when restricted editing is enabled
- my $subfieldsToAllowForRestrictedEditing = C4::Context->preference('SubfieldsToAllowForRestrictedEditing');
- my $allowAllSubfields = (
- not defined $subfieldsToAllowForRestrictedEditing
- or $subfieldsToAllowForRestrictedEditing eq q||
- ) ? 1 : 0;
- my @subfieldsToAllow = split(/ /, $subfieldsToAllowForRestrictedEditing);
-
- # If we're on restricted editing, and our field is not in the list of subfields to allow,
- # then it is read-only
- $subfield_data{marc_value}->{readonly} = (
- not $allowAllSubfields
- and $restrictededition
- and !grep { $tag . '$' . $subfieldtag eq $_ } @subfieldsToAllow
- ) ? 1: 0;
-
- return \%subfield_data;