Bug 17301 - Add callnumber to label-edit-batch.pl
[koha.git] / opac / opac-addbybiblionumber.pl
blob9227fa01dca9bf8f2ff41079bf4eff03c13ae95f
1 #!/usr/bin/perl
3 # Copyright 2000-2002 Katipo Communications
4 # Copyright 2016 Koha Development Team
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 use Modern::Perl;
23 use CGI qw ( -utf8 );
24 use C4::Biblio;
25 use C4::Output;
26 use C4::Auth;
28 use Koha::Virtualshelves;
30 my $query = new CGI;
31 my @biblionumbers = $query->multi_param('biblionumber');
32 my $selectedshelf = $query->param('selectedshelf');
33 my $newshelf = $query->param('newshelf');
34 my $shelfnumber = $query->param('shelfnumber');
35 my $newvirtualshelf = $query->param('newvirtualshelf');
36 my $category = $query->param('category');
37 my ( $errcode, $authorized ) = ( 0, 1 );
38 my @biblios;
40 # if virtualshelves is disabled, leave immediately
41 if ( !C4::Context->preference('virtualshelves') ) {
42 print $query->redirect("/cgi-bin/koha/errors/404.pl");
43 exit;
46 if ( scalar(@biblionumbers) == 1 ) {
47 @biblionumbers = ( split /\//, $biblionumbers[0] );
50 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
51 { template_name => "opac-addbybiblionumber.tt",
52 query => $query,
53 type => "opac",
54 authnotrequired => 0,
58 if ($newvirtualshelf) {
59 if ($loggedinuser > 0
60 and ( $category == 1
61 or $category == 2 and $loggedinuser > 0 && C4::Context->preference('OpacAllowPublicListCreation') )
62 ) {
63 my $shelf = eval { Koha::Virtualshelf->new( { shelfname => $newvirtualshelf, category => $category, owner => $loggedinuser, } )->store; };
64 if ( $@ or not $shelf ) {
65 $errcode = 1;
66 $authorized = 0;
67 } else {
68 for my $biblionumber (@biblionumbers) {
69 $shelf->add_biblio( $biblionumber, $loggedinuser );
72 #Reload the page where you came from
73 print $query->header;
74 print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
75 exit;
78 } elsif ($shelfnumber) {
79 my $shelfnumber = $query->param('shelfnumber');
80 my $shelf = Koha::Virtualshelves->find($shelfnumber);
81 if ( $shelf->can_biblios_be_added($loggedinuser) ) {
82 for my $biblionumber (@biblionumbers) {
83 $shelf->add_biblio( $biblionumber, $loggedinuser );
86 #Close this page and return
87 print $query->header;
88 print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
89 exit;
90 } else {
91 $authorized = 0;
93 } elsif ($selectedshelf) {
94 my $shelfnumber = $query->param('selectedshelf');
95 my $shelf = Koha::Virtualshelves->find($shelfnumber);
96 if ( $shelf->can_biblios_be_added($loggedinuser) ) {
97 $template->param(
98 singleshelf => 1,
99 shelfnumber => $shelf->shelfnumber,
100 shelfname => $shelf->shelfname,
102 } else {
103 $authorized = 0;
105 } else {
106 if ( $loggedinuser > 0 ) {
107 my $private_shelves = Koha::Virtualshelves->search(
108 { category => 1,
109 owner => $loggedinuser,
111 { order_by => 'shelfname' }
113 my $shelves_shared_with_me = Koha::Virtualshelves->search(
114 { category => 1,
115 'virtualshelfshares.borrowernumber' => $loggedinuser,
116 -or => {
117 allow_add => 1,
118 owner => $loggedinuser,
121 { join => 'virtualshelfshares', }
123 my $public_shelves = Koha::Virtualshelves->search(
124 { category => 2,
125 -or => {
126 allow_add => 1,
127 owner => $loggedinuser,
130 { order_by => 'shelfname' }
132 $template->param(
133 private_shelves => $private_shelves,
134 private_shelves_shared_with_me => $shelves_shared_with_me,
135 public_shelves => $public_shelves,
137 } else {
138 $authorized = 0;
142 if ($authorized) {
143 for my $biblionumber (@biblionumbers) {
144 my $data = GetBiblioData($biblionumber);
145 push(
146 @biblios,
147 { biblionumber => $biblionumber,
148 title => $data->{'title'},
149 author => $data->{'author'},
153 $template->param(
154 multiple => ( scalar(@biblios) > 1 ),
155 total => scalar @biblios,
156 biblios => \@biblios,
159 $template->param(
160 newshelf => $newshelf || 0,
161 OpacAllowPublicListCreation => C4::Context->preference('OpacAllowPublicListCreation'),
164 $template->param( authorized => $authorized, errcode => $errcode, );
165 output_html_with_http_headers $query, $cookie, $template->output;