Bug 7441: QA follow-up - Add note about missing NORMARC support
[koha.git] / virtualshelves / addbybiblionumber.pl
blob71270b743925b7b97a8482a1893b48403d4af2fd
1 #!/usr/bin/perl
3 #script to provide virtual shelf management
6 # Copyright 2000-2002 Katipo Communications
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 =head1 NAME
26 addbybiblionumber.pl
28 =head1 DESCRIPTION
30 This script allow to add a virtual in a virtual shelf from a biblionumber.
32 =head1 CGI PARAMETERS
34 =over 4
36 =item biblionumber
38 The biblionumber
40 =item shelfnumber
42 the shelfnumber where to add the virtual.
44 =item newvirtualshelf
46 if this parameter exists, then it must be equals to the name of the shelf
47 to add.
49 =item category
51 if this script has to add a shelf, it add one with this category.
53 =item newshelf
55 if this parameter exists, then we create a new shelf
57 =back
59 =cut
61 use strict;
62 use warnings;
64 use CGI qw ( -utf8 );
65 use C4::Biblio;
66 use C4::Output;
67 use C4::Auth;
69 use Koha::Virtualshelves;
71 our $query = new CGI;
72 our @biblionumber = HandleBiblioPars();
73 our $shelfnumber = $query->param('shelfnumber');
74 our $newvirtualshelf = $query->param('newvirtualshelf');
75 our $newshelf = $query->param('newshelf');
76 our $category = $query->param('category');
77 our $sortfield = $query->param('sortfield');
78 my $confirmed = $query->param('confirmed') || 0;
79 our $authorized = 1;
80 our $errcode = 0;
82 our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
84 template_name => "virtualshelves/addbybiblionumber.tt",
85 query => $query,
86 type => "intranet",
87 authnotrequired => 0,
88 flagsrequired => { catalogue => 1 },
92 if( $newvirtualshelf) {
93 HandleNewVirtualShelf();
94 exit if $authorized;
95 ShowTemplate(); #error message
97 elsif($shelfnumber && $confirmed) {
98 HandleShelfNumber();
99 exit if $authorized;
100 ShowTemplate(); #error message
102 elsif($shelfnumber) { #still needs confirmation
103 HandleSelectedShelf();
104 LoadBib() if $authorized;
105 ShowTemplate();
107 else {
108 HandleSelect();
109 LoadBib();
110 ShowTemplate();
112 #end
114 sub HandleBiblioPars {
115 my @bib= $query->multi_param('biblionumber');
116 if(@bib==0 && $query->param('biblionumbers')) {
117 my $str= $query->param('biblionumbers');
118 @bib= split '/', $str;
120 elsif(@bib==1 && $bib[0]=~/\//) {
121 @bib= split '/', $bib[0];
123 return @bib;
126 sub HandleNewVirtualShelf {
127 my $shelf = eval {
128 Koha::Virtualshelf->new(
130 shelfname => $newvirtualshelf,
131 category => $category,
132 sortfield => $sortfield,
133 owner => $loggedinuser,
135 )->store;
137 if ( $@ or not $shelf ) {
138 $authorized = 0;
139 $errcode = 1;
140 return;
143 for my $bib (@biblionumber){
144 $shelf->add_biblio( $bib, $loggedinuser );
146 #Reload the page where you came from
147 print $query->header;
148 print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
151 sub HandleShelfNumber {
152 my $shelf = Koha::Virtualshelves->find( $shelfnumber );
153 if($authorized = $shelf->can_biblios_be_added( $loggedinuser ) ) {
154 for my $bib (@biblionumber){
155 $shelf->add_biblio( $bib, $loggedinuser );
157 #Close this page and return
158 print $query->header;
159 print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
161 else {
162 $errcode=2; #no perm
166 sub HandleSelectedShelf {
167 my $shelf = Koha::Virtualshelves->find( $shelfnumber );
168 if($authorized = $shelf->can_biblios_be_added( $loggedinuser ) ) {
169 #confirm adding to specific shelf
170 $template->param(
171 singleshelf => 1,
172 shelfnumber => $shelf->shelfnumber,
173 shelfname => $shelf->shelfname,
176 else {
177 $errcode=2; #no perm
181 sub HandleSelect {
182 my $private_shelves = Koha::Virtualshelves->search(
184 category => 1,
185 owner => $loggedinuser,
187 { order_by => 'shelfname' }
189 my $shelves_shared_with_me = Koha::Virtualshelves->search(
191 category => 1,
192 'virtualshelfshares.borrowernumber' => $loggedinuser,
193 -or => {
194 allow_add => 1,
195 owner => $loggedinuser,
199 join => 'virtualshelfshares',
202 my $public_shelves= Koha::Virtualshelves->search(
204 category => 2,
205 -or => {
206 allow_add => 1,
207 owner => $loggedinuser,
210 { order_by => 'shelfname' }
212 $template->param (
213 private_shelves => $private_shelves,
214 private_shelves_shared_with_me => $shelves_shared_with_me,
215 public_shelves => $public_shelves,
219 sub LoadBib {
220 my @biblios;
221 for my $bib (@biblionumber) {
222 my $data = GetBiblioData($bib);
223 push(@biblios,
224 { biblionumber => $bib,
225 title => $data->{'title'},
226 author => $data->{'author'},
227 } );
229 $template->param(
230 multiple => (scalar(@biblios) > 1),
231 total => scalar @biblios,
232 biblios => \@biblios,
236 sub ShowTemplate {
237 $template->param (
238 newshelf => $newshelf||0,
239 authorized => $authorized,
240 errcode => $errcode,
242 output_html_with_http_headers $query, $cookie, $template->output;