Changing the way items are added to the cart and and lists from the searchresults...
[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::Circulation;  # not really used
30 use C4::Auth;
31 use C4::Output;
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 # multiple bibs might come in as '/' delimited string (from where, i don't see), or as array.
53
54 my $multiple = 0;
55 my @bibs;
56 if (scalar(@biblionumber) == 1) {
57         @biblionumber =  (split /\//,$biblionumber[0]);
58 }
59 if ($shelfnumber && ($shelfnumber != -1)) {
60         for my $bib (@biblionumber){
61                 &AddToShelfFromBiblio($bib,$shelfnumber);
62         }
63         print $query->header;
64         print "<html><body onload=\"window.close();\"><div>Please close this window to continue.</div></body></html>";
65         exit;
66 }
67 else {
68         if($selectedshelf){
69         # adding to specific shelf
70         my ( $singleshelf, $singleshelfname, $singlecategory ) = GetShelf( $query->param('selectedshelf') );
71                                 $template->param(
72                                 singleshelf             => 1,
73                                 shelfnumber         => $singleshelf,
74                                 shelfname           => $singleshelfname,
75                                 "category$singlecategory" => 1
76                         );
77         } else {
78         # offer choice of shelves
79     my ($shelflist) = GetShelves( $loggedinuser, 3 );
80     my @shelvesloop;
81     my %shelvesloop;
82     foreach my $element ( sort keys %$shelflist ) {
83         push( @shelvesloop, $element );
84                 $shelvesloop{$element} = $shelflist->{$element}->{'shelfname'};
85
86     my $CGIvirtualshelves;
87     if ( @shelvesloop > 0 ) {
88         $CGIvirtualshelves = CGI::scrolling_list (
89             -name     => 'shelfnumber',
90             -values   => \@shelvesloop,
91             -labels   => \%shelvesloop,
92             -size     => 1,
93             -tabindex => '',
94             -multiple => 0
95         );
96
97         $template->param (
98                 CGIvirtualshelves       => $CGIvirtualshelves,
99         );
100     }
101     }
102         }
103
104         my @biblios;
105         for my $bib (@biblionumber) {
106                 my $data = GetBiblioData( $bib );
107                 push(@biblios, 
108                         { biblionumber => $bib,
109                           title        => $data->{'title'},
110                           author       => $data->{'author'},
111                         } );
112         }
113         $template->param (
114                 newshelf => $newshelf,
115                 multiple => (scalar(@biblios) > 1),
116                 total    => scalar @biblios,
117                 biblios  => \@biblios,
118         );
119
120         output_html_with_http_headers $query, $cookie, $template->output;
121 }