Lines 32-37
use C4::Branch; # XXX subfield_is_koha_internal_p
Link Here
|
32 |
use C4::ClassSource; |
32 |
use C4::ClassSource; |
33 |
use C4::Dates; |
33 |
use C4::Dates; |
34 |
use List::MoreUtils qw/any/; |
34 |
use List::MoreUtils qw/any/; |
|
|
35 |
use Storable qw(thaw freeze); |
36 |
use URI::Escape; |
37 |
|
38 |
|
35 |
|
39 |
|
36 |
use MARC::File::XML; |
40 |
use MARC::File::XML; |
37 |
use URI::Escape; |
41 |
use URI::Escape; |
Lines 275-280
sub generate_subfield_form {
Link Here
|
275 |
return \%subfield_data; |
279 |
return \%subfield_data; |
276 |
} |
280 |
} |
277 |
|
281 |
|
|
|
282 |
sub removeFieldsForPrefill { |
283 |
#FIXME: this is not generic enough. We could define fields to remove in a syspref. |
284 |
my $item = shift; |
285 |
# Getting item tag |
286 |
my ($tag, $subtag) = GetMarcFromKohaField("items.barcode", ''); |
287 |
if ($tag) { |
288 |
my $field = $item->field($tag); |
289 |
if ($field) { |
290 |
$field->delete_subfield(code => 'f'); |
291 |
$field->delete_subfield(code => 'k'); |
292 |
$field->delete_subfield(code => 'u'); |
293 |
$field->delete_subfield(code => 'v'); |
294 |
$field->delete_subfield(code => 'x'); |
295 |
$field->delete_subfield(code => 'z'); |
296 |
} |
297 |
} |
298 |
return $item; |
299 |
|
300 |
} |
278 |
|
301 |
|
279 |
my $input = new CGI; |
302 |
my $input = new CGI; |
280 |
my $error = $input->param('error'); |
303 |
my $error = $input->param('error'); |
Lines 315-323
my $oldrecord = TransformMarcToKoha($dbh,$record);
Link Here
|
315 |
my $itemrecord; |
338 |
my $itemrecord; |
316 |
my $nextop="additem"; |
339 |
my $nextop="additem"; |
317 |
my @errors; # store errors found while checking data BEFORE saving item. |
340 |
my @errors; # store errors found while checking data BEFORE saving item. |
|
|
341 |
|
342 |
# Getting last created item cookie |
343 |
my $prefillitem = C4::Context->preference('PrefillItem'); |
344 |
my $justaddeditem; |
345 |
my $cookieitemrecord; |
346 |
if ($prefillitem) { |
347 |
my $lastitemcookie = $input->cookie('LastCreatedItem'); |
348 |
if ($lastitemcookie) { |
349 |
$lastitemcookie = uri_unescape($lastitemcookie); |
350 |
if ( thaw($lastitemcookie) ) { |
351 |
$cookieitemrecord = thaw($lastitemcookie) ; |
352 |
$cookieitemrecord = removeFieldsForPrefill($cookieitemrecord); |
353 |
} |
354 |
} |
355 |
} |
356 |
|
318 |
#------------------------------------------------------------------------------- |
357 |
#------------------------------------------------------------------------------- |
319 |
if ($op eq "additem") { |
358 |
if ($op eq "additem") { |
320 |
#------------------------------------------------------------------------------- |
359 |
|
|
|
360 |
#------------------------------------------------------------------------------- |
321 |
# rebuild |
361 |
# rebuild |
322 |
my @tags = $input->param('tag'); |
362 |
my @tags = $input->param('tag'); |
323 |
my @subfields = $input->param('subfield'); |
363 |
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'); |
374 |
my $add_multiple_copies_submit = $input->param('add_multiple_copies_submit'); |
335 |
my $number_of_copies = $input->param('number_of_copies'); |
375 |
my $number_of_copies = $input->param('number_of_copies'); |
336 |
|
376 |
|
|
|
377 |
# This is a bit tricky : if there is a cookie for the last created item and |
378 |
# we just added an item, the cookie value is not correct yet (it will be updated |
379 |
# next page). To prevent the form from being filled with outdated values, we |
380 |
# force the use of "add and duplicate" feature, so the form will be filled with |
381 |
# correct values. |
382 |
$add_duplicate_submit = 1 if ($prefillitem); |
383 |
$justaddeditem = 1; |
384 |
|
385 |
# if autoBarcode is set to 'incremental', calculate barcode... |
386 |
# NOTE: This code is subject to change in 3.2 with the implemenation of ajax based autobarcode code |
387 |
# NOTE: 'incremental' is the ONLY autoBarcode option available to those not using javascript |
388 |
if ( C4::Context->preference('autoBarcode') eq 'incremental' ) { |
389 |
my ( $tagfield, $tagsubfield ) = &GetMarcFromKohaField( "items.barcode", $frameworkcode ); |
390 |
unless ( $record->field($tagfield)->subfield($tagsubfield) ) { |
391 |
my $sth_barcode = $dbh->prepare("select max(abs(barcode)) from items"); |
392 |
$sth_barcode->execute; |
393 |
my ($newbarcode) = $sth_barcode->fetchrow; |
394 |
$newbarcode++; |
395 |
|
396 |
# OK, we have the new barcode, now create the entry in MARC record |
397 |
my $fieldItem = $record->field($tagfield); |
398 |
$record->delete_field($fieldItem); |
399 |
$fieldItem->add_subfields( $tagsubfield => $newbarcode ); |
400 |
$record->insert_fields_ordered($fieldItem); |
401 |
} |
402 |
} |
403 |
|
404 |
|
337 |
if (C4::Context->preference('autoBarcode') eq 'incremental') { |
405 |
if (C4::Context->preference('autoBarcode') eq 'incremental') { |
338 |
$record = _increment_barcode($record, $frameworkcode); |
406 |
$record = _increment_barcode($record, $frameworkcode); |
339 |
} |
407 |
} |
340 |
|
408 |
|
341 |
my $addedolditem = TransformMarcToKoha($dbh,$record); |
409 |
my $addedolditem = TransformMarcToKoha( $dbh, $record ); |
342 |
|
410 |
|
343 |
# If we have to add or add & duplicate, we add the item |
411 |
# If we have to add or add & duplicate, we add the item |
344 |
if ($add_submit || $add_duplicate_submit) { |
412 |
if ( $add_submit || $add_duplicate_submit ) { |
345 |
# check for item barcode # being unique |
413 |
|
346 |
my $exist_itemnumber = get_item_from_barcode($addedolditem->{'barcode'}); |
414 |
# check for item barcode # being unique |
347 |
push @errors,"barcode_not_unique" if($exist_itemnumber); |
415 |
my $exist_itemnumber = get_item_from_barcode( $addedolditem->{'barcode'} ); |
348 |
# if barcode exists, don't create, but report The problem. |
416 |
push @errors, "barcode_not_unique" if ($exist_itemnumber); |
349 |
unless ($exist_itemnumber) { |
417 |
|
350 |
my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber); |
418 |
# if barcode exists, don't create, but report The problem. |
351 |
set_item_default_location($oldbibitemnum); |
419 |
unless ($exist_itemnumber) { |
352 |
} |
420 |
my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) = AddItemFromMarc( $record, $biblionumber ); |
353 |
$nextop = "additem"; |
421 |
set_item_default_location($oldbibitemnum); |
354 |
if ($exist_itemnumber) { |
422 |
|
355 |
$itemrecord = $record; |
423 |
# Pushing the last created item cookie back |
356 |
} |
424 |
if ($prefillitem && defined $record) { |
|
|
425 |
my $itemcookie = $input->cookie( |
426 |
-name => 'LastCreatedItem', |
427 |
# We uri_escape the whole freezed structure so we're sure we won't have any encoding problems |
428 |
-value => uri_escape( freeze( $record ) ), |
429 |
-expires => '' |
430 |
); |
431 |
|
432 |
$cookie = ( $cookie, $itemcookie ); |
433 |
} |
434 |
|
435 |
} |
436 |
$nextop = "additem"; |
437 |
if ($exist_itemnumber) { |
438 |
$itemrecord = $record; |
439 |
} |
357 |
} |
440 |
} |
358 |
|
441 |
|
359 |
# If we have to add & duplicate |
442 |
# If we have to add & duplicate |
Lines 370-375
if ($op eq "additem") {
Link Here
|
370 |
$fieldItem->delete_subfields($tagsubfield); |
453 |
$fieldItem->delete_subfields($tagsubfield); |
371 |
$itemrecord->insert_fields_ordered($fieldItem); |
454 |
$itemrecord->insert_fields_ordered($fieldItem); |
372 |
} |
455 |
} |
|
|
456 |
$itemrecord = removeFieldsForPrefill($itemrecord) if ($prefillitem); |
373 |
} |
457 |
} |
374 |
|
458 |
|
375 |
# If we have to add multiple copies |
459 |
# If we have to add multiple copies |
Lines 698-703
if($itemrecord){
Link Here
|
698 |
} |
782 |
} |
699 |
# and now we add fields that are empty |
783 |
# and now we add fields that are empty |
700 |
|
784 |
|
|
|
785 |
# Using last created item if it exists |
786 |
|
787 |
$itemrecord = $cookieitemrecord if ($prefillitem and not $justaddeditem and $op ne "edititem"); |
788 |
|
789 |
# We generate form, and fill with values if defined |
701 |
foreach my $tag ( keys %{$tagslib}){ |
790 |
foreach my $tag ( keys %{$tagslib}){ |
702 |
foreach my $subtag (keys %{$tagslib->{$tag}}){ |
791 |
foreach my $subtag (keys %{$tagslib->{$tag}}){ |
703 |
next if subfield_is_koha_internal_p($subtag); |
792 |
next if subfield_is_koha_internal_p($subtag); |