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
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 with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA 02111-1307 USA
30 This script allow to add a virtual in a virtual shelf from a biblionumber.
42 the shelfnumber where to add the virtual.
46 if this parameter exists, then it must be equals to the name of the shelf
51 if this script has to add a shelf, it add one with this category.
55 if this parameter exists, then we create a new shelf
65 use C4::VirtualShelves qw/:DEFAULT GetRecentShelves/;
68 #splits incoming biblionumber(s) to array and adds each to shelf.
69 sub AddBibliosToShelf {
70 my ($shelfnumber,@biblionumber)=@_;
72 # multiple bibs might come in as '/' delimited string (from where, i don't see), or as array.
73 if (scalar(@biblionumber) == 1) {
74 @biblionumber = (split /\//,$biblionumber[0]);
76 for my $bib (@biblionumber){
77 AddToShelfFromBiblio($bib, $shelfnumber);
83 #use it only to debug !
86 sub AddBibliosToShelf {
87 my ($shelfnumber,@biblionumber)=@_;
89 # multiple bibs might come in as '/' delimited string (from where, i don't see), or as array.
90 if (scalar(@biblionumber) == 1) {
91 @biblionumber = (split /\//,$biblionumber[0]);
93 for my $bib (@biblionumber){
94 AddToShelfFromBiblio($bib, $shelfnumber);
100 # If set, then single item case.
101 my $biblionumber = $query->param('biblionumber');
103 # If set, then multiple item case.
104 my @biblionumber = $query->param('biblionumber');
105 my $biblionumbers = $query->param('biblionumbers');
107 my $shelfnumber = $query->param('shelfnumber');
108 my $newvirtualshelf = $query->param('newvirtualshelf');
109 my $newshelf = $query->param('newshelf');
110 my $category = $query->param('category');
111 my $sortfield = $query->param('sortfield');
112 my $confirmed = $query->param('confirmed') || 0;
115 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
117 template_name => "virtualshelves/addbybiblionumber.tmpl",
120 authnotrequired => 0,
121 flagsrequired => { catalogue => 1 },
126 if ($biblionumbers) {
127 @biblionumbers = split '/', $biblionumbers;
129 @biblionumbers = (@biblionumber);
132 $shelfnumber = AddShelf( $newvirtualshelf, $loggedinuser, $category, $sortfield ) if $newvirtualshelf;
133 if ( $shelfnumber || ( $shelfnumber == -1 ) ) { # the shelf already exist.
135 if ($confirmed == 1) {
136 AddBibliosToShelf($shelfnumber,@biblionumber);
138 "Content-Type: text/html\n\n<html><body onload=\"window.opener.location.reload(true);window.close()\"></body></html>";
141 my ( $singleshelf, $singleshelfname, $singlecategory ) = GetShelf( $query->param('shelfnumber') );
143 for my $bib (@biblionumber) {
144 my $data = GetBiblioData( $bib );
146 { biblionumber => $bib,
147 title => $data->{'title'},
148 author => $data->{'author'},
154 biblionumber => \@biblionumber,
155 biblios => \@biblios,
156 multiple => (scalar(@biblionumber) > 1),
158 shelfname => $singleshelfname,
159 shelfnumber => $singleshelf,
160 total => scalar(@biblionumber),
165 else { # this shelf doesn't already exist.
167 my ($shelflist) = GetRecentShelves(1, $limit, $loggedinuser);
170 for my $shelf ( @{ $shelflist->[0] } ) {
171 push( @shelvesloop, $shelf->{shelfnumber} );
172 $shelvesloop{$shelf->{shelfnumber}} = $shelf->{shelfname};
174 # then open shelves...
175 ($shelflist) = GetRecentShelves(3, $limit, undef);
176 for my $shelf ( @{ $shelflist->[0] } ) {
177 push( @shelvesloop, $shelf->{shelfnumber} );
178 $shelvesloop{$shelf->{shelfnumber}} = $shelf->{shelfname};
181 if(@shelvesloop gt 0){
182 my $CGIvirtualshelves = CGI::scrolling_list
184 -name => 'shelfnumber',
185 -values => \@shelvesloop,
186 -labels => \%shelvesloop,
193 CGIvirtualshelves => $CGIvirtualshelves,
197 for my $bib (@biblionumber) {
198 my $data = GetBiblioData( $bib );
200 { biblionumber => $bib,
201 title => $data->{'title'},
202 author => $data->{'author'},
206 newshelf => $newshelf,
208 multiple => (scalar(@biblionumber) > 1),
209 total => scalar(@biblionumber),
212 unless (@biblionumbers) {
213 my ( $bibliocount, @biblios ) = GetBiblio($biblionumber);
217 biblionumber => $biblionumber,
218 title => $biblios[0]->{'title'},
219 author => $biblios[0]->{'author'},
223 foreach my $biblionumber (@biblionumbers) {
224 my ( $bibliocount, @biblios ) = GetBiblio($biblionumber);
226 title=>$biblios[0]->{'title'},
227 author=>$biblios[0]->{'author'}
229 push @biblioloop, \%biblioiter;
233 biblioloop => \@biblioloop,
234 biblionumbers => $biblionumbers
239 output_html_with_http_headers $query, $cookie, $template->output;