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