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>.
24 use C4::Output qw( output_html_with_http_headers );
25 use C4::Auth qw( get_template_and_user );
28 use Koha::Virtualshelves;
31 my $op = $query->param('op') // q{};
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 $public = $query->param('public');
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( $op && $op !~ /^cud-/ ) {
60 } elsif ($newvirtualshelf) {
63 or $public and $loggedinuser > 0 && C4::Context->preference('OpacAllowPublicListCreation') )
65 my $shelf = eval { Koha::Virtualshelf->new( { shelfname => $newvirtualshelf, public => $public, owner => $loggedinuser, } )->store; };
66 if ( $@ or not $shelf ) {
70 for my $biblionumber (@biblionumbers) {
71 $shelf->add_biblio( $biblionumber, $loggedinuser );
74 #Reload the page where you came from
76 print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
80 } elsif ($shelfnumber) {
81 my $shelfnumber = $query->param('shelfnumber');
82 my $shelf = Koha::Virtualshelves->find($shelfnumber);
83 if ( $shelf->can_biblios_be_added($loggedinuser) ) {
84 for my $biblionumber (@biblionumbers) {
85 $shelf->add_biblio( $biblionumber, $loggedinuser );
88 #Close this page and return
90 print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
95 } elsif ($selectedshelf) {
96 my $shelfnumber = $query->param('selectedshelf');
97 my $shelf = Koha::Virtualshelves->find($shelfnumber);
98 if ( $shelf->can_biblios_be_added($loggedinuser) ) {
101 shelfnumber => $shelf->shelfnumber,
102 shelfname => $shelf->shelfname,
108 if ( $loggedinuser > 0 ) {
109 my $private_shelves = Koha::Virtualshelves->search(
111 owner => $loggedinuser,
112 allow_change_from_owner => 1,
114 { order_by => 'shelfname' }
116 my $shelves_shared_with_me = Koha::Virtualshelves->search(
118 'virtualshelfshares.borrowernumber' => $loggedinuser,
119 allow_change_from_others => 1,
121 { join => 'virtualshelfshares', }
124 if ( $loggedinuser ) {
125 if ( Koha::Patrons->find( $loggedinuser )->can_patron_change_permitted_staff_lists ) {
126 $public_shelves = Koha::Virtualshelves->search(
130 allow_change_from_owner => 1,
131 owner => $loggedinuser,
133 allow_change_from_others => 1,
134 allow_change_from_staff => 1,
135 allow_change_from_permitted_staff => 1
138 { order_by => 'shelfname' }
140 } elsif ( Koha::Patrons->find( $loggedinuser )->can_patron_change_staff_only_lists ) {
141 $public_shelves = Koha::Virtualshelves->search(
145 allow_change_from_owner => 1,
146 owner => $loggedinuser,
148 allow_change_from_others => 1,
149 allow_change_from_staff => 1
152 { order_by => 'shelfname' }
155 $public_shelves = Koha::Virtualshelves->search(
159 allow_change_from_owner => 1,
160 owner => $loggedinuser,
162 allow_change_from_others => 1,
165 {order_by => 'shelfname' }
169 $public_shelves = Koha::Virtualshelves->search(
173 allow_change_from_owner => 1,
174 owner => $loggedinuser,
176 allow_change_from_others => 1,
179 {order_by => 'shelfname' }
184 private_shelves => $private_shelves,
185 private_shelves_shared_with_me => $shelves_shared_with_me,
186 public_shelves => $public_shelves,
194 for my $biblionumber (@biblionumbers) {
195 my $biblio = Koha::Biblios->find( $biblionumber );
198 { biblionumber => $biblionumber,
199 title => $biblio->title,
200 subtitle => $biblio->subtitle,
201 medium => $biblio->medium,
202 part_number => $biblio->part_number,
203 part_name => $biblio->part_name,
204 author => $biblio->author,
209 multiple => ( scalar(@biblios) > 1 ),
210 total => scalar @biblios,
211 biblios => \@biblios,
215 newshelf => $newshelf || 0,
216 OpacAllowPublicListCreation => C4::Context->preference('OpacAllowPublicListCreation'),
219 $template->param( authorized => $authorized, errcode => $errcode, );
220 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };