Lines 48-54
use Koha::ItemTypes;
Link Here
|
48 |
use Koha::Libraries; |
48 |
use Koha::Libraries; |
49 |
use Koha::Patrons; |
49 |
use Koha::Patrons; |
50 |
use Koha::SearchEngine::Indexer; |
50 |
use Koha::SearchEngine::Indexer; |
51 |
use List::MoreUtils qw( any ); |
|
|
52 |
use C4::Search qw( enabled_staff_search_views ); |
51 |
use C4::Search qw( enabled_staff_search_views ); |
53 |
use Storable qw( freeze thaw ); |
52 |
use Storable qw( freeze thaw ); |
54 |
use URI::Escape qw( uri_escape_utf8 ); |
53 |
use URI::Escape qw( uri_escape_utf8 ); |
Lines 57-116
use C4::Members;
Link Here
|
57 |
use MARC::File::XML; |
56 |
use MARC::File::XML; |
58 |
use URI::Escape qw( uri_escape_utf8 ); |
57 |
use URI::Escape qw( uri_escape_utf8 ); |
59 |
use MIME::Base64 qw( decode_base64url encode_base64url ); |
58 |
use MIME::Base64 qw( decode_base64url encode_base64url ); |
|
|
59 |
use List::Util qw( first ); |
60 |
use List::MoreUtils qw( any uniq ); |
60 |
|
61 |
|
61 |
our $dbh = C4::Context->dbh; |
62 |
our $dbh = C4::Context->dbh; |
62 |
|
63 |
|
63 |
sub find_value { |
|
|
64 |
my ($tagfield,$insubfield,$record) = @_; |
65 |
my $result; |
66 |
my $indicator; |
67 |
foreach my $field ($record->field($tagfield)) { |
68 |
my @subfields = $field->subfields(); |
69 |
foreach my $subfield (@subfields) { |
70 |
if (@$subfield[0] eq $insubfield) { |
71 |
$result .= @$subfield[1]; |
72 |
$indicator = $field->indicator(1).$field->indicator(2); |
73 |
} |
74 |
} |
75 |
} |
76 |
return($indicator,$result); |
77 |
} |
78 |
|
79 |
sub get_item_from_barcode { |
80 |
my ($barcode)=@_; |
81 |
my $dbh=C4::Context->dbh; |
82 |
my $result; |
83 |
my $rq=$dbh->prepare("SELECT itemnumber from items where items.barcode=?"); |
84 |
$rq->execute($barcode); |
85 |
($result)=$rq->fetchrow; |
86 |
return($result); |
87 |
} |
88 |
|
89 |
# NOTE: This code is subject to change in the future with the implemenation of ajax based autobarcode code |
90 |
# NOTE: 'incremental' is the ONLY autoBarcode option available to those not using javascript |
91 |
sub _increment_barcode { |
92 |
my ($record, $frameworkcode) = @_; |
93 |
my ($tagfield,$tagsubfield) = &GetMarcFromKohaField( "items.barcode" ); |
94 |
unless ($record->field($tagfield)->subfield($tagsubfield)) { |
95 |
my $sth_barcode = $dbh->prepare("select max(abs(barcode)) from items"); |
96 |
$sth_barcode->execute; |
97 |
my ($newbarcode) = $sth_barcode->fetchrow; |
98 |
$newbarcode++; |
99 |
# OK, we have the new barcode, now create the entry in MARC record |
100 |
my $fieldItem = $record->field($tagfield); |
101 |
$record->delete_field($fieldItem); |
102 |
$fieldItem->add_subfields($tagsubfield => $newbarcode); |
103 |
$record->insert_fields_ordered($fieldItem); |
104 |
} |
105 |
return $record; |
106 |
} |
107 |
|
108 |
|
109 |
sub generate_subfield_form { |
64 |
sub generate_subfield_form { |
110 |
my ($tag, $subfieldtag, $value, $tagslib,$subfieldlib, $branches, $biblionumber, $temp, $loop_data, $i, $restrictededition, $item) = @_; |
65 |
my ($tag, $subfieldtag, $value, $tagslib,$subfieldlib, $branches, $biblionumber, $temp, $subfields, $i, $restrictededition, $item) = @_; |
111 |
|
66 |
|
112 |
my $frameworkcode = &GetFrameworkCode($biblionumber); |
67 |
my $frameworkcode = &GetFrameworkCode($biblionumber); |
113 |
|
68 |
|
|
|
69 |
$item //= {}; |
70 |
|
114 |
my %subfield_data; |
71 |
my %subfield_data; |
115 |
my $dbh = C4::Context->dbh; |
72 |
my $dbh = C4::Context->dbh; |
116 |
|
73 |
|
Lines 182-188
sub generate_subfield_form {
Link Here
|
182 |
# builds list, depending on authorised value... |
139 |
# builds list, depending on authorised value... |
183 |
if ( $subfieldlib->{authorised_value} eq "LOST" ) { |
140 |
if ( $subfieldlib->{authorised_value} eq "LOST" ) { |
184 |
my $ClaimReturnedLostValue = C4::Context->preference('ClaimReturnedLostValue'); |
141 |
my $ClaimReturnedLostValue = C4::Context->preference('ClaimReturnedLostValue'); |
185 |
my $item_is_return_claim = $ClaimReturnedLostValue && $item && $item->itemlost && $ClaimReturnedLostValue eq $item->itemlost; |
142 |
my $item_is_return_claim = $ClaimReturnedLostValue && exists $item->{itemlost} && $ClaimReturnedLostValue eq $item->{itemlost}; |
186 |
$subfield_data{IS_RETURN_CLAIM} = $item_is_return_claim; |
143 |
$subfield_data{IS_RETURN_CLAIM} = $item_is_return_claim; |
187 |
|
144 |
|
188 |
$subfield_data{IS_LOST_AV} = 1; |
145 |
$subfield_data{IS_LOST_AV} = 1; |
Lines 287-293
sub generate_subfield_form {
Link Here
|
287 |
item_style => 1, |
244 |
item_style => 1, |
288 |
}); |
245 |
}); |
289 |
my $pars= { dbh => $dbh, record => $temp, tagslib =>$tagslib, |
246 |
my $pars= { dbh => $dbh, record => $temp, tagslib =>$tagslib, |
290 |
id => $subfield_data{id}, tabloop => $loop_data }; |
247 |
id => $subfield_data{id}, tabloop => $subfields }; |
291 |
$plugin->build( $pars ); |
248 |
$plugin->build( $pars ); |
292 |
if( !$plugin->errstr ) { |
249 |
if( !$plugin->errstr ) { |
293 |
my $class= 'buttonDot'. ( $plugin->noclick? ' disabled': '' ); |
250 |
my $class= 'buttonDot'. ( $plugin->noclick? ' disabled': '' ); |
Lines 374-407
sub generate_subfield_form {
Link Here
|
374 |
return \%subfield_data; |
331 |
return \%subfield_data; |
375 |
} |
332 |
} |
376 |
|
333 |
|
377 |
# Removes some subfields when prefilling items |
|
|
378 |
# This function will remove any subfield that is not in the SubfieldsToUseWhenPrefill syspref |
379 |
sub removeFieldsForPrefill { |
380 |
|
381 |
my $item = shift; |
382 |
|
383 |
# Getting item tag |
384 |
my ($tag, $subtag) = GetMarcFromKohaField( "items.barcode" ); |
385 |
|
386 |
# Getting list of subfields to keep |
387 |
my $subfieldsToUseWhenPrefill = C4::Context->preference('SubfieldsToUseWhenPrefill'); |
388 |
|
389 |
# Removing subfields that are not in the syspref |
390 |
if ($tag && $subfieldsToUseWhenPrefill) { |
391 |
my $field = $item->field($tag); |
392 |
my @subfieldsToUse= split(/ /,$subfieldsToUseWhenPrefill); |
393 |
foreach my $subfield ($field->subfields()) { |
394 |
if (!grep { $subfield->[0] eq $_ } @subfieldsToUse) { |
395 |
$field->delete_subfield(code => $subfield->[0]); |
396 |
} |
397 |
|
398 |
} |
399 |
} |
400 |
|
401 |
return $item; |
402 |
|
403 |
} |
404 |
|
405 |
my $input = CGI->new; |
334 |
my $input = CGI->new; |
406 |
my $error = $input->param('error'); |
335 |
my $error = $input->param('error'); |
407 |
|
336 |
|
Lines 416-421
if( $input->param('itemnumber') && !$input->param('biblionumber') ){
Link Here
|
416 |
$itemnumber = $input->param('itemnumber'); |
345 |
$itemnumber = $input->param('itemnumber'); |
417 |
} |
346 |
} |
418 |
|
347 |
|
|
|
348 |
my $biblio = Koha::Biblios->find($biblionumber); |
349 |
|
419 |
my $op = $input->param('op') || q{}; |
350 |
my $op = $input->param('op') || q{}; |
420 |
my $hostitemnumber = $input->param('hostitemnumber'); |
351 |
my $hostitemnumber = $input->param('hostitemnumber'); |
421 |
my $marcflavour = C4::Context->preference("marcflavour"); |
352 |
my $marcflavour = C4::Context->preference("marcflavour"); |
Lines 427-433
my $fa_branch = $input->param('branch');
Link Here
|
427 |
my $fa_stickyduedate = $input->param('stickyduedate'); |
358 |
my $fa_stickyduedate = $input->param('stickyduedate'); |
428 |
my $fa_duedatespec = $input->param('duedatespec'); |
359 |
my $fa_duedatespec = $input->param('duedatespec'); |
429 |
|
360 |
|
430 |
my $frameworkcode = &GetFrameworkCode($biblionumber); |
361 |
our $frameworkcode = &GetFrameworkCode($biblionumber); |
431 |
|
362 |
|
432 |
# Defining which userflag is needing according to the framework currently used |
363 |
# Defining which userflag is needing according to the framework currently used |
433 |
my $userflags; |
364 |
my $userflags; |
Lines 455-483
$restrictededition = 0 if ($restrictededition != 0 && C4::Context->IsSuperLibra
Link Here
|
455 |
# In case user has fast cataloging permission (and we're in fast cataloging), editing is not restricted |
386 |
# In case user has fast cataloging permission (and we're in fast cataloging), editing is not restricted |
456 |
$restrictededition = 0 if ($restrictededition != 0 && $frameworkcode eq 'FA' && haspermission($uid, {'editcatalogue' => 'fast_cataloging'})); |
387 |
$restrictededition = 0 if ($restrictededition != 0 && $frameworkcode eq 'FA' && haspermission($uid, {'editcatalogue' => 'fast_cataloging'})); |
457 |
|
388 |
|
458 |
my $tagslib = &GetMarcStructure(1,$frameworkcode); |
389 |
our $tagslib = &GetMarcStructure(1,$frameworkcode); |
459 |
my $record = GetMarcBiblio({ biblionumber => $biblionumber }); |
390 |
my $record = GetMarcBiblio({ biblionumber => $biblionumber }); |
460 |
|
391 |
|
461 |
output_and_exit_if_error( $input, $cookie, $template, |
392 |
output_and_exit_if_error( $input, $cookie, $template, |
462 |
{ module => 'cataloguing', record => $record } ); |
393 |
{ module => 'cataloguing', record => $record } ); |
463 |
|
394 |
|
464 |
my $oldrecord = TransformMarcToKoha($record); |
395 |
my $oldrecord = TransformMarcToKoha($record); |
465 |
my $itemrecord; |
396 |
my $current_item; |
466 |
my $nextop="additem"; |
397 |
my $nextop="additem"; |
467 |
my @errors; # store errors found while checking data BEFORE saving item. |
398 |
my @errors; # store errors found while checking data BEFORE saving item. |
468 |
|
399 |
|
469 |
# Getting last created item cookie |
400 |
# Getting last created item cookie |
470 |
my $prefillitem = C4::Context->preference('PrefillItem'); |
401 |
my $prefillitem = C4::Context->preference('PrefillItem'); |
471 |
my $justaddeditem; |
402 |
my $item_from_cookie; |
472 |
my $cookieitemrecord; |
|
|
473 |
if ($prefillitem) { |
403 |
if ($prefillitem) { |
474 |
my $lastitemcookie = $input->cookie('LastCreatedItem'); |
404 |
my $lastitemcookie = $input->cookie('LastCreatedItem'); |
475 |
if ($lastitemcookie) { |
405 |
if ($lastitemcookie) { |
476 |
$lastitemcookie = decode_base64url($lastitemcookie); |
406 |
$lastitemcookie = decode_base64url($lastitemcookie); |
477 |
eval { |
407 |
eval { |
478 |
if ( thaw($lastitemcookie) ) { |
408 |
if ( thaw($lastitemcookie) ) { |
479 |
$cookieitemrecord = thaw($lastitemcookie); |
409 |
$item_from_cookie = thaw($lastitemcookie); |
480 |
$cookieitemrecord = removeFieldsForPrefill($cookieitemrecord); |
|
|
481 |
} |
410 |
} |
482 |
}; |
411 |
}; |
483 |
if ($@) { |
412 |
if ($@) { |
Lines 488-511
if ($prefillitem) {
Link Here
|
488 |
} |
417 |
} |
489 |
|
418 |
|
490 |
#------------------------------------------------------------------------------- |
419 |
#------------------------------------------------------------------------------- |
491 |
my $current_item; |
|
|
492 |
if ($op eq "additem") { |
420 |
if ($op eq "additem") { |
493 |
|
421 |
|
494 |
my $add_submit = $input->param('add_submit'); |
422 |
my $add_submit = $input->param('add_submit'); |
495 |
my $add_duplicate_submit = $input->param('add_duplicate_submit'); |
|
|
496 |
my $add_multiple_copies_submit = $input->param('add_multiple_copies_submit'); |
423 |
my $add_multiple_copies_submit = $input->param('add_multiple_copies_submit'); |
497 |
my $number_of_copies = $input->param('number_of_copies'); |
424 |
my $number_of_copies = $input->param('number_of_copies'); |
498 |
|
425 |
|
499 |
# This is a bit tricky : if there is a cookie for the last created item and |
|
|
500 |
# we just added an item, the cookie value is not correct yet (it will be updated |
501 |
# next page). To prevent the form from being filled with outdated values, we |
502 |
# force the use of "add and duplicate" feature, so the form will be filled with |
503 |
# correct values. |
504 |
$add_duplicate_submit = 1 if ($prefillitem); |
505 |
$justaddeditem = 1; |
506 |
|
507 |
my @columns = Koha::Items->columns; |
426 |
my @columns = Koha::Items->columns; |
508 |
my $biblio = Koha::Biblios->find($biblionumber); |
|
|
509 |
my $item = Koha::Item->new; |
427 |
my $item = Koha::Item->new; |
510 |
$item->biblionumber($biblio->biblionumber); |
428 |
$item->biblionumber($biblio->biblionumber); |
511 |
for my $c ( @columns ) { |
429 |
for my $c ( @columns ) { |
Lines 527-535
if ($op eq "additem") {
Link Here
|
527 |
} |
445 |
} |
528 |
$item->more_subfields_xml(undef); |
446 |
$item->more_subfields_xml(undef); |
529 |
} else { |
447 |
} else { |
530 |
my $v = $input->param("items.".$c); |
448 |
my @v = $input->multi_param("items.".$c); |
531 |
next unless defined $v; |
449 |
next unless @v; |
532 |
$item->$c($v); |
450 |
$item->$c(join ' | ', uniq @v); |
533 |
} |
451 |
} |
534 |
} |
452 |
} |
535 |
|
453 |
|
Lines 540-583
if ($op eq "additem") {
Link Here
|
540 |
} |
458 |
} |
541 |
|
459 |
|
542 |
# If we have to add or add & duplicate, we add the item |
460 |
# If we have to add or add & duplicate, we add the item |
543 |
if ( $add_submit || $add_duplicate_submit ) { |
461 |
if ( $add_submit || $prefillitem) { |
544 |
|
462 |
|
545 |
# check for item barcode # being unique |
463 |
# check for item barcode # being unique |
546 |
if ( Koha::Items->search({ barcode => $item->barcode })->count ) { |
464 |
if ( Koha::Items->search({ barcode => $item->barcode })->count ) { |
547 |
# if barcode exists, don't create, but report The problem. |
465 |
# if barcode exists, don't create, but report The problem. |
548 |
push @errors, "barcode_not_unique"; |
466 |
push @errors, "barcode_not_unique"; |
|
|
467 |
|
468 |
$current_item = $item->unblessed; # Restore edit form for the same item |
549 |
} |
469 |
} |
550 |
else { |
470 |
else { |
551 |
$item->store->discard_changes; |
471 |
$item->store->discard_changes; |
552 |
|
472 |
|
|
|
473 |
# This is a bit tricky : if there is a cookie for the last created item and |
474 |
# we just added an item, the cookie value is not correct yet (it will be updated |
475 |
# next page). To prevent the form from being filled with outdated values, we |
476 |
# force the use of "add and duplicate" feature, so the form will be filled with |
477 |
# correct values. |
478 |
|
553 |
# FIXME This need to be rewritten, we must store $item->unblessed instead |
479 |
# FIXME This need to be rewritten, we must store $item->unblessed instead |
554 |
## Pushing the last created item cookie back |
480 |
# Pushing the last created item cookie back |
555 |
#if ($prefillitem && defined $record) { |
481 |
if ( $prefillitem ) { |
556 |
# my $itemcookie = $input->cookie( |
482 |
$item_from_cookie = $input->cookie( |
557 |
# -name => 'LastCreatedItem', |
483 |
-name => 'LastCreatedItem', |
558 |
# # We encode_base64url the whole freezed structure so we're sure we won't have any encoding problems |
484 |
# We encode_base64url the whole freezed structure so we're sure we won't have any encoding problems |
559 |
# -value => encode_base64url( freeze( $record ) ), |
485 |
-value => encode_base64url( freeze( { %{$item->unblessed}, itemnumber => undef } ) ), |
560 |
# -HttpOnly => 1, |
486 |
-HttpOnly => 1, |
561 |
# -expires => '' |
487 |
-expires => '' |
562 |
# ); |
488 |
); |
563 |
|
489 |
|
564 |
# $cookie = [ $cookie, $itemcookie ]; |
490 |
$cookie = [ $cookie, $item_from_cookie ]; |
565 |
#} |
491 |
} |
566 |
|
492 |
|
567 |
} |
493 |
} |
568 |
$nextop = "additem"; |
494 |
$nextop = "additem"; |
569 |
|
495 |
|
570 |
|
|
|
571 |
# FIXME reset item to the item we were editing |
572 |
#if ($exist_itemnumber) { |
573 |
|
574 |
# $itemrecord = $record; |
575 |
#} |
576 |
$current_item = $item->unblessed; |
577 |
} |
496 |
} |
578 |
|
497 |
|
579 |
# If we have to add & duplicate |
498 |
# If we have to add & duplicate |
580 |
if ($add_duplicate_submit) { |
499 |
if ($prefillitem) { |
581 |
if (C4::Context->preference('autoBarcode') eq 'incremental') { |
500 |
if (C4::Context->preference('autoBarcode') eq 'incremental') { |
582 |
my ( $barcode ) = C4::Barcodes::ValueBuilder::incremental::get_barcode; |
501 |
my ( $barcode ) = C4::Barcodes::ValueBuilder::incremental::get_barcode; |
583 |
$current_item->{barcode} = $barcode; |
502 |
$current_item->{barcode} = $barcode; |
Lines 586-599
if ($op eq "additem") {
Link Here
|
586 |
# we have to clear the barcode field in the duplicate item record to make way for the new one generated by the javascript plugin |
505 |
# we have to clear the barcode field in the duplicate item record to make way for the new one generated by the javascript plugin |
587 |
$current_item->{barcode} = undef; # FIXME or delete? |
506 |
$current_item->{barcode} = undef; # FIXME or delete? |
588 |
} |
507 |
} |
589 |
# FIXME This subroutine needs to be adjusted |
|
|
590 |
# We want to pass $item |
591 |
# $itemrecord = removeFieldsForPrefill($itemrecord) if ($prefillitem); |
592 |
} |
508 |
} |
593 |
|
509 |
|
594 |
# If we have to add multiple copies |
510 |
# If we have to add multiple copies |
595 |
if ($add_multiple_copies_submit) { |
511 |
if ($add_multiple_copies_submit) { |
596 |
|
512 |
|
|
|
513 |
$current_item = $item->unblessed; |
514 |
|
597 |
my $copynumber = $current_item->{copynumber}; |
515 |
my $copynumber = $current_item->{copynumber}; |
598 |
my $oldbarcode = $current_item->{barcode}; |
516 |
my $oldbarcode = $current_item->{barcode}; |
599 |
|
517 |
|
Lines 604-610
if ($op eq "additem") {
Link Here
|
604 |
if ( $oldbarcode && !$testbarcode ) { |
522 |
if ( $oldbarcode && !$testbarcode ) { |
605 |
|
523 |
|
606 |
push @errors, "no_next_barcode"; |
524 |
push @errors, "no_next_barcode"; |
607 |
$itemrecord = $record; |
|
|
608 |
|
525 |
|
609 |
} |
526 |
} |
610 |
else { |
527 |
else { |
Lines 652-658
if ($op eq "additem") {
Link Here
|
652 |
if ( !$exist_itemnumber ) { |
569 |
if ( !$exist_itemnumber ) { |
653 |
delete $current_item->{itemnumber}; |
570 |
delete $current_item->{itemnumber}; |
654 |
$current_item = Koha::Item->new($current_item)->store( |
571 |
$current_item = Koha::Item->new($current_item)->store( |
655 |
{ skip_record_index => 1 } )->discard_changes->unblessed; |
572 |
{ skip_record_index => 1 } ); |
|
|
573 |
$current_item->discard_changes; # Cannot chain discard_changes |
574 |
$current_item = $current_item->unblessed; |
656 |
set_item_default_location($current_item->{itemnumber}); |
575 |
set_item_default_location($current_item->{itemnumber}); |
657 |
|
576 |
|
658 |
# We count the item only if it was really added |
577 |
# We count the item only if it was really added |
Lines 692-732
if ($op eq "additem") {
Link Here
|
692 |
} elsif ($op eq "edititem") { |
611 |
} elsif ($op eq "edititem") { |
693 |
#------------------------------------------------------------------------------- |
612 |
#------------------------------------------------------------------------------- |
694 |
# retrieve item if exist => then, it's a modif |
613 |
# retrieve item if exist => then, it's a modif |
695 |
$itemrecord = C4::Items::GetMarcItem($biblionumber,$itemnumber); |
614 |
$current_item = Koha::Items->find($itemnumber)->unblessed; |
|
|
615 |
# FIXME Handle non existent item |
696 |
$nextop = "saveitem"; |
616 |
$nextop = "saveitem"; |
697 |
#------------------------------------------------------------------------------- |
617 |
#------------------------------------------------------------------------------- |
698 |
} elsif ($op eq "dupeitem") { |
618 |
} elsif ($op eq "dupeitem") { |
699 |
#------------------------------------------------------------------------------- |
619 |
#------------------------------------------------------------------------------- |
700 |
# retrieve item if exist => then, it's a modif |
620 |
# retrieve item if exist => then, it's a modif |
701 |
$itemrecord = C4::Items::GetMarcItem($biblionumber,$itemnumber); |
621 |
my $item = Koha::Items->find($itemnumber); |
|
|
622 |
# FIXME Handle non existent item |
702 |
if (C4::Context->preference('autoBarcode') eq 'incremental') { |
623 |
if (C4::Context->preference('autoBarcode') eq 'incremental') { |
703 |
$itemrecord = _increment_barcode($itemrecord, $frameworkcode); |
624 |
my ( $barcode ) = C4::Barcodes::ValueBuilder::incremental::get_barcode; |
|
|
625 |
$item->barcode($barcode); |
704 |
} |
626 |
} |
705 |
else { |
627 |
else { |
706 |
# we have to clear the barcode field in the duplicate item record to make way for the new one generated by the javascript plugin |
628 |
$item->barcode(undef); # Don't save it! |
707 |
my ($tagfield,$tagsubfield) = &GetMarcFromKohaField( "items.barcode" ); |
|
|
708 |
my $fieldItem = $itemrecord->field($tagfield); |
709 |
$itemrecord->delete_field($fieldItem); |
710 |
$fieldItem->delete_subfields($tagsubfield); |
711 |
$itemrecord->insert_fields_ordered($fieldItem); |
712 |
} |
629 |
} |
713 |
|
630 |
|
714 |
#check for hidden subfield and remove them for the duplicated item |
|
|
715 |
foreach my $field ($itemrecord->fields()){ |
716 |
my $tag = $field->{_tag}; |
717 |
foreach my $subfield ($field->subfields()){ |
718 |
my $subfieldtag = $subfield->[0]; |
719 |
if ($tagslib->{$tag}->{$subfieldtag}->{'tab'} ne "10" |
720 |
|| abs($tagslib->{$tag}->{$subfieldtag}->{hidden})>4 ){ |
721 |
my $fieldItem = $itemrecord->field($tag); |
722 |
$itemrecord->delete_field($fieldItem); |
723 |
$fieldItem->delete_subfields($subfieldtag); |
724 |
$itemrecord->insert_fields_ordered($fieldItem); |
725 |
} |
726 |
} |
727 |
} |
728 |
|
729 |
$itemrecord = removeFieldsForPrefill($itemrecord) if ($prefillitem); |
730 |
$nextop = "additem"; |
631 |
$nextop = "additem"; |
731 |
#------------------------------------------------------------------------------- |
632 |
#------------------------------------------------------------------------------- |
732 |
} elsif ($op eq "delitem") { |
633 |
} elsif ($op eq "delitem") { |
Lines 795-803
if ($op eq "additem") {
Link Here
|
795 |
} |
696 |
} |
796 |
$item->more_subfields_xml(undef); |
697 |
$item->more_subfields_xml(undef); |
797 |
} else { |
698 |
} else { |
798 |
my $v = $input->param("items.".$c); |
699 |
my @v = $input->multi_param("items.".$c); |
799 |
next unless defined $v; |
700 |
next unless @v; |
800 |
$item->$c($v); |
701 |
$item->$c(join ' | ', uniq @v); |
801 |
} |
702 |
} |
802 |
} |
703 |
} |
803 |
|
704 |
|
Lines 805-810
if ($op eq "additem") {
Link Here
|
805 |
if ( Koha::Items->search({ barcode => $item->barcode, itemnumber => { '!=' => $item->itemnumber } })->count ) { |
706 |
if ( Koha::Items->search({ barcode => $item->barcode, itemnumber => { '!=' => $item->itemnumber } })->count ) { |
806 |
# FIXME We shouldn't need that, ->store would explode as there is a unique constraint on items.barcode |
707 |
# FIXME We shouldn't need that, ->store would explode as there is a unique constraint on items.barcode |
807 |
push @errors,"barcode_not_unique"; |
708 |
push @errors,"barcode_not_unique"; |
|
|
709 |
$current_item = $item->unblessed; # Restore edit form for the same item |
808 |
} else { |
710 |
} else { |
809 |
my $newitemlost = $item->itemlost; |
711 |
my $newitemlost = $item->itemlost; |
810 |
if ( $newitemlost && $newitemlost ge '1' && !$olditemlost ) { |
712 |
if ( $newitemlost && $newitemlost ge '1' && !$olditemlost ) { |
Lines 844-1056
if ($op) {
Link Here
|
844 |
#------------------------------------------------------------------------------- |
746 |
#------------------------------------------------------------------------------- |
845 |
|
747 |
|
846 |
# now, build existiing item list |
748 |
# now, build existiing item list |
847 |
my $temp = GetMarcBiblio({ biblionumber => $biblionumber }); |
|
|
848 |
#my @fields = $record->fields(); |
849 |
|
850 |
|
749 |
|
851 |
my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code |
750 |
my @items; |
852 |
my @big_array; |
751 |
for my $item ( $biblio->items->as_list, $biblio->host_items->as_list ) { |
853 |
#---- finds where items.itemnumber is stored |
752 |
push @items, $item->columns_to_str; |
854 |
my ( $itemtagfield, $itemtagsubfield) = &GetMarcFromKohaField( "items.itemnumber" ); |
|
|
855 |
my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField( "items.homebranch" ); |
856 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
857 |
marc_record => $temp, |
858 |
biblionumber => $biblionumber }); |
859 |
my @fields = $temp->fields(); |
860 |
|
861 |
|
862 |
my @hostitemnumbers; |
863 |
if ( C4::Context->preference('EasyAnalyticalRecords') ) { |
864 |
my $analyticfield = '773'; |
865 |
if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC') { |
866 |
$analyticfield = '773'; |
867 |
} elsif ($marcflavour eq 'UNIMARC') { |
868 |
$analyticfield = '461'; |
869 |
} |
870 |
foreach my $hostfield ($temp->field($analyticfield)){ |
871 |
my $hostbiblionumber = $hostfield->subfield('0'); |
872 |
if ($hostbiblionumber){ |
873 |
my $hostrecord = GetMarcBiblio({ |
874 |
biblionumber => $hostbiblionumber, |
875 |
embed_items => 1 }); |
876 |
if ($hostrecord) { |
877 |
my ($itemfield, undef) = GetMarcFromKohaField( 'items.itemnumber' ); |
878 |
foreach my $hostitem ($hostrecord->field($itemfield)){ |
879 |
if ($hostitem->subfield('9') eq $hostfield->subfield('9')){ |
880 |
push (@fields, $hostitem); |
881 |
push (@hostitemnumbers, $hostfield->subfield('9')); |
882 |
} |
883 |
} |
884 |
} |
885 |
} |
886 |
} |
887 |
} |
753 |
} |
888 |
|
754 |
|
889 |
foreach my $field (@fields) { |
755 |
my @witness_attributes = uniq map { |
890 |
next if ( $field->tag() < 10 ); |
756 |
my $item = $_; |
891 |
|
757 |
map { defined $item->{$_} && $item->{$_} ne "" ? $_ : () } keys %$item |
892 |
my @subf = $field->subfields or (); # don't use ||, as that forces $field->subfelds to be interpreted in scalar context |
758 |
} @items; |
893 |
my %this_row; |
|
|
894 |
# loop through each subfield |
895 |
my $i = 0; |
896 |
foreach my $subfield (@subf){ |
897 |
my $subfieldcode = $subfield->[0]; |
898 |
my $subfieldvalue= $subfield->[1]; |
899 |
|
900 |
next if ($tagslib->{$field->tag()}->{$subfieldcode}->{tab} ne 10 |
901 |
&& ($field->tag() ne $itemtagfield |
902 |
&& $subfieldcode ne $itemtagsubfield)); |
903 |
$witness{$subfieldcode} = $tagslib->{$field->tag()}->{$subfieldcode}->{lib} if ($tagslib->{$field->tag()}->{$subfieldcode}->{tab} eq 10); |
904 |
if ($tagslib->{$field->tag()}->{$subfieldcode}->{tab} eq 10) { |
905 |
$this_row{$subfieldcode} .= " | " if($this_row{$subfieldcode}); |
906 |
$this_row{$subfieldcode} .= GetAuthorisedValueDesc( $field->tag(), |
907 |
$subfieldcode, $subfieldvalue, '', $tagslib) |
908 |
|| $subfieldvalue; |
909 |
} |
910 |
|
759 |
|
911 |
if (($field->tag eq $branchtagfield) && ($subfieldcode eq $branchtagsubfield) && C4::Context->preference("IndependentBranches")) { |
760 |
our ( $itemtagfield, $itemtagsubfield ) = &GetMarcFromKohaField("items.itemnumber"); |
912 |
#verifying rights |
|
|
913 |
my $userenv = C4::Context->userenv(); |
914 |
unless (C4::Context->IsSuperLibrarian() or (($userenv->{'branch'} eq $subfieldvalue))){ |
915 |
$this_row{'nomod'} = 1; |
916 |
} |
917 |
} |
918 |
$this_row{itemnumber} = $subfieldvalue if ($field->tag() eq $itemtagfield && $subfieldcode eq $itemtagsubfield); |
919 |
|
920 |
if ( C4::Context->preference('EasyAnalyticalRecords') ) { |
921 |
foreach my $hostitemnumber (@hostitemnumbers) { |
922 |
my $item = Koha::Items->find( $hostitemnumber ); |
923 |
if ($this_row{itemnumber} eq $hostitemnumber) { |
924 |
$this_row{hostitemflag} = 1; |
925 |
$this_row{hostbiblionumber}= $item->biblio->biblionumber; |
926 |
last; |
927 |
} |
928 |
} |
929 |
} |
930 |
} |
931 |
if (%this_row) { |
932 |
push(@big_array, \%this_row); |
933 |
} |
934 |
} |
935 |
|
761 |
|
936 |
my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField( "items.holdingbranch" ); |
762 |
my $subfieldcode_attribute_mappings; |
937 |
@big_array = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @big_array; |
763 |
for my $subfield_code ( keys %{ $tagslib->{$itemtagfield} } ) { |
938 |
|
|
|
939 |
# now, construct template ! |
940 |
# First, the existing items for display |
941 |
my @item_value_loop; |
942 |
my @header_value_loop; |
943 |
for my $row ( @big_array ) { |
944 |
my %row_data; |
945 |
my @item_fields; |
946 |
foreach my $key (sort keys %witness){ |
947 |
my $item_field; |
948 |
if ( $row->{$key} ){ |
949 |
$item_field->{field} = $row->{$key}; |
950 |
} else { |
951 |
$item_field->{field} = ''; |
952 |
} |
953 |
|
764 |
|
954 |
for my $kohafield ( |
765 |
my $subfield = $tagslib->{$itemtagfield}->{$subfield_code}; |
955 |
qw( items.dateaccessioned items.onloan items.datelastseen items.datelastborrowed items.replacementpricedate ) |
|
|
956 |
) |
957 |
{ |
958 |
my ( undef, $subfield ) = GetMarcFromKohaField($kohafield); |
959 |
next unless $key eq $subfield; |
960 |
$item_field->{datatype} = 'date'; |
961 |
} |
962 |
|
766 |
|
963 |
push @item_fields, $item_field; |
767 |
next if IsMarcStructureInternal( $subfield ); |
|
|
768 |
next unless $subfield->{tab} eq 10; # Is this really needed? |
769 |
|
770 |
my $attribute; |
771 |
if ( $subfield->{kohafield} ) { |
772 |
( $attribute = $subfield->{kohafield} ) =~ s|^items\.||; |
773 |
} else { |
774 |
$attribute = $subfield_code; # It's in more_subfields_xml |
964 |
} |
775 |
} |
965 |
$row_data{item_value} = [ @item_fields ]; |
776 |
next unless grep { $attribute eq $_ } @witness_attributes; |
966 |
$row_data{itemnumber} = $row->{itemnumber}; |
777 |
$subfieldcode_attribute_mappings->{$subfield_code} = $attribute; |
967 |
#reporting this_row values |
|
|
968 |
$row_data{'nomod'} = $row->{'nomod'}; |
969 |
$row_data{'hostitemflag'} = $row->{'hostitemflag'}; |
970 |
$row_data{'hostbiblionumber'} = $row->{'hostbiblionumber'}; |
971 |
# $row_data{'countanalytics'} = $row->{'countanalytics'}; |
972 |
push(@item_value_loop,\%row_data); |
973 |
} |
778 |
} |
974 |
foreach my $subfield_code (sort keys(%witness)) { |
|
|
975 |
my %header_value; |
976 |
$header_value{header_value} = $witness{$subfield_code}; |
977 |
|
978 |
my $subfieldlib = $tagslib->{$itemtagfield}->{$subfield_code}; |
979 |
my $kohafield = $subfieldlib->{kohafield}; |
980 |
if ( $kohafield && $kohafield =~ /items.(.+)/ ) { |
981 |
$header_value{column_name} = $1; |
982 |
} |
983 |
|
779 |
|
984 |
push(@header_value_loop, \%header_value); |
780 |
my @header_value_loop = map { |
985 |
} |
781 |
{ |
|
|
782 |
header_value => $tagslib->{$itemtagfield}->{$_}->{lib}, |
783 |
attribute => $subfieldcode_attribute_mappings->{$_}, |
784 |
subfield_code => $_, |
785 |
} |
786 |
} sort keys %$subfieldcode_attribute_mappings; |
986 |
|
787 |
|
987 |
# now, build the item form for entering a new item |
788 |
# now, build the item form for entering a new item |
988 |
my @loop_data =(); |
|
|
989 |
my $i=0; |
990 |
|
991 |
my $branch = $input->param('branch') || C4::Context->userenv->{branch}; |
789 |
my $branch = $input->param('branch') || C4::Context->userenv->{branch}; |
992 |
my $libraries = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed;# build once ahead of time, instead of multiple times later. |
790 |
my $libraries = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed;# build once ahead of time, instead of multiple times later. |
993 |
for my $library ( @$libraries ) { |
791 |
for my $library ( @$libraries ) { |
994 |
$library->{selected} = 1 if $library->{branchcode} eq $branch |
792 |
$library->{selected} = 1 if $library->{branchcode} eq $branch |
995 |
} |
793 |
} |
996 |
|
794 |
|
997 |
my $item = Koha::Items->find($itemnumber); |
|
|
998 |
|
795 |
|
999 |
# We generate form, from actuel record |
796 |
# Using last created item if it exists |
1000 |
@fields = (); |
797 |
$current_item = $item_from_cookie |
1001 |
if($itemrecord){ |
798 |
if $item_from_cookie |
1002 |
foreach my $field ($itemrecord->fields()){ |
799 |
&& $prefillitem |
1003 |
my $tag = $field->{_tag}; |
800 |
&& $op ne "additem" |
1004 |
foreach my $subfield ( $field->subfields() ){ |
801 |
&& $op ne "edititem"; |
1005 |
|
802 |
|
1006 |
my $subfieldtag = $subfield->[0]; |
803 |
my @subfields_to_prefill = split ' ', C4::Context->preference('SubfieldsToUseWhenPrefill'); |
1007 |
my $value = $subfield->[1]; |
|
|
1008 |
my $subfieldlib = $tagslib->{$tag}->{$subfieldtag}; |
1009 |
|
804 |
|
1010 |
next if ($tagslib->{$tag}->{$subfieldtag}->{'tab'} ne "10"); |
805 |
if ( $current_item->{more_subfields_xml} ) { |
|
|
806 |
$current_item->{marc_more_subfields_xml} = MARC::Record->new_from_xml($current_item->{more_subfields_xml}, 'UTF-8'); |
807 |
} |
1011 |
|
808 |
|
1012 |
my $subfield_data = generate_subfield_form($tag, $subfieldtag, $value, $tagslib, $subfieldlib, $libraries, $biblionumber, $temp, \@loop_data, $i, $restrictededition, $item); |
809 |
# We generate form, and fill with values if defined |
1013 |
push @fields, "$tag$subfieldtag"; |
810 |
my $temp = GetMarcBiblio({ biblionumber => $biblionumber }); |
1014 |
push (@loop_data, $subfield_data); |
811 |
my $i = 0; |
1015 |
$i++; |
812 |
my @subfields; |
|
|
813 |
foreach my $tag ( keys %{$tagslib} ) { |
814 |
foreach my $subtag ( keys %{ $tagslib->{$tag} } ) { |
815 |
|
816 |
my $subfield = $tagslib->{$tag}{$subtag}; |
817 |
|
818 |
next if IsMarcStructureInternal( $subfield ); |
819 |
next if ( $subfield->{tab} ne "10" ); |
820 |
|
821 |
my @values = (); |
822 |
|
823 |
my $subfield_data; |
824 |
|
825 |
# If we are not adding a new item |
826 |
# OR |
827 |
# If the subfield must be prefilled with last catalogued item |
828 |
if ( |
829 |
$nextop ne 'additem' |
830 |
|| ( |
831 |
!$prefillitem |
832 |
|| ( $prefillitem && grep { $_ eq $subtag } |
833 |
@subfields_to_prefill ) |
834 |
) |
835 |
) |
836 |
{ |
837 |
my $kohafield = $subfield->{kohafield}; |
838 |
if ($kohafield) { |
839 |
|
840 |
# This is a mapped field |
841 |
( my $attribute = $kohafield ) =~ s|^items\.||; |
842 |
push @values, $subfield->{repeatable} |
843 |
? split '\s\|\s', $current_item->{$attribute} |
844 |
: $current_item->{$attribute} |
845 |
if defined $current_item->{$attribute}; |
846 |
} else { |
847 |
# Not mapped, picked the values from more_subfields_xml's MARC |
848 |
my $marc_more = $current_item->{marc_more_subfields_xml}; |
849 |
if ( $marc_more ) { |
850 |
for my $f ( $marc_more->fields($tag) ) { |
851 |
push @values, $f->subfield($subtag); |
1016 |
} |
852 |
} |
1017 |
|
|
|
1018 |
} |
853 |
} |
1019 |
} |
854 |
} |
1020 |
# and now we add fields that are empty |
855 |
} |
1021 |
|
|
|
1022 |
# Using last created item if it exists |
1023 |
|
856 |
|
1024 |
$itemrecord = $cookieitemrecord if ($prefillitem and not $justaddeditem and $op ne "edititem"); |
857 |
@values = ('') unless @values; |
1025 |
|
858 |
|
1026 |
# We generate form, and fill with values if defined |
859 |
for my $value (@values) { |
1027 |
foreach my $tag ( keys %{$tagslib}){ |
860 |
my $subfield_data = generate_subfield_form( |
1028 |
foreach my $subtag (keys %{$tagslib->{$tag}}){ |
861 |
$tag, $subtag, |
1029 |
next if IsMarcStructureInternal($tagslib->{$tag}{$subtag}); |
862 |
$value, $tagslib, |
1030 |
next if ($tagslib->{$tag}->{$subtag}->{'tab'} ne "10"); |
863 |
$subfield, $libraries, |
1031 |
next if any { /^$tag$subtag$/ } @fields; |
864 |
$biblionumber, $temp, |
1032 |
|
865 |
\@subfields, $i, |
1033 |
my @values = (undef); |
866 |
$restrictededition, $current_item, |
1034 |
@values = $itemrecord->field($tag)->subfield($subtag) if ($itemrecord && defined($itemrecord->field($tag)) && defined($itemrecord->field($tag)->subfield($subtag))); |
867 |
); |
1035 |
for my $value (@values){ |
868 |
push @subfields, $subfield_data; |
1036 |
my $subfield_data = generate_subfield_form($tag, $subtag, $value, $tagslib, $tagslib->{$tag}->{$subtag}, $libraries, $biblionumber, $temp, \@loop_data, $i, $restrictededition, $item); |
|
|
1037 |
push (@loop_data, $subfield_data); |
1038 |
$i++; |
869 |
$i++; |
1039 |
} |
870 |
} |
1040 |
} |
871 |
} |
1041 |
} |
872 |
} |
1042 |
@loop_data = sort { $a->{display_order} <=> $b->{display_order} || $a->{subfield} cmp $b->{subfield} } @loop_data; |
873 |
@subfields = sort { $a->{display_order} <=> $b->{display_order} || $a->{subfield} cmp $b->{subfield} } @subfields; |
1043 |
|
874 |
|
1044 |
# what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit. |
875 |
# what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit. |
1045 |
$template->param( |
876 |
$template->param( |
1046 |
biblionumber => $biblionumber, |
877 |
biblionumber => $biblionumber, |
1047 |
title => $oldrecord->{title}, |
878 |
title => $oldrecord->{title}, |
1048 |
author => $oldrecord->{author}, |
879 |
author => $oldrecord->{author}, |
1049 |
item_loop => \@item_value_loop, |
880 |
items => \@items, |
1050 |
item_header_loop => \@header_value_loop, |
881 |
item_header_loop => \@header_value_loop, |
1051 |
item => \@loop_data, |
882 |
subfields => \@subfields, |
1052 |
itemnumber => $itemnumber, |
883 |
itemnumber => $itemnumber, |
1053 |
barcode => $item ? $item->barcode : undef, |
884 |
barcode => $current_item->{barcode}, |
1054 |
itemtagfield => $itemtagfield, |
885 |
itemtagfield => $itemtagfield, |
1055 |
itemtagsubfield => $itemtagsubfield, |
886 |
itemtagsubfield => $itemtagsubfield, |
1056 |
op => $nextop, |
887 |
op => $nextop, |