Lines 89-101
if ($op eq "action") {
Link Here
|
89 |
my @tags = $input->param('tag'); |
89 |
my @tags = $input->param('tag'); |
90 |
my @subfields = $input->param('subfield'); |
90 |
my @subfields = $input->param('subfield'); |
91 |
my @values = $input->param('field_value'); |
91 |
my @values = $input->param('field_value'); |
|
|
92 |
my @disabled = $input->param('disable_input'); |
92 |
# build indicator hash. |
93 |
# build indicator hash. |
93 |
my @ind_tag = $input->param('ind_tag'); |
94 |
my @ind_tag = $input->param('ind_tag'); |
94 |
my @indicator = $input->param('indicator'); |
95 |
my @indicator = $input->param('indicator'); |
95 |
|
96 |
|
96 |
# Is there something to modify ? |
97 |
# Is there something to modify ? |
97 |
# TODO : We shall use this var to warn the user in case no modification was done to the items |
98 |
# TODO : We shall use this var to warn the user in case no modification was done to the items |
98 |
my $something_to_modify = scalar(grep {!/^$/} @values); |
99 |
my $values_to_modify = scalar(grep {!/^$/} @values); |
|
|
100 |
my $values_to_blank = scalar(@disabled); |
101 |
my $marcitem; |
99 |
|
102 |
|
100 |
# Once the job is done |
103 |
# Once the job is done |
101 |
if ($completedJobID) { |
104 |
if ($completedJobID) { |
Lines 114-121
if ($op eq "action") {
Link Here
|
114 |
# Calling the template |
117 |
# Calling the template |
115 |
add_saved_job_results_to_template($template, $completedJobID); |
118 |
add_saved_job_results_to_template($template, $completedJobID); |
116 |
|
119 |
|
117 |
# While the job is getting done |
|
|
118 |
} else { |
120 |
} else { |
|
|
121 |
# While the job is getting done |
119 |
|
122 |
|
120 |
# Job size is the number of items we have to process |
123 |
# Job size is the number of items we have to process |
121 |
my $job_size = scalar(@itemnumbers); |
124 |
my $job_size = scalar(@itemnumbers); |
Lines 128-133
if ($op eq "action") {
Link Here
|
128 |
$callback = progress_callback($job, $dbh); |
131 |
$callback = progress_callback($job, $dbh); |
129 |
} |
132 |
} |
130 |
|
133 |
|
|
|
134 |
#initializing values for updates |
135 |
my ( $itemtagfield, $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", ""); |
136 |
if ($values_to_modify){ |
137 |
my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM'); |
138 |
$marcitem = MARC::Record::new_from_xml($xml, 'UTF-8'); |
139 |
} |
140 |
if ($values_to_blank){ |
141 |
foreach my $disabledsubf (@disabled){ |
142 |
if ($marcitem && $marcitem->field($itemtagfield)){ |
143 |
$marcitem->field($itemtagfield)->update( $disabledsubf => "" ); |
144 |
} |
145 |
else { |
146 |
$marcitem = MARC::Record->new(); |
147 |
$marcitem->append_fields( MARC::Field->new( $itemtagfield, '', '', $disabledsubf => "" ) ); |
148 |
} |
149 |
} |
150 |
} |
151 |
|
131 |
# For each item |
152 |
# For each item |
132 |
my $i = 1; |
153 |
my $i = 1; |
133 |
foreach my $itemnumber(@itemnumbers){ |
154 |
foreach my $itemnumber(@itemnumbers){ |
Lines 140-155
if ($op eq "action") {
Link Here
|
140 |
$deleted_items++; |
161 |
$deleted_items++; |
141 |
} else { |
162 |
} else { |
142 |
$not_deleted_items++; |
163 |
$not_deleted_items++; |
143 |
push @not_deleted, { biblionumber => $itemdata->{'biblionumber'}, itemnumber => $itemdata->{'itemnumber'}, barcode => $itemdata->{'barcode'}, title => $itemdata->{'title'}, $return => 1 }; |
164 |
push @not_deleted, |
|
|
165 |
{ biblionumber => $itemdata->{'biblionumber'}, |
166 |
itemnumber => $itemdata->{'itemnumber'}, |
167 |
barcode => $itemdata->{'barcode'}, |
168 |
title => $itemdata->{'title'}, |
169 |
$return => 1 |
170 |
}; |
144 |
} |
171 |
} |
145 |
} else { |
172 |
} else { |
146 |
if ($something_to_modify) { |
173 |
if ($values_to_modify || $values_to_blank) { |
147 |
my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM'); |
174 |
my $localmarcitem = Item2Marc($itemdata); |
148 |
my $marcitem = MARC::Record::new_from_xml($xml, 'UTF-8'); |
175 |
UpdateMarcWith( $marcitem, $localmarcitem ); |
149 |
my $localitem = TransformMarcToKoha( $dbh, $marcitem, "", 'items' ); |
176 |
eval{ my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) = ModItemFromMarc( $localmarcitem, $itemdata->{biblionumber}, $itemnumber ) }; |
150 |
my $localmarcitem=Item2Marc($itemdata); |
|
|
151 |
UpdateMarcWith($marcitem,$localmarcitem); |
152 |
eval{my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = ModItemFromMarc($localmarcitem,$itemdata->{biblionumber},$itemnumber)}; |
153 |
} |
177 |
} |
154 |
} |
178 |
} |
155 |
$i++; |
179 |
$i++; |
Lines 505-511
sub UpdateMarcWith {
Link Here
|
505 |
my @fields_to=$marcto->field($itemtag); |
529 |
my @fields_to=$marcto->field($itemtag); |
506 |
foreach my $subfield ($fieldfrom->subfields()){ |
530 |
foreach my $subfield ($fieldfrom->subfields()){ |
507 |
foreach my $field_to_update (@fields_to){ |
531 |
foreach my $field_to_update (@fields_to){ |
508 |
$field_to_update->update($$subfield[0]=>$$subfield[1]) if ($$subfield[1] != '' or $$subfield[1] == '0'); |
532 |
if ($subfield->[1]){ |
|
|
533 |
$field_to_update->update($subfield->[0]=>$subfield->[1]); |
534 |
} |
535 |
else { |
536 |
$field_to_update->delete_subfield(code=> $subfield->[0]); |
537 |
} |
509 |
} |
538 |
} |
510 |
} |
539 |
} |
511 |
#warn "TO edited:",$marcto->as_formatted; |
540 |
#warn "TO edited:",$marcto->as_formatted; |
512 |
- |
|
|