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

(-)a/C4/ItemType.pm (-2 lines)
Lines 188-195 L<C4::Labels>, Link Here
188
L<C4::Overdues>,
188
L<C4::Overdues>,
189
L<C4::Reserves>,
189
L<C4::Reserves>,
190
L<C4::Search>,
190
L<C4::Search>,
191
L<C4::VirtualShelves::Page>,
192
L<C4::VirtualShelves>,
193
L<C4::XSLT>
191
L<C4::XSLT>
194
192
195
193
(-)a/C4/VirtualShelves.pm (-122 lines)
Lines 1-122 Link Here
1
package C4::VirtualShelves;
2
3
# Copyright 2000-2002 Katipo Communications
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use strict;
21
use warnings;
22
23
use Carp;
24
use C4::Context;
25
use C4::Debug;
26
use C4::Members;
27
28
use constant SHELVES_MASTHEAD_MAX => 10; #number under Lists button in masthead
29
use constant SHELVES_COMBO_MAX => 10; #add to combo in search
30
use constant SHELVES_MGRPAGE_MAX => 20; #managing page
31
use constant SHELVES_POPUP_MAX => 40; #addbybiblio popup
32
33
use constant SHARE_INVITATION_EXPIRY_DAYS => 14; #two weeks to accept
34
35
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
36
37
BEGIN {
38
    # set the version for version checking
39
    $VERSION = 3.07.00.049;
40
    require Exporter;
41
    @ISA    = qw(Exporter);
42
    @EXPORT = qw(
43
    );
44
        @EXPORT_OK = qw(
45
            &ShelvesMax
46
        );
47
}
48
49
50
=head1 NAME
51
52
C4::VirtualShelves - Functions for manipulating Koha virtual shelves
53
54
=head1 SYNOPSIS
55
56
  use C4::VirtualShelves;
57
58
=head1 DESCRIPTION
59
60
This module provides functions for manipulating virtual shelves,
61
including creating and deleting virtual shelves, and adding and removing
62
bibs to and from virtual shelves.
63
64
=head1 FUNCTIONS
65
66
=head2 ShelvesMax
67
68
    $howmany= ShelvesMax($context);
69
70
Tells how much shelves are shown in which context.
71
POPUP refers to addbybiblionumber popup, MGRPAGE is managing page (in opac or
72
staff), COMBO refers to the Add to-combo of search results. MASTHEAD is the
73
main Koha toolbar with Lists button.
74
75
=cut
76
77
sub ShelvesMax {
78
    my $which= shift;
79
    return SHELVES_POPUP_MAX if $which eq 'POPUP';
80
    return SHELVES_MGRPAGE_MAX if $which eq 'MGRPAGE';
81
    return SHELVES_COMBO_MAX if $which eq 'COMBO';
82
    return SHELVES_MASTHEAD_MAX if $which eq 'MASTHEAD';
83
    return SHELVES_MASTHEAD_MAX;
84
}
85
86
sub GetShelfCount {
87
    my ($owner, $category) = @_;
88
    my @params;
89
    # Find out how many shelves total meet the submitted criteria...
90
91
    my $dbh = C4::Context->dbh;
92
    my $query = "SELECT count(*) FROM virtualshelves vs ";
93
    if($category==1) {
94
        $query.= qq{
95
            LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber
96
            AND sh.borrowernumber=?
97
        WHERE category=1 AND (vs.owner=? OR sh.borrowernumber=?) };
98
        @params= ($owner, $owner, $owner);
99
    }
100
    else {
101
        $query.='WHERE category=2';
102
        @params= ();
103
    }
104
    my $sth = $dbh->prepare($query);
105
    $sth->execute(@params);
106
    my ($total)= $sth->fetchrow;
107
    return $total;
108
}
109
110
1;
111
112
__END__
113
114
=head1 AUTHOR
115
116
Koha Development Team <http://koha-community.org/>
117
118
=head1 SEE ALSO
119
120
C4::Circulation::Circ2(3)
121
122
=cut
(-)a/C4/VirtualShelves/Page.pm (-564 lines)
Lines 1-564 Link Here
1
package C4::VirtualShelves::Page;
2
3
#
4
# Copyright 2000-2002 Katipo Communications
5
#
6
# This file is part of Koha.
7
#
8
# Koha is free software; you can redistribute it and/or modify it
9
# under the terms of the GNU General Public License as published by
10
# the Free Software Foundation; either version 3 of the License, or
11
# (at your option) any later version.
12
#
13
# Koha is distributed in the hope that it will be useful, but
14
# WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
17
#
18
# You should have received a copy of the GNU General Public License
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21
# perldoc at the end of the file, per convention.
22
23
use strict;
24
use warnings;
25
26
use CGI qw ( -utf8 );
27
use Exporter;
28
use Data::Dumper;
29
30
use C4::VirtualShelves qw/:DEFAULT ShelvesMax/;
31
use C4::Biblio;
32
use C4::Items;
33
use C4::Reserves;
34
use C4::Koha;
35
use C4::Auth qw/get_session/;
36
use C4::Members;
37
use C4::Output;
38
use C4::Dates qw/format_date/;
39
use C4::Tags qw(get_tags);
40
use C4::Csv;
41
use C4::XSLT;
42
43
use Koha::Virtualshelves;
44
45
use constant VIRTUALSHELVES_COUNT => 20;
46
47
use vars qw($debug @EXPORT @ISA $VERSION);
48
49
BEGIN {
50
    $VERSION = 3.07.00.049;
51
    @ISA     = qw(Exporter);
52
    @EXPORT  = qw(&shelfpage);
53
    $debug   = $ENV{DEBUG} || 0;
54
}
55
56
my @messages;
57
our %pages = (
58
    intranet => { redirect => '/cgi-bin/koha/virtualshelves/shelves.pl', },
59
    opac     => { redirect => '/cgi-bin/koha/opac-shelves.pl', },
60
);
61
62
sub shelfpage {
63
    my ( $type, $query, $template, $loggedinuser, $cookie ) = @_;
64
    ( $pages{$type} ) or $type = 'opac';
65
    $query            or die "No query";
66
    $template         or die "No template";
67
    $template->param(
68
    loggedinuser => $loggedinuser,
69
    OpacAllowPublicListCreation => C4::Context->preference('OpacAllowPublicListCreation'),
70
    );
71
    my $shelves;
72
    my @paramsloop;
73
    my $totitems;
74
    my $shelfoff    = ( $query->param('shelfoff') ? $query->param('shelfoff') : 1 );
75
    $template->{VARS}->{'shelfoff'} = $shelfoff;
76
    my $itemoff     = ( $query->param('itemoff')  ? $query->param('itemoff')  : 1 );
77
    my $displaymode = ( $query->param('display')  ? $query->param('display')  : 'publicshelves' );
78
    my ( $shelflimit, $shelfoffset, $shelveslimit, $shelvesoffset );
79
    my $marcflavour = C4::Context->preference("marcflavour");
80
81
    unless ( $query->param('print') ) {
82
        $shelflimit = ( $type eq 'opac' ? C4::Context->preference('OPACnumSearchResults') : C4::Context->preference('numSearchResults') );
83
        $shelflimit = $shelflimit || ShelvesMax('MGRPAGE');
84
        $shelflimit = undef if $query->param('rss');
85
        $shelfoffset   = ( $itemoff - 1 ) * $shelflimit;     # Sets the offset to begin retrieving items at
86
        $shelveslimit  = $shelflimit;                        # Limits number of shelves returned for a given query (row_count)
87
        $shelvesoffset = ( $shelfoff - 1 ) * $shelflimit;    # Sets the offset to begin retrieving shelves at (offset)
88
    }
89
90
    # getting the Shelves list
91
    my $category = ( ( $displaymode eq 'privateshelves' ) ? 1 : 2 );
92
93
    my $shelflist;
94
    if ( $category == 2 ) {
95
        $shelflist = Koha::Virtualshelves->get_public_shelves({ limit => $shelveslimit, offset => $shelvesoffset });
96
    } else {
97
        $shelflist = Koha::Virtualshelves->get_private_shelves({ limit => $shelveslimit, offset => $shelvesoffset, borrowernumber => $loggedinuser });
98
    }
99
    my $totshelves = C4::VirtualShelves::GetShelfCount( $loggedinuser, $category );
100
101
    my $op = $query->param('op');
102
103
    # the format of this is unindented for ease of diff comparison to the old script
104
    # Note: do not mistake the assignment statements below for comparisons!
105
    if ( $query->param('modifyshelfcontents') ) {
106
        my ( $shelfnumber, $barcode, $item, $biblio );
107
        if ( $shelfnumber = $query->param('viewshelf') ) {
108
            #add to shelf
109
            if($barcode = $query->param('addbarcode') ) {
110
                if(ShelfPossibleAction( $loggedinuser, $shelfnumber, 'add')) {
111
                    $item = GetItem( 0, $barcode);
112
                    if (defined $item && $item->{'itemnumber'}) {
113
                        $biblio = GetBiblioFromItemNumber( $item->{'itemnumber'} );
114
                        Koha::Virtualshelves->find( $shelfnumber )->add_biblio( $biblio->{biblionumber}, $loggedinuser )
115
                          or push @paramsloop, { duplicatebiblio => $barcode };
116
                    }
117
                    else {
118
                        push @paramsloop, { failgetitem => $barcode };
119
                    }
120
                }
121
                else {
122
                    push @paramsloop, { nopermission => $shelfnumber };
123
                }
124
            }
125
            elsif(grep { /REM-(\d+)/ } $query->param) {
126
            #remove item(s) from shelf
127
                if(ShelfPossibleAction($loggedinuser, $shelfnumber, 'delete')) {
128
                    my @bib;
129
                    foreach($query->param) {
130
                        /REM-(\d+)/ or next;
131
                        push @bib, $1; #$1 is biblionumber
132
                    }
133
                    my $shelf = Koha::Virtualshelves->find( $shelfnumber );
134
                    my $number_of_biblios_removed = $shelf->remove_biblios( { biblionumbers => \@bib, borrowernumber => $loggedinuser } );
135
                    if( $number_of_biblios_removed == 0) {
136
                        push @paramsloop, {nothingdeleted => $shelfnumber};
137
                    }
138
                    elsif( $number_of_biblios_removed < @bib ) {
139
                        push @paramsloop, {somedeleted => $shelfnumber};
140
                    }
141
                }
142
                else {
143
                    push @paramsloop, { nopermission => $shelfnumber };
144
                }
145
            }
146
        }
147
        else {
148
            push @paramsloop, { noshelfnumber => 1 };
149
        }
150
    }
151
152
    my $showadd = 1;
153
154
    # set the default tab, etc. (for OPAC)
155
    my $shelf_type = ( $query->param('display') ? $query->param('display') : 'publicshelves' );
156
    if ( defined $shelf_type ) {
157
        if ( $shelf_type eq 'privateshelves' ) {
158
            $template->param( showprivateshelves => 1 );
159
        } elsif ( $shelf_type eq 'publicshelves' ) {
160
            $template->param( showpublicshelves => 1 );
161
            $showadd = 0;
162
        } else {
163
            $debug and warn "Invalid 'display' param ($shelf_type)";
164
        }
165
    } elsif ( $loggedinuser == -1 ) {
166
        $template->param( showpublicshelves => 1 );
167
    } else {
168
        $template->param( showprivateshelves => 1 );
169
    }
170
171
    my ( $okmanage, $okview );
172
    my $shelfnumber = $query->param('shelfnumber') || $query->param('viewshelf');
173
    if ($shelfnumber) {
174
        $okmanage = ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' );
175
        $okview   = ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' );
176
    }
177
178
    my $delflag = 0;
179
180
  SWITCH: {
181
        if ($op) {
182
        #Saving modified shelf
183
            if ( $op eq 'modifsave' ) {
184
                unless ($okmanage) {
185
                        push @paramsloop, { nopermission => $shelfnumber };
186
                        last SWITCH;
187
                }
188
                my $shelf = Koha::Virtualshelves->find( $shelfnumber );
189
                $shelf->shelfname($query->param('shelfname'));
190
                $shelf->sortfield($query->param('sortfield'));
191
                $shelf->allow_add($query->param('allow_add'));
192
                $shelf->allow_delete_own($query->param('allow_delete_own'));
193
                $shelf->allow_delete_other($query->param('allow_delete_other'));
194
                if( my $category = $query->param('category')) { #optional
195
                    $shelf->category($category);
196
                }
197
                eval { $shelf->store };
198
                if ( $@ ) {
199
                  push @paramsloop, {modifyfailure => $shelf->{shelfname}};
200
                  last SWITCH;
201
                }
202
203
                if($displaymode eq "viewshelf"){
204
                    print $query->redirect( $pages{$type}->{redirect} . "?viewshelf=$shelfnumber" );
205
                } elsif($displaymode eq "publicshelves"){
206
                    print $query->redirect( $pages{$type}->{redirect} );
207
                } else {
208
                    print $query->redirect( $pages{$type}->{redirect} . "?display=privateshelves" );
209
                }
210
                exit;
211
            }
212
        #Editing a shelf
213
        elsif ( $op eq 'modif' ) {
214
                my $shelf = Koha::Virtualshelves->find( $shelfnumber );
215
                my $member = GetMember( 'borrowernumber' => $shelf->owner );
216
                my $ownername = defined($member) ? $member->{firstname} . " " . $member->{surname} : '';
217
                $template->param(
218
                    edit                => 1,
219
                    display             => $displaymode,
220
                    shelfnumber         => $shelf->shelfnumber,
221
                    shelfname           => $shelf->shelfname,
222
                    owner               => $shelf->owner,
223
                    ownername           => $ownername,
224
                    "category".$shelf->category => 1,
225
                    category            => $shelf->category,
226
                    sortfield           => $shelf->sortfield,
227
                    allow_add           => $shelf->allow_add,
228
                    allow_delete_own    => $shelf->allow_delete_own,
229
                    allow_delete_other  => $shelf->allow_delete_other,
230
                );
231
            }
232
            last SWITCH;
233
        }
234
235
        #View a shelf
236
        if ( $shelfnumber = $query->param('viewshelf') ) {
237
            my $shelf = Koha::Virtualshelves->find( $shelfnumber );
238
            if (C4::Context->preference('TagsEnabled')) {
239
                $template->param(TagsEnabled => 1);
240
                    foreach (qw(TagsShowOnList TagsInputOnList)) {
241
                    C4::Context->preference($_) and $template->param($_ => 1);
242
                }
243
            }
244
            #check that the user can view the shelf
245
            if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' ) ) {
246
                my $items;
247
                my $tag_quantity;
248
                my $sortfield = ( $shelf->sortfield ? $shelf->sortfield : 'title' );
249
                $sortfield = $query->param('sort') || $sortfield; ## Passed in sorting overrides default sorting
250
                my $direction = $query->param('direction') || 'asc';
251
                $template->param(
252
                    sort      => $sortfield,
253
                    direction => $direction,
254
                );
255
                ( $items, $totitems ) = GetShelfContents( $shelfnumber, $shelflimit, $shelfoffset, $sortfield, $direction );
256
257
                # get biblionumbers stored in the cart
258
                # Note that it's not use at the intranet
259
                my @cart_list;
260
                my $cart_cookie = ( $type eq 'opac' ? "bib_list" : "intranet_bib_list" );
261
                if($query->cookie($cart_cookie)){
262
                    my $cart_list = $query->cookie($cart_cookie);
263
                    @cart_list = split(/\//, $cart_list);
264
                }
265
266
                my $borrower = GetMember( 'borrowernumber' => $loggedinuser );
267
268
                for my $this_item (@$items) {
269
                    my $biblionumber = $this_item->{'biblionumber'};
270
                    my $record = GetMarcBiblio($biblionumber);
271
                    if (C4::Context->preference("OPACXSLTResultsDisplay") && $type eq 'opac') {
272
                        $this_item->{XSLTBloc} = XSLTParse4Display($biblionumber, $record, "OPACXSLTResultsDisplay");
273
                    } elsif (C4::Context->preference("XSLTResultsDisplay") && $type eq 'intranet') {
274
                        $this_item->{XSLTBloc} = XSLTParse4Display($biblionumber, $record, "XSLTResultsDisplay");
275
                    }
276
277
                    # the virtualshelfcontents table does not store these columns nor are they retrieved from the items
278
                    # and itemtypes tables, so I'm commenting them out for now to quiet the log -crn
279
                    #$this_item->{imageurl} = $imgdir."/".$itemtypes->{ $this_item->{itemtype}  }->{'imageurl'};
280
                    #$this_item->{'description'} = $itemtypes->{ $this_item->{itemtype} }->{'description'};
281
                    $this_item->{'dateadded'} = format_date( $this_item->{'dateadded'} );
282
                    $this_item->{'imageurl'}  = getitemtypeinfo( $this_item->{'itemtype'}, $type )->{'imageurl'};
283
                    $this_item->{'coins'}     = GetCOinSBiblio( $record );
284
                    $this_item->{'subtitle'} = GetRecordValue('subtitle', $record, GetFrameworkCode($this_item->{'biblionumber'}));
285
                    $this_item->{'normalized_upc'}  = GetNormalizedUPC(       $record,$marcflavour);
286
                    $this_item->{'normalized_ean'}  = GetNormalizedEAN(       $record,$marcflavour);
287
                    $this_item->{'normalized_oclc'} = GetNormalizedOCLCNumber($record,$marcflavour);
288
                    $this_item->{'normalized_isbn'} = GetNormalizedISBN(undef,$record,$marcflavour);
289
                    if(!defined($this_item->{'size'})) { $this_item->{'size'} = "" }; #TT has problems with size
290
                    # Getting items infos for location display
291
                    my @items_infos = &GetItemsLocationInfo( $this_item->{'biblionumber'});
292
                    $this_item->{'itemsissued'} = CountItemsIssued( $this_item->{'biblionumber'} );
293
                    $this_item->{'ITEM_RESULTS'} = \@items_infos;
294
                    if ( grep {$_ eq $biblionumber} @cart_list) {
295
                        $this_item->{'incart'} = 1;
296
                    }
297
298
                    if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnList')) {
299
                        $this_item->{'TagLoop'} = get_tags({
300
                            biblionumber=>$this_item->{'biblionumber'}, approved=>1, 'sort'=>'-weight',
301
                            limit=>$tag_quantity
302
                            });
303
                    }
304
305
                    $this_item->{'allow_onshelf_holds'} = C4::Reserves::OnShelfHoldsAllowed($this_item, $borrower);
306
                }
307
                if($type eq 'intranet'){
308
                    # Build drop-down list for 'Add To:' menu...
309
                    my ($totalref, $pubshelves, $barshelves)=
310
                    C4::VirtualShelves::GetSomeShelfNames($loggedinuser,'COMBO',1);
311
                    $template->param(
312
                        addbarshelves     => $totalref->{bartotal},
313
                        addbarshelvesloop => $barshelves,
314
                        addpubshelves     => $totalref->{pubtotal},
315
                        addpubshelvesloop => $pubshelves,
316
                    );
317
                }
318
                push @paramsloop, { display => 'privateshelves' } if $shelf->category == 1;
319
                $showadd = 1;
320
                my $i = 0;
321
                my $manageshelf = ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' );
322
                my $can_delete_shelf = ShelfPossibleAction( $loggedinuser, $shelfnumber, 'delete_shelf' );
323
                $template->param(
324
                    shelfname           => $shelf->shelfname,
325
                    shelfnumber         => $shelfnumber,
326
                    viewshelf           => $shelfnumber,
327
                    sortfield           => $sortfield,
328
                    manageshelf         => $manageshelf,
329
                    allowremovingitems  => ShelfPossibleAction( $loggedinuser, $shelfnumber, 'delete'),
330
                    allowaddingitem     => ShelfPossibleAction( $loggedinuser, $shelfnumber, 'add'),
331
                    allowdeletingshelf  => $can_delete_shelf,
332
                    "category".$shelf->category => 1,
333
                    category            => $shelf->category,
334
                    itemsloop           => $items,
335
                    showprivateshelves  => $shelf->category==1,
336
                );
337
            } else {
338
                push @paramsloop, { nopermission => $shelfnumber };
339
            }
340
            last SWITCH;
341
        }
342
343
        if ( $query->param('shelves') ) {
344
            my $stay = 1;
345
346
            #Add a shelf
347
            my $shelfname = $query->param('addshelf');
348
349
            if ( $shelfname ) {
350
351
                # note: a user can always add a new shelf (except database administrator account)
352
                my $shelf = eval {
353
                    Koha::Virtualshelf->new(
354
                        {
355
                            shelfname          => $shelfname,
356
                            sortfield          => $query->param('sortfield'),
357
                            category           => $query->param('category'),
358
                            allow_add          => $query->param('allow_add'),
359
                            allow_delete_own   => $query->param('allow_delete_own'),
360
                            allow_delete_other => $query->param('allow_delete_other'),
361
                            owner              => $query->param('owner'),
362
                        }
363
                    )->store;
364
                };
365
                if ( $@ ) {
366
                    $showadd = 1;
367
                    push @messages, { type => 'error', code => ref($@) };
368
                } elsif ( not $shelf ) {
369
                    $showadd = 1;
370
                    push @messages, { type => 'error', 'error_on_insert' };
371
                } else {
372
                    print $query->redirect( $pages{$type}->{redirect} . "?viewshelf=$shelfnumber" );
373
                    exit;
374
                }
375
376
                $template->param(
377
                    shelfname => $shelfname,
378
                );
379
                $stay = 1;
380
            }
381
382
        #Deleting a shelf (asking for confirmation if it has entries)
383
            foreach ( $query->param() ) {
384
                /(DEL|REMSHR)-(\d+)/ or next;
385
                $delflag = 1;
386
                my $number = $2;
387
                unless ( defined $shelflist->{$number} ) {
388
                    push( @paramsloop, { unrecognized => $number } );
389
                    last;
390
                }
391
                #remove a share
392
                if(/REMSHR/) {
393
                    my $shelf = Koha::Virtualshelves->find( $number );
394
                    $shelf->delete_share( $loggedinuser );
395
                    delete $shelflist->{$number} if exists $shelflist->{$number};
396
                    $stay=0;
397
                    next;
398
                }
399
400
                my $can_manage = ShelfPossibleAction( $loggedinuser, $number, 'manage' );
401
                my $can_delete = ShelfPossibleAction( $loggedinuser, $number, 'delete_shelf' );
402
                unless ( $can_manage or $can_delete ) {
403
                    push( @paramsloop, { nopermission => $shelfnumber } );
404
                    last;
405
                }
406
                my $contents;
407
                ( $contents, $totshelves ) = GetShelfContents( $number, $shelveslimit, $shelvesoffset );
408
                if ( $totshelves > 0 ) {
409
                    unless ( scalar grep { /^CONFIRM-$number$/ } $query->param() ) {
410
                        if ( defined $shelflist->{$number} ) {
411
                            push( @paramsloop, { need_confirm => $shelflist->{$number}->{shelfname}, count => $totshelves, single => ($totshelves eq 1 ? 1:0) } );
412
                            $shelflist->{$number}->{confirm} = $number;
413
                        }
414
                        $stay = 0;
415
                        next;
416
                    }
417
                }
418
                my $name;
419
                if ( defined $shelflist->{$number} ) {
420
                    $name = $shelflist->{$number}->{'shelfname'};
421
                    delete $shelflist->{$number};
422
                }
423
                unless( Koha::Virtualshelves->find($number)->delete ) {
424
                    push( @paramsloop, { delete_fail => $name } );
425
                    last;
426
                }
427
                push( @paramsloop, { delete_ok => $name } );
428
429
                $stay = 0;
430
            }
431
            $showadd = 1;
432
            if ($stay){
433
                $template->param( shelves => 1 );
434
                $shelves = 1;
435
            }
436
            last SWITCH;
437
        }
438
    } # end of SWITCH block
439
440
    (@paramsloop) and $template->param( paramsloop => \@paramsloop );
441
    $showadd      and $template->param( showadd    => 1 );
442
    my @shelvesloop;
443
    my @shelveslooppriv;
444
    my $numberCanManage = 0;
445
446
    # rebuild shelflist in case a shelf has been added
447
    unless ( $delflag ) {
448
        if ( $category == 2 ) {
449
            $shelflist = Koha::Virtualshelves->get_public_shelves({ limit => $shelveslimit, offset => $shelvesoffset });
450
        } else {
451
            $shelflist = Koha::Virtualshelves->get_private_shelves({ limit => $shelveslimit, offset => $shelvesoffset, borrowernumber => $loggedinuser });
452
        }
453
    }
454
455
    $totshelves = C4::VirtualShelves::GetShelfCount( $loggedinuser, $category ) unless $delflag;
456
    foreach my $element ( sort { lc( $shelflist->{$a}->{'shelfname'} ) cmp lc( $shelflist->{$b}->{'shelfname'} ) } keys %$shelflist ) {
457
        my %line;
458
        $shelflist->{$element}->{shelf} = $element;
459
        my $category  = $shelflist->{$element}->{'category'};
460
        my $owner     = $shelflist->{$element}->{'owner'}||0;
461
        my $canmanage = ShelfPossibleAction( $loggedinuser, $element, 'manage' );
462
        my $candelete = ShelfPossibleAction( $loggedinuser, $element, 'delete_shelf' );
463
        $shelflist->{$element}->{"viewcategory$category"} = 1;
464
        $shelflist->{$element}->{manageshelf} = $canmanage;
465
        $shelflist->{$element}->{allowdeletingshelf} = $candelete;
466
        if($canmanage || ($loggedinuser && $owner==$loggedinuser)) {
467
            $shelflist->{$element}->{'mine'} = 1;
468
        }
469
        my $member = GetMember( 'borrowernumber' => $owner );
470
        $shelflist->{$element}->{ownername} = defined($member) ? $member->{firstname} . " " . $member->{surname} : '';
471
        $numberCanManage++ if $canmanage;    # possibly outmoded
472
        if ( $shelflist->{$element}->{'category'} eq '1' ) {
473
            my $shelf = Koha::Virtualshelves->find( $element );
474
            $shelflist->{$element}->{shares} = $shelf->is_shared;
475
            push( @shelveslooppriv, $shelflist->{$element} );
476
        } else {
477
            push( @shelvesloop, $shelflist->{$element} );
478
        }
479
    }
480
481
    my $url = $type eq 'opac' ? "/cgi-bin/koha/opac-shelves.pl" : "/cgi-bin/koha/virtualshelves/shelves.pl";
482
    my %qhash = ();
483
    foreach (qw(display viewshelf sortfield sort direction)) {
484
        $qhash{$_} = $query->param($_) if $query->param($_);
485
    }
486
    ( scalar keys %qhash ) and $url .= '?' . join '&', map { "$_=$qhash{$_}" } keys %qhash;
487
    if ( $shelflimit ) {
488
        if ( $shelfnumber && $totitems ) {
489
            $template->param(  pagination_bar => pagination_bar( $url, ( int( $totitems / $shelflimit ) ) + ( ( $totitems % $shelflimit ) > 0 ? 1 : 0 ), $itemoff, "itemoff" )  );
490
        } elsif ( $totshelves ) {
491
            $template->param(
492
                 pagination_bar => pagination_bar( $url, ( int( $totshelves / $shelveslimit ) ) + ( ( $totshelves % $shelveslimit ) > 0 ? 1 : 0 ), $shelfoff, "shelfoff" )  );
493
        }
494
    }
495
496
    $template->param(
497
        shelveslooppriv                                                    => \@shelveslooppriv,
498
        shelvesloop                                                        => \@shelvesloop,
499
        shelvesloopall                                                     => [ ( @shelvesloop, @shelveslooppriv ) ],
500
        numberCanManage                                                    => $numberCanManage,
501
        "BiblioDefaultView" . C4::Context->preference("BiblioDefaultView") => 1,
502
        csv_profiles                                                       => GetCsvProfilesLoop('marc')
503
    );
504
505
#Next call updates the shelves for the Lists button.
506
#May not always be needed (when nothing changed), but doesn't take much.
507
    my ($total, $pubshelves, $barshelves) = C4::VirtualShelves::GetSomeShelfNames($loggedinuser, 'MASTHEAD');
508
    $template->param(
509
            barshelves     => $total->{bartotal},
510
            barshelvesloop => $barshelves,
511
            pubshelves     => $total->{pubtotal},
512
            pubshelvesloop => $pubshelves,
513
            messages       => \@messages,
514
    );
515
516
    output_html_with_http_headers $query, $cookie, $template->output;
517
}
518
519
1;
520
__END__
521
522
=head1 NAME
523
524
VirtualShelves/Page.pm
525
526
=head1 DESCRIPTION
527
528
Module used for both OPAC and intranet pages.
529
530
=head1 CGI PARAMETERS
531
532
=over 4
533
534
=item C<modifyshelfcontents>
535
536
If this script has to modify the shelf content.
537
538
=item C<shelfnumber>
539
540
To know on which shelf to work.
541
542
=item C<addbarcode>
543
544
=item C<op>
545
546
 Op can be:
547
    * modif: show the template allowing modification of the shelves;
548
    * modifsave: save changes from modif mode.
549
550
=item C<viewshelf>
551
552
Load template with 'viewshelves param' displaying the shelf's information.
553
554
=item C<shelves>
555
556
If the param shelves == 1, then add or delete a shelf.
557
558
=item C<addshelf>
559
560
If the param shelves == 1, then addshelf is the name of the shelf to add.
561
562
=back
563
564
=cut
(-)a/basket/downloadcart.pl (-1 lines)
Lines 27-33 use C4::Auth; Link Here
27
use C4::Biblio;
27
use C4::Biblio;
28
use C4::Items;
28
use C4::Items;
29
use C4::Output;
29
use C4::Output;
30
use C4::VirtualShelves;
31
use C4::Record;
30
use C4::Record;
32
use C4::Ris;
31
use C4::Ris;
33
use C4::Csv;
32
use C4::Csv;
(-)a/catalogue/detail.pl (-1 lines)
Lines 36-42 use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn); Link Here
36
use C4::External::Amazon;
36
use C4::External::Amazon;
37
use C4::Search;		# enabled_staff_search_views
37
use C4::Search;		# enabled_staff_search_views
38
use C4::Tags qw(get_tags);
38
use C4::Tags qw(get_tags);
39
use C4::VirtualShelves;
40
use C4::XSLT;
39
use C4::XSLT;
41
use C4::Images;
40
use C4::Images;
42
use Koha::DateUtils;
41
use Koha::DateUtils;
(-)a/catalogue/search.pl (-1 lines)
Lines 147-153 use C4::Search; Link Here
147
use C4::Languages qw(getLanguages);
147
use C4::Languages qw(getLanguages);
148
use C4::Koha;
148
use C4::Koha;
149
use C4::Members qw(GetMember);
149
use C4::Members qw(GetMember);
150
use C4::VirtualShelves;
151
use URI::Escape;
150
use URI::Escape;
152
use POSIX qw(ceil floor);
151
use POSIX qw(ceil floor);
153
use C4::Branch; # GetBranches
152
use C4::Branch; # GetBranches
(-)a/opac/opac-addbybiblionumber.pl (-1 lines)
Lines 24-30 use warnings; Link Here
24
24
25
use CGI qw ( -utf8 );
25
use CGI qw ( -utf8 );
26
use C4::Biblio;
26
use C4::Biblio;
27
use C4::VirtualShelves qw/:DEFAULT/;
28
use C4::Output;
27
use C4::Output;
29
use C4::Auth;
28
use C4::Auth;
30
29
(-)a/opac/opac-detail.pl (-1 lines)
Lines 40-46 use C4::External::Syndetics qw(get_syndetics_index get_syndetics_summary get_syn Link Here
40
use C4::Review;
40
use C4::Review;
41
use C4::Ratings;
41
use C4::Ratings;
42
use C4::Members;
42
use C4::Members;
43
use C4::VirtualShelves;
44
use C4::XSLT;
43
use C4::XSLT;
45
use C4::ShelfBrowser;
44
use C4::ShelfBrowser;
46
use C4::Reserves;
45
use C4::Reserves;
(-)a/opac/opac-downloadcart.pl (-1 lines)
Lines 27-33 use C4::Auth; Link Here
27
use C4::Biblio;
27
use C4::Biblio;
28
use C4::Items;
28
use C4::Items;
29
use C4::Output;
29
use C4::Output;
30
use C4::VirtualShelves;
31
use C4::Record;
30
use C4::Record;
32
use C4::Ris;
31
use C4::Ris;
33
use C4::Csv;
32
use C4::Csv;
(-)a/opac/opac-downloadshelf.pl (-1 lines)
Lines 27-33 use C4::Auth; Link Here
27
use C4::Biblio;
27
use C4::Biblio;
28
use C4::Items;
28
use C4::Items;
29
use C4::Output;
29
use C4::Output;
30
use C4::VirtualShelves;
31
use C4::Record;
30
use C4::Record;
32
use C4::Ris;
31
use C4::Ris;
33
use C4::Csv;
32
use C4::Csv;
(-)a/opac/opac-sendshelf.pl (-1 lines)
Lines 31-37 use C4::Auth; Link Here
31
use C4::Biblio;
31
use C4::Biblio;
32
use C4::Items;
32
use C4::Items;
33
use C4::Output;
33
use C4::Output;
34
use C4::VirtualShelves;
35
use C4::Members;
34
use C4::Members;
36
use Koha::Email;
35
use Koha::Email;
37
use Koha::Virtualshelves;
36
use Koha::Virtualshelves;
(-)a/opac/opac-shareshelf.pl (-1 lines)
Lines 32-38 use C4::Context; Link Here
32
use C4::Letters;
32
use C4::Letters;
33
use C4::Members ();
33
use C4::Members ();
34
use C4::Output;
34
use C4::Output;
35
use C4::VirtualShelves;
36
35
37
use Koha::Virtualshelves;
36
use Koha::Virtualshelves;
38
use Koha::Virtualshelfshares;
37
use Koha::Virtualshelfshares;
(-)a/opac/opac-shelves.pl (-1 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use CGI qw ( -utf8 );
21
use CGI qw ( -utf8 );
22
use C4::VirtualShelves;
23
use C4::Auth;
22
use C4::Auth;
24
use C4::Biblio;
23
use C4::Biblio;
25
use C4::Koha;
24
use C4::Koha;
(-)a/t/db_dependent/Utils/Datatables_Virtualshelves.t (-2 lines)
Lines 24-31 use C4::Context; Link Here
24
use C4::Branch;
24
use C4::Branch;
25
use C4::Members;
25
use C4::Members;
26
26
27
use C4::VirtualShelves;
28
29
use Koha::Virtualshelf;
27
use Koha::Virtualshelf;
30
use Koha::Virtualshelves;
28
use Koha::Virtualshelves;
31
29
(-)a/t/db_dependent/VirtualShelves_Page.t (-14 lines)
Lines 1-14 Link Here
1
#!/usr/bin/perl
2
#
3
# This Koha test module is a stub!  
4
# Add more tests here!!!
5
6
use strict;
7
use warnings;
8
9
use Test::More tests => 1;
10
11
BEGIN {
12
        use_ok('C4::VirtualShelves::Page');
13
}
14
(-)a/virtualshelves/addbybiblionumber.pl (-1 lines)
Lines 64-70 use warnings; Link Here
64
use CGI qw ( -utf8 );
64
use CGI qw ( -utf8 );
65
use C4::Biblio;
65
use C4::Biblio;
66
use C4::Output;
66
use C4::Output;
67
use C4::VirtualShelves qw/:DEFAULT/;
68
use C4::Auth;
67
use C4::Auth;
69
68
70
use Koha::Virtualshelves;
69
use Koha::Virtualshelves;
(-)a/virtualshelves/downloadshelf.pl (-1 lines)
Lines 27-33 use C4::Auth; Link Here
27
use C4::Biblio;
27
use C4::Biblio;
28
use C4::Items;
28
use C4::Items;
29
use C4::Output;
29
use C4::Output;
30
use C4::VirtualShelves;
31
use C4::Record;
30
use C4::Record;
32
use C4::Ris;
31
use C4::Ris;
33
use C4::Csv;
32
use C4::Csv;
(-)a/virtualshelves/sendshelf.pl (-1 lines)
Lines 31-37 use C4::Auth; Link Here
31
use C4::Biblio;
31
use C4::Biblio;
32
use C4::Items;
32
use C4::Items;
33
use C4::Output;
33
use C4::Output;
34
use C4::VirtualShelves;
35
use Koha::Email;
34
use Koha::Email;
36
use Koha::Virtualshelves;
35
use Koha::Virtualshelves;
37
36
(-)a/virtualshelves/shelves.pl (-2 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use CGI qw ( -utf8 );
21
use CGI qw ( -utf8 );
22
use C4::VirtualShelves;
23
use C4::Auth;
22
use C4::Auth;
24
use C4::Biblio;
23
use C4::Biblio;
25
use C4::Csv;
24
use C4::Csv;
26
- 

Return to bug 14544