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