|
Lines 50-55
use Koha::Items;
Link Here
|
| 50 |
use Koha::ItemTypes; |
50 |
use Koha::ItemTypes; |
| 51 |
use Koha::Patrons; |
51 |
use Koha::Patrons; |
| 52 |
use Koha::SearchEngine::Indexer; |
52 |
use Koha::SearchEngine::Indexer; |
|
|
53 |
use Koha::UI::Form::Builder::Item; |
| 53 |
|
54 |
|
| 54 |
my $input = CGI->new; |
55 |
my $input = CGI->new; |
| 55 |
my $dbh = C4::Context->dbh; |
56 |
my $dbh = C4::Context->dbh; |
|
Lines 393-601
if ($op eq "show"){
Link Here
|
| 393 |
# Even if we do not display the items, we need the itemnumbers |
394 |
# Even if we do not display the items, we need the itemnumbers |
| 394 |
$template->param(itemnumbers_array => \@itemnumbers); |
395 |
$template->param(itemnumbers_array => \@itemnumbers); |
| 395 |
} |
396 |
} |
| 396 |
# now, build the item form for entering a new item |
397 |
# now, build the item form for entering a new item |
| 397 |
my @loop_data =(); |
398 |
my @loop_data =(); |
| 398 |
my $i=0; |
399 |
my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; |
| 399 |
my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; |
400 |
|
| 400 |
|
401 |
my $libraries = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed;# build once ahead of time, instead of multiple times later. |
| 401 |
my $libraries = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed;# build once ahead of time, instead of multiple times later. |
402 |
|
| 402 |
|
403 |
# Adding a default choice, in case the user does not want to modify the branch |
| 403 |
# Adding a default choice, in case the user does not want to modify the branch |
404 |
my $nochange_branch = { branchname => '', value => '', selected => 1 }; |
| 404 |
my $nochange_branch = { branchname => '', value => '', selected => 1 }; |
405 |
unshift (@$libraries, $nochange_branch); |
| 405 |
unshift (@$libraries, $nochange_branch); |
406 |
|
| 406 |
|
407 |
my $pref_itemcallnumber = C4::Context->preference('itemcallnumber'); |
| 407 |
my $pref_itemcallnumber = C4::Context->preference('itemcallnumber'); |
408 |
|
| 408 |
|
409 |
# Getting list of subfields to keep when restricted batchmod edit is enabled |
| 409 |
# Getting list of subfields to keep when restricted batchmod edit is enabled |
410 |
my @subfields_to_allow = $restrictededition ? split ' ', C4::Context->preference('SubfieldsToAllowForRestrictedBatchmod') : (); |
| 410 |
my $subfieldsToAllowForBatchmod = C4::Context->preference('SubfieldsToAllowForRestrictedBatchmod'); |
411 |
|
| 411 |
my $allowAllSubfields = ( |
412 |
my $subfields = Koha::UI::Form::Builder::Item->new->edit_form( |
| 412 |
not defined $subfieldsToAllowForBatchmod |
413 |
{ |
| 413 |
or $subfieldsToAllowForBatchmod eq q|| |
414 |
restricted_editition => $restrictededition, |
| 414 |
) ? 1 : 0; |
415 |
( |
| 415 |
my @subfieldsToAllow = split(/ /, $subfieldsToAllowForBatchmod); |
416 |
@subfields_to_allow |
| 416 |
|
417 |
? ( subfields_to_allow => \@subfields_to_allow ) |
| 417 |
foreach my $tag (sort keys %{$tagslib}) { |
418 |
: () |
| 418 |
# loop through each subfield |
419 |
), |
| 419 |
foreach my $subfield (sort keys %{$tagslib->{$tag}}) { |
420 |
subfields_to_ignore => ['items.barcode'], |
| 420 |
next if IsMarcStructureInternal( $tagslib->{$tag}{$subfield} ); |
421 |
prefill_with_default_values => $use_default_values, |
| 421 |
next if (not $allowAllSubfields and $restrictededition && !grep { $tag . '$' . $subfield eq $_ } @subfieldsToAllow ); |
|
|
| 422 |
next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "10"); |
| 423 |
# barcode is not meant to be batch-modified |
| 424 |
next if $tagslib->{$tag}->{$subfield}->{'kohafield'} eq 'items.barcode'; |
| 425 |
my %subfield_data; |
| 426 |
|
| 427 |
my $index_subfield = int(rand(1000000)); |
| 428 |
if ($subfield eq '@'){ |
| 429 |
$subfield_data{id} = "tag_".$tag."_subfield_00_".$index_subfield; |
| 430 |
} else { |
| 431 |
$subfield_data{id} = "tag_".$tag."_subfield_".$subfield."_".$index_subfield; |
| 432 |
} |
| 433 |
$subfield_data{tag} = $tag; |
| 434 |
$subfield_data{subfield} = $subfield; |
| 435 |
$subfield_data{marc_lib} ="<span id=\"error$i\" title=\"".$tagslib->{$tag}->{$subfield}->{lib}."\">".$tagslib->{$tag}->{$subfield}->{lib}."</span>"; |
| 436 |
$subfield_data{mandatory} = $tagslib->{$tag}->{$subfield}->{mandatory}; |
| 437 |
$subfield_data{repeatable} = $tagslib->{$tag}->{$subfield}->{repeatable}; |
| 438 |
my $value; |
| 439 |
if ( $use_default_values) { |
| 440 |
$value = $tagslib->{$tag}->{$subfield}->{defaultvalue}; |
| 441 |
# get today date & replace YYYY, MM, DD if provided in the default value |
| 442 |
my $today = dt_from_string; |
| 443 |
my $year = $today->year; |
| 444 |
my $month = $today->month; |
| 445 |
my $day = $today->day; |
| 446 |
$value =~ s/YYYY/$year/g; |
| 447 |
$value =~ s/MM/$month/g; |
| 448 |
$value =~ s/DD/$day/g; |
| 449 |
} |
| 450 |
$subfield_data{visibility} = "display:none;" if (($tagslib->{$tag}->{$subfield}->{hidden} > 4) || ($tagslib->{$tag}->{$subfield}->{hidden} < -4)); |
| 451 |
# testing branch value if IndependentBranches. |
| 452 |
|
| 453 |
if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) { |
| 454 |
my @authorised_values; |
| 455 |
my %authorised_lib; |
| 456 |
# builds list, depending on authorised value... |
| 457 |
|
| 458 |
if ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "branches" ) { |
| 459 |
foreach my $library (@$libraries) { |
| 460 |
push @authorised_values, $library->{branchcode}; |
| 461 |
$authorised_lib{$library->{branchcode}} = $library->{branchname}; |
| 462 |
} |
422 |
} |
| 463 |
$value = ""; |
423 |
); |
| 464 |
} |
|
|
| 465 |
elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) { |
| 466 |
push @authorised_values, ""; |
| 467 |
my $itemtypes = Koha::ItemTypes->search_with_localization; |
| 468 |
while ( my $itemtype = $itemtypes->next ) { |
| 469 |
push @authorised_values, $itemtype->itemtype; |
| 470 |
$authorised_lib{$itemtype->itemtype} = $itemtype->translated_description; |
| 471 |
} |
| 472 |
$value = ""; |
| 473 |
|
| 474 |
#---- class_sources |
| 475 |
} |
| 476 |
elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) { |
| 477 |
push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} ); |
| 478 |
|
| 479 |
my $class_sources = GetClassSources(); |
| 480 |
my $default_source = C4::Context->preference("DefaultClassificationSource"); |
| 481 |
|
| 482 |
foreach my $class_source (sort keys %$class_sources) { |
| 483 |
next unless $class_sources->{$class_source}->{'used'} or |
| 484 |
($value and $class_source eq $value) or |
| 485 |
($class_source eq $default_source); |
| 486 |
push @authorised_values, $class_source; |
| 487 |
$authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'}; |
| 488 |
} |
| 489 |
$value = ''; |
| 490 |
|
| 491 |
#---- "true" authorised value |
| 492 |
} |
| 493 |
else { |
| 494 |
push @authorised_values, ""; # unless ( $tagslib->{$tag}->{$subfield}->{mandatory} ); |
| 495 |
|
| 496 |
my @avs = Koha::AuthorisedValues->search_with_library_limits( |
| 497 |
{ |
| 498 |
category => $tagslib->{$tag}->{$subfield}->{authorised_value} |
| 499 |
}, |
| 500 |
{ order_by => 'lib' }, |
| 501 |
$branch_limit |
| 502 |
); |
| 503 |
for my $av ( @avs ) { |
| 504 |
push @authorised_values, $av->authorised_value; |
| 505 |
$authorised_lib{$av->authorised_value} = $av->lib; |
| 506 |
} |
| 507 |
$value=""; |
| 508 |
} |
| 509 |
$subfield_data{marc_value} = { |
| 510 |
type => 'select', |
| 511 |
id => "tag_".$tag."_subfield_".$subfield."_".$index_subfield, |
| 512 |
name => "field_value", |
| 513 |
values => \@authorised_values, |
| 514 |
labels => \%authorised_lib, |
| 515 |
default => $value, |
| 516 |
}; |
| 517 |
# it's a thesaurus / authority field |
| 518 |
} |
| 519 |
elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) { |
| 520 |
$subfield_data{marc_value} = { |
| 521 |
type => 'text1', |
| 522 |
id => $subfield_data{id}, |
| 523 |
value => $value, |
| 524 |
authtypecode => $tagslib->{$tag}->{$subfield}->{authtypecode}, |
| 525 |
} |
| 526 |
} |
| 527 |
elsif ( $tagslib->{$tag}->{$subfield}->{value_builder} ) { # plugin |
| 528 |
require Koha::FrameworkPlugin; |
| 529 |
my $plugin = Koha::FrameworkPlugin->new( { |
| 530 |
name => $tagslib->{$tag}->{$subfield}->{'value_builder'}, |
| 531 |
item_style => 1, |
| 532 |
}); |
| 533 |
my $temp; |
| 534 |
my $pars= { dbh => $dbh, record => $temp, tagslib => $tagslib, |
| 535 |
id => $subfield_data{id} }; |
| 536 |
$plugin->build( $pars ); |
| 537 |
if( !$plugin->errstr ) { |
| 538 |
$subfield_data{marc_value} = { |
| 539 |
type => 'text2', |
| 540 |
id => $subfield_data{id}, |
| 541 |
value => $value, |
| 542 |
javascript => $plugin->javascript, |
| 543 |
noclick => $plugin->noclick, |
| 544 |
}; |
| 545 |
} else { |
| 546 |
warn $plugin->errstr; |
| 547 |
$subfield_data{marc_value} = { # supply default input form |
| 548 |
type => 'text', |
| 549 |
id => $subfield_data{id}, |
| 550 |
value => $value, |
| 551 |
}; |
| 552 |
} |
| 553 |
} |
| 554 |
elsif ( $tag eq '' ) { # it's an hidden field |
| 555 |
$subfield_data{marc_value} = { |
| 556 |
type => 'hidden', |
| 557 |
id => $subfield_data{id}, |
| 558 |
value => $value, |
| 559 |
}; |
| 560 |
} |
| 561 |
elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) { # FIXME: shouldn't input type be "hidden" ? |
| 562 |
$subfield_data{marc_value} = { |
| 563 |
type => 'text', |
| 564 |
id => $subfield_data{id}, |
| 565 |
value => $value, |
| 566 |
}; |
| 567 |
} |
| 568 |
elsif ( length($value) > 100 |
| 569 |
or (C4::Context->preference("marcflavour") eq "UNIMARC" and |
| 570 |
300 <= $tag && $tag < 400 && $subfield eq 'a' ) |
| 571 |
or (C4::Context->preference("marcflavour") eq "MARC21" and |
| 572 |
500 <= $tag && $tag < 600 ) |
| 573 |
) { |
| 574 |
# oversize field (textarea) |
| 575 |
$subfield_data{marc_value} = { |
| 576 |
type => 'textarea', |
| 577 |
id => $subfield_data{id}, |
| 578 |
value => $value, |
| 579 |
}; |
| 580 |
} else { |
| 581 |
# it's a standard field |
| 582 |
$subfield_data{marc_value} = { |
| 583 |
type => 'text', |
| 584 |
id => $subfield_data{id}, |
| 585 |
value => $value, |
| 586 |
}; |
| 587 |
} |
| 588 |
# $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\">"; |
| 589 |
push (@loop_data, \%subfield_data); |
| 590 |
$i++ |
| 591 |
} |
| 592 |
} # -- End foreach tag |
| 593 |
|
424 |
|
| 594 |
|
425 |
|
| 595 |
|
426 |
|
| 596 |
# what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit. |
427 |
# what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit. |
| 597 |
$template->param( |
428 |
$template->param( |
| 598 |
item => \@loop_data, |
429 |
subfields => $subfields, |
| 599 |
notfoundbarcodes => \@notfoundbarcodes, |
430 |
notfoundbarcodes => \@notfoundbarcodes, |
| 600 |
notfounditemnumbers => \@notfounditemnumbers |
431 |
notfounditemnumbers => \@notfounditemnumbers |
| 601 |
); |
432 |
); |
| 602 |
- |
|
|