Bugfix correcting 'New List' behavior on opac-search.pl
[koha.git] / opac / opac-addbybiblionumber.pl
1 #!/usr/bin/perl
2
3 #script to provide virtualshelf management
4 # WARNING: This file uses 4-character tabs!
5 #
6 # $Header$
7 #
8 # Copyright 2000-2002 Katipo Communications
9 #
10 # This file is part of Koha.
11 #
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
15 # version.
16 #
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License along with
22 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA  02111-1307 USA
24
25 use strict;
26 use C4::Biblio;
27 use CGI;
28 use C4::VirtualShelves;
29 use C4::Auth;
30 use C4::Output;
31 use C4::Auth qw/get_session/;
32
33 my $query        = new CGI;
34 my @biblionumber = $query->param('biblionumber');
35 my $selectedshelf = $query->param('selectedshelf');
36 my $newshelf = $query->param('newshelf');
37 my $shelfnumber  = $query->param('shelfnumber');
38 my $newvirtualshelf = $query->param('newvirtualshelf');
39 my $category     = $query->param('category');
40
41 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
42     {
43         template_name   => "opac-addbybiblionumber.tmpl",
44         query           => $query,
45         type            => "opac",
46         authnotrequired => 1,
47     }
48 );
49
50 $shelfnumber = AddShelf(  $newvirtualshelf, $loggedinuser, $category ) if $newvirtualshelf;
51
52 # verify user is authorized to perform the action on the shelf...
53 my $authorized = 1;
54 if ($selectedshelf) {
55         $authorized = 0 unless ShelfPossibleAction( $loggedinuser, $selectedshelf );
56 }
57
58 # multiple bibs might come in as '/' delimited string (from where, i don't see), or as array.
59
60 my $multiple = 0;
61 my @bibs;
62 if (scalar(@biblionumber) == 1) {
63         @biblionumber =  (split /\//,$biblionumber[0]);
64 }
65 if ($shelfnumber && ($shelfnumber != -1)) {
66         for my $bib (@biblionumber){
67                 &AddToShelfFromBiblio($bib,$shelfnumber);
68         }
69         print $query->header;
70         print "<html><body onload=\"window.close();\"><div>Please close this window to continue.</div></body></html>";
71         exit;
72 }
73 else {
74         if($selectedshelf){
75         # adding to specific shelf
76         my ( $singleshelf, $singleshelfname, $singlecategory ) = GetShelf( $query->param('selectedshelf') );
77                                 $template->param(
78                                 singleshelf             => 1,
79                                 shelfnumber         => $singleshelf,
80                                 shelfname           => $singleshelfname,
81                                 "category$singlecategory" => 1
82                         );
83         } else {
84         # offer choice of shelves
85     my ($shelflist) = GetShelves( $loggedinuser, 3 );
86     my @shelvesloop;
87     my %shelvesloop;
88     foreach my $element ( sort keys %$shelflist ) {
89         push( @shelvesloop, $element );
90                 $shelvesloop{$element} = $shelflist->{$element}->{'shelfname'};
91
92     my $CGIvirtualshelves;
93     if ( @shelvesloop > 0 ) {
94         $CGIvirtualshelves = CGI::scrolling_list (
95             -name     => 'shelfnumber',
96             -id     => 'shelfnumber',
97             -values   => \@shelvesloop,
98             -labels   => \%shelvesloop,
99             -size     => 1,
100             -tabindex => '',
101             -multiple => 0
102         );
103
104         $template->param (
105                 CGIvirtualshelves       => $CGIvirtualshelves,
106         );
107     }
108     }
109         }
110
111         my @biblios;
112         for my $bib (@biblionumber) {
113                 my $data = GetBiblioData( $bib );
114                 push(@biblios, 
115                         { biblionumber => $bib,
116                           title        => $data->{'title'},
117                           author       => $data->{'author'},
118                         } );
119         }
120         $template->param (
121                 newshelf => $newshelf,
122                 multiple => (scalar(@biblios) > 1),
123                 total    => scalar @biblios,
124                 biblios  => \@biblios,
125                 authorized      => $authorized,
126         );
127
128         output_html_with_http_headers $query, $cookie, $template->output;
129 }