Lines 1-8
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
|
2 |
|
3 |
#script to provide virtualshelf management |
|
|
4 |
# |
5 |
# Copyright 2000-2002 Katipo Communications |
3 |
# Copyright 2000-2002 Katipo Communications |
|
|
4 |
# Copyright 2016 Koha Development Team |
6 |
# |
5 |
# |
7 |
# This file is part of Koha. |
6 |
# This file is part of Koha. |
8 |
# |
7 |
# |
Lines 19-26
Link Here
|
19 |
# You should have received a copy of the GNU General Public License |
18 |
# You should have received a copy of the GNU General Public License |
20 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
21 |
|
20 |
|
22 |
use strict; |
21 |
use Modern::Perl; |
23 |
use warnings; |
|
|
24 |
|
22 |
|
25 |
use CGI qw ( -utf8 ); |
23 |
use CGI qw ( -utf8 ); |
26 |
use C4::Biblio; |
24 |
use C4::Biblio; |
Lines 29-208
use C4::Auth;
Link Here
|
29 |
|
27 |
|
30 |
use Koha::Virtualshelves; |
28 |
use Koha::Virtualshelves; |
31 |
|
29 |
|
32 |
our $query = new CGI; |
30 |
my $query = new CGI; |
33 |
our @biblionumber = $query->param('biblionumber'); |
31 |
my @biblionumbers = $query->multi_param('biblionumber'); |
34 |
our $selectedshelf = $query->param('selectedshelf'); |
32 |
my $selectedshelf = $query->param('selectedshelf'); |
35 |
our $newshelf = $query->param('newshelf'); |
33 |
my $newshelf = $query->param('newshelf'); |
36 |
our $shelfnumber = $query->param('shelfnumber'); |
34 |
my $shelfnumber = $query->param('shelfnumber'); |
37 |
our $newvirtualshelf = $query->param('newvirtualshelf'); |
35 |
my $newvirtualshelf = $query->param('newvirtualshelf'); |
38 |
our $category = $query->param('category'); |
36 |
my $category = $query->param('category'); |
39 |
our $authorized = 1; |
37 |
my ( $errcode, $authorized ) = ( 0, 1 ); |
40 |
our $errcode = 0; |
38 |
my @biblios; |
41 |
our @biblios = (); |
|
|
42 |
|
39 |
|
43 |
# if virtualshelves is disabled, leave immediately |
40 |
# if virtualshelves is disabled, leave immediately |
44 |
if ( ! C4::Context->preference('virtualshelves') ) { |
41 |
if ( !C4::Context->preference('virtualshelves') ) { |
45 |
print $query->redirect("/cgi-bin/koha/errors/404.pl"); |
42 |
print $query->redirect("/cgi-bin/koha/errors/404.pl"); |
46 |
exit; |
43 |
exit; |
47 |
} |
44 |
} |
48 |
|
45 |
|
49 |
if (scalar(@biblionumber) == 1) { |
46 |
if ( scalar(@biblionumbers) == 1 ) { |
50 |
@biblionumber = (split /\//,$biblionumber[0]); |
47 |
@biblionumbers = ( split /\//, $biblionumbers[0] ); |
51 |
} |
48 |
} |
52 |
|
49 |
|
53 |
our ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
50 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
54 |
{ |
51 |
{ template_name => "opac-addbybiblionumber.tt", |
55 |
template_name => "opac-addbybiblionumber.tt", |
|
|
56 |
query => $query, |
52 |
query => $query, |
57 |
type => "opac", |
53 |
type => "opac", |
58 |
authnotrequired => 0, |
54 |
authnotrequired => 0, |
59 |
} |
55 |
} |
60 |
); |
56 |
); |
61 |
|
57 |
|
62 |
if( $newvirtualshelf) { |
58 |
if ($newvirtualshelf) { |
63 |
HandleNewVirtualShelf(); |
59 |
if ($loggedinuser > 0 |
64 |
exit if $authorized; |
60 |
and ( $category == 1 |
65 |
ShowTemplate(); #error message |
61 |
or $category == 2 and $loggedinuser > 0 && C4::Context->preference('OpacAllowPublicListCreation') ) |
66 |
} |
62 |
) { |
67 |
elsif($shelfnumber) { |
63 |
my $shelf = eval { Koha::Virtualshelf->new( { shelfname => $newvirtualshelf, category => $category, owner => $loggedinuser, } )->store; }; |
68 |
HandleShelfNumber(); |
|
|
69 |
exit if $authorized; |
70 |
ShowTemplate(); #error message |
71 |
} |
72 |
elsif($selectedshelf) { |
73 |
HandleSelectedShelf(); |
74 |
LoadBib() if $authorized; |
75 |
ShowTemplate(); |
76 |
} |
77 |
else { |
78 |
HandleSelect(); |
79 |
LoadBib() if $authorized; |
80 |
ShowTemplate(); |
81 |
} |
82 |
#end |
83 |
|
84 |
sub HandleNewVirtualShelf { |
85 |
if ( $loggedinuser > 0 and |
86 |
( |
87 |
$category == 1 |
88 |
or $category == 2 and $loggedinuser>0 && C4::Context->preference('OpacAllowPublicListCreation') |
89 |
) |
90 |
) { |
91 |
my $shelf = eval { |
92 |
Koha::Virtualshelf->new( |
93 |
{ |
94 |
shelfname => $newvirtualshelf, |
95 |
category => $category, |
96 |
owner => $loggedinuser, |
97 |
} |
98 |
)->store; |
99 |
}; |
100 |
if ( $@ or not $shelf ) { |
64 |
if ( $@ or not $shelf ) { |
|
|
65 |
$errcode = 1; |
101 |
$authorized = 0; |
66 |
$authorized = 0; |
102 |
$errcode = 1; |
67 |
} else { |
103 |
return; |
68 |
for my $biblionumber (@biblionumbers) { |
104 |
} |
69 |
$shelf->add_biblio( $biblionumber, $loggedinuser ); |
|
|
70 |
} |
105 |
|
71 |
|
106 |
for my $bib (@biblionumber) { |
72 |
#Reload the page where you came from |
107 |
$shelf->add_biblio( $bib, $loggedinuser ); |
73 |
print $query->header; |
|
|
74 |
print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>"; |
75 |
exit; |
108 |
} |
76 |
} |
109 |
|
|
|
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>"; |
113 |
} |
77 |
} |
114 |
} |
78 |
} elsif ($shelfnumber) { |
115 |
|
|
|
116 |
sub HandleShelfNumber { |
117 |
my $shelfnumber = $query->param('shelfnumber'); |
79 |
my $shelfnumber = $query->param('shelfnumber'); |
118 |
my $shelf = Koha::Virtualshelves->find( $shelfnumber ); |
80 |
my $shelf = Koha::Virtualshelves->find($shelfnumber); |
119 |
if ( $shelf->can_biblios_be_added( $loggedinuser ) ) { |
81 |
if ( $shelf->can_biblios_be_added($loggedinuser) ) { |
120 |
for my $bib (@biblionumber) { |
82 |
for my $biblionumber (@biblionumbers) { |
121 |
$shelf->add_biblio( $bib, $loggedinuser ); |
83 |
$shelf->add_biblio( $biblionumber, $loggedinuser ); |
122 |
} |
84 |
} |
|
|
85 |
|
123 |
#Close this page and return |
86 |
#Close this page and return |
124 |
print $query->header; |
87 |
print $query->header; |
125 |
print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>"; |
88 |
print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>"; |
|
|
89 |
exit; |
126 |
} else { |
90 |
} else { |
127 |
# TODO |
91 |
$authorized = 0; |
128 |
} |
92 |
} |
129 |
} |
93 |
} elsif ($selectedshelf) { |
130 |
|
|
|
131 |
sub HandleSelectedShelf { |
132 |
my $shelfnumber = $query->param('selectedshelf'); |
94 |
my $shelfnumber = $query->param('selectedshelf'); |
133 |
my $shelf = Koha::Virtualshelves->find( $shelfnumber ); |
95 |
my $shelf = Koha::Virtualshelves->find($shelfnumber); |
134 |
if ( $shelf->can_biblios_be_added( $loggedinuser ) ) { |
96 |
if ( $shelf->can_biblios_be_added($loggedinuser) ) { |
|
|
97 |
$template->param( |
98 |
singleshelf => 1, |
99 |
shelfnumber => $shelf->shelfnumber, |
100 |
shelfname => $shelf->shelfname, |
101 |
); |
102 |
} else { |
103 |
$authorized = 0; |
104 |
} |
105 |
} else { |
106 |
if ( $loggedinuser > 0 ) { |
107 |
my $private_shelves = Koha::Virtualshelves->search( |
108 |
{ category => 1, |
109 |
owner => $loggedinuser, |
110 |
}, |
111 |
{ order_by => 'shelfname' } |
112 |
); |
113 |
my $shelves_shared_with_me = Koha::Virtualshelves->search( |
114 |
{ category => 1, |
115 |
'virtualshelfshares.borrowernumber' => $loggedinuser, |
116 |
-or => { |
117 |
allow_add => 1, |
118 |
owner => $loggedinuser, |
119 |
} |
120 |
}, |
121 |
{ join => 'virtualshelfshares', } |
122 |
); |
123 |
my $public_shelves = Koha::Virtualshelves->search( |
124 |
{ category => 2, |
125 |
-or => { |
126 |
allow_add => 1, |
127 |
owner => $loggedinuser, |
128 |
} |
129 |
}, |
130 |
{ order_by => 'shelfname' } |
131 |
); |
135 |
$template->param( |
132 |
$template->param( |
136 |
singleshelf => 1, |
133 |
private_shelves => $private_shelves, |
137 |
shelfnumber => $shelf->shelfnumber, |
134 |
private_shelves_shared_with_me => $shelves_shared_with_me, |
138 |
shelfname => $shelf->shelfname, |
135 |
public_shelves => $public_shelves, |
139 |
); |
136 |
); |
140 |
} else { |
137 |
} else { |
141 |
# TODO |
138 |
$authorized = 0; |
142 |
} |
139 |
} |
143 |
} |
140 |
} |
144 |
|
141 |
|
145 |
sub HandleSelect { |
142 |
if ($authorized) { |
146 |
return unless $authorized= $loggedinuser>0; |
143 |
for my $biblionumber (@biblionumbers) { |
147 |
my $private_shelves = Koha::Virtualshelves->search( |
144 |
my $data = GetBiblioData($biblionumber); |
148 |
{ |
145 |
push( |
149 |
category => 1, |
146 |
@biblios, |
150 |
owner => $loggedinuser, |
147 |
{ biblionumber => $biblionumber, |
151 |
}, |
148 |
title => $data->{'title'}, |
152 |
{ order_by => 'shelfname' } |
149 |
author => $data->{'author'}, |
153 |
); |
|
|
154 |
my $shelves_shared_with_me = Koha::Virtualshelves->search( |
155 |
{ |
156 |
category => 1, |
157 |
'virtualshelfshares.borrowernumber' => $loggedinuser, |
158 |
-or => { |
159 |
allow_add => 1, |
160 |
owner => $loggedinuser, |
161 |
} |
162 |
}, |
163 |
{ |
164 |
join => 'virtualshelfshares', |
165 |
} |
166 |
); |
167 |
my $public_shelves= Koha::Virtualshelves->search( |
168 |
{ |
169 |
category => 2, |
170 |
-or => { |
171 |
allow_add => 1, |
172 |
owner => $loggedinuser, |
173 |
} |
150 |
} |
174 |
}, |
151 |
); |
175 |
{ order_by => 'shelfname' } |
|
|
176 |
); |
177 |
$template->param ( |
178 |
private_shelves => $private_shelves, |
179 |
private_shelves_shared_with_me => $shelves_shared_with_me, |
180 |
public_shelves => $public_shelves, |
181 |
); |
182 |
} |
183 |
|
184 |
sub LoadBib { |
185 |
for my $bib (@biblionumber) { |
186 |
my $data = GetBiblioData( $bib ); |
187 |
push(@biblios, |
188 |
{ biblionumber => $bib, |
189 |
title => $data->{'title'}, |
190 |
author => $data->{'author'}, |
191 |
} ); |
192 |
} |
152 |
} |
193 |
$template->param( |
153 |
$template->param( |
194 |
multiple => (scalar(@biblios) > 1), |
154 |
multiple => ( scalar(@biblios) > 1 ), |
195 |
total => scalar @biblios, |
155 |
total => scalar @biblios, |
196 |
biblios => \@biblios, |
156 |
biblios => \@biblios, |
197 |
); |
157 |
); |
198 |
} |
|
|
199 |
|
158 |
|
200 |
sub ShowTemplate { |
159 |
$template->param( |
201 |
$template->param ( |
160 |
newshelf => $newshelf || 0, |
202 |
newshelf => $newshelf||0, |
161 |
OpacAllowPublicListCreation => C4::Context->preference('OpacAllowPublicListCreation'), |
203 |
authorized => $authorized, |
|
|
204 |
errcode => $errcode, |
205 |
OpacAllowPublicListCreation => C4::Context->preference('OpacAllowPublicListCreation'), |
206 |
); |
162 |
); |
207 |
output_html_with_http_headers $query, $cookie, $template->output; |
|
|
208 |
} |
163 |
} |
|
|
164 |
$template->param( authorized => $authorized, errcode => $errcode, ); |
165 |
output_html_with_http_headers $query, $cookie, $template->output; |