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

(-)a/C4/Utils/DataTables/VirtualShelves.pm (-1 / +20 lines)
Lines 15-26 sub search { Link Here
15
    my $dt_params = $params->{dt_params};
15
    my $dt_params = $params->{dt_params};
16
16
17
    # public is default
17
    # public is default
18
    $type = 2 if not $type or $type != 1;
18
    $type = 2 unless $type && ( $type == 1 || $type == 3 );
19
19
20
    # If not logged in user, be carreful and set the borrowernumber to 0
20
    # If not logged in user, be carreful and set the borrowernumber to 0
21
    # to prevent private lists lack
21
    # to prevent private lists lack
22
    my $loggedinuser = C4::Context->userenv->{'number'} || 0;
22
    my $loggedinuser = C4::Context->userenv->{'number'} || 0;
23
23
24
    if ( $type == 3 ) {
25
        my $permissions =
26
          C4::Auth::haspermission( C4::Context->userenv->{id}, { lists => '*' } );
27
28
        unless (
29
            $permissions
30
            && (   $permissions->{superlibrarian} == 1
31
                || $permissions->{lists} == 1 )
32
          )
33
        {
34
            return {
35
                iTotalRecords        => 0,
36
                iTotalDisplayRecords => 0,
37
                shelves              => [],
38
            };
39
        }
40
    }
41
24
    my ($iTotalRecords, $iTotalDisplayRecords);
42
    my ($iTotalRecords, $iTotalDisplayRecords);
25
43
26
    my $dbh = C4::Context->dbh;
44
    my $dbh = C4::Context->dbh;
Lines 125-130 sub search { Link Here
125
        $shelf->{can_delete_shelf} = $s->can_be_deleted( $loggedinuser );
143
        $shelf->{can_delete_shelf} = $s->can_be_deleted( $loggedinuser );
126
        $shelf->{is_shared} = $s->is_shared;
144
        $shelf->{is_shared} = $s->is_shared;
127
    }
145
    }
146
128
    return {
147
    return {
129
        iTotalRecords => $iTotalRecords,
148
        iTotalRecords => $iTotalRecords,
130
        iTotalDisplayRecords => $iTotalDisplayRecords,
149
        iTotalDisplayRecords => $iTotalDisplayRecords,
(-)a/Koha/Virtualshelf.pm (-1 / +39 lines)
Lines 47-53 Koha::Virtualshelf - Koha Virtualshelf Object class Link Here
47
=cut
47
=cut
48
48
49
our $PRIVATE = 1;
49
our $PRIVATE = 1;
50
our $PUBLIC = 2;
50
our $PUBLIC  = 2;
51
our $STAFF   = 3;
51
52
52
sub store {
53
sub store {
53
    my ( $self ) = @_;
54
    my ( $self ) = @_;
Lines 71-86 sub store { Link Here
71
    return $self->SUPER::store( $self );
72
    return $self->SUPER::store( $self );
72
}
73
}
73
74
75
=head3 is_public
76
77
  my $bool = $shelf->is_public;
78
79
  Returns true if shelf has been made public.
80
81
=cut
82
74
sub is_public {
83
sub is_public {
75
    my ( $self ) = @_;
84
    my ( $self ) = @_;
76
    return $self->category == $PUBLIC;
85
    return $self->category == $PUBLIC;
77
}
86
}
78
87
88
=head3 is_private
89
90
  my $bool = $shelf->is_private;
91
92
  Returns true if shelf is a private shelf.
93
94
=cut
95
79
sub is_private {
96
sub is_private {
80
    my ( $self ) = @_;
97
    my ( $self ) = @_;
81
    return $self->category == $PRIVATE;
98
    return $self->category == $PRIVATE;
82
}
99
}
83
100
101
=head3 is_staff
102
103
  my $bool = $shelf->is_staff;
104
105
  Returns true if shelf is available to staff only.
106
107
=cut
108
109
sub is_staff {
110
    my ( $self ) = @_;
111
    return $self->category == $STAFF;
112
}
113
84
sub is_shelfname_valid {
114
sub is_shelfname_valid {
85
    my ( $self ) = @_;
115
    my ( $self ) = @_;
86
116
Lines 221-226 sub can_be_viewed { Link Here
221
    return 1 if $self->is_public;
251
    return 1 if $self->is_public;
222
    return 0 unless $borrowernumber;
252
    return 0 unless $borrowernumber;
223
    return 1 if $self->owner == $borrowernumber;
253
    return 1 if $self->owner == $borrowernumber;
254
    return 1 if $self->category == 3;
224
    return $self->get_shares->search(
255
    return $self->get_shares->search(
225
        {
256
        {
226
            borrowernumber => $borrowernumber,
257
            borrowernumber => $borrowernumber,
Lines 243-250 sub can_be_deleted { Link Here
243
274
244
sub can_be_managed {
275
sub can_be_managed {
245
    my ( $self, $borrowernumber ) = @_;
276
    my ( $self, $borrowernumber ) = @_;
277
246
    return 1
278
    return 1
247
      if $borrowernumber and $self->owner == $borrowernumber;
279
      if $borrowernumber and $self->owner == $borrowernumber;
280
281
    my $patron = Koha::Patrons->find( $borrowernumber );
282
    my $permissions = C4::Auth::haspermission( $patron->userid, { lists => '*' } );
283
    return 1
284
      if $borrowernumber and $self->category == 3 and $permissions and $permissions->{lists} == 1;
285
248
    return 0;
286
    return 0;
249
}
287
}
250
288
(-)a/Koha/Virtualshelves.pm (-5 / +33 lines)
Lines 35-44 Koha::Virtualshelf - Koha Virtualshelf Object class Link Here
35
35
36
=cut
36
=cut
37
37
38
=head3 type
39
40
=cut
41
42
sub get_private_shelves {
38
sub get_private_shelves {
43
    my ( $self, $params ) = @_;
39
    my ( $self, $params ) = @_;
44
    my $page = $params->{page};
40
    my $page = $params->{page};
Lines 62-68 sub get_private_shelves { Link Here
62
    );
58
    );
63
}
59
}
64
60
65
66
sub get_public_shelves {
61
sub get_public_shelves {
67
    my ( $self, $params ) = @_;
62
    my ( $self, $params ) = @_;
68
    my $page = $params->{page};
63
    my $page = $params->{page};
Lines 80-85 sub get_public_shelves { Link Here
80
    );
75
    );
81
}
76
}
82
77
78
=head3 get_staff_shelves
79
80
    my $shelves = $virtual_shelves->get_staff_shelves( { page => $page, rows => $rowss );
81
82
    Returns item lists that are visible to all staff that can manage patron lists
83
84
=cut
85
86
sub get_staff_shelves {
87
    my ( $self, $params ) = @_;
88
    my $page = $params->{page};
89
    my $rows = $params->{rows};
90
91
    $self->search(
92
        {
93
            category => 3,
94
        },
95
        {
96
            group_by => 'shelfnumber',
97
            order_by => 'shelfname',
98
            ( ( $page and $rows ) ? ( page => $page, rows => $rows ) : () ),
99
        }
100
    );
101
}
102
83
sub get_some_shelves {
103
sub get_some_shelves {
84
    my ( $self, $params ) = @_;
104
    my ( $self, $params ) = @_;
85
    my $borrowernumber = $params->{borrowernumber} || 0;
105
    my $borrowernumber = $params->{borrowernumber} || 0;
Lines 160-169 sub get_shelves_containing_record { Link Here
160
    );
180
    );
161
}
181
}
162
182
183
=head3 _type
184
185
=cut
186
163
sub _type {
187
sub _type {
164
    return 'Virtualshelve';
188
    return 'Virtualshelve';
165
}
189
}
166
190
191
=head3 object_class
192
193
=cut
194
167
sub object_class {
195
sub object_class {
168
    return 'Koha::Virtualshelf';
196
    return 'Koha::Virtualshelf';
169
}
197
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/addbybiblionumber.tt (+1 lines)
Lines 97-102 Link Here
97
        <select name="category" id="category">
97
        <select name="category" id="category">
98
        <option value="1">Private</option>
98
        <option value="1">Private</option>
99
        <option value="2">Public</option>
99
        <option value="2">Public</option>
100
        <option value="3">Staff only</option>
100
        </select>
101
        </select>
101
    </li></ol>
102
    </li></ol>
102
    </fieldset>
103
    </fieldset>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt (-2 / +26 lines)
Lines 3-9 Link Here
3
[% USE Koha %]
3
[% USE Koha %]
4
[% USE KohaDates %]
4
[% USE KohaDates %]
5
[% SET PRIVATE = 1 %]
5
[% SET PRIVATE = 1 %]
6
[% SET PUBLIC = 2 %]
6
[% SET PUBLIC  = 2 %]
7
[% SET STAFF   = 3 %]
7
[% SET footerjs = 1 %]
8
[% SET footerjs = 1 %]
8
[% INCLUDE 'doc-head-open.inc' %]
9
[% INCLUDE 'doc-head-open.inc' %]
9
<title>Koha &rsaquo; [% IF op == 'view' %]Lists &rsaquo; Contents of [% shelf.shelfname | html %][% ELSE %]Lists[% END %][% IF op == 'add_form' %] &rsaquo; Create new list[% END %][% IF op == 'edit_form' %] &rsaquo; Edit list [% shelf.shelfname | html %][% END %]</title>
10
<title>Koha &rsaquo; [% IF op == 'view' %]Lists &rsaquo; Contents of [% shelf.shelfname | html %][% ELSE %]Lists[% END %][% IF op == 'add_form' %] &rsaquo; Create new list[% END %][% IF op == 'edit_form' %] &rsaquo; Edit list [% shelf.shelfname | html %][% END %]</title>
Lines 48-53 Link Here
48
        [% ELSE %]
49
        [% ELSE %]
49
            Your lists
50
            Your lists
50
        [% END %]
51
        [% END %]
52
    [% ELSIF shelf AND shelf.is_staff %] &rsaquo;
53
        [% IF op == 'view' %]
54
            <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=list&amp;category=[% STAFF %]">Staff lists</a>
55
        [% ELSE %]
56
            Public lists
57
        [% END %]
51
    [% ELSIF shelf AND shelf.is_public %] &rsaquo;
58
    [% ELSIF shelf AND shelf.is_public %] &rsaquo;
52
        [% IF op == 'view' %]
59
        [% IF op == 'view' %]
53
            <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=list&amp;category=[% PUBLIC | uri %]">Public lists</a>
60
            <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=list&amp;category=[% PUBLIC | uri %]">Public lists</a>
Lines 301-306 Link Here
301
                [% ELSE %]
308
                [% ELSE %]
302
                    <option value="1">Private</option>
309
                    <option value="1">Private</option>
303
                [% END %]
310
                [% END %]
311
312
                [% IF shelf.is_staff %]
313
                    <option value="3" selected="selected">Staff only</option>
314
                [% ELSE %]
315
                    <option value="3">Staff only</option>
316
                [% END %]
317
304
                [% IF shelf.is_public %]
318
                [% IF shelf.is_public %]
305
                    <option value="2" selected="selected">Public</option>
319
                    <option value="2" selected="selected">Public</option>
306
                [% ELSE %]
320
                [% ELSE %]
Lines 335-340 Link Here
335
        <ul>
349
        <ul>
336
            <li id="privateshelves_tab" class="active"><a href="#tab_content">Your lists</a></li>
350
            <li id="privateshelves_tab" class="active"><a href="#tab_content">Your lists</a></li>
337
            <li id="publicshelves_tab" class="active"><a href="#tab_content">Public lists</a></li>
351
            <li id="publicshelves_tab" class="active"><a href="#tab_content">Public lists</a></li>
352
            [% IF can_manage_lists %]
353
                <li id="staffshelves_tab" class="active"><a href="#tab_content">[% CAN_user_lists %] Staff lists</a></li>
354
            [% END %]
338
        </ul>
355
        </ul>
339
356
340
        <div id="tab_content">
357
        <div id="tab_content">
Lines 451-456 Link Here
451
            $(document).ready(function(){
468
            $(document).ready(function(){
452
                [% IF category == PUBLIC %]
469
                [% IF category == PUBLIC %]
453
                    var type = [% PUBLIC | html %];
470
                    var type = [% PUBLIC | html %];
471
                [% ELSIF category == STAFF %]
472
                    var type = [% STAFF %];
454
                [% ELSE %]
473
                [% ELSE %]
455
                    var type = [% PRIVATE | html %];
474
                    var type = [% PRIVATE | html %];
456
                [% END %]
475
                [% END %]
Lines 510-516 Link Here
510
                dtListResults.fnAddFilters("filter", 750);
529
                dtListResults.fnAddFilters("filter", 750);
511
530
512
                var tabs = $("#tabs").tabs({
531
                var tabs = $("#tabs").tabs({
513
                    [% IF category == PUBLIC %]
532
                    [% IF category == STAFF %]
533
                        active: 2,
534
                    [% ELSIF category == PUBLIC %]
514
                        active: 1,
535
                        active: 1,
515
                    [% ELSE %]
536
                    [% ELSE %]
516
                        active: 0,
537
                        active: 0,
Lines 523-528 Link Here
523
                        } else if ( active == 1 ) {
544
                        } else if ( active == 1 ) {
524
                            type = [% PUBLIC | html %];
545
                            type = [% PUBLIC | html %];
525
                            dtListResults.fnDraw();
546
                            dtListResults.fnDraw();
547
                        } else if ( active == 2 ) {
548
                            type = [% STAFF %];
549
                            dtListResults.fnDraw();
526
                        }
550
                        }
527
                    }
551
                    }
528
                });
552
                });
(-)a/virtualshelves/shelves.pl (-1 / +4 lines)
Lines 346-351 if ( $op eq 'view' ) { Link Here
346
    }
346
    }
347
}
347
}
348
348
349
my $permissions = C4::Auth::haspermission( C4::Context->userenv->{id}, { lists => '*' } );
350
my $can_manage_lists = $permissions && ( $permissions->{superlibrarian} == 1 || $permissions->{lists} == 1 );
351
349
$template->param(
352
$template->param(
350
    op       => $op,
353
    op       => $op,
351
    referer  => $referer,
354
    referer  => $referer,
Lines 354-359 $template->param( Link Here
354
    category => $category,
357
    category => $category,
355
    print    => scalar $query->param('print') || 0,
358
    print    => scalar $query->param('print') || 0,
356
    csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc', used_for => 'export_records' }) ],
359
    csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc', used_for => 'export_records' }) ],
360
    can_manage_lists => $can_manage_lists,
357
);
361
);
358
362
359
output_html_with_http_headers $query, $cookie, $template->output;
363
output_html_with_http_headers $query, $cookie, $template->output;
360
- 

Return to bug 20718