Lines 126-167
sub show_accept {
Link Here
|
126 |
my $shelfnumber = $param->{shelfnumber}; |
126 |
my $shelfnumber = $param->{shelfnumber}; |
127 |
my $shelf = Koha::Virtualshelves->find( $shelfnumber ); |
127 |
my $shelf = Koha::Virtualshelves->find( $shelfnumber ); |
128 |
|
128 |
|
129 |
# The key for accepting is checked later in Koha::Virtualshelf->share |
129 |
# The key for accepting is checked later in Koha::Virtualshelfshare |
130 |
# You must not be the owner and the list must be private |
130 |
# You must not be the owner and the list must be private |
131 |
if ( $shelf->category == 2 or $shelf->owner == $param->{loggedinuser} ) { |
131 |
if( !$shelf ) { |
132 |
return; |
132 |
$param->{errcode} = 2; |
|
|
133 |
} elsif( $shelf->category == 2 ) { |
134 |
$param->{errcode} = 5; |
135 |
} elsif( $shelf->owner == $param->{loggedinuser} ) { |
136 |
$param->{errcode} = 8; |
133 |
} |
137 |
} |
134 |
|
138 |
return if $param->{errcode}; |
135 |
# We could have used ->find with the share id, but we don't want to change |
139 |
|
136 |
# the url sent to the patron |
140 |
# Look for shelfnumber and invitekey in shares, expiration check later |
137 |
my $shared_shelves = Koha::Virtualshelfshares->search( |
141 |
my $key = keytostring( stringtokey( $param->{key}, 0 ), 1 ); |
138 |
{ |
142 |
my $shared_shelves = Koha::Virtualshelfshares->search({ |
139 |
shelfnumber => $param->{shelfnumber}, |
143 |
shelfnumber => $param->{shelfnumber}, |
140 |
}, |
144 |
invitekey => $key, |
141 |
{ |
145 |
}); |
142 |
order_by => { -desc => 'sharedate' }, |
146 |
my $shared_shelf = $shared_shelves ? $shared_shelves->next : undef; # we pick the first, but there should only be one |
143 |
} |
147 |
|
144 |
); |
148 |
if ( $shared_shelf ) { |
145 |
|
149 |
my $is_accepted = eval { $shared_shelf->accept( $key, $param->{loggedinuser} ) }; |
146 |
if ( $shared_shelves ) { |
150 |
if( $is_accepted ) { |
147 |
my $key = keytostring( stringtokey( $param->{key}, 0 ), 1 ); |
151 |
notify_owner($param); |
148 |
while ( my $shared_shelf = $shared_shelves->next ) { |
152 |
#redirect to view of this shared list |
149 |
my $is_accepted = eval { $shared_shelf->accept( $key, $param->{loggedinuser} ) }; |
153 |
print $param->{query}->redirect( |
150 |
if ( $is_accepted ) { |
154 |
-uri => SHELVES_URL . $param->{shelfnumber}, |
151 |
notify_owner($param); |
155 |
-cookie => $param->{cookie} |
152 |
|
156 |
); |
153 |
#redirect to view of this shared list |
157 |
exit; |
154 |
print $param->{query}->redirect( |
|
|
155 |
-uri => SHELVES_URL . $param->{shelfnumber}, |
156 |
-cookie => $param->{cookie} |
157 |
); |
158 |
exit; |
159 |
} |
160 |
} |
158 |
} |
161 |
$param->{errcode} = 7; #not accepted (key not found or expired) |
|
|
162 |
} else { |
163 |
# This shelf is not shared |
164 |
} |
159 |
} |
|
|
160 |
$param->{errcode} = 7; # not accepted: key invalid or expired |
165 |
} |
161 |
} |
166 |
|
162 |
|
167 |
sub notify_owner { |
163 |
sub notify_owner { |
168 |
- |
|
|