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

(-)a/Koha/Template/Plugin/Branches.pm (-5 / +14 lines)
Lines 57-78 sub GetURL { Link Here
57
57
58
sub all {
58
sub all {
59
    my ( $self, $params ) = @_;
59
    my ( $self, $params ) = @_;
60
    my $selected = $params->{selected};
60
    my $selected = $params->{selected} || ();
61
    my $unfiltered = $params->{unfiltered} || 0;
61
    my $unfiltered = $params->{unfiltered} || 0;
62
    my $search_params = $params->{search_params} || {};
62
    my $search_params = $params->{search_params} || {};
63
    my $do_not_select_my_library = $params->{do_not_select_my_library} || 0; # By default we select the library of the logged in user if no selected passed
63
64
64
    if ( !$unfiltered ) {
65
    if ( !$unfiltered ) {
65
        $search_params->{only_from_group} = $params->{only_from_group} || 0;
66
        $search_params->{only_from_group} = $params->{only_from_group} || 0;
66
    }
67
    }
67
68
69
    my @selected =
70
      ref $selected eq 'Koha::Libraries'
71
      ? $selected->get_column('branchcode')
72
      : $selected;
73
68
    my $libraries = $unfiltered
74
    my $libraries = $unfiltered
69
      ? Koha::Libraries->search( $search_params, { order_by => ['branchname'] } )->unblessed
75
      ? Koha::Libraries->search( $search_params, { order_by => ['branchname'] } )->unblessed
70
      : Koha::Libraries->search_filtered( $search_params, { order_by => ['branchname'] } )->unblessed;
76
      : Koha::Libraries->search_filtered( $search_params, { order_by => ['branchname'] } )->unblessed;
71
77
72
    for my $l ( @$libraries ) {
78
    for my $l (@$libraries) {
73
        if (       defined $selected and $l->{branchcode} eq $selected
79
        if ( grep { $l->{branchcode} eq $_ } @selected
74
            or not defined $selected and C4::Context->userenv and $l->{branchcode} eq ( C4::Context->userenv->{branch} // q{} )
80
            or  not @selected
75
        ) {
81
                and not $do_not_select_my_library
82
                and C4::Context->userenv
83
                and $l->{branchcode} eq ( C4::Context->userenv->{branch} // q{} ) )
84
        {
76
            $l->{selected} = 1;
85
            $l->{selected} = 1;
77
        }
86
        }
78
    }
87
    }
(-)a/admin/itemtypes.pl (-21 / +1 lines)
Lines 59-76 undef($sip_media_type) if defined($sip_media_type) and $sip_media_type =~ /^\s*$ Link Here
59
if ( $op eq 'add_form' ) {
59
if ( $op eq 'add_form' ) {
60
    my $itemtype = Koha::ItemTypes->find($itemtype_code);
60
    my $itemtype = Koha::ItemTypes->find($itemtype_code);
61
61
62
    my $selected_branches = $itemtype ? $itemtype->get_library_limits : undef;
63
    my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed;
64
    my @branches_loop;
65
    foreach my $branch ( @$branches ) {
66
        my $selected = ($selected_branches && grep {$_->branchcode eq $branch->{branchcode}} @{ $selected_branches->as_list } ) ? 1 : 0;
67
        push @branches_loop, {
68
            branchcode => $branch->{branchcode},
69
            branchname => $branch->{branchname},
70
            selected   => $selected,
71
        };
72
    }
73
74
    my $imagesets = C4::Koha::getImageSets( checked => ( $itemtype ? $itemtype->imageurl : undef ) );
62
    my $imagesets = C4::Koha::getImageSets( checked => ( $itemtype ? $itemtype->imageurl : undef ) );
75
    my $searchcategory = GetAuthorisedValues("ITEMTYPECAT");
63
    my $searchcategory = GetAuthorisedValues("ITEMTYPECAT");
76
    my $translated_languages = C4::Languages::getTranslatedLanguages( undef , C4::Context->preference('template') );
64
    my $translated_languages = C4::Languages::getTranslatedLanguages( undef , C4::Context->preference('template') );
Lines 79-85 if ( $op eq 'add_form' ) { Link Here
79
        imagesets => $imagesets,
67
        imagesets => $imagesets,
80
        searchcategory => $searchcategory,
68
        searchcategory => $searchcategory,
81
        can_be_translated => ( scalar(@$translated_languages) > 1 ? 1 : 0 ),
69
        can_be_translated => ( scalar(@$translated_languages) > 1 ? 1 : 0 ),
82
        branches_loop    => \@branches_loop,
83
    );
70
    );
84
} elsif ( $op eq 'add_validate' ) {
71
} elsif ( $op eq 'add_validate' ) {
85
    my $is_a_modif   = $input->param('is_a_modif');
72
    my $is_a_modif   = $input->param('is_a_modif');
Lines 196-210 if ( $op eq 'add_form' ) { Link Here
196
}
183
}
197
184
198
if ( $op eq 'list' ) {
185
if ( $op eq 'list' ) {
199
    my @itypes = Koha::ItemTypes->search->as_list;
200
    my @itemtypes;
201
    foreach my $itype (@itypes) {
202
        my $itemtype = $itype->unblessed;
203
        $itemtype->{branches} = $itype->library_limits ? $itype->library_limits->as_list : [];
204
        push @itemtypes, $itemtype;
205
    }
206
    $template->param(
186
    $template->param(
207
        itemtypes => \@itemtypes,
187
        itemtypes => scalar Koha::ItemTypes->search,
208
        messages  => \@messages,
188
        messages  => \@messages,
209
    );
189
    );
210
}
190
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt (-17 / +12 lines)
Lines 1-6 Link Here
1
[% USE raw %]
1
[% USE raw %]
2
[% USE Asset %]
2
[% USE Asset %]
3
[% USE Koha %]
3
[% USE Koha %]
4
[% USE Branches %]
4
[% USE AuthorisedValues %]
5
[% USE AuthorisedValues %]
5
[% USE Price %]
6
[% USE Price %]
6
[% USE ColumnsSettings %]
7
[% USE ColumnsSettings %]
Lines 287-299 Item types administration Link Here
287
                <li><label for="branches">Library limitation: </label>
288
                <li><label for="branches">Library limitation: </label>
288
                    <select id="branches" name="branches" multiple size="10">
289
                    <select id="branches" name="branches" multiple size="10">
289
                        <option value="">All libraries</option>
290
                        <option value="">All libraries</option>
290
                        [% FOREACH branch IN branches_loop %]
291
                        [% PROCESS options_for_libraries libraries => Branches.all( selected => itemtype.get_library_limits, unfiltered => 1, do_not_select_my_library => 1 ) %]
291
                        [% IF ( branch.selected ) %]
292
                            <option selected="selected" value="[% branch.branchcode | html %]">[% branch.branchname | html %]</option>
293
                        [% ELSE %]
294
                            <option value="[% branch.branchcode | html %]">[% branch.branchname | html %]</option>
295
                        [% END %]
296
                        [% END %]
297
                    </select>
292
                    </select>
298
                    <span>Select 'All libraries' if this authorized value must be displayed all the time. Otherwise select libraries you want to associate with this value.</span>
293
                    <span>Select 'All libraries' if this authorized value must be displayed all the time. Otherwise select libraries you want to associate with this value.</span>
299
                </li>
294
                </li>
Lines 414-433 Item types administration Link Here
414
            <td>[% itemtype.processfee | $Price %]</td>
409
            <td>[% itemtype.processfee | $Price %]</td>
415
            <td>[% itemtype.checkinmsg | html_line_break | $raw %]</td>
410
            <td>[% itemtype.checkinmsg | html_line_break | $raw %]</td>
416
            <td>
411
            <td>
417
                [% IF itemtype.branches.size > 0 %]
412
                [% SET library_limits = itemtype.library_limits %]
418
                    [% branches_str = "" %]
413
                [% IF library_limits.count > 0 %]
419
                    [% FOREACH branch IN itemtype.branches %]
414
                    [% library_str = "" %]
415
                    [% FOREACH library IN library_limits %]
420
                        [%- IF loop.first -%]
416
                        [%- IF loop.first -%]
421
                        [% branches_str = branch.branchname _ " (" _ branch.branchcode _ ")" %]
417
                            [% library_str = library.branchname _ " (" _ library.branchcode _ ")" %]
422
                        [% ELSE %]
418
                        [% ELSE %]
423
                        [% branches_str = branches_str _ "\n" _ branch.branchname _ " (" _ branch.branchcode _ ")" %]
419
                            [% library_str = library_str _ "\n" _ library.branchname _ " (" _ library.branchcode _ ")" %]
424
                        [% END %]
420
                        [% END %]
425
                    [% END %]
421
                    [% END %]
426
                    <span class="library_limitation" title="[% branches_str | html %]">
422
                    <span class="library_limitation" title="[% library_str | html %]">
427
                        [% IF itemtype.branches.size > 1 %]
423
                        [% IF library_limits.count > 1 %]
428
                            [% itemtype.branches.size | html %] library limitations
424
                            [% library_limits.count | html %] library limitations
429
                        [% ELSE %]
425
                        [% ELSE %]
430
                            [% itemtype.branches.size | html %] library limitation
426
                            [% library_limits.count | html %] library limitation
431
                        [% END %]
427
                        [% END %]
432
                [% ELSE %]
428
                [% ELSE %]
433
                    No limitation
429
                    No limitation
434
- 

Return to bug 23271