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');
44 our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
46 template_name => "opac-addbybiblionumber.tt",
53 if( $newvirtualshelf) {
54 HandleNewVirtualShelf();
56 ShowTemplate(); #error message
61 ShowTemplate(); #error message
63 elsif($selectedshelf) {
64 HandleSelectedShelf();
65 LoadBib() if $authorized;
70 LoadBib() if $authorized;
75 sub AddBibliosToShelf {
76 #splits incoming biblionumber(s) to array and adds each to shelf.
77 my ($shelfnumber,@biblionumber)=@_;
79 #multiple bibs might come in as '/' delimited string (from where, i don't see), or as array.
80 if (scalar(@biblionumber) == 1) {
81 @biblionumber = (split /\//,$biblionumber[0]);
83 for my $bib (@biblionumber) {
84 my $shelf = Koha::Virtualshelves->find( $shelfnumber );
85 $shelf->add_biblio( $bib, $loggedinuser );
89 sub HandleNewVirtualShelf {
90 if($authorized= ShelfPossibleAction($loggedinuser, undef, $category==1? 'new_private': 'new_public')) {
92 Koha::Virtualshelf->new(
94 shelfname => $newvirtualshelf,
95 category => $category,
96 owner => $loggedinuser,
100 if ( $@ or not $shelf ) {
105 AddBibliosToShelf($shelfnumber, @biblionumber);
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 if($authorized= ShelfPossibleAction($loggedinuser, $shelfnumber, 'add')) {
114 AddBibliosToShelf($shelfnumber,@biblionumber);
115 #Close this page and return
116 print $query->header;
117 print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
121 sub HandleSelectedShelf {
122 if($authorized= ShelfPossibleAction( $loggedinuser, $selectedshelf, 'add')){
123 #adding to specific shelf
124 my $shelfnumber = $query->param('selectedshelf');
125 my $shelf = Koha::Virtualshelves->find( $shelfnumber );
128 shelfnumber => $shelf->shelfnumber,
129 shelfname => $shelf->shelfname,
135 return unless $authorized= $loggedinuser>0;
136 my $private_shelves = Koha::Virtualshelves->search(
139 owner => $loggedinuser,
141 { order_by => 'shelfname' }
143 my $shelves_shared_with_me = Koha::Virtualshelves->search(
146 'virtualshelfshares.borrowernumber' => $loggedinuser,
149 owner => $loggedinuser,
153 join => 'virtualshelfshares',
156 my $public_shelves= Koha::Virtualshelves->search(
161 owner => $loggedinuser,
164 { order_by => 'shelfname' }
167 private_shelves => $private_shelves,
168 private_shelves_shared_with_me => $shelves_shared_with_me,
169 public_shelves => $public_shelves,
174 #see comment in AddBibliosToShelf
175 if (scalar(@biblionumber) == 1) {
176 @biblionumber = (split /\//,$biblionumber[0]);
178 for my $bib (@biblionumber) {
179 my $data = GetBiblioData( $bib );
181 { biblionumber => $bib,
182 title => $data->{'title'},
183 author => $data->{'author'},
187 multiple => (scalar(@biblios) > 1),
188 total => scalar @biblios,
189 biblios => \@biblios,
195 newshelf => $newshelf||0,
196 authorized => $authorized,
198 OpacAllowPublicListCreation => C4::Context->preference('OpacAllowPublicListCreation'),
200 output_html_with_http_headers $query, $cookie, $template->output;