Bug 15113: koha-rebuild-zebra should check USE_INDEXER_DAEMON and skip if enabled
[koha.git] / opac / opac-addbybiblionumber.pl
blob92153d898de5f849f9c717061b65e00e14b32635
1 #!/usr/bin/perl
3 #script to provide virtualshelf management
4 # WARNING: This file uses 4-character tabs!
6 # $Header$
8 # Copyright 2000-2002 Katipo Communications
10 # This file is part of Koha.
12 # Koha is free software; you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 3 of the License, or
15 # (at your option) any later version.
17 # Koha is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with Koha; if not, see <http://www.gnu.org/licenses>.
25 use strict;
26 use warnings;
28 use CGI qw ( -utf8 );
29 use C4::Biblio;
30 use C4::VirtualShelves qw/:DEFAULT GetAllShelves/;
31 use C4::Output;
32 use C4::Auth;
34 our $query = new CGI;
35 our @biblionumber = $query->param('biblionumber');
36 our $selectedshelf = $query->param('selectedshelf');
37 our $newshelf = $query->param('newshelf');
38 our $shelfnumber = $query->param('shelfnumber');
39 our $newvirtualshelf = $query->param('newvirtualshelf');
40 our $category = $query->param('category');
41 our $authorized = 1;
42 our $errcode = 0;
43 our @biblios;
45 # if virtualshelves is disabled, leave immediately
46 if ( ! C4::Context->preference('virtualshelves') ) {
47 print $query->redirect("/cgi-bin/koha/errors/404.pl");
48 exit;
51 if (scalar(@biblionumber) == 1) {
52 @biblionumber = (split /\//,$biblionumber[0]);
55 our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
57 template_name => "opac-addbybiblionumber.tt",
58 query => $query,
59 type => "opac",
60 authnotrequired => 0,
64 if( $newvirtualshelf) {
65 HandleNewVirtualShelf();
66 exit if $authorized;
67 ShowTemplate(); #error message
69 elsif($shelfnumber) {
70 HandleShelfNumber();
71 exit if $authorized;
72 ShowTemplate(); #error message
74 elsif($selectedshelf) {
75 HandleSelectedShelf();
76 LoadBib() if $authorized;
77 ShowTemplate();
79 else {
80 HandleSelect();
81 LoadBib() if $authorized;
82 ShowTemplate();
84 #end
86 sub AddBibliosToShelf {
87 #splits incoming biblionumber(s) to array and adds each to shelf.
88 my ($shelfnumber,@biblionumber)=@_;
90 #multiple bibs might come in as '/' delimited string (from where, i don't see), or as array.
91 if (scalar(@biblionumber) == 1) {
92 @biblionumber = (split /\//,$biblionumber[0]);
94 for my $bib (@biblionumber) {
95 AddToShelf($bib, $shelfnumber, $loggedinuser);
99 sub HandleNewVirtualShelf {
100 if($authorized= ShelfPossibleAction($loggedinuser, undef, $category==1? 'new_private': 'new_public')) {
101 $shelfnumber = AddShelf( {
102 shelfname => $newvirtualshelf,
103 category => $category }, $loggedinuser);
104 if($shelfnumber == -1) {
105 $authorized=0;
106 $errcode=1;
107 return;
109 AddBibliosToShelf($shelfnumber, @biblionumber);
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 if($authorized= ShelfPossibleAction($loggedinuser, $shelfnumber, 'add')) {
118 AddBibliosToShelf($shelfnumber,@biblionumber);
119 #Close this page and return
120 print $query->header;
121 print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
125 sub HandleSelectedShelf {
126 if($authorized= ShelfPossibleAction( $loggedinuser, $selectedshelf, 'add')){
127 #adding to specific shelf
128 my ($singleshelf, $singleshelfname)= GetShelf($query->param('selectedshelf'));
129 $template->param(
130 singleshelf => 1,
131 shelfnumber => $singleshelf,
132 shelfname => $singleshelfname,
137 sub HandleSelect {
138 return unless $authorized= $loggedinuser>0;
139 my $privateshelves = GetAllShelves(1,$loggedinuser,1);
140 if(@{$privateshelves}){
141 $template->param (
142 privatevirtualshelves => $privateshelves,
143 existingshelves => 1
146 my $publicshelves = GetAllShelves(2,$loggedinuser,1);
147 if(@{$publicshelves}){
148 $template->param (
149 publicvirtualshelves => $publicshelves,
150 existingshelves => 1
155 sub LoadBib {
156 #see comment in AddBibliosToShelf
157 if (scalar(@biblionumber) == 1) {
158 @biblionumber = (split /\//,$biblionumber[0]);
160 for my $bib (@biblionumber) {
161 my $data = GetBiblioData( $bib );
162 push(@biblios,
163 { biblionumber => $bib,
164 title => $data->{'title'},
165 author => $data->{'author'},
166 } );
168 $template->param(
169 multiple => (scalar(@biblios) > 1),
170 total => scalar @biblios,
171 biblios => \@biblios,
175 sub ShowTemplate {
176 $template->param (
177 newshelf => $newshelf||0,
178 authorized => $authorized,
179 errcode => $errcode,
180 OpacAllowPublicListCreation => C4::Context->preference('OpacAllowPublicListCreation'),
182 output_html_with_http_headers $query, $cookie, $template->output;