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 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
- 

Return to bug 28445