|
Lines 44-50
BEGIN {
Link Here
|
| 44 |
&ModShelf |
44 |
&ModShelf |
| 45 |
&ShelfPossibleAction |
45 |
&ShelfPossibleAction |
| 46 |
&DelFromShelf &DelShelf |
46 |
&DelFromShelf &DelShelf |
| 47 |
&GetBibliosShelves &AddShare |
47 |
&GetBibliosShelves &AddShare &AcceptShare &IsSharedList |
| 48 |
); |
48 |
); |
| 49 |
@EXPORT_OK = qw( |
49 |
@EXPORT_OK = qw( |
| 50 |
&GetAllShelves &ShelvesMax |
50 |
&GetAllShelves &ShelvesMax |
|
Lines 434-439
ShelfPossibleAction($loggedinuser, $shelfnumber, $action);
Link Here
|
| 434 |
C<$loggedinuser,$shelfnumber,$action> |
434 |
C<$loggedinuser,$shelfnumber,$action> |
| 435 |
|
435 |
|
| 436 |
$action can be "view", "add", "delete", "manage", "new_public", "new_private". |
436 |
$action can be "view", "add", "delete", "manage", "new_public", "new_private". |
|
|
437 |
New additional actions are: invite, acceptshare. |
| 437 |
Note that add/delete here refers to adding/deleting entries from the list. Deleting the list itself falls under manage. |
438 |
Note that add/delete here refers to adding/deleting entries from the list. Deleting the list itself falls under manage. |
| 438 |
new_public and new_private refers to creating a new public or private list. |
439 |
new_public and new_private refers to creating a new public or private list. |
| 439 |
The distinction between deleting your own entries from the list or entries from |
440 |
The distinction between deleting your own entries from the list or entries from |
|
Lines 441-446
others is made in DelFromShelf.
Link Here
|
| 441 |
|
442 |
|
| 442 |
Returns 1 if the user can do the $action in the $shelfnumber shelf. |
443 |
Returns 1 if the user can do the $action in the $shelfnumber shelf. |
| 443 |
Returns 0 otherwise. |
444 |
Returns 0 otherwise. |
|
|
445 |
For the actions invite and acceptshare a second errorcode is returned if the |
| 446 |
result is false. See opac-shareshelf.pl |
| 444 |
|
447 |
|
| 445 |
=cut |
448 |
=cut |
| 446 |
|
449 |
|
|
Lines 490-495
sub ShelfPossibleAction {
Link Here
|
| 490 |
#DelFromShelf checks the situation per biblio |
493 |
#DelFromShelf checks the situation per biblio |
| 491 |
return 1 if $user>0 && ($shelf->{allow_delete_own}==1 || $shelf->{allow_delete_other}==1); |
494 |
return 1 if $user>0 && ($shelf->{allow_delete_own}==1 || $shelf->{allow_delete_other}==1); |
| 492 |
} |
495 |
} |
|
|
496 |
elsif($action eq 'invite') { |
| 497 |
#for sharing you must be the owner and the list must be private |
| 498 |
if( $shelf->{category}==1 ) { |
| 499 |
return 1 if $shelf->{owner}==$user; |
| 500 |
return (0, 4); # code 4: should be owner |
| 501 |
} |
| 502 |
else { |
| 503 |
return (0, 5); # code 5: should be private list |
| 504 |
} |
| 505 |
} |
| 506 |
elsif($action eq 'acceptshare') { |
| 507 |
#the key for accepting is checked later in AcceptShare |
| 508 |
#you must not be the owner, list must be private |
| 509 |
if( $shelf->{category}==1 ) { |
| 510 |
return (0, 8) if $shelf->{owner}==$user; |
| 511 |
#code 8: should not be owner |
| 512 |
return 1; |
| 513 |
} |
| 514 |
else { |
| 515 |
return (0, 5); # code 5: should be private list |
| 516 |
} |
| 517 |
} |
| 493 |
elsif($action eq 'manage') { |
518 |
elsif($action eq 'manage') { |
| 494 |
return 1 if $user && $shelf->{owner}==$user; |
519 |
return 1 if $user && $shelf->{owner}==$user; |
| 495 |
} |
520 |
} |
|
Lines 667-672
sub AddShare {
Link Here
|
| 667 |
$dbh->do($sql, undef, ($shelfnumber, $key, SHARE_INVITATION_EXPIRY_DAYS)); |
692 |
$dbh->do($sql, undef, ($shelfnumber, $key, SHARE_INVITATION_EXPIRY_DAYS)); |
| 668 |
} |
693 |
} |
| 669 |
|
694 |
|
|
|
695 |
=head2 AcceptShare |
| 696 |
|
| 697 |
my $result= AcceptShare($shelfnumber, $key, $borrowernumber); |
| 698 |
|
| 699 |
Checks acceptation of a share request. |
| 700 |
Key must be found for this shelf. Invitation must not have expired. |
| 701 |
Returns true when accepted, false otherwise. |
| 702 |
|
| 703 |
=cut |
| 704 |
|
| 705 |
sub AcceptShare { |
| 706 |
my ($shelfnumber, $key, $borrowernumber)= @_; |
| 707 |
return if !$shelfnumber || !$key || !$borrowernumber; |
| 708 |
|
| 709 |
my $sql; |
| 710 |
my $dbh = C4::Context->dbh; |
| 711 |
$sql=" |
| 712 |
UPDATE virtualshelfshares |
| 713 |
SET invitekey=NULL, sharedate=NULL, borrowernumber=? |
| 714 |
WHERE shelfnumber=? AND invitekey=? AND sharedate>NOW() |
| 715 |
"; |
| 716 |
my $i= $dbh->do($sql, undef, ($borrowernumber, $shelfnumber, $key)); |
| 717 |
return if !defined($i) || !$i || $i eq '0E0'; #not found |
| 718 |
return 1; |
| 719 |
} |
| 720 |
|
| 721 |
=head2 IsSharedList |
| 722 |
|
| 723 |
my $bool= IsSharedList( $shelfnumber ); |
| 724 |
|
| 725 |
IsSharedList checks if a (private) list has shares. |
| 726 |
Note that such a check would not be useful for public lists. A public list has |
| 727 |
no shares, but is visible for anyone by nature.. |
| 728 |
Used to determine the list type in the display of Your lists (all private). |
| 729 |
Returns boolean value. |
| 730 |
|
| 731 |
=cut |
| 732 |
|
| 733 |
sub IsSharedList { |
| 734 |
my ($shelfnumber) = @_; |
| 735 |
my $dbh = C4::Context->dbh; |
| 736 |
my $sql="SELECT id FROM virtualshelfshares WHERE shelfnumber=? AND borrowernumber IS NOT NULL"; |
| 737 |
my $sth = $dbh->prepare($sql); |
| 738 |
$sth->execute($shelfnumber); |
| 739 |
my ($rv)= $sth->fetchrow_array; |
| 740 |
return defined($rv); |
| 741 |
} |
| 742 |
|
| 670 |
# internal subs |
743 |
# internal subs |
| 671 |
|
744 |
|
| 672 |
sub _shelf_count { |
745 |
sub _shelf_count { |