Bug 15182: Conditionally load Koha::NorwegianPatronDB
[koha.git] / opac / opac-addbybiblionumber.pl
blobb8ad33064ce0b7d5548b7316ed36e42e75f505d6
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;
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",
51 query => $query,
52 type => "opac",
53 authnotrequired => 0,
57 if( $newvirtualshelf) {
58 HandleNewVirtualShelf();
59 exit if $authorized;
60 ShowTemplate(); #error message
62 elsif($shelfnumber) {
63 HandleShelfNumber();
64 exit if $authorized;
65 ShowTemplate(); #error message
67 elsif($selectedshelf) {
68 HandleSelectedShelf();
69 LoadBib() if $authorized;
70 ShowTemplate();
72 else {
73 HandleSelect();
74 LoadBib() if $authorized;
75 ShowTemplate();
77 #end
79 sub HandleNewVirtualShelf {
80 if ( $loggedinuser > 0 and
82 $category == 1
83 or $category == 2 and $loggedinuser>0 && C4::Context->preference('OpacAllowPublicListCreation')
85 ) {
86 my $shelf = eval {
87 Koha::Virtualshelf->new(
89 shelfname => $newvirtualshelf,
90 category => $category,
91 owner => $loggedinuser,
93 )->store;
95 if ( $@ or not $shelf ) {
96 $authorized = 0;
97 $errcode = 1;
98 return;
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>";
121 } else {
122 # TODO
126 sub HandleSelectedShelf {
127 my $shelfnumber = $query->param('selectedshelf');
128 my $shelf = Koha::Virtualshelves->find( $shelfnumber );
129 if ( $shelf->can_biblios_be_added( $loggedinuser ) ) {
130 $template->param(
131 singleshelf => 1,
132 shelfnumber => $shelf->shelfnumber,
133 shelfname => $shelf->shelfname,
135 } else {
136 # TODO
140 sub HandleSelect {
141 return unless $authorized= $loggedinuser>0;
142 my $private_shelves = Koha::Virtualshelves->search(
144 category => 1,
145 owner => $loggedinuser,
147 { order_by => 'shelfname' }
149 my $shelves_shared_with_me = Koha::Virtualshelves->search(
151 category => 1,
152 'virtualshelfshares.borrowernumber' => $loggedinuser,
153 -or => {
154 allow_add => 1,
155 owner => $loggedinuser,
159 join => 'virtualshelfshares',
162 my $public_shelves= Koha::Virtualshelves->search(
164 category => 2,
165 -or => {
166 allow_add => 1,
167 owner => $loggedinuser,
170 { order_by => 'shelfname' }
172 $template->param (
173 private_shelves => $private_shelves,
174 private_shelves_shared_with_me => $shelves_shared_with_me,
175 public_shelves => $public_shelves,
179 sub LoadBib {
180 for my $bib (@biblionumber) {
181 my $data = GetBiblioData( $bib );
182 push(@biblios,
183 { biblionumber => $bib,
184 title => $data->{'title'},
185 author => $data->{'author'},
186 } );
188 $template->param(
189 multiple => (scalar(@biblios) > 1),
190 total => scalar @biblios,
191 biblios => \@biblios,
195 sub ShowTemplate {
196 $template->param (
197 newshelf => $newshelf||0,
198 authorized => $authorized,
199 errcode => $errcode,
200 OpacAllowPublicListCreation => C4::Context->preference('OpacAllowPublicListCreation'),
202 output_html_with_http_headers $query, $cookie, $template->output;