View | Details | Raw Unified | Return to bug 28445
Collapse All | Expand All

(-)a/Koha/UI/Form/Builder/Item.pm (-30 / +127 lines)
Lines 24-29 use C4::ClassSource qw( GetClassSources ); Link Here
24
use Koha::DateUtils qw( dt_from_string );
24
use Koha::DateUtils qw( dt_from_string );
25
use Koha::Libraries;
25
use Koha::Libraries;
26
26
27
=head1 NAME
28
29
Koha::UI::Form::Builder::Item
30
31
Helper to build a form to add or edit a new item.
32
33
=head1 API
34
35
=head2 Class methods
36
37
=cut
38
39
=head3 new
40
41
    my $form = Koha::UI::Form::Builder::Item->new(
42
        {
43
            biblionumber => $biblionumber,
44
            item => $current_item,
45
        }
46
    );
47
48
Constructor.
49
biblionumber should be passed if we are creating a new item.
50
For edition, an hashref representating the item to edit item must be passed.
51
52
=cut
53
54
27
sub new {
55
sub new {
28
    my ( $class, $params ) = @_;
56
    my ( $class, $params ) = @_;
29
57
Lines 35-40 sub new { Link Here
35
    return $self;
63
    return $self;
36
}
64
}
37
65
66
=head3 generate_subfield_form
67
68
Generate subfield's info for given tag, subfieldtag, etc.
69
70
=cut
71
38
sub generate_subfield_form {
72
sub generate_subfield_form {
39
73
40
    my ($self, $params)    = @_;
74
    my ($self, $params)    = @_;
Lines 45-52 sub generate_subfield_form { Link Here
45
    my $libraries   = $params->{libraries};
79
    my $libraries   = $params->{libraries};
46
    my $marc_record = $params->{marc_record};
80
    my $marc_record = $params->{marc_record};
47
    my $restricted_edition = $params->{restricted_editition};
81
    my $restricted_edition = $params->{restricted_editition};
82
    my $prefill_with_default_values = $params->{prefill_with_default_values};
83
    my $branch_limit = $params->{branch_limit};
48
84
49
    my $item = $self->{item};
85
    my $item         = $self->{item};
50
    my $subfield     = $tagslib->{$tag}{$subfieldtag};
86
    my $subfield     = $tagslib->{$tag}{$subfieldtag};
51
    my $biblionumber = $self->{biblionumber};
87
    my $biblionumber = $self->{biblionumber};
52
88
Lines 79-85 sub generate_subfield_form { Link Here
79
    $subfield_data{kohafield} =
115
    $subfield_data{kohafield} =
80
      $subfield->{kohafield} || 'items.more_subfields_xml';
116
      $subfield->{kohafield} || 'items.more_subfields_xml';
81
117
82
    if ( !defined($value) || $value eq '' ) {
118
    if ( $prefill_with_default_values && ( !defined($value) || $value eq '' ) ) {
83
        $value = $subfield->{defaultvalue};
119
        $value = $subfield->{defaultvalue};
84
        if ($value) {
120
        if ($value) {
85
121
Lines 108-114 sub generate_subfield_form { Link Here
108
      if ( ( $subfield->{hidden} > 4 ) || ( $subfield->{hidden} <= -4 ) );
144
      if ( ( $subfield->{hidden} > 4 ) || ( $subfield->{hidden} <= -4 ) );
109
145
110
    my $pref_itemcallnumber = C4::Context->preference('itemcallnumber');
146
    my $pref_itemcallnumber = C4::Context->preference('itemcallnumber');
111
    if (  !$value
147
    if (  $prefill_with_default_values
148
        && !$value
149
        && $subfield->{kohafield}
112
        && $subfield->{kohafield} eq 'items.itemcallnumber'
150
        && $subfield->{kohafield} eq 'items.itemcallnumber'
113
        && $pref_itemcallnumber )
151
        && $pref_itemcallnumber )
114
    {
152
    {
Lines 128-149 sub generate_subfield_form { Link Here
128
        }
166
        }
129
    }
167
    }
130
168
131
    my $default_location = C4::Context->preference('NewItemsDefaultLocation');
132
    if (  !$value
133
        && $subfield->{kohafield} eq 'items.location'
134
        && $default_location )
135
    {
136
        $value = $default_location;
137
    }
138
139
    if (   $frameworkcode eq 'FA'
140
        && $subfield->{kohafield} eq 'items.barcode'
141
        && !$value )
142
    {
143
        my $input = CGI->new;
144
        $value = $input->param('barcode');
145
    }
146
147
    if ( $subfield->{authorised_value} ) {
169
    if ( $subfield->{authorised_value} ) {
148
        my @authorised_values;
170
        my @authorised_values;
149
        my %authorised_lib;
171
        my %authorised_lib;
Lines 178-185 sub generate_subfield_form { Link Here
178
        }
200
        }
179
        elsif ( $subfield->{authorised_value} eq "itemtypes" ) {
201
        elsif ( $subfield->{authorised_value} eq "itemtypes" ) {
180
            push @authorised_values, "";
202
            push @authorised_values, "";
181
            my $branch_limit =
182
              C4::Context->userenv && C4::Context->userenv->{"branch"};
183
            my $itemtypes;
203
            my $itemtypes;
184
            if ($branch_limit) {
204
            if ($branch_limit) {
185
                $itemtypes = Koha::ItemTypes->search_with_localization(
205
                $itemtypes = Koha::ItemTypes->search_with_localization(
Lines 194-200 sub generate_subfield_form { Link Here
194
                  $itemtype->translated_description;
214
                  $itemtype->translated_description;
195
            }
215
            }
196
216
197
            unless ($value) {
217
            if (!$value && $biblionumber) {
198
                my $itype_sth = $dbh->prepare(
218
                my $itype_sth = $dbh->prepare(
199
                    "SELECT itemtype FROM biblioitems WHERE biblionumber = ?");
219
                    "SELECT itemtype FROM biblioitems WHERE biblionumber = ?");
200
                $itype_sth->execute($biblionumber);
220
                $itype_sth->execute($biblionumber);
Lines 219-225 sub generate_subfield_form { Link Here
219
                $authorised_lib{$class_source} =
239
                $authorised_lib{$class_source} =
220
                  $class_sources->{$class_source}->{'description'};
240
                  $class_sources->{$class_source}->{'description'};
221
            }
241
            }
222
            $value = $default_source unless ($value);
242
            $value = $default_source if !$value && $prefill_with_default_values;
223
243
224
            #---- "true" authorised value
244
            #---- "true" authorised value
225
        }
245
        }
Lines 380-395 sub generate_subfield_form { Link Here
380
    return \%subfield_data;
400
    return \%subfield_data;
381
}
401
}
382
402
403
    my $subfields =
404
      Koha::UI::Form::Builder::Item->new(
405
        { biblionumber => $biblionumber, item => $current_item } )->edit_form(
406
        {
407
            branchcode           => $branchcode,
408
            restricted_editition => $restrictededition,
409
            (
410
                @subfields_to_prefill
411
                ? ( subfields_to_prefill => \@subfields_to_prefill )
412
                : ()
413
            ),
414
            prefill_with_default_values => 1,
415
            branch_limit => C4::Context->userenv->{"branch"},
416
        }
417
    );
418
419
Returns the list of subfields to display on the add/edit item form.
420
421
Use it in the view with:
422
  [% PROCESS subfields_for_item subfields => subfields %]
423
424
Parameters:
425
426
=over
427
428
=item branchcode
429
430
Pre-select a library (for logged in user)
431
432
=item restricted_editition
433
434
Flag to restrict the edition if the user does not have necessary permissions.
435
436
=item subfields_to_prefill
437
438
List of subfields to prefill (value of syspref SubfieldsToUseWhenPrefill)
439
440
=item subfields_to_allow
441
442
List of subfields to allow (value of syspref SubfieldsToAllowForRestrictedBatchmod)
443
444
=item subfields_to_ignore
445
446
List of subfields to ignore/skip
447
448
=item prefill_with_default_values
449
450
Flag to prefill with the default values defined in the framework.
451
452
=item branch_limit
453
454
Limit info depending on the library (so far only item types).
455
456
=item default_branches_empty
457
458
Flag to add an empty option to the library list.
459
460
=back
461
462
=cut
463
383
sub edit_form {
464
sub edit_form {
384
    my ( $self, $params ) = @_;
465
    my ( $self, $params ) = @_;
385
466
386
    my $branchcode         = $params->{branchcode};
467
    my $branchcode         = $params->{branchcode};
387
    my $restricted_edition = $params->{restricted_editition};
468
    my $restricted_edition = $params->{restricted_editition};
388
    my $subfields_to_prefill = $params->{subfields_to_prefill} || [];
469
    my $subfields_to_prefill = $params->{subfields_to_prefill} || [];
470
    my $subfields_to_allow = $params->{subfields_to_allow} || [];
471
    my $subfields_to_ignore= $params->{subfields_to_ignore} || [];
472
    my $prefill_with_default_values = $params->{prefill_with_default_values};
473
    my $branch_limit = $params->{branch_limit};
474
389
    my $libraries =
475
    my $libraries =
390
      Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed;
476
      Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed;
391
    for my $library (@$libraries) {
477
    for my $library (@$libraries) {
392
        $library->{selected} = 1 if $library->{branchcode} eq $branchcode;
478
        $library->{selected} = 1 if $branchcode && $library->{branchcode} eq $branchcode;
393
    }
479
    }
394
480
395
    my $item           = $self->{item};
481
    my $item           = $self->{item};
Lines 405-411 sub edit_form { Link Here
405
            my $subfield = $tagslib->{$tag}{$subfieldtag};
491
            my $subfield = $tagslib->{$tag}{$subfieldtag};
406
492
407
            next if IsMarcStructureInternal($subfield);
493
            next if IsMarcStructureInternal($subfield);
408
            next if ( $subfield->{tab} ne "10" );
494
            next if $subfield->{tab} ne "10";
495
            next if @$subfields_to_allow && !grep { $subfield->{kohafield} eq $_ } @$subfields_to_allow;
496
            next
497
              if grep { $subfield->{kohafield} && $subfield->{kohafield} eq $_ }
498
              @$subfields_to_ignore;
409
499
410
            my @values = ();
500
            my @values = ();
411
501
Lines 442-453 sub edit_form { Link Here
442
532
443
            for my $value (@values) {
533
            for my $value (@values) {
444
                my $subfield_data = $self->generate_subfield_form(
534
                my $subfield_data = $self->generate_subfield_form(
445
                    {tag => $tag,          subfieldtag => $subfieldtag,      value => $value,
535
                    {
446
                    tagslib => $tagslib,      libraries => $libraries,
536
                        tag                => $tag,
447
                    marc_record => $marc_record, restricted_edition => $restricted_edition,
537
                        subfieldtag        => $subfieldtag,
448
                });
538
                        value              => $value,
539
                        tagslib            => $tagslib,
540
                        libraries          => $libraries,
541
                        marc_record        => $marc_record,
542
                        restricted_edition => $restricted_edition,
543
                        prefill_with_default_values => $prefill_with_default_values,
544
                        branch_limit       => $branch_limit,
545
                    }
546
                );
449
                push @subfields, $subfield_data;
547
                push @subfields, $subfield_data;
450
                $i++;
451
            }
548
            }
452
        }
549
        }
453
    }
550
    }
(-)a/cataloguing/additem.pl (-2 / +9 lines)
Lines 571-579 my $subfields = Link Here
571
            @subfields_to_prefill
571
            @subfields_to_prefill
572
            ? ( subfields_to_prefill => \@subfields_to_prefill )
572
            ? ( subfields_to_prefill => \@subfields_to_prefill )
573
            : ()
573
            : ()
574
        )
574
        ),
575
        prefill_with_default_values => 1,
576
        branch_limit => C4::Context->userenv->{"branch"},
575
    }
577
    }
576
    );
578
);
579
580
if (   $frameworkcode eq 'FA' ) {
581
    my ( $barcode_field ) = grep {$_->{kohafield} eq 'items.barcode'} @$subfields;
582
    $barcode_field->{marc_value}->{value} ||= $input->param('barcode');
583
}
577
584
578
if( my $default_location = C4::Context->preference('NewItemsDefaultLocation') ) {
585
if( my $default_location = C4::Context->preference('NewItemsDefaultLocation') ) {
579
    my ( $location_field ) = grep {$_->{kohafield} eq 'items.location'} @$subfields;
586
    my ( $location_field ) = grep {$_->{kohafield} eq 'items.location'} @$subfields;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt (-71 / +1 lines)
Lines 248-324 Link Here
248
                        <h2>Edit items</h2>
248
                        <h2>Edit items</h2>
249
                        <div class="hint">Checking the box right next to the subfield label will disable the entry and delete the subfield on all selected items. Leave fields blank to make no change.</div>
249
                        <div class="hint">Checking the box right next to the subfield label will disable the entry and delete the subfield on all selected items. Leave fields blank to make no change.</div>
250
                        <fieldset class="rows">
250
                        <fieldset class="rows">
251
                            <ol>
251
                            [% PROCESS subfields_for_item subfields => subfields, add_regex => 1, add_delete_checkbox => 1 %]
252
                                [% FOREACH ite IN item %]
253
                                    <li>
254
                                        <div class="subfield_line" style="[% ite.visibility | html %]" id="subfield[% ite.tag | html %][% ite.subfield | html %][% ite.random | html %]">
255
                                            [% SET mv = ite.marc_value %]
256
                                            [% IF ( ite.mandatory ) %]
257
                                                <label class="required" for="[%- mv.id | html -%]">
258
                                            [% ELSE %]
259
                                                <label for="[%- mv.id | html -%]">
260
                                            [% END %]
261
                                                [% ite.subfield | html %] - [% ite.marc_lib | $raw %]
262
                                            </label>
263
264
                                            [% IF ( mv.type == 'select' ) -%]
265
                                                <select name="[%- mv.name | html -%]" id="[%- mv.id | html -%]" tabindex="1" class="input_marceditor select2">
266
                                                    [%- FOREACH aval IN mv.values %]
267
                                                        [% ite.subfield | html %] -
268
                                                        [% IF aval == mv.default %]
269
                                                            <option value="[%- aval | html -%]" selected="selected">[%- mv.labels.$aval | html -%]</option>
270
                                                        [% ELSE %]
271
                                                            <option value="[%- aval | html -%]">[%- mv.labels.$aval | html -%]</option>
272
                                                        [% END %]
273
                                                    [%- END -%]
274
                                                </select>
275
                                            [% ELSIF ( mv.type == 'text1' ) %]
276
                                                <input type="text" tabindex="1" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" size="50" maxlength="255" value="[%- mv.value | html -%]" />
277
                                                <a href="#" class="buttonDot" onclick="Dopop('/cgi-bin/koha/authorities/auth_finder.pl?authtypecode=[%- mv.authtypecode | uri -%]&index=[%- mv.id | uri -%]','[%- mv.id | uri -%]'); return false;" title="Tag editor">...</a>
278
                                            [% ELSIF ( mv.type == 'text2' ) %]
279
                                                <input type="text" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" size="50" maxlength="255" value="[%- mv.value | html -%]" />
280
                                                [% IF mv.noclick %]
281
                                                    <a href="#" class="buttonDot disabled" title="No popup">...</a>
282
                                                [% ELSE %]
283
                                                    <a href="#" id="buttonDot_[% mv.id | html %]" class="buttonDot" title="Tag editor">...</a>
284
                                                [% END %]
285
                                            [% ELSIF ( mv.type == 'text' ) %]
286
                                                <input type="text" tabindex="1" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" size="50" maxlength="255" value="[%- mv.value | html -%]" />
287
                                            [% ELSIF ( mv.type == 'hidden' ) %]
288
                                                <input type="hidden" tabindex="1" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" size="50" maxlength="255" value="[%- mv.value | html -%]" />
289
                                            [% ELSIF ( mv.type == 'textarea' ) %]
290
                                                <textarea tabindex="1" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" size="50" maxlength="255">[%- mv.value | html -%]"</textarea>
291
                                            [%- END # /IF mv.type == ... -%]
292
293
                                            <span name="regex_fields" style="display: none;">
294
                                                s/<input type="text" id="[% mv.id | html %]" name="regex_search" placeholder="regex pattern" />/
295
                                                <input type="text" id="[% mv.id | html %]" name="regex_replace" placeholder="regex replacement" />/
296
                                                <input type="text" id="[% mv.id | html %]" name="regex_modifiers" placeholder="ig" size="3" />
297
                                            </span>
298
299
                                            [% UNLESS ( ite.mandatory ) %]
300
                                                <input type="checkbox" id="row[% ite.tag | html %][% ite.subfield | html %][% ite.random | html %]" title="Check to delete subfield [% ite.subfield | html %]" name="disable_input" value="[% ite.subfield | html %]" />
301
                                            [% ELSE %]
302
                                                <span class="required">Required</span>
303
                                            [% END %]
304
305
                                            [% IF (mv.type == 'text' || mv.type == 'text2' || mv.type == 'textarea' ) %]
306
                                                <a href="#" name="field_regex" id="[% ite.id | html %]" >RegEx</a>
307
                                            [% END %]
308
309
                                            <input type="hidden" name="tag" value="[% ite.tag | html %]" />
310
                                            <input type="hidden" name="subfield" value="[% ite.subfield | html %]" />
311
                                            <input type="hidden" name="mandatory" value="[% ite.mandatory | html %]" />
312
                                            [% IF ( ite.repeatable ) %]
313
                                                <a href="#" class="buttonPlus" onclick="CloneItemSubfield(this.parentNode.parentNode); return false;">
314
                                                    <img src="[% interface | html %]/[% theme | html %]/img/clone-subfield.png" alt="Clone" title="Clone this subfield" />
315
                                                </a>
316
                                            [% END %]
317
                                            <span class="hint" id="hint[% ite.tag | html %][% ite.subfield | html %][% ite.random | html %]"></span>
318
                                        </div> <!-- /.subfield_line -->
319
                                    </li>
320
                                [% END # /FOREACH ite %]
321
                            </ol>
322
                        </fieldset>
252
                        </fieldset>
323
253
324
                        <fieldset class="rows">
254
                        <fieldset class="rows">
(-)a/tools/batchMod.pl (-198 / +28 lines)
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
- 

Return to bug 28445