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>.
30 use Koha::Virtualshelves;
33 our @biblionumber = $query->param('biblionumber');
34 our $selectedshelf = $query->param('selectedshelf');
35 our $newshelf = $query->param('newshelf');
36 our $shelfnumber = $query->param('shelfnumber');
37 our $newvirtualshelf = $query->param('newvirtualshelf');
38 our $category = $query->param('category');
44 if (scalar(@biblionumber) == 1) {
45 @biblionumber = (split /\//,$biblionumber[0]);
48 our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
50 template_name => "opac-addbybiblionumber.tt",
57 if( $newvirtualshelf) {
58 HandleNewVirtualShelf();
60 ShowTemplate(); #error message
65 ShowTemplate(); #error message
67 elsif($selectedshelf) {
68 HandleSelectedShelf();
69 LoadBib() if $authorized;
74 LoadBib() if $authorized;
79 sub HandleNewVirtualShelf {
80 if ( $loggedinuser > 0 and
83 or $category == 2 and $loggedinuser>0 && C4::Context->preference('OpacAllowPublicListCreation')
87 Koha::Virtualshelf->new(
89 shelfname => $newvirtualshelf,
90 category => $category,
91 owner => $loggedinuser,
95 if ( $@ or not $shelf ) {
101 for my $bib (@biblionumber) {
102 $shelf->add_biblio( $bib, $loggedinuser );
105 #Reload the page where you came from
106 print $query->header;
107 print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
111 sub HandleShelfNumber {
112 my $shelfnumber = $query->param('shelfnumber');
113 my $shelf = Koha::Virtualshelves->find( $shelfnumber );
114 if ( $shelf->can_biblios_be_added( $loggedinuser ) ) {
115 for my $bib (@biblionumber) {
116 $shelf->add_biblio( $bib, $loggedinuser );
118 #Close this page and return
119 print $query->header;
120 print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
126 sub HandleSelectedShelf {
127 my $shelfnumber = $query->param('selectedshelf');
128 my $shelf = Koha::Virtualshelves->find( $shelfnumber );
129 if ( $shelf->can_biblios_be_added( $loggedinuser ) ) {
132 shelfnumber => $shelf->shelfnumber,
133 shelfname => $shelf->shelfname,
141 return unless $authorized= $loggedinuser>0;
142 my $private_shelves = Koha::Virtualshelves->search(
145 owner => $loggedinuser,
147 { order_by => 'shelfname' }
149 my $shelves_shared_with_me = Koha::Virtualshelves->search(
152 'virtualshelfshares.borrowernumber' => $loggedinuser,
155 owner => $loggedinuser,
159 join => 'virtualshelfshares',
162 my $public_shelves= Koha::Virtualshelves->search(
167 owner => $loggedinuser,
170 { order_by => 'shelfname' }
173 private_shelves => $private_shelves,
174 private_shelves_shared_with_me => $shelves_shared_with_me,
175 public_shelves => $public_shelves,
180 for my $bib (@biblionumber) {
181 my $data = GetBiblioData( $bib );
183 { biblionumber => $bib,
184 title => $data->{'title'},
185 author => $data->{'author'},
189 multiple => (scalar(@biblios) > 1),
190 total => scalar @biblios,
191 biblios => \@biblios,
197 newshelf => $newshelf||0,
198 authorized => $authorized,
200 OpacAllowPublicListCreation => C4::Context->preference('OpacAllowPublicListCreation'),
202 output_html_with_http_headers $query, $cookie, $template->output;