From 9a7360d49bdb1439f79ffe6c924b33d9e807ec10 Mon Sep 17 00:00:00 2001 From: Henri-Damien LAURENT Date: Fri, 9 Apr 2010 14:17:16 +0200 Subject: [PATCH 2/2] Bug 6018 : MT3269 Fixing tools/batchMod.pl tags/subfields display display all the subfields used in framework no matter if they are hidden or shown --- tools/batchMod.pl | 237 +++++++++++++++++++++++++++++------------------------ 1 files changed, 131 insertions(+), 106 deletions(-) diff --git a/tools/batchMod.pl b/tools/batchMod.pl index 358125a..9ef1593 100755 --- a/tools/batchMod.pl +++ b/tools/batchMod.pl @@ -27,7 +27,7 @@ use C4::Biblio; use C4::Items; use C4::Context; use C4::Koha; # XXX subfield_is_koha_internal_p -use C4::Branch; # XXX subfield_is_koha_internal_p +use C4::Branch; use C4::BackgroundJob; use C4::ClassSource; use C4::Dates; @@ -73,7 +73,7 @@ my $nextop=""; my @errors; # store errors found while checking data BEFORE saving item. my $items_display_hashref; my $frameworkcode=""; -my $tagslib = &GetMarcStructure(1,$frameworkcode); +my $tagslib = &GetMarcStructure(1,''); my $deleted_items = 0; # Numbers of deleted items my $not_deleted_items = 0; # Numbers of items that could not be deleted @@ -82,6 +82,7 @@ my @not_deleted; # List of the itemnumbers that could not be deleted my %cookies = parse CGI::Cookie($cookie); my $sessionID = $cookies{'CGISESSID'}->value; +my ( $itemtagfield, $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", ""); #--- ---------------------------------------------------------------------------- if ($op eq "action") { @@ -133,7 +134,6 @@ if ($op eq "action") { } #initializing values for updates - my ( $itemtagfield, $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", ""); if ($values_to_modify){ my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM'); $marcitem = MARC::Record::new_from_xml($xml, 'UTF-8'); @@ -246,13 +246,13 @@ unshift (@$branches, $nochange_branch); my $pref_itemcallnumber = C4::Context->preference('itemcallnumber'); - foreach my $tag (sort keys %{$tagslib}) { # loop through each subfield + next if ($tag ne $itemtagfield); foreach my $subfield (sort keys %{$tagslib->{$tag}}) { next if subfield_is_koha_internal_p($subfield); - next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "10"); - # barcode and stocknumber are not meant to be batch-modified + #field disabled + next if (!defined ($tagslib->{$tag}->{$subfield}->{'tab'}) || $tagslib->{$tag}->{$subfield}->{'tab'} eq -1); next if $tagslib->{$tag}->{$subfield}->{'kohafield'} eq 'items.barcode'; next if $tagslib->{$tag}->{$subfield}->{'kohafield'} eq 'items.stocknumber'; my %subfield_data; @@ -280,121 +280,146 @@ foreach my $tag (sort keys %{$tagslib}) { $value =~ s/MM/$month/g; $value =~ s/DD/$day/g; } - $subfield_data{visibility} = "display:none;" if (($tagslib->{$tag}->{$subfield}->{hidden} > 4) || ($tagslib->{$tag}->{$subfield}->{hidden} < -4)); + #$subfield_data{visibility} = "display:none;" if (($tagslib->{$tag}->{$subfield}->{hidden} > 4) || ($tagslib->{$tag}->{$subfield}->{hidden} < -4)); # testing branch value if IndependantBranches. - my $attributes_no_value = qq(tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255" ); - my $attributes = qq($attributes_no_value value="$value" ); + my $attributes_no_value; + my $not_editable = 0; + + my $attributes_no_value; + my $not_editable = 0; + # Disable barcode and stock numbers batch editing + my @not_editable_koha_fields = ( 'items.barcode', 'items.stocknumber' ); + foreach (@not_editable_koha_fields) { + my ($bctag, $bcsubfield) = GetMarcFromKohaField($_, $frameworkcode); + if (($bctag eq $subfield_data{tag}) && ($bcsubfield eq $subfield_data{subfield})) { + $not_editable = 1; + } + + } + + my $attributes; + # If a field is found to be non-editable, + if ($not_editable) { + # We mark it as disabled, so the user won't be able to edit it + $attributes_no_value = qq(disabled="disabled"); + $attributes = $attributes_no_value; + # We also remove it's data, so it won't be modified + undef($subfield_data{tag}); + undef($subfield_data{subfield}); + } else { + $attributes_no_value = qq(tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255" ); + $attributes = qq($attributes_no_value value="$value" ); + } if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) { my @authorised_values; my %authorised_lib; # builds list, depending on authorised value... - - if ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "branches" ) { - foreach my $thisbranch (@$branches) { - push @authorised_values, $thisbranch->{value}; - $authorised_lib{$thisbranch->{value}} = $thisbranch->{branchname}; - } - $value = ""; - } - elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) { - push @authorised_values, ""; - my $sth = $dbh->prepare("select itemtype,description from itemtypes order by description"); - $sth->execute; - while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) { - push @authorised_values, $itemtype; - $authorised_lib{$itemtype} = $description; - } - $value = ""; - - #---- class_sources - } - elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) { - push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} ); - - 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'}; + my @not_editable_koha_fields = ( 'items.barcode', 'items.stocknumber' ); + foreach (@not_editable_koha_fields) { + my ($bctag, $bcsubfield) = GetMarcFromKohaField($_, $frameworkcode); + if (($bctag eq $subfield_data{tag}) && ($bcsubfield eq $subfield_data{subfield})) { + $not_editable = 1; } - $value = ''; + } + elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) { + push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} ); + my $sth = $dbh->prepare("select itemtype,description from itemtypes order by description"); + $sth->execute; + while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) { + push @authorised_values, $itemtype; + $authorised_lib{$itemtype} = $description; + } #---- "true" authorised value } - else { - push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} ); - $authorised_values_sth->execute( $tagslib->{$tag}->{$subfield}->{authorised_value} ); - while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) { - push @authorised_values, $value; - $authorised_lib{$value} = $lib; + elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) { + push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} ); + + 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 } - } - $subfield_data{marc_value} =CGI::scrolling_list( # FIXME: factor out scrolling_list - -name => "field_value", - -values => \@authorised_values, - -default => $value, - -labels => \%authorised_lib, - -override => 1, - -size => 1, - -multiple => 0, - -tabindex => 1, - -id => "tag_".$tag."_subfield_".$subfield."_".$index_subfield, - -class => "input_marceditor", - ); - # it's a thesaurus / authority field - } - elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) { - $subfield_data{marc_value} = " - {$tag}->{$subfield}->{authtypecode}."&index=$subfield_data{id}','$subfield_data{id}'); return false;\" title=\"Tag Editor\">... - "; - # it's a plugin field - } - elsif ( $tagslib->{$tag}->{$subfield}->{value_builder} ) { - # opening plugin - my $plugin = C4::Context->intranetdir . "/cataloguing/value_builder/" . $tagslib->{$tag}->{$subfield}->{'value_builder'}; - if (do $plugin) { - my $temp; - my $extended_param = plugin_parameters( $dbh, $temp, $tagslib, $subfield_data{id}, \@loop_data ); - my ( $function_name, $javascript ) = plugin_javascript( $dbh, $temp, $tagslib, $subfield_data{id}, \@loop_data ); - $subfield_data{marc_value} = qq[ - ... - $javascript]; + else { + push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} ); + $authorised_values_sth->execute( $tagslib->{$tag}->{$subfield}->{authorised_value} ); + while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) { + push @authorised_values, $value; + $authorised_lib{$value} = $lib; + } + } + $subfield_data{marc_value} =CGI::scrolling_list( # FIXME: factor out scrolling_list + -name => "field_value", + -values => \@authorised_values, + -default => $value, + -labels => \%authorised_lib, + -override => 1, + -size => 1, + -multiple => 0, + -tabindex => 1, + -id => "tag_".$tag."_subfield_".$subfield."_".$index_subfield, + -class => "input_marceditor", + ); + # it's a thesaurus / authority field + } + elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) { + $subfield_data{marc_value} = " + {$tag}->{$subfield}->{authtypecode}."&index=$subfield_data{id}','$subfield_data{id}'); return false;\" title=\"Tag Editor\">... + "; + # it's a plugin field + } + elsif ( $tagslib->{$tag}->{$subfield}->{value_builder} ) { + # opening plugin + my $plugin = C4::Context->intranetdir . "/cataloguing/value_builder/" . $tagslib->{$tag}->{$subfield}->{'value_builder'}; + if (do $plugin) { + my $temp; + my $extended_param = plugin_parameters( $dbh, $temp, $tagslib, $subfield_data{id}, \@loop_data ); + my ( $function_name, $javascript ) = plugin_javascript( $dbh, $temp, $tagslib, $subfield_data{id}, \@loop_data ); + $subfield_data{marc_value} = qq[ + ... + $javascript]; + } else { + warn "Plugin Failed: $plugin"; + $subfield_data{marc_value} = ""; # supply default input form + } + } +# Donot hide any field in edit +# elsif ( $tag eq '' ) { # it's an hidden field +# $subfield_data{marc_value} = qq(); +# } +# elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) { # FIXME: shouldn't input type be "hidden" ? +# $subfield_data{marc_value} = qq(); +# } + elsif ( length($value) > 100 + or (C4::Context->preference("marcflavour") eq "UNIMARC" and + 300 <= $tag && $tag < 400 && $subfield eq 'a' ) + or (C4::Context->preference("marcflavour") eq "MARC21" and + 500 <= $tag && $tag < 600 ) + ) { + # oversize field (textarea) + $subfield_data{marc_value} = "\n"; } else { - warn "Plugin Failed: $plugin"; - $subfield_data{marc_value} = ""; # supply default input form + # it's a standard field + $subfield_data{marc_value} = ""; } + # $subfield_data{marc_value}=""; + push (@loop_data, \%subfield_data); + $i++ } - elsif ( $tag eq '' ) { # it's an hidden field - $subfield_data{marc_value} = qq(); - } - elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) { # FIXME: shouldn't input type be "hidden" ? - $subfield_data{marc_value} = qq(); - } - elsif ( length($value) > 100 - or (C4::Context->preference("marcflavour") eq "UNIMARC" and - 300 <= $tag && $tag < 400 && $subfield eq 'a' ) - or (C4::Context->preference("marcflavour") eq "MARC21" and - 500 <= $tag && $tag < 600 ) - ) { - # oversize field (textarea) - $subfield_data{marc_value} = "\n"; - } else { - # it's a standard field - $subfield_data{marc_value} = ""; - } -# $subfield_data{marc_value}=""; - push (@loop_data, \%subfield_data); - $i++ - } } # -- End foreach tag -- 1.7.1