Bug 929 : Last follow up, implementing the last of Katrins suggestions
[koha.git] / opac / opac-addbybiblionumber.pl
blobfd3124b46bc4f62f6c05764b90215e82a927aacf
1 #!/usr/bin/perl
3 #script to provide virtualshelf management
4 # WARNING: This file uses 4-character tabs!
6 # $Header$
8 # Copyright 2000-2002 Katipo Communications
10 # This file is part of Koha.
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.
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.
21 # You should have received a copy of the GNU General Public License along
22 # with Koha; if not, write to the Free Software Foundation, Inc.,
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 use strict;
26 use warnings;
28 use C4::Biblio;
29 use CGI;
30 use C4::VirtualShelves qw/:DEFAULT GetAllShelves RefreshShelvesSummary/;
31 use C4::Auth;
32 use C4::Output;
33 use C4::Auth qw/get_session/;
34 use C4::Debug;
36 #splits incoming biblionumber(s) to array and adds each to shelf.
37 sub AddBibliosToShelf {
38 my ($shelfnumber,@biblionumber)=@_;
40 # multiple bibs might come in as '/' delimited string (from where, i don't see), or as array.
41 if (scalar(@biblionumber) == 1) {
42 @biblionumber = (split /\//,$biblionumber[0]);
44 for my $bib (@biblionumber){
45 AddToShelf($bib, $shelfnumber);
49 my $query = new CGI;
50 my @biblionumber = $query->param('biblionumber');
51 my $selectedshelf = $query->param('selectedshelf');
52 my $newshelf = $query->param('newshelf');
53 my $shelfnumber = $query->param('shelfnumber');
54 my $newvirtualshelf = $query->param('newvirtualshelf');
55 my $category = $query->param('category');
57 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
59 template_name => "opac-addbybiblionumber.tmpl",
60 query => $query,
61 type => "opac",
62 authnotrequired =>( C4::Context->preference("OpacPublic") ? 1 : 0 ),
66 if ($newvirtualshelf) {
67 $shelfnumber = AddShelf( $newvirtualshelf, $loggedinuser, $category );
68 AddBibliosToShelf($shelfnumber, @biblionumber);
69 RefreshShelvesSummary($query->cookie("CGISESSID"),$loggedinuser,($loggedinuser == -1 ? 20 : 10));
70 print $query->header;
71 print "<html><meta http-equiv=\"refresh\" content=\"0;url=opac-shelves.pl?display=privateshelves\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
72 exit;
75 # verify user is authorized to perform the action on the shelf...
76 my $authorized = 1;
77 if ($selectedshelf) {
78 $authorized = 0 unless ShelfPossibleAction( $loggedinuser, $selectedshelf );
81 if ($shelfnumber && ($shelfnumber != -1)) {
82 AddBibliosToShelf($shelfnumber,@biblionumber);
83 RefreshShelvesSummary($query->cookie("CGISESSID"),$loggedinuser,($loggedinuser == -1 ? 20 : 10));
84 print $query->header;
85 print "<html><meta http-equiv=\"refresh\" content=\"0;url=opac-shelves.pl?display=privateshelves\" /><body onload=\"self.close();\"></body></html>";
86 exit;
88 else {
89 if($selectedshelf){
90 # adding to specific shelf
91 my ( $singleshelf, $singleshelfname, $singlecategory ) = GetShelf( $query->param('selectedshelf') );
92 $template->param(
93 singleshelf => 1,
94 shelfnumber => $singleshelf,
95 shelfname => $singleshelfname,
96 "category$singlecategory" => 1
98 } else {
100 my $privateshelves = GetAllShelves(1,$loggedinuser);
101 if(@{$privateshelves}){
102 $template->param (
103 privatevirtualshelves => $privateshelves,
104 existingshelves => 1
107 my $publicshelves = GetAllShelves(2,$loggedinuser);
108 if(@{$publicshelves}){
109 $template->param (
110 publicvirtualshelves => $publicshelves,
111 existingshelves => 1
116 my @biblios;
117 for my $bib (@biblionumber) {
118 my $data = GetBiblioData( $bib );
119 push(@biblios,
120 { biblionumber => $bib,
121 title => $data->{'title'},
122 author => $data->{'author'},
123 } );
125 $template->param (
126 newshelf => $newshelf,
127 multiple => (scalar(@biblios) > 1),
128 total => scalar @biblios,
129 biblios => \@biblios,
130 authorized => $authorized,
133 output_html_with_http_headers $query, $cookie, $template->output;