3 # Copyright 2000-2002 Katipo Communications
4 # Copyright 2016 Koha Development Team
6 # This file is part of Koha.
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.
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.
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>.
29 use Koha
::Virtualshelves
;
32 my @biblionumbers = $query->multi_param('biblionumber');
33 my $selectedshelf = $query->param('selectedshelf');
34 my $newshelf = $query->param('newshelf');
35 my $shelfnumber = $query->param('shelfnumber');
36 my $newvirtualshelf = $query->param('newvirtualshelf');
37 my $category = $query->param('category');
38 my ( $errcode, $authorized ) = ( 0, 1 );
41 # if virtualshelves is disabled, leave immediately
42 if ( !C4
::Context
->preference('virtualshelves') ) {
43 print $query->redirect("/cgi-bin/koha/errors/404.pl");
47 if ( scalar(@biblionumbers) == 1 ) {
48 @biblionumbers = ( split /\//, $biblionumbers[0] );
51 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
52 { template_name
=> "opac-addbybiblionumber.tt",
58 if ($newvirtualshelf) {
61 or $category == 2 and $loggedinuser > 0 && C4
::Context
->preference('OpacAllowPublicListCreation') )
63 my $shelf = eval { Koha
::Virtualshelf
->new( { shelfname
=> $newvirtualshelf, category
=> $category, owner
=> $loggedinuser, } )->store; };
64 if ( $@
or not $shelf ) {
68 for my $biblionumber (@biblionumbers) {
69 $shelf->add_biblio( $biblionumber, $loggedinuser );
72 #Reload the page where you came from
74 print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
78 } elsif ($shelfnumber) {
79 my $shelfnumber = $query->param('shelfnumber');
80 my $shelf = Koha
::Virtualshelves
->find($shelfnumber);
81 if ( $shelf->can_biblios_be_added($loggedinuser) ) {
82 for my $biblionumber (@biblionumbers) {
83 $shelf->add_biblio( $biblionumber, $loggedinuser );
86 #Close this page and return
88 print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
93 } elsif ($selectedshelf) {
94 my $shelfnumber = $query->param('selectedshelf');
95 my $shelf = Koha
::Virtualshelves
->find($shelfnumber);
96 if ( $shelf->can_biblios_be_added($loggedinuser) ) {
99 shelfnumber
=> $shelf->shelfnumber,
100 shelfname
=> $shelf->shelfname,
106 if ( $loggedinuser > 0 ) {
107 my $private_shelves = Koha
::Virtualshelves
->search(
109 owner
=> $loggedinuser,
110 allow_change_from_owner
=> 1,
112 { order_by
=> 'shelfname' }
114 my $shelves_shared_with_me = Koha
::Virtualshelves
->search(
116 'virtualshelfshares.borrowernumber' => $loggedinuser,
117 allow_change_from_others
=> 1,
119 { join => 'virtualshelfshares', }
121 my $public_shelves = Koha
::Virtualshelves
->search(
125 allow_change_from_owner
=> 1,
126 owner
=> $loggedinuser,
128 allow_change_from_others
=> 1,
131 { order_by
=> 'shelfname' }
134 private_shelves
=> $private_shelves,
135 private_shelves_shared_with_me
=> $shelves_shared_with_me,
136 public_shelves
=> $public_shelves,
144 for my $biblionumber (@biblionumbers) {
145 my $biblio = Koha
::Biblios
->find( $biblionumber );
148 { biblionumber
=> $biblionumber,
149 title
=> $biblio->title,
150 subtitle
=> $biblio->subtitle,
151 medium
=> $biblio->medium,
152 part_number
=> $biblio->part_number,
153 part_name
=> $biblio->part_name,
154 author
=> $biblio->author,
159 multiple
=> ( scalar(@biblios) > 1 ),
160 total
=> scalar @biblios,
161 biblios
=> \
@biblios,
165 newshelf
=> $newshelf || 0,
166 OpacAllowPublicListCreation
=> C4
::Context
->preference('OpacAllowPublicListCreation'),
169 $template->param( authorized
=> $authorized, errcode
=> $errcode, );
170 output_html_with_http_headers
$query, $cookie, $template->output, undef, { force_no_caching
=> 1 };