kohabug 2238 This patch allows patrons to add books to public open/free lists whether...
[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
32 my $query        = new CGI;
33 my @biblionumber = $query->param('biblionumber');
34 my $selectedshelf = $query->param('selectedshelf');
35 my $newshelf = $query->param('newshelf');
36 my $shelfnumber  = $query->param('shelfnumber');
37 my $newvirtualshelf = $query->param('newvirtualshelf');
38 my $category     = $query->param('category');
39
40 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
41     {
42         template_name   => "opac-addbybiblionumber.tmpl",
43         query           => $query,
44         type            => "opac",
45         authnotrequired => 1,
46     }
47 );
48
49 $shelfnumber = AddShelf(  $newvirtualshelf, $loggedinuser, $category ) if $newvirtualshelf;
50
51 # verify user is authorized to perform the action on the shelf...
52 my $authorized = 1 if ( (ShelfPossibleAction( $loggedinuser, $selectedshelf )) );
53
54 # multiple bibs might come in as '/' delimited string (from where, i don't see), or as array.
55
56 my $multiple = 0;
57 my @bibs;
58 if (scalar(@biblionumber) == 1) {
59         @biblionumber =  (split /\//,$biblionumber[0]);
60 }
61 if ($shelfnumber && ($shelfnumber != -1)) {
62         for my $bib (@biblionumber){
63                 &AddToShelfFromBiblio($bib,$shelfnumber);
64         }       
65         print $query->header;
66         print "<html><body onload=\"window.close();\"><div>Please close this window to continue.</div></body></html>";
67         exit;
68 }
69 else {
70         if($selectedshelf){
71         # adding to specific shelf
72         my ( $singleshelf, $singleshelfname, $singlecategory ) = GetShelf( $query->param('selectedshelf') );
73                                 $template->param(
74                                 singleshelf             => 1,
75                                 shelfnumber         => $singleshelf,
76                                 shelfname           => $singleshelfname,
77                                 "category$singlecategory" => 1
78                         );
79         } else {
80         # offer choice of shelves
81     my ($shelflist) = GetShelves( $loggedinuser, 3 );
82     my @shelvesloop;
83     my %shelvesloop;
84     foreach my $element ( sort keys %$shelflist ) {
85         push( @shelvesloop, $element );
86                 $shelvesloop{$element} = $shelflist->{$element}->{'shelfname'};
87
88     my $CGIvirtualshelves;
89     if ( @shelvesloop > 0 ) {
90         $CGIvirtualshelves = CGI::scrolling_list (
91             -name     => 'shelfnumber',
92             -id     => 'shelfnumber',
93             -values   => \@shelvesloop,
94             -labels   => \%shelvesloop,
95             -size     => 1,
96             -tabindex => '',
97             -multiple => 0
98         );
99
100         $template->param (
101                 CGIvirtualshelves       => $CGIvirtualshelves,
102         );
103     }
104     }
105         }
106
107         my @biblios;
108         for my $bib (@biblionumber) {
109                 my $data = GetBiblioData( $bib );
110                 push(@biblios, 
111                         { biblionumber => $bib,
112                           title        => $data->{'title'},
113                           author       => $data->{'author'},
114                         } );
115         }
116         $template->param (
117                 newshelf => $newshelf,
118                 multiple => (scalar(@biblios) > 1),
119                 total    => scalar @biblios,
120                 biblios  => \@biblios,
121                 authorized      => $authorized,
122         );
123
124         output_html_with_http_headers $query, $cookie, $template->output;
125 }