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