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');
43 # if virtualshelves is disabled, leave immediately
44 if ( ! C4
::Context
->preference('virtualshelves') ) {
45 print $query->redirect("/cgi-bin/koha/errors/404.pl");
49 if (scalar(@biblionumber) == 1) {
50 @biblionumber = (split /\//,$biblionumber[0]);
53 our ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
55 template_name
=> "opac-addbybiblionumber.tt",
62 if( $newvirtualshelf) {
63 HandleNewVirtualShelf
();
65 ShowTemplate
(); #error message
70 ShowTemplate
(); #error message
72 elsif($selectedshelf) {
73 HandleSelectedShelf
();
74 LoadBib
() if $authorized;
79 LoadBib
() if $authorized;
84 sub HandleNewVirtualShelf
{
85 if ( $loggedinuser > 0 and
88 or $category == 2 and $loggedinuser>0 && C4
::Context
->preference('OpacAllowPublicListCreation')
92 Koha
::Virtualshelf
->new(
94 shelfname
=> $newvirtualshelf,
95 category
=> $category,
96 owner
=> $loggedinuser,
100 if ( $@
or not $shelf ) {
106 for my $bib (@biblionumber) {
107 $shelf->add_biblio( $bib, $loggedinuser );
110 #Reload the page where you came from
111 print $query->header;
112 print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
116 sub HandleShelfNumber
{
117 my $shelfnumber = $query->param('shelfnumber');
118 my $shelf = Koha
::Virtualshelves
->find( $shelfnumber );
119 if ( $shelf->can_biblios_be_added( $loggedinuser ) ) {
120 for my $bib (@biblionumber) {
121 $shelf->add_biblio( $bib, $loggedinuser );
123 #Close this page and return
124 print $query->header;
125 print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
131 sub HandleSelectedShelf
{
132 my $shelfnumber = $query->param('selectedshelf');
133 my $shelf = Koha
::Virtualshelves
->find( $shelfnumber );
134 if ( $shelf->can_biblios_be_added( $loggedinuser ) ) {
137 shelfnumber
=> $shelf->shelfnumber,
138 shelfname
=> $shelf->shelfname,
146 return unless $authorized= $loggedinuser>0;
147 my $private_shelves = Koha
::Virtualshelves
->search(
150 owner
=> $loggedinuser,
152 { order_by
=> 'shelfname' }
154 my $shelves_shared_with_me = Koha
::Virtualshelves
->search(
157 'virtualshelfshares.borrowernumber' => $loggedinuser,
160 owner
=> $loggedinuser,
164 join => 'virtualshelfshares',
167 my $public_shelves= Koha
::Virtualshelves
->search(
172 owner
=> $loggedinuser,
175 { order_by
=> 'shelfname' }
178 private_shelves
=> $private_shelves,
179 private_shelves_shared_with_me
=> $shelves_shared_with_me,
180 public_shelves
=> $public_shelves,
185 for my $bib (@biblionumber) {
186 my $data = GetBiblioData
( $bib );
188 { biblionumber
=> $bib,
189 title
=> $data->{'title'},
190 author
=> $data->{'author'},
194 multiple
=> (scalar(@biblios) > 1),
195 total
=> scalar @biblios,
196 biblios
=> \
@biblios,
202 newshelf
=> $newshelf||0,
203 authorized
=> $authorized,
205 OpacAllowPublicListCreation
=> C4
::Context
->preference('OpacAllowPublicListCreation'),
207 output_html_with_http_headers
$query, $cookie, $template->output;