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>.
28 This script allow to add a virtual in a virtual shelf from a biblionumber.
40 the shelfnumber where to add the virtual.
44 if this parameter exists, then it must be equals to the name of the shelf
49 if this script has to add a shelf, it adds one with this 'public' setting.
53 if this parameter exists, then we create a new shelf
62 use C4::Output qw( output_html_with_http_headers );
63 use C4::Auth qw( get_template_and_user );
66 use Koha::Virtualshelves;
69 my $shelfnumber = $query->param('shelfnumber');
70 my $newvirtualshelf = $query->param('newvirtualshelf');
71 my $newshelf = $query->param('newshelf');
72 my $public = $query->param('public');
73 my $sortfield = $query->param('sortfield');
74 my $confirmed = $query->param('confirmed') || 0;
75 my ( $errcode, $authorized ) = ( 0, 1 );
76 my @biblionumbers = $query->multi_param('biblionumber');
78 if ( @biblionumbers == 0 && $query->param('biblionumbers') ) {
79 my $str = $query->param('biblionumbers');
80 @biblionumbers = split '/', $str;
81 } elsif ( @biblionumbers == 1 && $biblionumbers[0] =~ /\// ) {
82 @biblionumbers = split '/', $biblionumbers[0];
85 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
86 { template_name => "virtualshelves/addbybiblionumber.tt",
89 flagsrequired => { catalogue => 1 },
93 if ($newvirtualshelf) {
95 Koha::Virtualshelf->new(
97 shelfname => $newvirtualshelf,
99 sortfield => $sortfield,
100 owner => $loggedinuser,
104 if ( $@ or not $shelf ) {
109 for my $biblionumber (@biblionumbers) {
110 $shelf->add_biblio( $biblionumber, $loggedinuser );
113 #Reload the page where you came from
114 print $query->header;
115 print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
119 } elsif ( $shelfnumber && $confirmed ) {
120 my $shelf = Koha::Virtualshelves->find($shelfnumber);
121 if ( $shelf->can_biblios_be_added($loggedinuser) ) {
122 for my $biblionumber (@biblionumbers) {
123 $shelf->add_biblio( $biblionumber, $loggedinuser );
126 #Close this page and return
127 print $query->header;
128 print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
131 $errcode = 2; #no perm
135 } elsif ($shelfnumber) { #still needs confirmation
136 my $shelf = Koha::Virtualshelves->find($shelfnumber);
137 if ( $shelf->can_biblios_be_added($loggedinuser) ) {
139 #confirm adding to specific shelf
142 shelfnumber => $shelf->shelfnumber,
143 shelfname => $shelf->shelfname,
147 $errcode = 2; #no perm
151 my $private_shelves = Koha::Virtualshelves->search(
153 owner => $loggedinuser,
154 allow_change_from_owner => 1,
156 { order_by => 'shelfname' }
158 my $shelves_shared_with_me = Koha::Virtualshelves->search(
160 'virtualshelfshares.borrowernumber' => $loggedinuser,
161 allow_change_from_others => 1,
163 { join => 'virtualshelfshares', }
165 my $public_shelves = Koha::Virtualshelves->search(
169 allow_change_from_owner => 1,
170 owner => $loggedinuser,
172 allow_change_from_others => 1,
173 allow_change_from_staff => 1,
176 { order_by => 'shelfname' }
179 private_shelves => $private_shelves,
180 private_shelves_shared_with_me => $shelves_shared_with_me,
181 public_shelves => $public_shelves,
187 for my $biblionumber (@biblionumbers) {
188 my $biblio = Koha::Biblios->find( $biblionumber );
191 { biblionumber => $biblionumber,
192 title => $biblio->title,
193 author => $biblio->author,
198 multiple => ( scalar(@biblios) > 1 ),
199 total => scalar @biblios,
200 biblios => \@biblios,
204 newshelf => $newshelf || 0,
205 authorized => $authorized,
208 output_html_with_http_headers $query, $cookie, $template->output;