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

(-)a/C4/Koha.pm (-9 / +20 lines)
Lines 509-516 C<$opac> If set to a true value, displays OPAC descriptions rather than normal o Link Here
509
=cut
509
=cut
510
510
511
sub GetAuthorisedValues {
511
sub GetAuthorisedValues {
512
    my $category = shift // '';      # optional parameter
512
    my $category = shift // '';             # optional parameter
513
    my $opac     = shift ? 1 : 0;    # normalise to be safe
513
    my $opac     = shift ? 1 : 0;           # normalise to be safe
514
    my $options  = shift // '';
515
    my $no_limit;
516
    if ($options) { $no_limit = $options->{'no_limit'}; }    #optional parameter to ignore library limitation
514
517
515
    # Is this cached already?
518
    # Is this cached already?
516
    my $branch_limit = C4::Context::mybranch();
519
    my $branch_limit = C4::Context::mybranch();
Lines 521-546 sub GetAuthorisedValues { Link Here
521
524
522
    my @results;
525
    my @results;
523
    my $dbh   = C4::Context->dbh;
526
    my $dbh   = C4::Context->dbh;
527
    
528
    my $select_clause = 'SELECT av.*';
529
    my @where_args;
530
    if ( $branch_limit && $no_limit ) {
531
        $select_clause .= ', IF (branchcode = ? OR branchcode IS NULL, 0, 1) as restricted';
532
        push @where_args, $branch_limit;
533
    }
534
524
    my $query = qq{
535
    my $query = qq{
525
        SELECT DISTINCT av.*
536
        $select_clause
526
        FROM authorised_values av
537
        FROM authorised_values av
527
    };
538
    };
528
    $query .= qq{
539
    $query .= qq{
529
          LEFT JOIN authorised_values_branches ON ( id = av_id )
540
          LEFT JOIN authorised_values_branches ON ( id = av_id )
530
    } if $branch_limit;
541
    } if $branch_limit;
531
    my @where_strings;
542
    my @where_strings;
532
    my @where_args;
543
    if($category) {
533
534
    if ($category) {
535
        push @where_strings, "category = ?";
544
        push @where_strings, "category = ?";
536
        push @where_args,    $category;
545
        push @where_args,    $category;
537
    }
546
    }
538
    if ($branch_limit) {
547
548
    if ( $branch_limit && !defined $no_limit ) {
539
        push @where_strings, "( branchcode = ? OR branchcode IS NULL )";
549
        push @where_strings, "( branchcode = ? OR branchcode IS NULL )";
540
        push @where_args,    $branch_limit;
550
        push @where_args,    $branch_limit;
541
    }
551
    }
542
    if ( @where_strings > 0 ) {
552
543
        $query .= " WHERE " . join( " AND ", @where_strings );
553
    if(@where_strings > 0) {
554
        $query .= " WHERE " . join(" AND ", @where_strings);
544
    }
555
    }
545
    $query .= ' ORDER BY category, '
556
    $query .= ' ORDER BY category, '
546
        . (
557
        . (
(-)a/Koha/UI/Form/Builder/Item.pm (-10 / +20 lines)
Lines 169-174 sub generate_subfield_form { Link Here
169
    if ( $subfield->{authorised_value} ) {
169
    if ( $subfield->{authorised_value} ) {
170
        my @authorised_values;
170
        my @authorised_values;
171
        my %authorised_lib;
171
        my %authorised_lib;
172
        my %restricted_values;
172
173
173
        # builds list, depending on authorised value...
174
        # builds list, depending on authorised value...
174
        if ( $subfield->{authorised_value} eq "LOST" ) {
175
        if ( $subfield->{authorised_value} eq "LOST" ) {
Lines 202-217 sub generate_subfield_form { Link Here
202
            }
203
            }
203
        } elsif ( $subfield->{authorised_value} eq "itemtypes" ) {
204
        } elsif ( $subfield->{authorised_value} eq "itemtypes" ) {
204
            push @authorised_values, "";
205
            push @authorised_values, "";
205
            my $itemtypes;
206
            my $all_itemtypes = Koha::ItemTypes->search_with_localization;
207
            my $filtered_itemtypes;
206
            if ($branch_limit) {
208
            if ($branch_limit) {
207
                $itemtypes = Koha::ItemTypes->search_with_localization( { branchcode => $branch_limit } );
209
                $filtered_itemtypes = Koha::ItemTypes->search_with_localization( { branchcode => $branch_limit } );
208
            } else {
210
            } else {
209
                $itemtypes = Koha::ItemTypes->search_with_localization;
211
                $filtered_itemtypes = $all_itemtypes;
210
            }
212
            }
211
            while ( my $itemtype = $itemtypes->next ) {
213
            while (my $itemtype = $filtered_itemtypes->next) {
212
                push @authorised_values, $itemtype->itemtype;
214
                push @authorised_values, $itemtype->itemtype;
213
                $authorised_lib{ $itemtype->itemtype } = $itemtype->translated_description;
215
                $authorised_lib{ $itemtype->itemtype } = $itemtype->translated_description;
214
            }
216
            }
217
            while (my $itemtype = $all_itemtypes->next) {
218
                if (!grep { $_ eq $itemtype->itemtype } @authorised_values) {
219
                    $restricted_values{ $itemtype->itemtype } = $itemtype->translated_description;
220
                }
221
            }
215
222
216
            if ( !$value && $biblionumber ) {
223
            if ( !$value && $biblionumber ) {
217
                my $itype_sth = $dbh->prepare("SELECT itemtype FROM biblioitems WHERE biblionumber = ?");
224
                my $itype_sth = $dbh->prepare("SELECT itemtype FROM biblioitems WHERE biblionumber = ?");
Lines 245-254 sub generate_subfield_form { Link Here
245
            #---- "true" authorised value
252
            #---- "true" authorised value
246
        } else {
253
        } else {
247
            push @authorised_values, qq{};
254
            push @authorised_values, qq{};
248
            my $av = GetAuthorisedValues( $subfield->{authorised_value} );
255
            my $av = GetAuthorisedValues( $subfield->{authorised_value}, undef, { 'no_limit' => 1 } );
249
            for my $r (@$av) {
256
            for my $r (@$av) {
250
                push @authorised_values, $r->{authorised_value};
257
                push @authorised_values, $r->{authorised_value};
251
                $authorised_lib{ $r->{authorised_value} } = $r->{lib};
258
                $authorised_lib{ $r->{authorised_value} } = $r->{lib};
259
                $restricted_values{ $r->{authorised_value} } = $r->{restricted};
252
            }
260
            }
253
        }
261
        }
254
262
Lines 266-276 sub generate_subfield_form { Link Here
266
            };
274
            };
267
        } else {
275
        } else {
268
            $subfield_data{marc_value} = {
276
            $subfield_data{marc_value} = {
269
                type    => 'select',
277
                type       => 'select',
270
                id      => "tag_" . $tag . "_subfield_" . $subfieldtag . "_" . $index_subfield,
278
                id         => "tag_" . $tag . "_subfield_" . $subfieldtag . "_" . $index_subfield,
271
                values  => \@authorised_values,
279
                values     => \@authorised_values,
272
                labels  => \%authorised_lib,
280
                labels     => \%authorised_lib,
273
                default => $value,
281
                restricted => \%restricted_values,
282
                default    => $value,
274
                (
283
                (
275
                      ( grep { $_ eq $subfield->{authorised_value} } (qw(branches itemtypes cn_source)) )
284
                      ( grep { $_ eq $subfield->{authorised_value} } (qw(branches itemtypes cn_source)) )
276
                    ? ()
285
                    ? ()
Lines 278-283 sub generate_subfield_form { Link Here
278
                ),
287
                ),
279
            };
288
            };
280
        }
289
        }
290
281
    }
291
    }
282
292
283
    # it's a thesaurus / authority field
293
    # it's a thesaurus / authority field
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc (-4 / +15 lines)
Lines 124-143 Link Here
124
                            [% FOREACH aval IN mv.values %]
124
                            [% FOREACH aval IN mv.values %]
125
                                [% IF aval == mv.default %]
125
                                [% IF aval == mv.default %]
126
                                    [% SET matched = 1 %]
126
                                    [% SET matched = 1 %]
127
                                    <option value="[%- aval | html -%]" selected="selected">[%- mv.labels.$aval | html -%]</option>
127
                                    [% IF mv.restricted.$aval %]
128
                                        <option value="[%- aval | html -%]" selected="selected" style="float:right" title="This value ([%- mv.labels.$aval | html -%]) is limited to other librairies">[%- mv.labels.$aval | html -%] &#9888;</option>
129
                                    [% ELSE %]
130
                                        <option value="[%- aval | html -%]" selected="selected">[%- mv.labels.$aval | html -%]</option>
131
                                    [% END %]
128
                                [% ELSE %]
132
                                [% ELSE %]
129
                                    [% IF subfield.IS_LOST_AV && Koha.Preference("ClaimReturnedLostValue") && aval == Koha.Preference("ClaimReturnedLostValue") %]
133
                                    [% IF subfield.IS_LOST_AV && Koha.Preference("ClaimReturnedLostValue") && aval == Koha.Preference("ClaimReturnedLostValue") %]
130
                                        <option disabled="disabled" value="[%- aval | html -%]" title="Return claims must be processed from the patron details page">[%- mv.labels.$aval | html -%]</option>
134
                                        <option disabled="disabled" value="[%- aval | html -%]" title="Return claims must be processed from the patron details page">[%- mv.labels.$aval | html -%]</option>
131
                                    [% ELSIF subfield.IS_LOST_AV && Koha.Preference("BundleLostValue") && aval == Koha.Preference("BundleLostValue") %]
135
                                    [% ELSIF subfield.IS_LOST_AV && Koha.Preference("BundleLostValue") && aval == Koha.Preference("BundleLostValue") %]
132
                                        <option disabled="disabled" value="[%- aval | html -%]" title="Bundle losses are set at checkin automatically">[%- mv.labels.$aval | html -%]</option>
136
                                        <option disabled="disabled" value="[%- aval | html -%]" title="Bundle losses are set at checkin automatically">[%- mv.labels.$aval | html -%]</option>
133
                                    [% ELSE %]
137
                                    [% ELSE %]
134
                                        <option value="[%- aval | html -%]">[%- mv.labels.$aval | html -%]</option>
138
                                        [% UNLESS mv.restricted.$aval %]
139
                                            <option value="[%- aval | html -%]">[%- mv.labels.$aval | html -%]</option>
140
                                        [% END %]
135
                                    [% END %]
141
                                    [% END %]
136
                                [% END %]
142
                                [% END %]
137
                            [% END %]
143
                            [% END %]
138
                            [% UNLESS matched || ( ( kohafield == 'items.damaged' || kohafield == 'items.itemlost' || kohafield == 'items.withdrawn' || kohafield == 'items.notforloan' ) && mv.default == '0' ) %]
144
                            [% UNLESS matched || ( ( kohafield == 'items.damaged' || kohafield == 'items.itemlost' || kohafield == 'items.withdrawn' || kohafield == 'items.notforloan' ) && mv.default == '0' ) %]
139
                                [%# If the current value is not in the authorised list  and is not a field where 0 means unset #%]
145
                                [%# If the current value is not in the authorised list  and is not a field where 0 means unset #%]
140
                                <option value="[%- mv.default | html -%]" selected="selected">[%- mv.default | html -%] (Not an authorised value)</option>
146
                                [% IF mv.restricted %]
147
                                    [% FOREACH code IN mv.restricted.keys %]
148
                                        [% IF mv.default == code %]
149
                                            <option value="[%- code | html -%]" selected="selected" style="float:right" title="This value ([%- mv.restricted.$code | html -%]) is limited to other librairies">[%- mv.restricted.$code | html -%] &#9888;</option>
150
                                        [% END %]
151
                                    [% END %]
152
                                [% END %]
141
                            [% END %]
153
                            [% END %]
142
                        </select>
154
                        </select>
143
                        [% UNLESS matched || ( ( kohafield == 'items.damaged' || kohafield == 'items.itemlost' || kohafield == 'items.withdrawn' || kohafield == 'items.notforloan' ) && mv.default == '0' ) %]
155
                        [% UNLESS matched || ( ( kohafield == 'items.damaged' || kohafield == 'items.itemlost' || kohafield == 'items.withdrawn' || kohafield == 'items.notforloan' ) && mv.default == '0' ) %]
144
- 

Return to bug 32748