|
Line 0
Link Here
|
|
|
1 |
package Koha::MarcEditor; |
| 2 |
|
| 3 |
# Copyright 2000-2002 Katipo Communications |
| 4 |
# Copyright 2004-2010 BibLibre |
| 5 |
# Copyright 2019 University of Helsinki (The National Library Of Finland) |
| 6 |
# |
| 7 |
# This file is part of Koha. |
| 8 |
# |
| 9 |
# Koha is free software; you can redistribute it and/or modify it under the |
| 10 |
# terms of the GNU General Public License as published by the Free Software |
| 11 |
# Foundation; either version 3 of the License, or (at your option) any later |
| 12 |
# version. |
| 13 |
# |
| 14 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
| 15 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
| 16 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 17 |
# |
| 18 |
# You should have received a copy of the GNU General Public License along |
| 19 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
| 20 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 |
|
| 22 |
use Modern::Perl; |
| 23 |
|
| 24 |
use Readonly; |
| 25 |
|
| 26 |
use C4::ClassSource; |
| 27 |
use C4::Context; |
| 28 |
|
| 29 |
use Koha::DateUtils; |
| 30 |
|
| 31 |
use base qw(Class::Accessor); |
| 32 |
|
| 33 |
# Constants to refer to the standard editor types |
| 34 |
Readonly our $EDITOR_BIBLIO => 'biblio'; |
| 35 |
Readonly our $EDITOR_AUTHORITY => 'authority'; |
| 36 |
|
| 37 |
=head1 NAME |
| 38 |
|
| 39 |
Koha::MarcEditor - Koha MARC Editor class |
| 40 |
|
| 41 |
=head1 API |
| 42 |
|
| 43 |
=head2 Class Methods |
| 44 |
|
| 45 |
=cut |
| 46 |
|
| 47 |
=head2 new |
| 48 |
|
| 49 |
my $editor = Koha::MarcEditor->new({ |
| 50 |
type => $Koha::MarcEditor::EDITOR_BIBLIO, |
| 51 |
tags => $self->{tags}, |
| 52 |
used_tags => $tagsUsedLib, |
| 53 |
mandatory_z3950 => $mandatory_z3950, |
| 54 |
hostitemnumber => $hostitemnumber |
| 55 |
}); |
| 56 |
|
| 57 |
Returns a new MarcEditor object. |
| 58 |
|
| 59 |
=cut |
| 60 |
|
| 61 |
sub new { |
| 62 |
my ($class, $params) = @_; |
| 63 |
|
| 64 |
my $self = $class->SUPER::new(); |
| 65 |
$self->_init($params); |
| 66 |
return $self; |
| 67 |
} |
| 68 |
|
| 69 |
=head2 Instance Methods |
| 70 |
|
| 71 |
=head3 build_tabs |
| 72 |
|
| 73 |
$editor->build_tabs($template, $record, $encoding); |
| 74 |
|
| 75 |
Builds tab data in the template |
| 76 |
|
| 77 |
=cut |
| 78 |
|
| 79 |
sub build_tabs { |
| 80 |
my ( $self, $template, $record, $encoding ) = @_; |
| 81 |
|
| 82 |
# fill arrays |
| 83 |
my @loop_data = (); |
| 84 |
my $tag; |
| 85 |
|
| 86 |
# in this array, we will push all the 10 tabs |
| 87 |
# to avoid having 10 tabs in the template : they will all be in the same BIG_LOOP |
| 88 |
my @BIG_LOOP; |
| 89 |
my %seen; |
| 90 |
my @tab_data; # all tags to display |
| 91 |
my $max_num_tab=-1; |
| 92 |
|
| 93 |
if (defined $self->{used_tags}) { |
| 94 |
foreach my $used ( @{$self->{used_tags}} ) { |
| 95 |
push @tab_data,$used->{tagfield} if not $seen{$used->{tagfield}}; |
| 96 |
$seen{$used->{tagfield}}++; |
| 97 |
} |
| 98 |
|
| 99 |
foreach (@{$self->{used_tags}}) { |
| 100 |
if($_->{tab} > -1 && $_->{tab} >= $max_num_tab && $_->{tagfield} ne '995'){ # FIXME : MARC21 ? |
| 101 |
$max_num_tab = $_->{tab}; |
| 102 |
} |
| 103 |
} |
| 104 |
if ($max_num_tab >= 9) { |
| 105 |
$max_num_tab = 9; |
| 106 |
} |
| 107 |
} else { |
| 108 |
foreach my $used ( keys %{$self->{tags}} ) { |
| 109 |
push @tab_data,$used if not $seen{$used}; |
| 110 |
$seen{$used}++; |
| 111 |
} |
| 112 |
@tab_data = sort @tab_data; |
| 113 |
$max_num_tab = 9; |
| 114 |
} |
| 115 |
|
| 116 |
# loop through each tab 0 through 9 |
| 117 |
for ( my $tabloop = 0 ; $tabloop <= $max_num_tab ; $tabloop++ ) { |
| 118 |
my @loop_data = (); #innerloop in the template. |
| 119 |
my $i = 0; |
| 120 |
foreach my $tag (@tab_data) { |
| 121 |
$i++; |
| 122 |
next if ! $tag; |
| 123 |
my ($indicator1, $indicator2); |
| 124 |
my $index_tag = $self->_create_key(); |
| 125 |
|
| 126 |
# if MARC::Record is not empty =>use it as master loop, then add missing subfields that should be in the tab. |
| 127 |
# if MARC::Record is empty => use tab as master loop. |
| 128 |
if ( $record ne -1 && ( $record->field($tag) || $tag eq '000' ) ) { |
| 129 |
my @fields; |
| 130 |
if ( $tag ne '000' ) { |
| 131 |
@fields = $record->field($tag); |
| 132 |
} |
| 133 |
else { |
| 134 |
push @fields, $record->leader(); # if tag == 000 |
| 135 |
} |
| 136 |
# loop through each field |
| 137 |
foreach my $field (@fields) { |
| 138 |
|
| 139 |
my @subfields_data; |
| 140 |
if ( $tag < 10 ) { |
| 141 |
my ( $value, $subfield ); |
| 142 |
if ( $tag ne '000' ) { |
| 143 |
$value = $field->data(); |
| 144 |
$subfield = "@"; |
| 145 |
} |
| 146 |
else { |
| 147 |
$value = $field; |
| 148 |
$subfield = '@'; |
| 149 |
} |
| 150 |
next if ( $self->{tags}->{$tag}->{$subfield}->{tab} ne $tabloop ); |
| 151 |
next if $self->{tags}->{$tag}->{$subfield}->{hidden} && $subfield ne '9' |
| 152 |
&& $self->{type} eq $Koha::MarcEditor::EDITOR_AUTHORITY; |
| 153 |
next |
| 154 |
if ( $self->{tags}->{$tag}->{$subfield}->{kohafield} eq |
| 155 |
'biblio.biblionumber' ); |
| 156 |
push( |
| 157 |
@subfields_data, |
| 158 |
$self->_create_input( |
| 159 |
$tag, $subfield, $value, $index_tag, $tabloop, $record, |
| 160 |
) |
| 161 |
); |
| 162 |
} |
| 163 |
else { |
| 164 |
my @subfields = $field->subfields(); |
| 165 |
foreach my $subfieldcount ( 0 .. $#subfields ) { |
| 166 |
my $subfield = $subfields[$subfieldcount][0]; |
| 167 |
my $value = $subfields[$subfieldcount][1]; |
| 168 |
next if ( length $subfield != 1 ); |
| 169 |
next if ( $self->{tags}->{$tag}->{$subfield}->{tab} ne $tabloop ); |
| 170 |
next if $self->{tags}->{$tag}->{$subfield}->{hidden} && $subfield ne '9' |
| 171 |
&& $self->{type} eq $Koha::MarcEditor::EDITOR_AUTHORITY; |
| 172 |
push( |
| 173 |
@subfields_data, |
| 174 |
$self->_create_input( |
| 175 |
$tag, $subfield, $value, $index_tag, $tabloop, |
| 176 |
$record |
| 177 |
) |
| 178 |
); |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
# now, loop again to add parameter subfield that are not in the MARC::Record |
| 183 |
foreach my $subfield ( sort( keys %{ $self->{tags}->{$tag} } ) ) { |
| 184 |
next if ( length $subfield != 1 ); |
| 185 |
next if ( $self->{tags}->{$tag}->{$subfield}->{tab} ne $tabloop ); |
| 186 |
next if ( $tag < 10 ); |
| 187 |
next if $self->{tags}->{$tag}->{$subfield}->{hidden} && $subfield ne '9' |
| 188 |
&& $self->{type} eq $Koha::MarcEditor::EDITOR_AUTHORITY; |
| 189 |
next |
| 190 |
if ( ( $self->{tags}->{$tag}->{$subfield}->{hidden} <= -4 ) |
| 191 |
or ( $self->{tags}->{$tag}->{$subfield}->{hidden} >= 5 ) ) |
| 192 |
and $self->{type} ne $Koha::MarcEditor::EDITOR_AUTHORITY |
| 193 |
and not ( $subfield eq "9" and |
| 194 |
exists($self->{tags}->{$tag}->{'a'}->{authtypecode}) and |
| 195 |
defined($self->{tags}->{$tag}->{'a'}->{authtypecode}) and |
| 196 |
$self->{tags}->{$tag}->{'a'}->{authtypecode} ne "" |
| 197 |
) |
| 198 |
; #check for visibility flag |
| 199 |
# if subfield is $9 in a field whose $a is authority-controlled, |
| 200 |
# always include in the form regardless of the hidden setting - bug 2206 |
| 201 |
next if ( defined( $field->subfield($subfield) ) ); |
| 202 |
push( |
| 203 |
@subfields_data, |
| 204 |
$self->_create_input( |
| 205 |
$tag, $subfield, '', $index_tag, $tabloop, $record |
| 206 |
) |
| 207 |
); |
| 208 |
} |
| 209 |
if ( $#subfields_data >= 0 ) { |
| 210 |
# build the tag entry. |
| 211 |
# note that the random() field is mandatory. Otherwise, on repeated fields, you'll |
| 212 |
# have twice the same "name" value, and cgi->param() will return only one, making |
| 213 |
# all subfields to be merged in a single field. |
| 214 |
my %tag_data = ( |
| 215 |
tag => $tag, |
| 216 |
index => $index_tag, |
| 217 |
tag_lib => $self->{tags}->{$tag}->{lib}, |
| 218 |
repeatable => $self->{tags}->{$tag}->{repeatable}, |
| 219 |
mandatory => $self->{tags}->{$tag}->{mandatory}, |
| 220 |
subfield_loop => \@subfields_data, |
| 221 |
fixedfield => $tag < 10 ? 1 : 0, |
| 222 |
random => $self->_create_key(), |
| 223 |
); |
| 224 |
if ($tag >= 10){ # no indicator for 00x tags |
| 225 |
$tag_data{indicator1} = $self->_format_indicator($field->indicator(1)), |
| 226 |
$tag_data{indicator2} = $self->_format_indicator($field->indicator(2)), |
| 227 |
} |
| 228 |
push( @loop_data, \%tag_data ); |
| 229 |
} |
| 230 |
} # foreach $field end |
| 231 |
|
| 232 |
# if breeding is empty |
| 233 |
} |
| 234 |
else { |
| 235 |
my @subfields_data; |
| 236 |
foreach my $subfield ( sort( keys %{ $self->{tags}->{$tag} } ) ) { |
| 237 |
next if ( length $subfield != 1 ); |
| 238 |
next if $self->{tags}->{$tag}->{$subfield}->{hidden} && $subfield ne '9' |
| 239 |
&& $self->{type} eq $Koha::MarcEditor::EDITOR_AUTHORITY; |
| 240 |
next |
| 241 |
if ( ( $self->{tags}->{$tag}->{$subfield}->{hidden} <= -4 ) |
| 242 |
or ( $self->{tags}->{$tag}->{$subfield}->{hidden} >= 5 ) ) |
| 243 |
and $self->{type} ne $Koha::MarcEditor::EDITOR_AUTHORITY |
| 244 |
and not ( $subfield eq "9" and |
| 245 |
exists($self->{tags}->{$tag}->{'a'}->{authtypecode}) and |
| 246 |
defined($self->{tags}->{$tag}->{'a'}->{authtypecode}) and |
| 247 |
$self->{tags}->{$tag}->{'a'}->{authtypecode} ne "" |
| 248 |
) |
| 249 |
; #check for visibility flag |
| 250 |
# if subfield is $9 in a field whose $a is authority-controlled, |
| 251 |
# always include in the form regardless of the hidden setting - bug 2206 |
| 252 |
next |
| 253 |
if ( $self->{tags}->{$tag}->{$subfield}->{tab} ne $tabloop ); |
| 254 |
push( |
| 255 |
@subfields_data, |
| 256 |
$self->_create_input( |
| 257 |
$tag, $subfield, '', $index_tag, $tabloop, $record |
| 258 |
) |
| 259 |
); |
| 260 |
} |
| 261 |
if ( $#subfields_data >= 0 ) { |
| 262 |
my %tag_data = ( |
| 263 |
tag => $tag, |
| 264 |
index => $index_tag, |
| 265 |
tag_lib => $self->{tags}->{$tag}->{lib}, |
| 266 |
repeatable => $self->{tags}->{$tag}->{repeatable}, |
| 267 |
mandatory => $self->{tags}->{$tag}->{mandatory}, |
| 268 |
indicator1 => ( $indicator1 || $self->{tags}->{$tag}->{ind1_defaultvalue} ), #if not set, try to load the default value |
| 269 |
indicator2 => ( $indicator2 || $self->{tags}->{$tag}->{ind2_defaultvalue} ), #use short-circuit operator for efficiency |
| 270 |
subfield_loop => \@subfields_data, |
| 271 |
tagfirstsubfield => $subfields_data[0], |
| 272 |
fixedfield => $tag < 10 ? 1 : 0, |
| 273 |
); |
| 274 |
|
| 275 |
push @loop_data, \%tag_data; |
| 276 |
} |
| 277 |
} |
| 278 |
} |
| 279 |
if ( $#loop_data >= 0 ) { |
| 280 |
push @BIG_LOOP, { |
| 281 |
number => $tabloop, |
| 282 |
innerloop => \@loop_data, |
| 283 |
}; |
| 284 |
} |
| 285 |
} |
| 286 |
$template->param( BIG_LOOP => \@BIG_LOOP ); |
| 287 |
} |
| 288 |
|
| 289 |
=head2 Internal methods |
| 290 |
|
| 291 |
=cut |
| 292 |
|
| 293 |
=head3 _init |
| 294 |
|
| 295 |
$self->init(\%params); |
| 296 |
|
| 297 |
Initialize settings |
| 298 |
|
| 299 |
=cut |
| 300 |
|
| 301 |
sub _init { |
| 302 |
my ($self, $params) = @_; |
| 303 |
|
| 304 |
$self->{type} = $params->{type}; |
| 305 |
$self->{tags} = $params->{tags}; |
| 306 |
$self->{used_tags} = $params->{used_tags}; |
| 307 |
$self->{mandatory_z3950} = $params->{mandatory_z3950}; |
| 308 |
$self->{hostitemnumber} = $params->{hostitemnumber} // ''; |
| 309 |
} |
| 310 |
|
| 311 |
=head3 _build_authorized_values_list |
| 312 |
|
| 313 |
$subfield_data{marc_value} = $self->_build_authorized_values_list( |
| 314 |
$tag, $subfield, $value, $index_tag, $index_subfield |
| 315 |
); |
| 316 |
|
| 317 |
Builds a list of authorized values |
| 318 |
|
| 319 |
=cut |
| 320 |
|
| 321 |
sub _build_authorized_values_list { |
| 322 |
my ( $self, $tag, $subfield, $value, $index_tag, $index_subfield ) = @_; |
| 323 |
|
| 324 |
my @authorised_values; |
| 325 |
my %authorised_lib; |
| 326 |
|
| 327 |
# builds list, depending on authorised value... |
| 328 |
|
| 329 |
#---- branch |
| 330 |
if ( $self->{tags}->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) { |
| 331 |
my $libraries = Koha::Libraries->search_filtered({}, {order_by => ['branchname']}); |
| 332 |
while ( my $l = $libraries->next ) { |
| 333 |
push @authorised_values, $l->branchcode;; |
| 334 |
$authorised_lib{$l->branchcode} = $l->branchname; |
| 335 |
} |
| 336 |
} |
| 337 |
elsif ( $self->{tags}->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) { |
| 338 |
push @authorised_values, ""; |
| 339 |
|
| 340 |
my $itemtype; |
| 341 |
my $itemtypes = Koha::ItemTypes->search_with_localization; |
| 342 |
while ( $itemtype = $itemtypes->next ) { |
| 343 |
push @authorised_values, $itemtype->itemtype; |
| 344 |
$authorised_lib{$itemtype->itemtype} = $itemtype->translated_description; |
| 345 |
} |
| 346 |
$value = $itemtype unless ($value); |
| 347 |
} |
| 348 |
elsif ( $self->{tags}->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) { |
| 349 |
push @authorised_values, ""; |
| 350 |
|
| 351 |
my $class_sources = GetClassSources(); |
| 352 |
|
| 353 |
my $default_source = C4::Context->preference("DefaultClassificationSource"); |
| 354 |
|
| 355 |
foreach my $class_source (sort keys %$class_sources) { |
| 356 |
next unless $class_sources->{$class_source}->{'used'} or |
| 357 |
($value and $class_source eq $value) or |
| 358 |
($class_source eq $default_source); |
| 359 |
push @authorised_values, $class_source; |
| 360 |
$authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'}; |
| 361 |
} |
| 362 |
$value = $default_source unless $value; |
| 363 |
} |
| 364 |
else { |
| 365 |
my $branch_limit = $self->{type} ne $Koha::MarcEditor::EDITOR_AUTHORITY && C4::Context->userenv |
| 366 |
? C4::Context->userenv->{'branch'} : ''; |
| 367 |
|
| 368 |
my $query; |
| 369 |
if ($branch_limit) { |
| 370 |
$query = "SELECT authorised_value, lib |
| 371 |
FROM authorised_values"; |
| 372 |
$query .= qq{ LEFT JOIN authorised_values_branches ON ( id = av_id )} if $branch_limit; |
| 373 |
$query .= " WHERE category = ?"; |
| 374 |
$query .= " AND ( branchcode = ? OR branchcode IS NULL )" if $branch_limit; |
| 375 |
$query .= " GROUP BY lib ORDER BY lib, lib_opac"; |
| 376 |
} else { |
| 377 |
$query = "SELECT authorised_value,lib |
| 378 |
FROM authorised_values |
| 379 |
WHERE category=? ORDER BY lib"; |
| 380 |
} |
| 381 |
my $authorised_values_sth = C4::Context->dbh->prepare( $query ); |
| 382 |
|
| 383 |
$authorised_values_sth->execute( |
| 384 |
$self->{tags}->{$tag}->{$subfield}->{authorised_value}, |
| 385 |
$branch_limit ? $branch_limit : (), |
| 386 |
); |
| 387 |
|
| 388 |
push @authorised_values, ""; |
| 389 |
|
| 390 |
while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) { |
| 391 |
push @authorised_values, $value; |
| 392 |
$authorised_lib{$value} = $lib; |
| 393 |
} |
| 394 |
$authorised_values_sth->finish; |
| 395 |
} |
| 396 |
return { |
| 397 |
type => 'select', |
| 398 |
id => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield, |
| 399 |
name => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield, |
| 400 |
default => $value, |
| 401 |
values => \@authorised_values, |
| 402 |
labels => \%authorised_lib, |
| 403 |
}; |
| 404 |
} |
| 405 |
|
| 406 |
=head3 _create_input |
| 407 |
|
| 408 |
builds the <input ...> entry for a subfield. |
| 409 |
|
| 410 |
=cut |
| 411 |
|
| 412 |
sub _create_input { |
| 413 |
my ( $self, $tag, $subfield, $value, $index_tag, $tabloop, $rec ) = @_; |
| 414 |
|
| 415 |
my $index_subfield = $self->_create_key(); # create a specific key for each subfield |
| 416 |
my $tagdef = $self->{tags}->{$tag}; |
| 417 |
|
| 418 |
# if there is no value provided but a default value in parameters, get it |
| 419 |
if ( $value eq '' ) { |
| 420 |
$value = $tagdef->{$subfield}->{defaultvalue} // q{}; |
| 421 |
|
| 422 |
# get today date & replace <<YYYY>>, <<MM>>, <<DD>> if provided in the default value |
| 423 |
my $today_dt = dt_from_string; |
| 424 |
my $year = $today_dt->strftime('%Y'); |
| 425 |
my $month = $today_dt->strftime('%m'); |
| 426 |
my $day = $today_dt->strftime('%d'); |
| 427 |
$value =~ s/<<YYYY>>/$year/g; |
| 428 |
$value =~ s/<<MM>>/$month/g; |
| 429 |
$value =~ s/<<DD>>/$day/g; |
| 430 |
# And <<USER>> with surname (?) |
| 431 |
my $username=(C4::Context->userenv?C4::Context->userenv->{'surname'}:"superlibrarian"); |
| 432 |
$value=~s/<<USER>>/$username/g; |
| 433 |
} |
| 434 |
|
| 435 |
# map '@' as "subfield" label for fixed fields |
| 436 |
# to something that's allowed in a div id. |
| 437 |
my $id_subfield = $subfield; |
| 438 |
$id_subfield = "00" if $id_subfield eq "@"; |
| 439 |
|
| 440 |
my %subfield_data = ( |
| 441 |
tag => $tag, |
| 442 |
subfield => $id_subfield, |
| 443 |
marc_lib => $tagdef->{$subfield}->{lib}, |
| 444 |
tag_mandatory => $tagdef->{mandatory}, |
| 445 |
mandatory => $tagdef->{$subfield}->{mandatory}, |
| 446 |
repeatable => $tagdef->{$subfield}->{repeatable}, |
| 447 |
kohafield => $tagdef->{$subfield}->{kohafield}, |
| 448 |
index => $index_tag, |
| 449 |
id => "tag_".$tag."_subfield_".$id_subfield."_".$index_tag."_".$index_subfield, |
| 450 |
value => $value, |
| 451 |
maxlength => $tagdef->{$subfield}->{maxlength}, |
| 452 |
random => $self->_create_key(), |
| 453 |
); |
| 454 |
|
| 455 |
if(exists $self->{mandatory_z3950}->{$tag.$subfield}){ |
| 456 |
$subfield_data{z3950_mandatory} = $self->{mandatory_z3950}->{$tag.$subfield}; |
| 457 |
} |
| 458 |
|
| 459 |
if ($self->{type} eq $Koha::MarcEditor::EDITOR_AUTHORITY) { |
| 460 |
# Authority subfield is hidden unless mandatory or contains something. |
| 461 |
$subfield_data{visibility} = "display:none;" |
| 462 |
if( $tagdef->{$subfield}->{hidden} and $value ne '' |
| 463 |
or ($value eq '' and !$tagdef->{$subfield}->{mandatory}) |
| 464 |
); |
| 465 |
} else { |
| 466 |
# Subfield is hidden depending of hidden and mandatory flag, and is always |
| 467 |
# shown if it contains anything or if its field is mandatory. |
| 468 |
$subfield_data{visibility} = "display:none;" |
| 469 |
if $tagdef->{$subfield}->{hidden} % 2 == 1 && |
| 470 |
$value eq '' && |
| 471 |
!$tagdef->{$subfield}->{mandatory} && |
| 472 |
!$tagdef->{mandatory}; |
| 473 |
|
| 474 |
# expand all subfields of 773 if there is a host item provided in the input |
| 475 |
$subfield_data{visibility} ="" if ($tag eq 773 and $self->{hostitemnumber}); |
| 476 |
} |
| 477 |
|
| 478 |
# it's an authorised field |
| 479 |
if ( $tagdef->{$subfield}->{authorised_value} ) { |
| 480 |
$subfield_data{marc_value} = |
| 481 |
$self->_build_authorized_values_list( $tag, $subfield, $value, $index_tag, $index_subfield ); |
| 482 |
|
| 483 |
# it's a subfield $9 linking to an authority record - see bug 2206 |
| 484 |
} |
| 485 |
elsif ($self->{type} eq $Koha::MarcEditor::EDITOR_BIBLIO and |
| 486 |
$subfield eq "9" and |
| 487 |
exists($tagdef->{'a'}->{authtypecode}) and |
| 488 |
defined($tagdef->{'a'}->{authtypecode}) and |
| 489 |
$tagdef->{'a'}->{authtypecode} ne '') { |
| 490 |
|
| 491 |
$subfield_data{marc_value} = { |
| 492 |
type => 'text', |
| 493 |
id => $subfield_data{id}, |
| 494 |
name => $subfield_data{id}, |
| 495 |
value => $value, |
| 496 |
size => 5, |
| 497 |
maxlength => $subfield_data{maxlength}, |
| 498 |
readonly => 1, |
| 499 |
}; |
| 500 |
|
| 501 |
# it's a thesaurus / authority field |
| 502 |
} |
| 503 |
elsif ( $tagdef->{$subfield}->{authtypecode} ) { |
| 504 |
# when authorities auto-creation is allowed, do not set readonly |
| 505 |
my $is_readonly = $self->{type} eq $Koha::MarcEditor::EDITOR_BIBLIO && !C4::Context->preference("BiblioAddsAuthorities"); |
| 506 |
|
| 507 |
$subfield_data{marc_value} = { |
| 508 |
type => $self->{type} eq $Koha::MarcEditor::EDITOR_AUTHORITY ? 'text1' : 'text', |
| 509 |
id => $subfield_data{id}, |
| 510 |
name => $subfield_data{id}, |
| 511 |
value => $value, |
| 512 |
size => 67, |
| 513 |
maxlength => $subfield_data{maxlength}, |
| 514 |
readonly => $is_readonly, |
| 515 |
authtype => $tagdef->{$subfield}->{authtypecode}, |
| 516 |
}; |
| 517 |
|
| 518 |
# it's a plugin field |
| 519 |
} elsif ( $tagdef->{$subfield}->{'value_builder'} ) { |
| 520 |
require Koha::FrameworkPlugin; |
| 521 |
my $plugin = Koha::FrameworkPlugin->new( { |
| 522 |
name => $tagdef->{$subfield}->{'value_builder'}, |
| 523 |
}); |
| 524 |
my $pars= { dbh => C4::Context->dbh, record => $rec, tagslib => $self->{tags}, |
| 525 |
id => $subfield_data{id}, tabloop => $tabloop }; |
| 526 |
$plugin->build( $pars ); |
| 527 |
if( !$plugin->errstr ) { |
| 528 |
$subfield_data{marc_value} = { |
| 529 |
type => $self->{type} eq $Koha::MarcEditor::EDITOR_AUTHORITY ? 'text2' : 'text_complex', |
| 530 |
id => $subfield_data{id}, |
| 531 |
name => $subfield_data{id}, |
| 532 |
value => $value, |
| 533 |
size => 67, |
| 534 |
maxlength => $subfield_data{maxlength}, |
| 535 |
javascript => $plugin->javascript, |
| 536 |
noclick => $plugin->noclick, |
| 537 |
}; |
| 538 |
} else { |
| 539 |
warn $plugin->errstr; |
| 540 |
# supply default input form |
| 541 |
$subfield_data{marc_value} = { |
| 542 |
type => 'text', |
| 543 |
id => $subfield_data{id}, |
| 544 |
name => $subfield_data{id}, |
| 545 |
value => $value, |
| 546 |
size => 67, |
| 547 |
maxlength => $subfield_data{maxlength}, |
| 548 |
readonly => 0, |
| 549 |
}; |
| 550 |
} |
| 551 |
|
| 552 |
# it's an hidden field |
| 553 |
} elsif ( $tag eq '' ) { |
| 554 |
$subfield_data{marc_value} = { |
| 555 |
type => 'hidden', |
| 556 |
id => $subfield_data{id}, |
| 557 |
name => $subfield_data{id}, |
| 558 |
value => $value, |
| 559 |
size => 67, |
| 560 |
maxlength => $subfield_data{maxlength}, |
| 561 |
}; |
| 562 |
|
| 563 |
} |
| 564 |
else { |
| 565 |
# it's a standard field |
| 566 |
if ( |
| 567 |
length($value) > 100 |
| 568 |
or |
| 569 |
( C4::Context->preference("marcflavour") eq "UNIMARC" && $tag >= 300 |
| 570 |
and $tag < 400 && $subfield eq 'a' ) |
| 571 |
or ( $tag >= 500 |
| 572 |
and $tag < 600 |
| 573 |
&& C4::Context->preference("marcflavour") eq "MARC21" ) |
| 574 |
) |
| 575 |
{ |
| 576 |
$subfield_data{marc_value} = { |
| 577 |
type => 'textarea', |
| 578 |
id => $subfield_data{id}, |
| 579 |
name => $subfield_data{id}, |
| 580 |
value => $value, |
| 581 |
}; |
| 582 |
|
| 583 |
} |
| 584 |
else { |
| 585 |
$subfield_data{marc_value} = { |
| 586 |
type => 'text', |
| 587 |
id => $subfield_data{id}, |
| 588 |
name => $subfield_data{id}, |
| 589 |
value => $value, |
| 590 |
size => 67, |
| 591 |
maxlength => $subfield_data{maxlength}, |
| 592 |
readonly => 0, |
| 593 |
}; |
| 594 |
|
| 595 |
} |
| 596 |
} |
| 597 |
$subfield_data{'index_subfield'} = $index_subfield; |
| 598 |
return \%subfield_data; |
| 599 |
} |
| 600 |
|
| 601 |
|
| 602 |
=head3 _format_indicator |
| 603 |
|
| 604 |
Translate indicator value for output form - specifically, map |
| 605 |
indicator = ' ' to ''. This is for the convenience of a cataloger |
| 606 |
using a mouse to select an indicator input. |
| 607 |
|
| 608 |
=cut |
| 609 |
|
| 610 |
sub _format_indicator { |
| 611 |
my ($self, $ind_value) = @_; |
| 612 |
return '' if not defined $ind_value; |
| 613 |
return '' if $ind_value eq ' '; |
| 614 |
return $ind_value; |
| 615 |
} |
| 616 |
|
| 617 |
=head3 _create_key |
| 618 |
|
| 619 |
$key = $self->_create_key(): |
| 620 |
|
| 621 |
Creates a random value to set it into the input name |
| 622 |
|
| 623 |
=cut |
| 624 |
|
| 625 |
sub _create_key { |
| 626 |
return int(rand(1000000)); |
| 627 |
} |
| 628 |
|
| 629 |
|
| 630 |
1; |