perltidy finishreceive.pl and two comments added
[koha.git] / virtualshelves / addbybiblionumber.pl
1 #!/usr/bin/perl
2
3 #script to provide virtual shelf management
4 #
5 #
6 # Copyright 2000-2002 Katipo Communications
7 #
8 # This file is part of Koha.
9 #
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
14 #
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA  02111-1307 USA
22
23
24 =head1 NAME
25
26     addbybiblionumber.pl
27
28 =head1 DESCRIPTION
29
30     This script allow to add a virtual in a virtual shelf from a biblionumber.
31
32 =head1 CGI PARAMETERS
33
34 =over 4
35
36 =item biblionumber
37
38     The biblionumber
39
40 =item shelfnumber
41
42     the shelfnumber where to add the virtual.
43
44 =item newvirtualshelf
45
46     if this parameter exists, then it must be equals to the name of the shelf
47     to add.
48
49 =item category
50
51     if this script has to add a shelf, it add one with this category.
52
53 =back
54
55 =cut
56
57 use strict;
58 use C4::Biblio;
59 use CGI;
60 use C4::Output;
61 use C4::VirtualShelves qw/:DEFAULT GetRecentShelves/;
62 use C4::Circulation;
63 use C4::Auth;
64
65 #use it only to debug !
66 use CGI::Carp qw/fatalsToBrowser/;
67 use warnings;
68
69 my $query           = new CGI;
70 my $biblionumber    = $query->param('biblionumber');
71 my $shelfnumber     = $query->param('shelfnumber');
72 my $newvirtualshelf = $query->param('newvirtualshelf');
73 my $category        = $query->param('category');
74 my $sortfield           = $query->param('sortfield');
75
76 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
77     {
78         template_name   => "virtualshelves/addbybiblionumber.tmpl",
79         query           => $query,
80         type            => "intranet",
81         authnotrequired => 0,
82         flagsrequired   => { catalogue => 1 },
83     }
84 );
85
86 $shelfnumber = AddShelf( $newvirtualshelf, $loggedinuser, $category, $sortfield )
87   if $newvirtualshelf;
88 if ( $shelfnumber || ( $shelfnumber == -1 ) ) {    # the shelf already exist.
89     AddToShelfFromBiblio( $biblionumber, $shelfnumber );
90     print
91 "Content-Type: text/html\n\n<html><body onload=\"window.close()\"></body></html>";
92     exit;
93 }
94 else {    # this shelf doesn't already exist.
95     my ( $bibliocount, @biblios ) = GetBiblio($biblionumber);
96
97         my $limit = 10;
98         my ($shelflist) = GetRecentShelves(1, $limit, $loggedinuser);
99     my @shelvesloop;
100     my %shelvesloop;
101     for my $shelf ( @{ $shelflist->[0] } ) {
102         push( @shelvesloop, $shelf->{shelfnumber} );
103                 $shelvesloop{$shelf->{shelfnumber}} = $shelf->{shelfname};
104         }
105         # then open shelves...
106         my ($shelflist) = GetRecentShelves(3, $limit, undef);
107     for my $shelf ( @{ $shelflist->[0] } ) {
108         push( @shelvesloop, $shelf->{shelfnumber} );
109                 $shelvesloop{$shelf->{shelfnumber}} = $shelf->{shelfname};
110         }
111         if(@shelvesloop gt 0){
112     my $CGIvirtualshelves = CGI::scrolling_list(
113         -name     => 'shelfnumber',
114         -values   => \@shelvesloop,
115         -labels   => \%shelvesloop,
116         -size     => 1,
117         -tabindex => '',
118         -multiple => 0
119     );
120     $template->param(
121                 CGIvirtualshelves => $CGIvirtualshelves,
122     );
123         }
124
125     $template->param(
126         biblionumber      => $biblionumber,
127         title             => $biblios[0]->{'title'},
128         author            => $biblios[0]->{'author'},
129     );
130
131     output_html_with_http_headers $query, $cookie, $template->output;
132 }