Bug 16699: Remove requirement from borrowernumberQueryParam
[koha.git] / opac / opac-addbybiblionumber.pl
bloba5decf723912a428e30333bf38884c85d4809c25
1 #!/usr/bin/perl
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>.
22 use strict;
23 use warnings;
25 use CGI qw ( -utf8 );
26 use C4::Biblio;
27 use C4::Output;
28 use C4::Auth;
30 use Koha::Virtualshelves;
32 our $query = new CGI;
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');
39 our $authorized = 1;
40 our $errcode = 0;
41 our @biblios = ();
43 # if virtualshelves is disabled, leave immediately
44 if ( ! C4::Context->preference('virtualshelves') ) {
45 print $query->redirect("/cgi-bin/koha/errors/404.pl");
46 exit;
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",
56 query => $query,
57 type => "opac",
58 authnotrequired => 0,
62 if( $newvirtualshelf) {
63 HandleNewVirtualShelf();
64 exit if $authorized;
65 ShowTemplate(); #error message
67 elsif($shelfnumber) {
68 HandleShelfNumber();
69 exit if $authorized;
70 ShowTemplate(); #error message
72 elsif($selectedshelf) {
73 HandleSelectedShelf();
74 LoadBib() if $authorized;
75 ShowTemplate();
77 else {
78 HandleSelect();
79 LoadBib() if $authorized;
80 ShowTemplate();
82 #end
84 sub HandleNewVirtualShelf {
85 if ( $loggedinuser > 0 and
87 $category == 1
88 or $category == 2 and $loggedinuser>0 && C4::Context->preference('OpacAllowPublicListCreation')
90 ) {
91 my $shelf = eval {
92 Koha::Virtualshelf->new(
94 shelfname => $newvirtualshelf,
95 category => $category,
96 owner => $loggedinuser,
98 )->store;
100 if ( $@ or not $shelf ) {
101 $authorized = 0;
102 $errcode = 1;
103 return;
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>";
126 } else {
127 # TODO
131 sub HandleSelectedShelf {
132 my $shelfnumber = $query->param('selectedshelf');
133 my $shelf = Koha::Virtualshelves->find( $shelfnumber );
134 if ( $shelf->can_biblios_be_added( $loggedinuser ) ) {
135 $template->param(
136 singleshelf => 1,
137 shelfnumber => $shelf->shelfnumber,
138 shelfname => $shelf->shelfname,
140 } else {
141 # TODO
145 sub HandleSelect {
146 return unless $authorized= $loggedinuser>0;
147 my $private_shelves = Koha::Virtualshelves->search(
149 category => 1,
150 owner => $loggedinuser,
152 { order_by => 'shelfname' }
154 my $shelves_shared_with_me = Koha::Virtualshelves->search(
156 category => 1,
157 'virtualshelfshares.borrowernumber' => $loggedinuser,
158 -or => {
159 allow_add => 1,
160 owner => $loggedinuser,
164 join => 'virtualshelfshares',
167 my $public_shelves= Koha::Virtualshelves->search(
169 category => 2,
170 -or => {
171 allow_add => 1,
172 owner => $loggedinuser,
175 { order_by => 'shelfname' }
177 $template->param (
178 private_shelves => $private_shelves,
179 private_shelves_shared_with_me => $shelves_shared_with_me,
180 public_shelves => $public_shelves,
184 sub LoadBib {
185 for my $bib (@biblionumber) {
186 my $data = GetBiblioData( $bib );
187 push(@biblios,
188 { biblionumber => $bib,
189 title => $data->{'title'},
190 author => $data->{'author'},
191 } );
193 $template->param(
194 multiple => (scalar(@biblios) > 1),
195 total => scalar @biblios,
196 biblios => \@biblios,
200 sub ShowTemplate {
201 $template->param (
202 newshelf => $newshelf||0,
203 authorized => $authorized,
204 errcode => $errcode,
205 OpacAllowPublicListCreation => C4::Context->preference('OpacAllowPublicListCreation'),
207 output_html_with_http_headers $query, $cookie, $template->output;