|
Lines 41-47
BEGIN {
Link Here
|
| 41 |
@ISA = qw(Exporter); |
41 |
@ISA = qw(Exporter); |
| 42 |
@EXPORT = qw( |
42 |
@EXPORT = qw( |
| 43 |
&GetShelfContents |
43 |
&GetShelfContents |
| 44 |
&ShelfPossibleAction |
|
|
| 45 |
); |
44 |
); |
| 46 |
@EXPORT_OK = qw( |
45 |
@EXPORT_OK = qw( |
| 47 |
&ShelvesMax |
46 |
&ShelvesMax |
|
Lines 163-269
sub GetShelfContents {
Link Here
|
| 163 |
# or newer, for your version of DBI. |
162 |
# or newer, for your version of DBI. |
| 164 |
} |
163 |
} |
| 165 |
|
164 |
|
| 166 |
=head2 ShelfPossibleAction |
|
|
| 167 |
|
| 168 |
ShelfPossibleAction($loggedinuser, $shelfnumber, $action); |
| 169 |
|
| 170 |
C<$loggedinuser,$shelfnumber,$action> |
| 171 |
|
| 172 |
$action can be "view", "add", "delete", "manage", "new_public", "new_private". |
| 173 |
New additional actions are: invite, acceptshare. |
| 174 |
Note that add/delete here refers to adding/deleting entries from the list. Deleting the list itself falls under manage. |
| 175 |
new_public and new_private refers to creating a new public or private list. |
| 176 |
The distinction between deleting your own entries from the list or entries from |
| 177 |
others is made when deleting a content from the shelf. |
| 178 |
|
| 179 |
Returns 1 if the user can do the $action in the $shelfnumber shelf. |
| 180 |
Returns 0 otherwise. |
| 181 |
For the actions invite and acceptshare a second errorcode is returned if the |
| 182 |
result is false. See opac-shareshelf.pl |
| 183 |
|
| 184 |
=cut |
| 185 |
|
| 186 |
sub ShelfPossibleAction { |
| 187 |
my ( $user, $shelfnumber, $action ) = @_; |
| 188 |
$action= 'view' unless $action; |
| 189 |
$user=0 unless $user; |
| 190 |
|
| 191 |
if($action =~ /^new/) { #no shelfnumber needed |
| 192 |
if($action eq 'new_private') { |
| 193 |
return $user>0; |
| 194 |
} |
| 195 |
elsif($action eq 'new_public') { |
| 196 |
return $user>0 && C4::Context->preference('OpacAllowPublicListCreation'); |
| 197 |
} |
| 198 |
return 0; |
| 199 |
} |
| 200 |
|
| 201 |
return 0 unless defined($shelfnumber); |
| 202 |
|
| 203 |
if ( $user > 0 and $action eq 'delete_shelf' ) { |
| 204 |
my $borrower = C4::Members::GetMember( borrowernumber => $user ); |
| 205 |
require C4::Auth; |
| 206 |
return 1 |
| 207 |
if C4::Auth::haspermission( $borrower->{userid}, { lists => 'delete_public_lists' } ); |
| 208 |
} |
| 209 |
|
| 210 |
my $dbh = C4::Context->dbh; |
| 211 |
my $query = q{ |
| 212 |
SELECT COALESCE(owner,0) AS owner, category, allow_add, allow_delete_own, allow_delete_other, COALESCE(sh.borrowernumber,0) AS borrowernumber |
| 213 |
FROM virtualshelves vs |
| 214 |
LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber |
| 215 |
AND sh.borrowernumber=? |
| 216 |
WHERE vs.shelfnumber=? |
| 217 |
}; |
| 218 |
my $sth = $dbh->prepare($query); |
| 219 |
$sth->execute($user, $shelfnumber); |
| 220 |
my $shelf= $sth->fetchrow_hashref; |
| 221 |
|
| 222 |
return 0 unless $shelf && ($shelf->{category}==2 || $shelf->{owner}==$user || ($user && $shelf->{borrowernumber}==$user)); |
| 223 |
if($action eq 'view') { |
| 224 |
#already handled in the above condition |
| 225 |
return 1; |
| 226 |
} |
| 227 |
elsif($action eq 'add') { |
| 228 |
return 0 if $user<=0; #should be logged in |
| 229 |
return 1 if $shelf->{allow_add}==1 || $shelf->{owner}==$user; |
| 230 |
#owner may always add |
| 231 |
} |
| 232 |
elsif($action eq 'delete') { |
| 233 |
#this answer is just diplomatic: it says that you may be able to delete |
| 234 |
#some items from that shelf |
| 235 |
#it does not answer the question about a specific biblio |
| 236 |
#Koha::Virtualshelf->remove_biblios checks the situation per biblio |
| 237 |
return 1 if $user>0 && ($shelf->{allow_delete_own}==1 || $shelf->{allow_delete_other}==1); |
| 238 |
} |
| 239 |
elsif($action eq 'invite') { |
| 240 |
#for sharing you must be the owner and the list must be private |
| 241 |
if( $shelf->{category}==1 ) { |
| 242 |
return 1 if $shelf->{owner}==$user; |
| 243 |
return (0, 4); # code 4: should be owner |
| 244 |
} |
| 245 |
else { |
| 246 |
return (0, 5); # code 5: should be private list |
| 247 |
} |
| 248 |
} |
| 249 |
elsif($action eq 'acceptshare') { |
| 250 |
#the key for accepting is checked later in Koha::Virtualshelf->share |
| 251 |
#you must not be the owner, list must be private |
| 252 |
if( $shelf->{category}==1 ) { |
| 253 |
return (0, 8) if $shelf->{owner}==$user; |
| 254 |
#code 8: should not be owner |
| 255 |
return 1; |
| 256 |
} |
| 257 |
else { |
| 258 |
return (0, 5); # code 5: should be private list |
| 259 |
} |
| 260 |
} |
| 261 |
elsif($action eq 'manage' or $action eq 'delete_shelf') { |
| 262 |
return 1 if $user && $shelf->{owner}==$user; |
| 263 |
} |
| 264 |
return 0; |
| 265 |
} |
| 266 |
|
| 267 |
=head2 ShelvesMax |
165 |
=head2 ShelvesMax |
| 268 |
|
166 |
|
| 269 |
$howmany= ShelvesMax($context); |
167 |
$howmany= ShelvesMax($context); |