fix to remove leading/trailing whitespace from entered barcode.
[koha.git] / virtualshelves / addbybiblionumber.pl
blobd565493d62bddb9bb4d79b05dd45183bcf4eddbf
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 with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA 02111-1307 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 =back
55 =cut
57 use strict;
58 use C4::Biblio;
59 use CGI;
60 use C4::Output;
61 use C4::VirtualShelves qw/:DEFAULT GetRecentShelves/;
62 use C4::Circulation;
63 use C4::Auth;
65 #use it only to debug !
66 use CGI::Carp qw/fatalsToBrowser/;
67 use warnings;
69 my $query = new CGI;
71 # If set, then single item case.
72 my $biblionumber = $query->param('biblionumber');
74 # If set, then multiple item case.
75 my $biblionumbers = $query->param('biblionumbers');
77 my $shelfnumber = $query->param('shelfnumber');
78 my $newvirtualshelf = $query->param('newvirtualshelf');
79 my $category = $query->param('category');
80 my $sortfield = $query->param('sortfield');
82 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
84 template_name => "virtualshelves/addbybiblionumber.tmpl",
85 query => $query,
86 type => "intranet",
87 authnotrequired => 0,
88 flagsrequired => { catalogue => 1 },
92 my @biblionumbers;
93 if ($biblionumbers) {
94 @biblionumbers = split '/', $biblionumbers;
95 } else {
96 @biblionumbers = ($biblionumber);
99 $shelfnumber = AddShelf( $newvirtualshelf, $loggedinuser, $category, $sortfield )
100 if $newvirtualshelf;
101 if ( $shelfnumber || ( $shelfnumber == -1 ) ) { # the shelf already exist.
102 foreach my $biblionumber (@biblionumbers) {
103 AddToShelfFromBiblio( $biblionumber, $shelfnumber );
105 print
106 "Content-Type: text/html\n\n<html><body onload=\"window.close()\"></body></html>";
107 exit;
109 else { # this shelf doesn't already exist.
110 my $limit = 10;
111 my ($shelflist) = GetRecentShelves(1, $limit, $loggedinuser);
112 my @shelvesloop;
113 my %shelvesloop;
114 for my $shelf ( @{ $shelflist->[0] } ) {
115 push( @shelvesloop, $shelf->{shelfnumber} );
116 $shelvesloop{$shelf->{shelfnumber}} = $shelf->{shelfname};
118 # then open shelves...
119 my ($shelflist) = GetRecentShelves(3, $limit, undef);
120 for my $shelf ( @{ $shelflist->[0] } ) {
121 push( @shelvesloop, $shelf->{shelfnumber} );
122 $shelvesloop{$shelf->{shelfnumber}} = $shelf->{shelfname};
124 if(@shelvesloop gt 0){
125 my $CGIvirtualshelves = CGI::scrolling_list
127 -name => 'shelfnumber',
128 -values => \@shelvesloop,
129 -labels => \%shelvesloop,
130 -size => 1,
131 -tabindex => '',
132 -multiple => 0
134 $template->param
136 CGIvirtualshelves => $CGIvirtualshelves,
140 unless ($biblionumbers) {
141 my ( $bibliocount, @biblios ) = GetBiblio($biblionumber);
143 $template->param
145 biblionumber => $biblionumber,
146 title => $biblios[0]->{'title'},
147 author => $biblios[0]->{'author'},
149 } else {
150 my @biblioloop = ();
151 foreach my $biblionumber (@biblionumbers) {
152 my ( $bibliocount, @biblios ) = GetBiblio($biblionumber);
153 my %biblioiter = (
154 title=>$biblios[0]->{'title'},
155 author=>$biblios[0]->{'author'}
157 push @biblioloop, \%biblioiter;
159 $template->param
161 biblioloop => \@biblioloop,
162 biblionumbers => $biblionumbers
166 output_html_with_http_headers $query, $cookie, $template->output;