Lines 33-38
use C4::ClassSource;
Link Here
|
33 |
use C4::Dates; |
33 |
use C4::Dates; |
34 |
use List::MoreUtils qw/any/; |
34 |
use List::MoreUtils qw/any/; |
35 |
use C4::Search; |
35 |
use C4::Search; |
|
|
36 |
use Storable qw(thaw freeze); |
37 |
use URI::Escape; |
38 |
|
36 |
|
39 |
|
37 |
use MARC::File::XML; |
40 |
use MARC::File::XML; |
38 |
use URI::Escape; |
41 |
use URI::Escape; |
Lines 277-282
sub generate_subfield_form {
Link Here
|
277 |
return \%subfield_data; |
280 |
return \%subfield_data; |
278 |
} |
281 |
} |
279 |
|
282 |
|
|
|
283 |
# Removes some subfields when prefilling items |
284 |
# This function will remove any subfield that is not in the SubfieldsToUseWhenPrefill syspref |
285 |
sub removeFieldsForPrefill { |
286 |
|
287 |
my $item = shift; |
288 |
|
289 |
# Getting item tag |
290 |
my ($tag, $subtag) = GetMarcFromKohaField("items.barcode", ''); |
291 |
|
292 |
# Getting list of subfields to keep |
293 |
my $subfieldsToUseWhenPrefill = C4::Context->preference('SubfieldsToUseWhenPrefill'); |
294 |
|
295 |
# Removing subfields that are not in the syspref |
296 |
if ($tag && $subfieldsToUseWhenPrefill) { |
297 |
my $field = $item->field($tag); |
298 |
my @subfieldsToUse= split(/ /,$subfieldsToUseWhenPrefill); |
299 |
foreach my $subfield ($field->subfields()) { |
300 |
if (!grep { $subfield->[0] eq $_ } @subfieldsToUse) { |
301 |
$field->delete_subfield(code => $subfield->[0]); |
302 |
} |
303 |
|
304 |
} |
305 |
} |
306 |
|
307 |
return $item; |
308 |
|
309 |
} |
280 |
|
310 |
|
281 |
my $input = new CGI; |
311 |
my $input = new CGI; |
282 |
my $error = $input->param('error'); |
312 |
my $error = $input->param('error'); |
Lines 315-323
my $oldrecord = TransformMarcToKoha($dbh,$record);
Link Here
|
315 |
my $itemrecord; |
345 |
my $itemrecord; |
316 |
my $nextop="additem"; |
346 |
my $nextop="additem"; |
317 |
my @errors; # store errors found while checking data BEFORE saving item. |
347 |
my @errors; # store errors found while checking data BEFORE saving item. |
|
|
348 |
|
349 |
# Getting last created item cookie |
350 |
my $prefillitem = C4::Context->preference('PrefillItem'); |
351 |
my $justaddeditem; |
352 |
my $cookieitemrecord; |
353 |
if ($prefillitem) { |
354 |
my $lastitemcookie = $input->cookie('LastCreatedItem'); |
355 |
if ($lastitemcookie) { |
356 |
$lastitemcookie = uri_unescape($lastitemcookie); |
357 |
if ( thaw($lastitemcookie) ) { |
358 |
$cookieitemrecord = thaw($lastitemcookie) ; |
359 |
$cookieitemrecord = removeFieldsForPrefill($cookieitemrecord); |
360 |
} |
361 |
} |
362 |
} |
363 |
|
318 |
#------------------------------------------------------------------------------- |
364 |
#------------------------------------------------------------------------------- |
319 |
if ($op eq "additem") { |
365 |
if ($op eq "additem") { |
320 |
#------------------------------------------------------------------------------- |
366 |
|
|
|
367 |
#------------------------------------------------------------------------------- |
321 |
# rebuild |
368 |
# rebuild |
322 |
my @tags = $input->param('tag'); |
369 |
my @tags = $input->param('tag'); |
323 |
my @subfields = $input->param('subfield'); |
370 |
my @subfields = $input->param('subfield'); |
Lines 334-359
if ($op eq "additem") {
Link Here
|
334 |
my $add_multiple_copies_submit = $input->param('add_multiple_copies_submit'); |
381 |
my $add_multiple_copies_submit = $input->param('add_multiple_copies_submit'); |
335 |
my $number_of_copies = $input->param('number_of_copies'); |
382 |
my $number_of_copies = $input->param('number_of_copies'); |
336 |
|
383 |
|
|
|
384 |
# This is a bit tricky : if there is a cookie for the last created item and |
385 |
# we just added an item, the cookie value is not correct yet (it will be updated |
386 |
# next page). To prevent the form from being filled with outdated values, we |
387 |
# force the use of "add and duplicate" feature, so the form will be filled with |
388 |
# correct values. |
389 |
$add_duplicate_submit = 1 if ($prefillitem); |
390 |
$justaddeditem = 1; |
391 |
|
392 |
# if autoBarcode is set to 'incremental', calculate barcode... |
393 |
if ( C4::Context->preference('autoBarcode') eq 'incremental' ) { |
394 |
$record = _increment_barcode($record, $frameworkcode); |
395 |
} |
396 |
|
397 |
|
337 |
if (C4::Context->preference('autoBarcode') eq 'incremental') { |
398 |
if (C4::Context->preference('autoBarcode') eq 'incremental') { |
338 |
$record = _increment_barcode($record, $frameworkcode); |
399 |
$record = _increment_barcode($record, $frameworkcode); |
339 |
} |
400 |
} |
340 |
|
401 |
|
341 |
my $addedolditem = TransformMarcToKoha($dbh,$record); |
402 |
my $addedolditem = TransformMarcToKoha( $dbh, $record ); |
342 |
|
403 |
|
343 |
# If we have to add or add & duplicate, we add the item |
404 |
# If we have to add or add & duplicate, we add the item |
344 |
if ($add_submit || $add_duplicate_submit) { |
405 |
if ( $add_submit || $add_duplicate_submit ) { |
345 |
# check for item barcode # being unique |
406 |
|
346 |
my $exist_itemnumber = get_item_from_barcode($addedolditem->{'barcode'}); |
407 |
# check for item barcode # being unique |
347 |
push @errors,"barcode_not_unique" if($exist_itemnumber); |
408 |
my $exist_itemnumber = get_item_from_barcode( $addedolditem->{'barcode'} ); |
348 |
# if barcode exists, don't create, but report The problem. |
409 |
push @errors, "barcode_not_unique" if ($exist_itemnumber); |
349 |
unless ($exist_itemnumber) { |
410 |
|
350 |
my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber); |
411 |
# if barcode exists, don't create, but report The problem. |
351 |
set_item_default_location($oldbibitemnum); |
412 |
unless ($exist_itemnumber) { |
352 |
} |
413 |
my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) = AddItemFromMarc( $record, $biblionumber ); |
353 |
$nextop = "additem"; |
414 |
set_item_default_location($oldbibitemnum); |
354 |
if ($exist_itemnumber) { |
415 |
|
355 |
$itemrecord = $record; |
416 |
# Pushing the last created item cookie back |
356 |
} |
417 |
if ($prefillitem && defined $record) { |
|
|
418 |
my $itemcookie = $input->cookie( |
419 |
-name => 'LastCreatedItem', |
420 |
# We uri_escape the whole freezed structure so we're sure we won't have any encoding problems |
421 |
-value => uri_escape_utf8( freeze( $record ) ), |
422 |
-expires => '' |
423 |
); |
424 |
|
425 |
$cookie = [ $cookie, $itemcookie ]; |
426 |
} |
427 |
|
428 |
} |
429 |
$nextop = "additem"; |
430 |
if ($exist_itemnumber) { |
431 |
$itemrecord = $record; |
432 |
} |
357 |
} |
433 |
} |
358 |
|
434 |
|
359 |
# If we have to add & duplicate |
435 |
# If we have to add & duplicate |
Lines 370-375
if ($op eq "additem") {
Link Here
|
370 |
$fieldItem->delete_subfields($tagsubfield); |
446 |
$fieldItem->delete_subfields($tagsubfield); |
371 |
$itemrecord->insert_fields_ordered($fieldItem); |
447 |
$itemrecord->insert_fields_ordered($fieldItem); |
372 |
} |
448 |
} |
|
|
449 |
$itemrecord = removeFieldsForPrefill($itemrecord) if ($prefillitem); |
373 |
} |
450 |
} |
374 |
|
451 |
|
375 |
# If we have to add multiple copies |
452 |
# If we have to add multiple copies |
Lines 696-701
if($itemrecord){
Link Here
|
696 |
} |
773 |
} |
697 |
# and now we add fields that are empty |
774 |
# and now we add fields that are empty |
698 |
|
775 |
|
|
|
776 |
# Using last created item if it exists |
777 |
|
778 |
$itemrecord = $cookieitemrecord if ($prefillitem and not $justaddeditem and $op ne "edititem"); |
779 |
|
780 |
# We generate form, and fill with values if defined |
699 |
foreach my $tag ( keys %{$tagslib}){ |
781 |
foreach my $tag ( keys %{$tagslib}){ |
700 |
foreach my $subtag (keys %{$tagslib->{$tag}}){ |
782 |
foreach my $subtag (keys %{$tagslib->{$tag}}){ |
701 |
next if subfield_is_koha_internal_p($subtag); |
783 |
next if subfield_is_koha_internal_p($subtag); |