4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
32 use C4::BackgroundJob;
37 use List::MoreUtils qw/uniq/;
40 use Koha::Exceptions::Exception;
41 use Koha::AuthorisedValues;
47 use Koha::SearchEngine::Indexer;
50 my $dbh = C4::Context->dbh;
51 my $error = $input->param('error');
52 my @itemnumbers = $input->multi_param('itemnumber');
53 my $biblionumber = $input->param('biblionumber');
54 my $op = $input->param('op');
55 my $del = $input->param('del');
56 my $del_records = $input->param('del_records');
57 my $src = $input->param('src');
58 my $use_default_values = $input->param('use_default_values');
59 my $exclude_from_local_holds_priority = $input->param('exclude_from_local_holds_priority');
64 $template_name = "tools/batchMod.tt";
65 $template_flag = { tools => '*' };
68 $template_name = ($del) ? "tools/batchMod-del.tt" : "tools/batchMod-edit.tt";
69 $template_flag = ($del) ? { tools => 'items_batchdel' } : { tools => 'items_batchmod' };
72 my ($template, $loggedinuser, $cookie)
73 = get_template_and_user({template_name => $template_name,
76 flagsrequired => $template_flag,
79 $template->param( searchid => scalar $input->param('searchid'), );
81 # Does the user have a restricted item edition permission?
82 my $uid = $loggedinuser ? Koha::Patrons->find( $loggedinuser )->userid : undef;
83 my $restrictededition = $uid ? haspermission($uid, {'tools' => 'items_batchmod_restricted'}) : undef;
84 # In case user is a superlibrarian, edition is not restricted
85 $restrictededition = 0 if ($restrictededition != 0 && C4::Context->IsSuperLibrarian());
87 $template->param(del => $del);
90 my @errors; # store errors found while checking data BEFORE saving item.
91 my $items_display_hashref;
92 our $tagslib = &GetMarcStructure(1);
94 my $deleted_items = 0; # Number of deleted items
95 my $deleted_records = 0; # Number of deleted records ( with no items attached )
96 my $not_deleted_items = 0; # Number of items that could not be deleted
97 my @not_deleted; # List of the itemnumbers that could not be deleted
98 my $modified_items = 0; # Numbers of modified items
99 my $modified_fields = 0; # Numbers of modified fields
101 my %cookies = parse CGI::Cookie($cookie);
102 my $sessionID = $cookies{'CGISESSID'}->value;
105 #--- ----------------------------------------------------------------------------
106 if ($op eq "action") {
107 #-------------------------------------------------------------------------------
108 my @tags = $input->multi_param('tag');
109 my @subfields = $input->multi_param('subfield');
110 my @values = $input->multi_param('field_value');
111 my @searches = $input->multi_param('regex_search');
112 my @replaces = $input->multi_param('regex_replace');
113 my @modifiers = $input->multi_param('regex_modifiers');
114 my @disabled = $input->multi_param('disable_input');
115 # build indicator hash.
116 my @ind_tag = $input->multi_param('ind_tag');
117 my @indicator = $input->multi_param('indicator');
119 # Is there something to modify ?
120 # TODO : We shall use this var to warn the user in case no modification was done to the items
121 my $values_to_modify = scalar(grep {!/^$/} @values) || scalar(grep {!/^$/} @searches);
122 my $values_to_blank = scalar(@disabled);
126 #initializing values for updates
127 my ( $itemtagfield, $itemtagsubfield) = &GetMarcFromKohaField( "items.itemnumber" );
128 if ($values_to_modify){
129 my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM');
130 $marcitem = MARC::Record::new_from_xml($xml, 'UTF-8');
132 if ($values_to_blank){
133 foreach my $disabledsubf (@disabled){
134 if ($marcitem && $marcitem->field($itemtagfield)){
135 $marcitem->field($itemtagfield)->update( $disabledsubf => "" );
138 $marcitem = MARC::Record->new();
139 $marcitem->append_fields( MARC::Field->new( $itemtagfield, '', '', $disabledsubf => "" ) );
144 my $upd_biblionumbers;
145 my $del_biblionumbers;
147 my $schema = Koha::Database->new->schema;
152 foreach my $itemnumber (@itemnumbers) {
153 my $item = Koha::Items->find($itemnumber);
156 ; # Should have been tested earlier, but just in case...
157 my $itemdata = $item->unblessed;
159 my $return = $item->safe_delete;
160 if ( ref( $return ) ) {
162 push @$upd_biblionumbers, $itemdata->{'biblionumber'};
165 $not_deleted_items++;
168 biblionumber => $itemdata->{'biblionumber'},
169 itemnumber => $itemdata->{'itemnumber'},
170 barcode => $itemdata->{'barcode'},
171 title => $itemdata->{'title'},
176 # If there are no items left, delete the biblio
178 my $itemscount = Koha::Biblios->find( $itemdata->{'biblionumber'} )->items->count;
179 if ( $itemscount == 0 ) {
180 my $error = DelBiblio( $itemdata->{'biblionumber'}, { skip_record_index => 1 } );
183 push @$del_biblionumbers, $itemdata->{'biblionumber'};
184 if ( $src eq 'CATALOGUING' ) {
185 # We are coming catalogue/detail.pl, there were items from a single bib record
186 $template->param( biblio_deleted => 1 );
193 my $modified_holds_priority = 0;
194 if ( defined $exclude_from_local_holds_priority && $exclude_from_local_holds_priority ne "" ) {
195 if(!defined $item->exclude_from_local_holds_priority || $item->exclude_from_local_holds_priority != $exclude_from_local_holds_priority) {
196 $item->exclude_from_local_holds_priority($exclude_from_local_holds_priority)->store;
197 $modified_holds_priority = 1;
201 if ( $values_to_modify || $values_to_blank ) {
202 my $localmarcitem = Item2Marc($itemdata);
204 for ( my $i = 0 ; $i < @tags ; $i++ ) {
205 my $search = $searches[$i];
209 my $subfield = $subfields[$i];
210 my $replace = $replaces[$i];
212 my $value = $localmarcitem->field( $tag )->subfield( $subfield );
213 my $old_value = $value;
215 my @available_modifiers = qw( i g );
216 my $retained_modifiers = q||;
217 for my $modifier ( split //, $modifiers[$i] ) {
218 $retained_modifiers .= $modifier
219 if grep {/$modifier/} @available_modifiers;
221 if ( $retained_modifiers =~ m/^(ig|gi)$/ ) {
222 $value =~ s/$search/$replace/ig;
224 elsif ( $retained_modifiers eq 'i' ) {
225 $value =~ s/$search/$replace/i;
227 elsif ( $retained_modifiers eq 'g' ) {
228 $value =~ s/$search/$replace/g;
231 $value =~ s/$search/$replace/;
234 my @fields_to = $localmarcitem->field($tag);
235 foreach my $field_to_update ( @fields_to ) {
236 unless ( $old_value eq $value ) {
238 $field_to_update->update( $subfield => $value );
243 $modified += UpdateMarcWith( $marcitem, $localmarcitem );
247 my $item = ModItemFromMarc(
249 $itemdata->{biblionumber},
251 { skip_record_index => 1 },
259 { skip_record_index => 1 }
260 ) if $item->{itemlost}
261 and not $itemdata->{itemlost};
264 push @$upd_biblionumbers, $itemdata->{'biblionumber'};
267 $modified_items++ if $modified || $modified_holds_priority;
268 $modified_fields += $modified + $modified_holds_priority;
273 Koha::Exceptions::Exception->throw(
274 'Some items have not been deleted, rolling back');
280 if ( $_->isa('Koha::Exceptions::Exception') ) {
281 $template->param( deletion_failed => 1 );
283 die "Something terrible has happened!"
284 if ($_ =~ /Rollback failed/); # Rollback failed
286 $upd_biblionumbers = [ uniq @$upd_biblionumbers ]; # Only update each bib once
288 # Don't send specialUpdate for records we are going to delete
289 my %del_bib_hash = map{ $_ => undef } @$del_biblionumbers;
290 @$upd_biblionumbers = grep( ! exists( $del_bib_hash{$_} ), @$upd_biblionumbers );
292 my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
293 $indexer->index_records( $upd_biblionumbers, 'specialUpdate', "biblioserver", undef ) if @$upd_biblionumbers;
294 $indexer->index_records( $del_biblionumbers, 'recordDelete', "biblioserver", undef ) if @$del_biblionumbers;
296 # Once the job is done
297 # If we have a reasonable amount of items, we display them
298 my $max_items = $del ? C4::Context->preference("MaxItemsToDisplayForBatchDel") : C4::Context->preference("MaxItemsToDisplayForBatchMod");
299 if (scalar(@itemnumbers) <= $max_items ){
300 if (scalar(@itemnumbers) <= 1000 ) {
301 $items_display_hashref=BuildItemsData(@itemnumbers);
303 # Else, we only display the barcode
304 my @simple_items_display = map {
306 my $item = Koha::Items->find($itemnumber);
308 itemnumber => $itemnumber,
309 barcode => $item ? ( $item->barcode // q{} ) : q{},
310 biblionumber => $item ? $item->biblio->biblionumber : q{},
313 $template->param("simple_items_display" => \@simple_items_display);
316 $template->param( "too_many_items_display" => scalar(@itemnumbers) );
317 $template->param( "job_completed" => 1 );
320 # Calling the template
322 modified_items => $modified_items,
323 modified_fields => $modified_fields,
328 #-------------------------------------------------------------------------------
329 # build screen with existing items. and "new" one
330 #-------------------------------------------------------------------------------
333 my $filefh = $input->upload('uploadfile');
334 my $filecontent = $input->param('filecontent');
335 my ( @notfoundbarcodes, @notfounditemnumbers);
337 my $split_chars = C4::Context->preference('BarcodeSeparators');
339 binmode $filefh, ':encoding(UTF-8)';
341 while (my $content=<$filefh>){
342 $content =~ s/[\r\n]*$//;
343 push @contentlist, $content if $content;
346 if ($filecontent eq 'barcode_file') {
347 @contentlist = grep /\S/, ( map { split /[$split_chars]/ } @contentlist );
348 @contentlist = uniq @contentlist;
349 # Note: adding lc for case insensitivity
350 my %itemdata = map { lc($_->{barcode}) => $_->{itemnumber} } @{ Koha::Items->search({ barcode => \@contentlist }, { columns => [ 'itemnumber', 'barcode' ] } )->unblessed };
351 @itemnumbers = map { exists $itemdata{lc $_} ? $itemdata{lc $_} : () } @contentlist;
352 @notfoundbarcodes = grep { !exists $itemdata{lc $_} } @contentlist;
354 elsif ( $filecontent eq 'itemid_file') {
355 @contentlist = uniq @contentlist;
356 my %itemdata = map { $_->{itemnumber} => 1 } @{ Koha::Items->search({ itemnumber => \@contentlist }, { columns => [ 'itemnumber' ] } )->unblessed };
357 @itemnumbers = grep { exists $itemdata{$_} } @contentlist;
358 @notfounditemnumbers = grep { !exists $itemdata{$_} } @contentlist;
361 if (defined $biblionumber && !@itemnumbers){
362 my @all_items = GetItemsInfo( $biblionumber );
363 foreach my $itm (@all_items) {
364 push @itemnumbers, $itm->{itemnumber};
367 if ( my $list = $input->param('barcodelist') ) {
368 my @barcodelist = grep /\S/, ( split /[$split_chars]/, $list );
369 @barcodelist = uniq @barcodelist;
370 # Note: adding lc for case insensitivity
371 my %itemdata = map { lc($_->{barcode}) => $_->{itemnumber} } @{ Koha::Items->search({ barcode => \@barcodelist }, { columns => [ 'itemnumber', 'barcode' ] } )->unblessed };
372 @itemnumbers = map { exists $itemdata{lc $_} ? $itemdata{lc $_} : () } @barcodelist;
373 @notfoundbarcodes = grep { !exists $itemdata{lc $_} } @barcodelist;
377 # Flag to tell the template there are valid results, hidden or not
378 if(scalar(@itemnumbers) > 0){ $template->param("itemresults" => 1); }
379 # Only display the items if there are no more than pref MaxItemsToProcessForBatchMod or MaxItemsToDisplayForBatchDel
380 my $max_display_items = $del
381 ? C4::Context->preference("MaxItemsToDisplayForBatchDel")
382 : C4::Context->preference("MaxItemsToDisplayForBatchMod");
383 $template->param("too_many_items_process" => scalar(@itemnumbers)) if !$del && scalar(@itemnumbers) > C4::Context->preference("MaxItemsToProcessForBatchMod");
384 if (scalar(@itemnumbers) <= ( $max_display_items // 1000 ) ) {
385 $items_display_hashref=BuildItemsData(@itemnumbers);
387 $template->param("too_many_items_display" => scalar(@itemnumbers));
388 # Even if we do not display the items, we need the itemnumbers
389 $template->param(itemnumbers_array => \@itemnumbers);
391 # now, build the item form for entering a new item
394 my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
396 my $libraries = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed;# build once ahead of time, instead of multiple times later.
398 # Adding a default choice, in case the user does not want to modify the branch
399 my $nochange_branch = { branchname => '', value => '', selected => 1 };
400 unshift (@$libraries, $nochange_branch);
402 my $pref_itemcallnumber = C4::Context->preference('itemcallnumber');
404 # Getting list of subfields to keep when restricted batchmod edit is enabled
405 my $subfieldsToAllowForBatchmod = C4::Context->preference('SubfieldsToAllowForRestrictedBatchmod');
406 my $allowAllSubfields = (
407 not defined $subfieldsToAllowForBatchmod
408 or $subfieldsToAllowForBatchmod eq q||
410 my @subfieldsToAllow = split(/ /, $subfieldsToAllowForBatchmod);
412 foreach my $tag (sort keys %{$tagslib}) {
413 # loop through each subfield
414 foreach my $subfield (sort keys %{$tagslib->{$tag}}) {
415 next if IsMarcStructureInternal( $tagslib->{$tag}{$subfield} );
416 next if (not $allowAllSubfields and $restrictededition && !grep { $tag . '$' . $subfield eq $_ } @subfieldsToAllow );
417 next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "10");
418 # barcode is not meant to be batch-modified
419 next if $tagslib->{$tag}->{$subfield}->{'kohafield'} eq 'items.barcode';
422 my $index_subfield = int(rand(1000000));
423 if ($subfield eq '@'){
424 $subfield_data{id} = "tag_".$tag."_subfield_00_".$index_subfield;
426 $subfield_data{id} = "tag_".$tag."_subfield_".$subfield."_".$index_subfield;
428 $subfield_data{tag} = $tag;
429 $subfield_data{subfield} = $subfield;
430 $subfield_data{marc_lib} ="<span id=\"error$i\" title=\"".$tagslib->{$tag}->{$subfield}->{lib}."\">".$tagslib->{$tag}->{$subfield}->{lib}."</span>";
431 $subfield_data{mandatory} = $tagslib->{$tag}->{$subfield}->{mandatory};
432 $subfield_data{repeatable} = $tagslib->{$tag}->{$subfield}->{repeatable};
434 if ( $use_default_values) {
435 $value = $tagslib->{$tag}->{$subfield}->{defaultvalue};
436 # get today date & replace YYYY, MM, DD if provided in the default value
437 my $today = dt_from_string;
438 my $year = $today->year;
439 my $month = $today->month;
440 my $day = $today->day;
441 $value =~ s/YYYY/$year/g;
442 $value =~ s/MM/$month/g;
443 $value =~ s/DD/$day/g;
445 $subfield_data{visibility} = "display:none;" if (($tagslib->{$tag}->{$subfield}->{hidden} > 4) || ($tagslib->{$tag}->{$subfield}->{hidden} < -4));
446 # testing branch value if IndependentBranches.
448 if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
449 my @authorised_values;
451 # builds list, depending on authorised value...
453 if ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "branches" ) {
454 foreach my $library (@$libraries) {
455 push @authorised_values, $library->{branchcode};
456 $authorised_lib{$library->{branchcode}} = $library->{branchname};
460 elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
461 push @authorised_values, "";
462 my $itemtypes = Koha::ItemTypes->search_with_localization;
463 while ( my $itemtype = $itemtypes->next ) {
464 push @authorised_values, $itemtype->itemtype;
465 $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description;
471 elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {
472 push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
474 my $class_sources = GetClassSources();
475 my $default_source = C4::Context->preference("DefaultClassificationSource");
477 foreach my $class_source (sort keys %$class_sources) {
478 next unless $class_sources->{$class_source}->{'used'} or
479 ($value and $class_source eq $value) or
480 ($class_source eq $default_source);
481 push @authorised_values, $class_source;
482 $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
486 #---- "true" authorised value
489 push @authorised_values, ""; # unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
491 my @avs = Koha::AuthorisedValues->search_with_library_limits(
493 category => $tagslib->{$tag}->{$subfield}->{authorised_value}
495 { order_by => 'lib' },
498 for my $av ( @avs ) {
499 push @authorised_values, $av->authorised_value;
500 $authorised_lib{$av->authorised_value} = $av->lib;
504 $subfield_data{marc_value} = {
506 id => "tag_".$tag."_subfield_".$subfield."_".$index_subfield,
507 name => "field_value",
508 values => \@authorised_values,
509 labels => \%authorised_lib,
512 # it's a thesaurus / authority field
514 elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) {
515 $subfield_data{marc_value} = {
517 id => $subfield_data{id},
519 authtypecode => $tagslib->{$tag}->{$subfield}->{authtypecode},
522 elsif ( $tagslib->{$tag}->{$subfield}->{value_builder} ) { # plugin
523 require Koha::FrameworkPlugin;
524 my $plugin = Koha::FrameworkPlugin->new( {
525 name => $tagslib->{$tag}->{$subfield}->{'value_builder'},
529 my $pars= { dbh => $dbh, record => $temp, tagslib => $tagslib,
530 id => $subfield_data{id}, tabloop => \@loop_data };
531 $plugin->build( $pars );
532 if( !$plugin->errstr ) {
533 $subfield_data{marc_value} = {
535 id => $subfield_data{id},
537 javascript => $plugin->javascript,
538 noclick => $plugin->noclick,
541 warn $plugin->errstr;
542 $subfield_data{marc_value} = { # supply default input form
544 id => $subfield_data{id},
549 elsif ( $tag eq '' ) { # it's an hidden field
550 $subfield_data{marc_value} = {
552 id => $subfield_data{id},
556 elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) { # FIXME: shouldn't input type be "hidden" ?
557 $subfield_data{marc_value} = {
559 id => $subfield_data{id},
563 elsif ( length($value) > 100
564 or (C4::Context->preference("marcflavour") eq "UNIMARC" and
565 300 <= $tag && $tag < 400 && $subfield eq 'a' )
566 or (C4::Context->preference("marcflavour") eq "MARC21" and
567 500 <= $tag && $tag < 600 )
569 # oversize field (textarea)
570 $subfield_data{marc_value} = {
572 id => $subfield_data{id},
576 # it's a standard field
577 $subfield_data{marc_value} = {
579 id => $subfield_data{id},
583 # $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\">";
584 push (@loop_data, \%subfield_data);
587 } # -- End foreach tag
591 # what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit.
594 notfoundbarcodes => \@notfoundbarcodes,
595 notfounditemnumbers => \@notfounditemnumbers
598 } # -- End action="show"
600 $template->param(%$items_display_hashref) if $items_display_hashref;
604 $template->param( $op => 1 ) if $op;
606 if ($op eq "action") {
608 #my @not_deleted_loop = map{{itemnumber=>$_}}@not_deleted;
611 not_deleted_items => $not_deleted_items,
612 deleted_items => $deleted_items,
613 delete_records => $del_records,
614 deleted_records => $deleted_records,
615 not_deleted_loop => \@not_deleted
619 foreach my $error (@errors) {
620 $template->param($error => 1) if $error;
622 $template->param(src => $src);
623 $template->param(biblionumber => $biblionumber);
624 output_html_with_http_headers $input, $cookie, $template->output;
628 # ---------------- Functions
632 # now, build existiing item list
633 my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code
635 #---- finds where items.itemnumber is stored
636 my ( $itemtagfield, $itemtagsubfield) = &GetMarcFromKohaField( "items.itemnumber" );
637 my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField( "items.homebranch" );
638 foreach my $itemnumber (@itemnumbers){
639 my $itemdata = Koha::Items->find($itemnumber);
640 next unless $itemdata; # Should have been tested earlier, but just in case...
641 $itemdata = $itemdata->unblessed;
642 my $itemmarc=Item2Marc($itemdata);
644 foreach my $field (grep {$_->tag() eq $itemtagfield} $itemmarc->fields()) {
645 # loop through each subfield
646 my $itembranchcode=$field->subfield($branchtagsubfield);
647 if ($itembranchcode && C4::Context->preference("IndependentBranches")) {
649 my $userenv = C4::Context->userenv();
650 unless (C4::Context->IsSuperLibrarian() or (($userenv->{'branch'} eq $itembranchcode))){
651 $this_row{'nomod'}=1;
654 my $tag=$field->tag();
655 foreach my $subfield ($field->subfields) {
656 my ($subfcode,$subfvalue)=@$subfield;
657 next if ($tagslib->{$tag}->{$subfcode}->{tab} ne 10
658 && $tag ne $itemtagfield
659 && $subfcode ne $itemtagsubfield);
661 $witness{$subfcode} = $tagslib->{$tag}->{$subfcode}->{lib} if ($tagslib->{$tag}->{$subfcode}->{tab} eq 10);
662 if ($tagslib->{$tag}->{$subfcode}->{tab} eq 10) {
663 $this_row{$subfcode}=GetAuthorisedValueDesc( $tag,
664 $subfcode, $subfvalue, '', $tagslib)
668 $this_row{itemnumber} = $subfvalue if ($tag eq $itemtagfield && $subfcode eq $itemtagsubfield);
672 # grab title, author, and ISBN to identify bib that the item
673 # belongs to in the display
674 my $biblio = Koha::Biblios->find( $itemdata->{biblionumber} );
675 $this_row{title} = $biblio->title;
676 $this_row{author} = $biblio->author;
677 $this_row{isbn} = $biblio->biblioitem->isbn;
678 $this_row{biblionumber} = $biblio->biblionumber;
679 $this_row{holds} = $biblio->holds->count;
680 $this_row{item_holds} = Koha::Holds->search( { itemnumber => $itemnumber } )->count;
681 $this_row{item} = Koha::Items->find($itemnumber);
684 push(@big_array, \%this_row);
687 @big_array = sort {$a->{0} cmp $b->{0}} @big_array;
689 # now, construct template !
690 # First, the existing items for display
692 my @witnesscodessorted=sort keys %witness;
693 for my $row ( @big_array ) {
695 my @item_fields = map +{ field => $_ || '' }, @$row{ @witnesscodessorted };
696 $row_data{item_value} = [ @item_fields ];
697 $row_data{itemnumber} = $row->{itemnumber};
698 #reporting this_row values
699 $row_data{'nomod'} = $row->{'nomod'};
700 $row_data{bibinfo} = $row->{bibinfo};
701 $row_data{author} = $row->{author};
702 $row_data{title} = $row->{title};
703 $row_data{isbn} = $row->{isbn};
704 $row_data{biblionumber} = $row->{biblionumber};
705 $row_data{holds} = $row->{holds};
706 $row_data{item_holds} = $row->{item_holds};
707 $row_data{item} = $row->{item};
708 $row_data{safe_to_delete} = $row->{item}->safe_to_delete;
709 my $is_on_loan = C4::Circulation::IsItemIssued( $row->{itemnumber} );
710 $row_data{onloan} = $is_on_loan ? 1 : 0;
711 push(@item_value_loop,\%row_data);
713 my @header_loop=map { { header_value=> $witness{$_}} } @witnesscodessorted;
715 my @cannot_be_deleted = map {
716 $_->{safe_to_delete} == 1 ? () : $_->{item}->barcode
719 item_loop => \@item_value_loop,
720 cannot_be_deleted => \@cannot_be_deleted,
721 item_header_loop => \@header_loop
725 #BE WARN : it is not the general case
726 # This function can be OK in the item marc record special case
727 # Where subfield is not repeated
728 # And where we are sure that field should correspond
731 my ($marcfrom,$marcto)=@_;
732 my ( $itemtag, $itemtagsubfield) = &GetMarcFromKohaField( "items.itemnumber" );
733 my $fieldfrom=$marcfrom->field($itemtag);
734 my @fields_to=$marcto->field($itemtag);
737 return $modified unless $fieldfrom;
739 foreach my $subfield ( $fieldfrom->subfields() ) {
740 foreach my $field_to_update ( @fields_to ) {
741 if ( $subfield->[1] ) {
742 unless ( $field_to_update->subfield($subfield->[0]) eq $subfield->[1] ) {
744 $field_to_update->update( $subfield->[0] => $subfield->[1] );
749 $field_to_update->delete_subfield( code => $subfield->[0] );
757 my ($tagfield,$insubfield,$record) = @_;
760 foreach my $field ($record->field($tagfield)) {
761 my @subfields = $field->subfields();
762 foreach my $subfield (@subfields) {
763 if (@$subfield[0] eq $insubfield) {
764 $result .= @$subfield[1];
765 $indicator = $field->indicator(1).$field->indicator(2);
769 return($indicator,$result);