bug 2615: remove unneeded 'require Exporter'
[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 qw/:DEFAULT GetRecentShelves RefreshShelvesSummary/;
29 use C4::Auth;
30 use C4::Output;
31 use C4::Auth qw/get_session/;
32 use C4::Debug;
33
34 my $query               = new CGI;
35 my @biblionumber        = $query->param('biblionumber');
36 my $selectedshelf       = $query->param('selectedshelf');
37 my $newshelf            = $query->param('newshelf');
38 my $shelfnumber         = $query->param('shelfnumber');
39 my $newvirtualshelf     = $query->param('newvirtualshelf');
40 my $category            = $query->param('category');
41
42 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
43     {
44         template_name   => "opac-addbybiblionumber.tmpl",
45         query           => $query,
46         type            => "opac",
47         authnotrequired => 1,
48     }
49 );
50
51 if ($newvirtualshelf) {
52         $shelfnumber = AddShelf(  $newvirtualshelf, $loggedinuser, $category );
53         RefreshShelvesSummary($query->cookie("CGISESSID"),$loggedinuser,($loggedinuser == -1 ? 20 : 10));
54         print $query->header;
55         print "<html><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
56         exit;
57 }
58
59 # verify user is authorized to perform the action on the shelf...
60 my $authorized = 1;
61 if ($selectedshelf) {
62         $authorized = 0 unless ShelfPossibleAction( $loggedinuser, $selectedshelf );
63 }
64
65 # multiple bibs might come in as '/' delimited string (from where, i don't see), or as array.
66
67 my $multiple = 0;
68 my @bibs;
69 if (scalar(@biblionumber) == 1) {
70         @biblionumber =  (split /\//,$biblionumber[0]);
71 }
72 if ($shelfnumber && ($shelfnumber != -1)) {
73         for my $bib (@biblionumber){
74                 AddToShelfFromBiblio($bib,$shelfnumber);
75         }
76         RefreshShelvesSummary($query->cookie("CGISESSID"),$loggedinuser,($loggedinuser == -1 ? 20 : 10));
77         print $query->header;
78         print "<html><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
79         exit;
80 }
81 else {
82         if($selectedshelf){
83         # adding to specific shelf
84         my ( $singleshelf, $singleshelfname, $singlecategory ) = GetShelf( $query->param('selectedshelf') );
85                                 $template->param(
86                                 singleshelf             => 1,
87                                 shelfnumber         => $singleshelf,
88                                 shelfname           => $singleshelfname,
89                                 "category$singlecategory" => 1
90                         );
91         } else {
92         # offer choice of shelves
93         # first private shelves...
94         my $limit = 10;
95         my ($shelflist) = GetRecentShelves(1, $limit, $loggedinuser);
96     my @shelvesloop;
97     my %shelvesloop;
98     for my $shelf ( @{${@$shelflist}[0]} ) {
99         push( @shelvesloop, $shelf->{shelfnumber} );
100                 $shelvesloop{$shelf->{shelfnumber}} = $shelf->{shelfname};
101         }
102         # then open shelves...
103         my ($shelflist) = GetRecentShelves(3, $limit, undef);
104     for my $shelf ( @{${@$shelflist}[0]} ) {
105         push( @shelvesloop, $shelf->{shelfnumber} );
106                 $shelvesloop{$shelf->{shelfnumber}} = $shelf->{shelfname};
107         }
108     my $CGIvirtualshelves;
109     if ( @shelvesloop > 0 ) {
110         $CGIvirtualshelves = CGI::scrolling_list (
111             -name     => 'shelfnumber',
112             -id     => 'shelfnumber',
113             -values   => \@shelvesloop,
114             -labels   => \%shelvesloop,
115             -size     => 1,
116             -tabindex => '',
117             -multiple => 0
118         );
119
120         $template->param (
121                 CGIvirtualshelves       => $CGIvirtualshelves,
122         );
123     }
124         }
125
126         my @biblios;
127         for my $bib (@biblionumber) {
128                 my $data = GetBiblioData( $bib );
129                 push(@biblios, 
130                         { biblionumber => $bib,
131                           title        => $data->{'title'},
132                           author       => $data->{'author'},
133                         } );
134         }
135         $template->param (
136                 newshelf => $newshelf,
137                 multiple => (scalar(@biblios) > 1),
138                 total    => scalar @biblios,
139                 biblios  => \@biblios,
140                 authorized      => $authorized,
141         );
142
143         output_html_with_http_headers $query, $cookie, $template->output;
144 }