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