3 #script to provide virtual shelf management
6 # Copyright 2000-2002 Katipo Communications
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
30 This script allow to add a virtual in a virtual shelf from a biblionumber.
42 the shelfnumber where to add the virtual.
46 if this parameter exists, then it must be equals to the name of the shelf
51 if this script has to add a shelf, it add one with this category.
55 if this parameter exists, then we create a new shelf
67 use C4::VirtualShelves qw/:DEFAULT/;
70 use Koha::Virtualshelves;
73 our @biblionumber = HandleBiblioPars();
74 our $shelfnumber = $query->param('shelfnumber');
75 our $newvirtualshelf = $query->param('newvirtualshelf');
76 our $newshelf = $query->param('newshelf');
77 our $category = $query->param('category');
78 our $sortfield = $query->param('sortfield');
79 my $confirmed = $query->param('confirmed') || 0;
83 our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
85 template_name => "virtualshelves/addbybiblionumber.tt",
89 flagsrequired => { catalogue => 1 },
93 if( $newvirtualshelf) {
94 HandleNewVirtualShelf();
96 ShowTemplate(); #error message
98 elsif($shelfnumber && $confirmed) {
101 ShowTemplate(); #error message
103 elsif($shelfnumber) { #still needs confirmation
104 HandleSelectedShelf();
105 LoadBib() if $authorized;
115 sub HandleBiblioPars {
116 my @bib= $query->param('biblionumber');
117 if(@bib==0 && $query->param('biblionumbers')) {
118 my $str= $query->param('biblionumbers');
119 @bib= split '/', $str;
121 elsif(@bib==1 && $bib[0]=~/\//) {
122 @bib= split '/', $bib[0];
127 sub AddBibliosToShelf {
128 my ($shelfnumber, @biblionumber)=@_;
129 for my $bib (@biblionumber){
130 AddToShelf($bib, $shelfnumber, $loggedinuser);
134 sub HandleNewVirtualShelf {
136 Koha::Virtualshelf->new(
138 shelfname => $newvirtualshelf,
139 category => $category,
140 sortfield => $sortfield,
141 owner => $loggedinuser,
145 if ( $@ or not $shelf ) {
151 AddBibliosToShelf($shelfnumber, @biblionumber);
152 #Reload the page where you came from
153 print $query->header;
154 print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
157 sub HandleShelfNumber {
158 if($authorized= ShelfPossibleAction($loggedinuser, $shelfnumber, 'add')) {
159 AddBibliosToShelf($shelfnumber, @biblionumber);
160 #Close this page and return
161 print $query->header;
162 print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
169 sub HandleSelectedShelf {
170 if($authorized= ShelfPossibleAction( $loggedinuser, $shelfnumber, 'add')){
171 #confirm adding to specific shelf
172 my $shelf = Koha::Virtualshelves->find( $shelfnumber );
175 shelfnumber => $shelf->shelfnumber,
176 shelfname => $shelf->shelfname,
185 my $private_shelves = Koha::Virtualshelves->search(
188 owner => $loggedinuser,
190 { order_by => 'shelfname' }
192 my $shelves_shared_with_me = Koha::Virtualshelves->search(
195 'virtualshelfshares.borrowernumber' => $loggedinuser,
198 owner => $loggedinuser,
202 join => 'virtualshelfshares',
205 my $public_shelves= Koha::Virtualshelves->search(
210 owner => $loggedinuser,
213 { order_by => 'shelfname' }
216 private_shelves => $private_shelves,
217 private_shelves_shared_with_me => $shelves_shared_with_me,
218 public_shelves => $public_shelves,
224 for my $bib (@biblionumber) {
225 my $data = GetBiblioData($bib);
227 { biblionumber => $bib,
228 title => $data->{'title'},
229 author => $data->{'author'},
233 multiple => (scalar(@biblios) > 1),
234 total => scalar @biblios,
235 biblios => \@biblios,
241 newshelf => $newshelf||0,
242 authorized => $authorized,
245 output_html_with_http_headers $query, $cookie, $template->output;