3 #script to provide virtualshelf management
4 # WARNING: This file uses 4-character tabs!
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
13 # under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 3 of the License, or
15 # (at your option) any later version.
17 # Koha is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with Koha; if not, see <http://www.gnu.org/licenses>.
30 use C4
::VirtualShelves qw
/:DEFAULT GetAllShelves/;
35 our @biblionumber = $query->param('biblionumber');
36 our $selectedshelf = $query->param('selectedshelf');
37 our $newshelf = $query->param('newshelf');
38 our $shelfnumber = $query->param('shelfnumber');
39 our $newvirtualshelf = $query->param('newvirtualshelf');
40 our $category = $query->param('category');
45 # if virtualshelves is disabled, leave immediately
46 if ( ! C4
::Context
->preference('virtualshelves') ) {
47 print $query->redirect("/cgi-bin/koha/errors/404.pl");
51 if (scalar(@biblionumber) == 1) {
52 @biblionumber = (split /\//,$biblionumber[0]);
55 our ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
57 template_name
=> "opac-addbybiblionumber.tt",
64 if( $newvirtualshelf) {
65 HandleNewVirtualShelf
();
67 ShowTemplate
(); #error message
72 ShowTemplate
(); #error message
74 elsif($selectedshelf) {
75 HandleSelectedShelf
();
76 LoadBib
() if $authorized;
81 LoadBib
() if $authorized;
86 sub AddBibliosToShelf
{
87 #splits incoming biblionumber(s) to array and adds each to shelf.
88 my ($shelfnumber,@biblionumber)=@_;
90 #multiple bibs might come in as '/' delimited string (from where, i don't see), or as array.
91 if (scalar(@biblionumber) == 1) {
92 @biblionumber = (split /\//,$biblionumber[0]);
94 for my $bib (@biblionumber) {
95 AddToShelf
($bib, $shelfnumber, $loggedinuser);
99 sub HandleNewVirtualShelf
{
100 if($authorized= ShelfPossibleAction
($loggedinuser, undef, $category==1?
'new_private': 'new_public')) {
101 $shelfnumber = AddShelf
( {
102 shelfname
=> $newvirtualshelf,
103 category
=> $category }, $loggedinuser);
104 if($shelfnumber == -1) {
109 AddBibliosToShelf
($shelfnumber, @biblionumber);
110 #Reload the page where you came from
111 print $query->header;
112 print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
116 sub HandleShelfNumber
{
117 if($authorized= ShelfPossibleAction
($loggedinuser, $shelfnumber, 'add')) {
118 AddBibliosToShelf
($shelfnumber,@biblionumber);
119 #Close this page and return
120 print $query->header;
121 print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
125 sub HandleSelectedShelf
{
126 if($authorized= ShelfPossibleAction
( $loggedinuser, $selectedshelf, 'add')){
127 #adding to specific shelf
128 my ($singleshelf, $singleshelfname)= GetShelf
($query->param('selectedshelf'));
131 shelfnumber
=> $singleshelf,
132 shelfname
=> $singleshelfname,
138 return unless $authorized= $loggedinuser>0;
139 my $privateshelves = GetAllShelves
(1,$loggedinuser,1);
140 if(@
{$privateshelves}){
142 privatevirtualshelves
=> $privateshelves,
146 my $publicshelves = GetAllShelves
(2,$loggedinuser,1);
147 if(@
{$publicshelves}){
149 publicvirtualshelves
=> $publicshelves,
156 #see comment in AddBibliosToShelf
157 if (scalar(@biblionumber) == 1) {
158 @biblionumber = (split /\//,$biblionumber[0]);
160 for my $bib (@biblionumber) {
161 my $data = GetBiblioData
( $bib );
163 { biblionumber
=> $bib,
164 title
=> $data->{'title'},
165 author
=> $data->{'author'},
169 multiple
=> (scalar(@biblios) > 1),
170 total
=> scalar @biblios,
171 biblios
=> \
@biblios,
177 newshelf
=> $newshelf||0,
178 authorized
=> $authorized,
180 OpacAllowPublicListCreation
=> C4
::Context
->preference('OpacAllowPublicListCreation'),
182 output_html_with_http_headers
$query, $cookie, $template->output;