Bug 8918: Fix reserve priority in ILS-DI
[koha.git] / virtualshelves / addbybiblionumber.pl
blob5fd82b3cd05014e3f67972a16d91517fcc674818
1 #!/usr/bin/perl
3 #script to provide virtual shelf management
6 # Copyright 2000-2002 Katipo Communications
8 # This file is part of Koha.
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.
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.
19 # You should have received a copy of the GNU General Public License along
20 # with Koha; if not, write to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 =head1 NAME
26 addbybiblionumber.pl
28 =head1 DESCRIPTION
30 This script allow to add a virtual in a virtual shelf from a biblionumber.
32 =head1 CGI PARAMETERS
34 =over 4
36 =item biblionumber
38 The biblionumber
40 =item shelfnumber
42 the shelfnumber where to add the virtual.
44 =item newvirtualshelf
46 if this parameter exists, then it must be equals to the name of the shelf
47 to add.
49 =item category
51 if this script has to add a shelf, it add one with this category.
53 =item newshelf
55 if this parameter exists, then we create a new shelf
57 =back
59 =cut
61 use strict;
62 use warnings;
64 use CGI;
65 use C4::Biblio;
66 use C4::Output;
67 use C4::VirtualShelves qw/:DEFAULT GetAllShelves/;
68 use C4::Auth;
71 our $query = new CGI;
72 our @biblionumber = HandleBiblioPars();
73 our $shelfnumber = $query->param('shelfnumber');
74 our $newvirtualshelf = $query->param('newvirtualshelf');
75 our $newshelf = $query->param('newshelf');
76 our $category = $query->param('category');
77 our $sortfield = $query->param('sortfield');
78 my $confirmed = $query->param('confirmed') || 0;
79 our $authorized = 1;
80 our $errcode = 0;
82 our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
84 template_name => "virtualshelves/addbybiblionumber.tmpl",
85 query => $query,
86 type => "intranet",
87 authnotrequired => 0,
88 flagsrequired => { catalogue => 1 },
92 if( $newvirtualshelf) {
93 HandleNewVirtualShelf();
94 exit if $authorized;
95 ShowTemplate(); #error message
97 elsif($shelfnumber && $confirmed) {
98 HandleShelfNumber();
99 exit if $authorized;
100 ShowTemplate(); #error message
102 elsif($shelfnumber) { #still needs confirmation
103 HandleSelectedShelf();
104 LoadBib() if $authorized;
105 ShowTemplate();
107 else {
108 HandleSelect();
109 LoadBib();
110 ShowTemplate();
112 #end
114 sub HandleBiblioPars {
115 my @bib= $query->param('biblionumber');
116 if(@bib==0 && $query->param('biblionumbers')) {
117 my $str= $query->param('biblionumbers');
118 @bib= split '/', $str;
120 elsif(@bib==1 && $bib[0]=~/\//) {
121 @bib= split '/', $bib[0];
123 return @bib;
126 sub AddBibliosToShelf {
127 my ($shelfnumber, @biblionumber)=@_;
128 for my $bib (@biblionumber){
129 AddToShelf($bib, $shelfnumber, $loggedinuser);
133 sub HandleNewVirtualShelf {
134 $shelfnumber = AddShelf( {
135 shelfname => $newvirtualshelf,
136 sortfield => $sortfield,
137 category => $category }, $loggedinuser);
138 if($shelfnumber == -1) {
139 $authorized=0;
140 $errcode=1; #add failed
141 return;
143 AddBibliosToShelf($shelfnumber, @biblionumber);
144 #Reload the page where you came from
145 print $query->header;
146 print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
149 sub HandleShelfNumber {
150 if($authorized= ShelfPossibleAction($loggedinuser, $shelfnumber, 'add')) {
151 AddBibliosToShelf($shelfnumber, @biblionumber);
152 #Close this page and return
153 print $query->header;
154 print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
156 else {
157 $errcode=2; #no perm
161 sub HandleSelectedShelf {
162 if($authorized= ShelfPossibleAction( $loggedinuser, $shelfnumber, 'add')){
163 #confirm adding to specific shelf
164 my ($singleshelf, $singleshelfname)= GetShelf($shelfnumber);
165 $template->param(
166 singleshelf => 1,
167 shelfnumber => $singleshelf,
168 shelfname => $singleshelfname,
171 else {
172 $errcode=2; #no perm
176 sub HandleSelect {
177 my $privateshelves = GetAllShelves(1,$loggedinuser,1);
178 my $publicshelves = GetAllShelves(2,$loggedinuser,1);
179 $template->param(
180 privatevirtualshelves => $privateshelves,
181 publicvirtualshelves => $publicshelves,
185 sub LoadBib {
186 my @biblios;
187 for my $bib (@biblionumber) {
188 my $data = GetBiblioData($bib);
189 push(@biblios,
190 { biblionumber => $bib,
191 title => $data->{'title'},
192 author => $data->{'author'},
193 } );
195 $template->param(
196 multiple => (scalar(@biblios) > 1),
197 total => scalar @biblios,
198 biblios => \@biblios,
202 sub ShowTemplate {
203 $template->param (
204 newshelf => $newshelf||0,
205 authorized => $authorized,
206 errcode => $errcode,
208 output_html_with_http_headers $query, $cookie, $template->output;