rel_3_0 moved to HEAD
[koha.git] / opac / opac-addbookbybiblionumber.pl
1 #!/usr/bin/perl
2
3 #script to provide bookshelf 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::Output;
29 use C4::BookShelves;
30 use C4::Circulation::Circ2;
31 use C4::Auth;
32 use C4::Interface::CGI::Output;
33
34 my $query        = new CGI;
35 my $biblionumber = $query->param('biblionumber');
36 my $shelfnumber  = $query->param('shelfnumber');
37 my $newbookshelf = $query->param('newbookshelf');
38 my $category     = $query->param('category');
39
40 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
41     {
42         template_name   => "opac-addbookbybiblionumber.tmpl",
43         query           => $query,
44         type            => "opac",
45         authnotrequired => 1,
46     }
47 );
48
49 $shelfnumber = AddShelf( '', $newbookshelf, $loggedinuser, $category ) if $newbookshelf;
50
51 # to know if we had to add more than one biblio.
52 my $multiple = 0;
53 $multiple = 1 if $biblionumber =~ /^(\d*\/)*$/;
54
55
56 if ($shelfnumber) {
57
58     if ($multiple){
59         foreach (split /\//,$biblionumber){
60             &AddToShelfFromBiblio($_,$shelfnumber);
61         }
62     }
63     else {
64         &AddToShelfFromBiblio( $biblionumber, $shelfnumber );
65     }
66     print $query->header;
67     print "<html><body onload=\"window.close();\"></body></html>";
68     exit;
69 }
70 else {
71     my ($shelflist) = GetShelves( $loggedinuser, 3 );
72     my @shelvesloop;
73     my %shelvesloop;
74     foreach my $element ( sort keys %$shelflist ) {
75         push( @shelvesloop, $element );
76             $shelvesloop{$element} = $shelflist->{$element}->{'shelfname'};
77     }
78
79     my $CGIbookshelves;
80     if ( @shelvesloop > 0 ) {
81         $CGIbookshelves = CGI::scrolling_list (
82             -name     => 'shelfnumber',
83             -values   => \@shelvesloop,
84             -labels   => \%shelvesloop,
85             -size     => 1,
86             -tabindex => '',
87             -multiple => 0
88         );
89     }
90
91     if ( $multiple ) {
92         my @biblios;
93         foreach (split /\//,$biblionumber){
94             my $data = GetBiblioData($_);
95             push @biblios,$data;
96         }
97         $template->param (
98             multiple => 1,
99             biblionumber => $biblionumber,
100             total    => scalar @biblios,
101             biblios  => \@biblios,
102         );
103     }
104     else { # just one to add.
105         my $data = GetBiblioData( $biblionumber );
106         $template->param (
107             biblionumber => $biblionumber,
108             title        => $data->{'title'},
109             author       => $data->{'author'},
110         );
111     }
112
113     $template->param (
114         CGIbookshelves       => $CGIbookshelves,
115     );
116
117     output_html_with_http_headers $query, $cookie, $template->output;
118 }