3 #script to provide virtualshelf management
5 # Copyright 2000-2002 Katipo Communications
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
27 use C4::VirtualShelves qw/:DEFAULT/;
31 use Koha::Virtualshelves;
34 our @biblionumber = $query->param('biblionumber');
35 our $selectedshelf = $query->param('selectedshelf');
36 our $newshelf = $query->param('newshelf');
37 our $shelfnumber = $query->param('shelfnumber');
38 our $newvirtualshelf = $query->param('newvirtualshelf');
39 our $category = $query->param('category');
45 if (scalar(@biblionumber) == 1) {
46 @biblionumber = (split /\//,$biblionumber[0]);
49 our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
51 template_name => "opac-addbybiblionumber.tt",
58 if( $newvirtualshelf) {
59 HandleNewVirtualShelf();
61 ShowTemplate(); #error message
66 ShowTemplate(); #error message
68 elsif($selectedshelf) {
69 HandleSelectedShelf();
70 LoadBib() if $authorized;
75 LoadBib() if $authorized;
80 sub HandleNewVirtualShelf {
81 if ( $loggedinuser > 0 and
84 or $category == 2 and $loggedinuser>0 && C4::Context->preference('OpacAllowPublicListCreation')
88 Koha::Virtualshelf->new(
90 shelfname => $newvirtualshelf,
91 category => $category,
92 owner => $loggedinuser,
96 if ( $@ or not $shelf ) {
102 for my $bib (@biblionumber) {
103 $shelf->add_biblio( $bib, $loggedinuser );
106 #Reload the page where you came from
107 print $query->header;
108 print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
112 sub HandleShelfNumber {
113 my $shelfnumber = $query->param('shelfnumber');
114 my $shelf = Koha::Virtualshelves->find( $shelfnumber );
115 if ( $shelf->can_biblios_be_added( $loggedinuser ) ) {
116 for my $bib (@biblionumber) {
117 $shelf->add_biblio( $bib, $loggedinuser );
119 #Close this page and return
120 print $query->header;
121 print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
127 sub HandleSelectedShelf {
128 my $shelfnumber = $query->param('selectedshelf');
129 my $shelf = Koha::Virtualshelves->find( $shelfnumber );
130 if ( $shelf->can_biblios_be_added( $loggedinuser ) ) {
133 shelfnumber => $shelf->shelfnumber,
134 shelfname => $shelf->shelfname,
142 return unless $authorized= $loggedinuser>0;
143 my $private_shelves = Koha::Virtualshelves->search(
146 owner => $loggedinuser,
148 { order_by => 'shelfname' }
150 my $shelves_shared_with_me = Koha::Virtualshelves->search(
153 'virtualshelfshares.borrowernumber' => $loggedinuser,
156 owner => $loggedinuser,
160 join => 'virtualshelfshares',
163 my $public_shelves= Koha::Virtualshelves->search(
168 owner => $loggedinuser,
171 { order_by => 'shelfname' }
174 private_shelves => $private_shelves,
175 private_shelves_shared_with_me => $shelves_shared_with_me,
176 public_shelves => $public_shelves,
181 for my $bib (@biblionumber) {
182 my $data = GetBiblioData( $bib );
184 { biblionumber => $bib,
185 title => $data->{'title'},
186 author => $data->{'author'},
190 multiple => (scalar(@biblios) > 1),
191 total => scalar @biblios,
192 biblios => \@biblios,
198 newshelf => $newshelf||0,
199 authorized => $authorized,
201 OpacAllowPublicListCreation => C4::Context->preference('OpacAllowPublicListCreation'),
203 output_html_with_http_headers $query, $cookie, $template->output;