From d68e11c29abda4120a1b3b2ddd853ae32ae8b75c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 21 Nov 2019 14:26:57 +0100 Subject: [PATCH] Bug 23282: Display all item's subfields when batch item editing This is a start, but the display needs to be adjusted. Also there is something wrong in the logic (.pl). What is supposed to happen if a librarian decides to display in tab 10 a subfield that is not part of 942? Should we allow that? --- .../prog/en/modules/tools/batchMod-edit.tt | 4 +- tools/batchMod.pl | 413 +++++++++++---------- 2 files changed, 213 insertions(+), 204 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt index 61331ba73e..b54586aaed 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt @@ -148,7 +148,7 @@ $(document).ready(function(){

Show/hide columns: [% FOREACH item_header_loo IN item_header_loop %] - + [% END %]

@@ -158,7 +158,7 @@ $(document).ready(function(){ [% FOREACH item_header_loo IN item_header_loop %] - + [% END %] diff --git a/tools/batchMod.pl b/tools/batchMod.pl index 2e6473784c..0a14eaad68 100755 --- a/tools/batchMod.pl +++ b/tools/batchMod.pl @@ -99,6 +99,208 @@ my %cookies = parse CGI::Cookie($cookie); my $sessionID = $cookies{'CGISESSID'}->value; + + +# now, build the item form for entering a new item +my @loop_data =(); +my $i=0; +my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; + +my $libraries = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed;# build once ahead of time, instead of multiple times later. + +# Adding a default choice, in case the user does not want to modify the branch +my $nochange_branch = { branchname => '', value => '', selected => 1 }; +unshift (@$libraries, $nochange_branch); + +my $pref_itemcallnumber = C4::Context->preference('itemcallnumber'); + +# Getting list of subfields to keep when restricted batchmod edit is enabled +my $subfieldsToAllowForBatchmod = C4::Context->preference('SubfieldsToAllowForRestrictedBatchmod'); +my $allowAllSubfields = ( + not defined $subfieldsToAllowForBatchmod + or $subfieldsToAllowForBatchmod eq q|| +) ? 1 : 0; +my @subfieldsToAllow = split(/ /, $subfieldsToAllowForBatchmod); + +our @item_subfields; +foreach my $tag (sort keys %{$tagslib}) { + # loop through each subfield + foreach my $subfield (sort keys %{$tagslib->{$tag}}) { + next if IsMarcStructureInternal( $tagslib->{$tag}{$subfield} ); + next if (not $allowAllSubfields and $restrictededition && !grep { $tag . '$' . $subfield eq $_ } @subfieldsToAllow ); + next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "10"); + # barcode and stocknumber are not meant to be batch-modified + next if $tagslib->{$tag}->{$subfield}->{'kohafield'} eq 'items.barcode'; + next if $tagslib->{$tag}->{$subfield}->{'kohafield'} eq 'items.stocknumber'; + my %subfield_data; + + push @item_subfields, { subfield => $subfield, lib => $tagslib->{$tag}->{$subfield}->{lib} }; + + my $index_subfield = int(rand(1000000)); + if ($subfield eq '@'){ + $subfield_data{id} = "tag_".$tag."_subfield_00_".$index_subfield; + } else { + $subfield_data{id} = "tag_".$tag."_subfield_".$subfield."_".$index_subfield; + } + $subfield_data{tag} = $tag; + $subfield_data{subfield} = $subfield; + $subfield_data{marc_lib} ="{$tag}->{$subfield}->{lib}."\">".$tagslib->{$tag}->{$subfield}->{lib}.""; + $subfield_data{mandatory} = $tagslib->{$tag}->{$subfield}->{mandatory}; + $subfield_data{repeatable} = $tagslib->{$tag}->{$subfield}->{repeatable}; + my ($x,$value); + if ( $use_default_values) { + $value = $tagslib->{$tag}->{$subfield}->{defaultvalue}; + # get today date & replace YYYY, MM, DD if provided in the default value + my $today = dt_from_string; + my $year = $today->year; + my $month = $today->month; + my $day = $today->day; + $value =~ s/YYYY/$year/g; + $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)); + # testing branch value if IndependentBranches. + + 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 $library (@$libraries) { + push @authorised_values, $library->{branchcode}; + $authorised_lib{$library->{branchcode}} = $library->{branchname}; + } + $value = ""; + } + elsif ( $tagslib->{$tag}->{$subfield}->{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; + } + $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'}; + } + $value = ''; + + #---- "true" authorised value + } + else { + push @authorised_values, ""; # unless ( $tagslib->{$tag}->{$subfield}->{mandatory} ); + + my @avs = Koha::AuthorisedValues->search({ category => $tagslib->{$tag}->{$subfield}->{authorised_value}, branchcode => $branch_limit },{order_by=>'lib'}); + for my $av ( @avs ) { + push @authorised_values, $av->authorised_value; + $authorised_lib{$av->authorised_value} = $av->lib; + } + $value=""; + } + $subfield_data{marc_value} = { + type => 'select', + id => "tag_".$tag."_subfield_".$subfield."_".$index_subfield, + name => "field_value", + values => \@authorised_values, + labels => \%authorised_lib, + default => $value, + }; + # it's a thesaurus / authority field + } + elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) { + $subfield_data{marc_value} = { + type => 'text1', + id => $subfield_data{id}, + value => $value, + authtypecode => $tagslib->{$tag}->{$subfield}->{authtypecode}, + } + } + elsif ( $tagslib->{$tag}->{$subfield}->{value_builder} ) { # plugin + require Koha::FrameworkPlugin; + my $plugin = Koha::FrameworkPlugin->new( { + name => $tagslib->{$tag}->{$subfield}->{'value_builder'}, + item_style => 1, + }); + my $temp; + my $pars= { dbh => $dbh, record => $temp, tagslib => $tagslib, + id => $subfield_data{id}, tabloop => \@loop_data }; + $plugin->build( $pars ); + if( !$plugin->errstr ) { + $subfield_data{marc_value} = { + type => 'text2', + id => $subfield_data{id}, + value => $value, + javascript => $plugin->javascript, + noclick => $plugin->noclick, + }; + } else { + warn $plugin->errstr; + $subfield_data{marc_value} = { # supply default input form + type => 'text', + id => $subfield_data{id}, + value => $value, + }; + } + } + elsif ( $tag eq '' ) { # it's an hidden field + $subfield_data{marc_value} = { + type => 'hidden', + id => $subfield_data{id}, + value => $value, + }; + } + elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) { # FIXME: shouldn't input type be "hidden" ? + $subfield_data{marc_value} = { + type => 'text', + id => $subfield_data{id}, + value => $value, + }; + } + 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} = { + type => 'textarea', + id => $subfield_data{id}, + value => $value, + }; + } else { + # it's a standard field + $subfield_data{marc_value} = { + type => 'text', + id => $subfield_data{id}, + value => $value, + }; + } +# $subfield_data{marc_value}=""; + push (@loop_data, \%subfield_data); + $i++ + } +} # -- End foreach tag + + + + + #--- ---------------------------------------------------------------------------- if ($op eq "action") { #------------------------------------------------------------------------------- @@ -294,6 +496,10 @@ if ($op eq "show"){ } } + + + + # Flag to tell the template there are valid results, hidden or not if(scalar(@itemnumbers) > 0){ $template->param("itemresults" => 1); } # Only display the items if there are no more than pref MaxItemsToProcessForBatchMod or MaxItemsToDisplayForBatchDel @@ -308,200 +514,6 @@ if ($op eq "show"){ # Even if we do not display the items, we need the itemnumbers $template->param(itemnumbers_array => \@itemnumbers); } -# now, build the item form for entering a new item -my @loop_data =(); -my $i=0; -my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; - -my $libraries = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed;# build once ahead of time, instead of multiple times later. - -# Adding a default choice, in case the user does not want to modify the branch -my $nochange_branch = { branchname => '', value => '', selected => 1 }; -unshift (@$libraries, $nochange_branch); - -my $pref_itemcallnumber = C4::Context->preference('itemcallnumber'); - -# Getting list of subfields to keep when restricted batchmod edit is enabled -my $subfieldsToAllowForBatchmod = C4::Context->preference('SubfieldsToAllowForRestrictedBatchmod'); -my $allowAllSubfields = ( - not defined $subfieldsToAllowForBatchmod - or $subfieldsToAllowForBatchmod eq q|| -) ? 1 : 0; -my @subfieldsToAllow = split(/ /, $subfieldsToAllowForBatchmod); - -foreach my $tag (sort keys %{$tagslib}) { - # loop through each subfield - foreach my $subfield (sort keys %{$tagslib->{$tag}}) { - next if IsMarcStructureInternal( $tagslib->{$tag}{$subfield} ); - next if (not $allowAllSubfields and $restrictededition && !grep { $tag . '$' . $subfield eq $_ } @subfieldsToAllow ); - next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "10"); - # barcode and stocknumber are not meant to be batch-modified - next if $tagslib->{$tag}->{$subfield}->{'kohafield'} eq 'items.barcode'; - next if $tagslib->{$tag}->{$subfield}->{'kohafield'} eq 'items.stocknumber'; - my %subfield_data; - - my $index_subfield = int(rand(1000000)); - if ($subfield eq '@'){ - $subfield_data{id} = "tag_".$tag."_subfield_00_".$index_subfield; - } else { - $subfield_data{id} = "tag_".$tag."_subfield_".$subfield."_".$index_subfield; - } - $subfield_data{tag} = $tag; - $subfield_data{subfield} = $subfield; - $subfield_data{marc_lib} ="{$tag}->{$subfield}->{lib}."\">".$tagslib->{$tag}->{$subfield}->{lib}.""; - $subfield_data{mandatory} = $tagslib->{$tag}->{$subfield}->{mandatory}; - $subfield_data{repeatable} = $tagslib->{$tag}->{$subfield}->{repeatable}; - my ($x,$value); - if ( $use_default_values) { - $value = $tagslib->{$tag}->{$subfield}->{defaultvalue}; - # get today date & replace YYYY, MM, DD if provided in the default value - my $today = dt_from_string; - my $year = $today->year; - my $month = $today->month; - my $day = $today->day; - $value =~ s/YYYY/$year/g; - $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)); - # testing branch value if IndependentBranches. - - 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 $library (@$libraries) { - push @authorised_values, $library->{branchcode}; - $authorised_lib{$library->{branchcode}} = $library->{branchname}; - } - $value = ""; - } - elsif ( $tagslib->{$tag}->{$subfield}->{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; - } - $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'}; - } - $value = ''; - - #---- "true" authorised value - } - else { - push @authorised_values, ""; # unless ( $tagslib->{$tag}->{$subfield}->{mandatory} ); - - my @avs = Koha::AuthorisedValues->search({ category => $tagslib->{$tag}->{$subfield}->{authorised_value}, branchcode => $branch_limit },{order_by=>'lib'}); - for my $av ( @avs ) { - push @authorised_values, $av->authorised_value; - $authorised_lib{$av->authorised_value} = $av->lib; - } - $value=""; - } - $subfield_data{marc_value} = { - type => 'select', - id => "tag_".$tag."_subfield_".$subfield."_".$index_subfield, - name => "field_value", - values => \@authorised_values, - labels => \%authorised_lib, - default => $value, - }; - # it's a thesaurus / authority field - } - elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) { - $subfield_data{marc_value} = { - type => 'text1', - id => $subfield_data{id}, - value => $value, - authtypecode => $tagslib->{$tag}->{$subfield}->{authtypecode}, - } - } - elsif ( $tagslib->{$tag}->{$subfield}->{value_builder} ) { # plugin - require Koha::FrameworkPlugin; - my $plugin = Koha::FrameworkPlugin->new( { - name => $tagslib->{$tag}->{$subfield}->{'value_builder'}, - item_style => 1, - }); - my $temp; - my $pars= { dbh => $dbh, record => $temp, tagslib => $tagslib, - id => $subfield_data{id}, tabloop => \@loop_data }; - $plugin->build( $pars ); - if( !$plugin->errstr ) { - $subfield_data{marc_value} = { - type => 'text2', - id => $subfield_data{id}, - value => $value, - javascript => $plugin->javascript, - noclick => $plugin->noclick, - }; - } else { - warn $plugin->errstr; - $subfield_data{marc_value} = { # supply default input form - type => 'text', - id => $subfield_data{id}, - value => $value, - }; - } - } - elsif ( $tag eq '' ) { # it's an hidden field - $subfield_data{marc_value} = { - type => 'hidden', - id => $subfield_data{id}, - value => $value, - }; - } - elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) { # FIXME: shouldn't input type be "hidden" ? - $subfield_data{marc_value} = { - type => 'text', - id => $subfield_data{id}, - value => $value, - }; - } - 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} = { - type => 'textarea', - id => $subfield_data{id}, - value => $value, - }; - } else { - # it's a standard field - $subfield_data{marc_value} = { - type => 'text', - id => $subfield_data{id}, - value => $value, - }; - } -# $subfield_data{marc_value}=""; - push (@loop_data, \%subfield_data); - $i++ - } -} # -- End foreach tag - - # what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit. $template->param( @@ -573,12 +585,8 @@ sub BuildItemsData{ && $tag ne $itemtagfield && $subfcode ne $itemtagsubfield); - $witness{$subfcode} = $tagslib->{$tag}->{$subfcode}->{lib} if ($tagslib->{$tag}->{$subfcode}->{tab} eq 10); - if ($tagslib->{$tag}->{$subfcode}->{tab} eq 10) { - $this_row{$subfcode}=GetAuthorisedValueDesc( $tag, - $subfcode, $subfvalue, '', $tagslib) - || $subfvalue; - } + $witness{$subfcode} = $tagslib->{$tag}->{$subfcode}->{lib}; + $this_row{$subfcode} = GetAuthorisedValueDesc( $tag, $subfcode, $subfvalue, '', $tagslib ) || $subfvalue; $this_row{itemnumber} = $subfvalue if ($tag eq $itemtagfield && $subfcode eq $itemtagsubfield); } @@ -606,7 +614,8 @@ sub BuildItemsData{ my @witnesscodessorted=sort keys %witness; for my $row ( @big_array ) { my %row_data; - my @item_fields = map +{ field => $_ || '' }, @$row{ @witnesscodessorted }; + my @item_fields = map +{ field => $_ || '' }, @$row{ map { $_->{subfield} } @item_subfields }; + $row_data{item_value} = [ @item_fields ]; $row_data{itemnumber} = $row->{itemnumber}; #reporting this_row values @@ -622,7 +631,7 @@ sub BuildItemsData{ $row_data{onloan} = $is_on_loan ? 1 : 0; push(@item_value_loop,\%row_data); } - my @header_loop=map { { header_value=> $witness{$_}} } @witnesscodessorted; + my @header_loop = @item_subfields; return { item_loop => \@item_value_loop, item_header_loop => \@header_loop }; } -- 2.11.0
Title Holds [% item_header_loo.header_value | html %] [% item_header_loo.lib | html %]