Bug 2505 - Add commented use warnings where missing in the cataloguing/ directory
[koha.git] / virtualshelves / addbybiblionumber.pl
blobd53a8c4e820e596161de2b81bdd137e3ebf2e761
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 under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along
20 # with Koha; if not, write to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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; FIXME - Bug 2505
63 use C4::Biblio;
64 use CGI;
65 use C4::Output;
66 use C4::VirtualShelves qw/:DEFAULT GetRecentShelves/;
67 use C4::Circulation;
68 use C4::Auth;
70 # splits incoming biblionumber(s) to array and adds each to shelf.
71 sub AddBibliosToShelf {
72 my ($shelfnumber,@biblionumber)=@_;
74 # multiple bibs might come in as '/' delimited string (from where, i don't see), or as array.
75 # (Note : they come in as '/' when added from the cart)
76 if (scalar(@biblionumber) == 1) {
77 @biblionumber = (split /\//,$biblionumber[0]);
79 for my $bib (@biblionumber){
80 AddToShelfFromBiblio($bib, $shelfnumber);
84 my $query = new CGI;
86 # If set, then single item case.
87 my $biblionumber = $query->param('biblionumber');
89 # If set, then multiple item case.
90 my @biblionumber = $query->param('biblionumber');
91 my $biblionumbers = $query->param('biblionumbers');
93 my $shelfnumber = $query->param('shelfnumber');
94 my $newvirtualshelf = $query->param('newvirtualshelf');
95 my $newshelf = $query->param('newshelf');
96 my $category = $query->param('category');
97 my $sortfield = $query->param('sortfield');
98 my $confirmed = $query->param('confirmed') || 0;
101 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
103 template_name => "virtualshelves/addbybiblionumber.tmpl",
104 query => $query,
105 type => "intranet",
106 authnotrequired => 0,
107 flagsrequired => { catalogue => 1 },
111 my @biblionumbers;
112 if ($biblionumbers) {
113 @biblionumbers = split '/', $biblionumbers;
114 } else {
115 @biblionumbers = (@biblionumber);
117 if (scalar(@biblionumber) == 1) {
118 @biblionumber = (split /\//,$biblionumber[0]);
121 $shelfnumber = AddShelf( $newvirtualshelf, $loggedinuser, $category, $sortfield ) if $newvirtualshelf;
122 if ( $shelfnumber || ( $shelfnumber == -1 ) ) { # the shelf already exist.
124 if ($confirmed == 1) {
125 AddBibliosToShelf($shelfnumber,@biblionumber);
126 print
127 "Content-Type: text/html\n\n<html><body onload=\"window.opener.location.reload(true);window.close()\"></body></html>";
128 exit;
129 } else {
130 my ( $singleshelf, $singleshelfname, $singlecategory ) = GetShelf( $query->param('shelfnumber') );
131 my @biblios;
132 for my $bib (@biblionumber) {
133 my $data = GetBiblioData( $bib );
134 push(@biblios,
135 { biblionumber => $bib,
136 title => $data->{'title'},
137 author => $data->{'author'},
138 } );
141 $template->param
143 biblionumber => \@biblionumber,
144 biblios => \@biblios,
145 multiple => (scalar(@biblionumber) > 1),
146 singleshelf => 1,
147 shelfname => $singleshelfname,
148 shelfnumber => $singleshelf,
149 total => scalar(@biblionumber),
150 confirm => 1,
154 else { # this shelf doesn't already exist.
155 my $limit = 10;
156 my ($shelflist) = GetRecentShelves(1, $limit, $loggedinuser);
157 my @shelvesloop;
158 my %shelvesloop;
159 for my $shelf ( @{ $shelflist->[0] } ) {
160 push( @shelvesloop, $shelf->{shelfnumber} );
161 $shelvesloop{$shelf->{shelfnumber}} = $shelf->{shelfname};
163 # then open shelves...
164 ($shelflist) = GetRecentShelves(3, $limit, undef);
165 for my $shelf ( @{ $shelflist->[0] } ) {
166 push( @shelvesloop, $shelf->{shelfnumber} );
167 $shelvesloop{$shelf->{shelfnumber}} = $shelf->{shelfname};
170 if(@shelvesloop gt 0){
171 my $CGIvirtualshelves = CGI::scrolling_list
173 -name => 'shelfnumber',
174 -values => \@shelvesloop,
175 -labels => \%shelvesloop,
176 -size => 1,
177 -tabindex => '',
178 -multiple => 0
180 $template->param
182 CGIvirtualshelves => $CGIvirtualshelves,
185 my @biblios;
186 for my $bib (@biblionumber) {
187 my $data = GetBiblioData( $bib );
188 push(@biblios,
189 { biblionumber => $bib,
190 title => $data->{'title'},
191 author => $data->{'author'},
192 } );
194 $template->param(
195 newshelf => $newshelf,
196 biblios=>\@biblios,
197 multiple => (scalar(@biblionumber) > 1),
198 total => scalar(@biblionumber),
201 unless (@biblionumbers) {
202 my ( $bibliocount, @biblios ) = GetBiblio($biblionumber);
204 $template->param
206 biblionumber => $biblionumber,
207 title => $biblios[0]->{'title'},
208 author => $biblios[0]->{'author'},
210 } else {
211 my @biblioloop = ();
212 foreach my $biblionumber (@biblionumbers) {
213 my ( $bibliocount, @biblios ) = GetBiblio($biblionumber);
214 my %biblioiter = (
215 title=>$biblios[0]->{'title'},
216 author=>$biblios[0]->{'author'}
218 push @biblioloop, \%biblioiter;
220 $template->param
222 biblioloop => \@biblioloop,
223 biblionumbers => $biblionumbers
228 output_html_with_http_headers $query, $cookie, $template->output;